From d494d2a6dbb591c7b3f5f5d1dc60c0fd2d28a589 Mon Sep 17 00:00:00 2001 From: Kai Muehlbauer Date: Tue, 9 Nov 2021 15:32:48 +0100 Subject: [PATCH] WIP: change imports per review discussion --- xarray/tests/test_plugins.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/xarray/tests/test_plugins.py b/xarray/tests/test_plugins.py index 086beba97f8..7fef517c914 100644 --- a/xarray/tests/test_plugins.py +++ b/xarray/tests/test_plugins.py @@ -6,13 +6,9 @@ try: import importlib.metadata as importlib_metadata - - from importlib_metadata import EntryPoint - except ImportError: # if the fallback library is missing, we are doomed. - import importlib_metadata as importlib_metadata # type: ignore[no-redef] - from importlib_metadata import EntryPoint # type: ignore[no-redef] + import importlib_metadata # type: ignore[no-redef] class DummyBackendEntrypointArgs(common.BackendEntrypoint): @@ -43,7 +39,10 @@ def dummy_duplicated_entrypoints(): ["engine2", "xarray.tests.test_plugins:backend_1", "xarray.backends"], ["engine2", "xarray.tests.test_plugins:backend_2", "xarray.backends"], ] - eps = [EntryPoint(name, value, group) for name, value, group in specs] + eps = [ + importlib_metadata.EntryPoint(name, value, group) + for name, value, group in specs + ] return eps @@ -55,7 +54,7 @@ def test_remove_duplicates(dummy_duplicated_entrypoints) -> None: def test_broken_plugin() -> None: - broken_backend = EntryPoint( + broken_backend = importlib_metadata.EntryPoint( "broken_backend", "xarray.tests.test_plugins:backend_1", "xarray.backends", @@ -85,7 +84,10 @@ def test_backends_dict_from_pkg() -> None: ["engine1", "xarray.tests.test_plugins:backend_1", "xarray.backends"], ["engine2", "xarray.tests.test_plugins:backend_2", "xarray.backends"], ] - entrypoints = [EntryPoint(name, value, group) for name, value, group in specs] + entrypoints = [ + importlib_metadata.EntryPoint(name, value, group) + for name, value, group in specs + ] engines = plugins.backends_dict_from_pkg(entrypoints) assert len(engines) == 2 assert engines.keys() == set(("engine1", "engine2")) @@ -129,7 +131,7 @@ def test_set_missing_parameters_raise_error() -> None: mock.MagicMock(return_value=DummyBackendEntrypoint1), ) def test_build_engines() -> None: - dummy_pkg_entrypoint = EntryPoint( + dummy_pkg_entrypoint = importlib_metadata.EntryPoint( "cfgrib", "xarray.tests.test_plugins:backend_1", "xarray_backends" ) backend_entrypoints = plugins.build_engines([dummy_pkg_entrypoint]) @@ -147,8 +149,12 @@ def test_build_engines() -> None: ) def test_build_engines_sorted() -> None: dummy_pkg_entrypoints = [ - EntryPoint("dummy2", "xarray.tests.test_plugins:backend_1", "xarray.backends"), - EntryPoint("dummy1", "xarray.tests.test_plugins:backend_1", "xarray.backends"), + importlib_metadata.EntryPoint( + "dummy2", "xarray.tests.test_plugins:backend_1", "xarray.backends" + ), + importlib_metadata.EntryPoint( + "dummy1", "xarray.tests.test_plugins:backend_1", "xarray.backends" + ), ] backend_entrypoints = plugins.build_engines(dummy_pkg_entrypoints) backend_entrypoints = list(backend_entrypoints)