Skip to content

Commit

Permalink
WIP: change imports per review discussion
Browse files Browse the repository at this point in the history
  • Loading branch information
kmuehlbauer committed Nov 9, 2021
1 parent 823778d commit d494d2a
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions xarray/tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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


Expand All @@ -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",
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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])
Expand All @@ -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)
Expand Down

0 comments on commit d494d2a

Please sign in to comment.