Example #1
0
def test_broken_plugin():
    broken_backend = pkg_resources.EntryPoint.parse(
        "broken_backend = xarray.tests.test_plugins:backend_1")
    with pytest.warns(RuntimeWarning) as record:
        _ = plugins.build_engines([broken_backend])
    assert len(record) == 1
    message = str(record[0].message)
    assert "Engine 'broken_backend'" in message
Example #2
0
def test_build_engines():
    dummy_cfgrib_pkg_entrypoint = pkg_resources.EntryPoint.parse(
        "cfgrib = xarray.tests.test_plugins:backend_1")
    backend_entrypoints = plugins.build_engines([dummy_cfgrib_pkg_entrypoint])
    assert backend_entrypoints["cfgrib"] is dummy_cfgrib
    assert backend_entrypoints["cfgrib"].open_dataset_parameters == (
        "filename_or_obj",
        "decoder",
    )
Example #3
0
def test_broken_plugin() -> None:
    broken_backend = EntryPoint(
        "broken_backend",
        "xarray.tests.test_plugins:backend_1",
        "xarray.backends",
    )
    with pytest.warns(RuntimeWarning) as record:
        _ = plugins.build_engines([broken_backend])
    assert len(record) == 1
    message = str(record[0].message)
    assert "Engine 'broken_backend'" in message
Example #4
0
def test_build_engines() -> None:
    dummy_pkg_entrypoint = EntryPoint(
        "cfgrib", "xarray.tests.test_plugins:backend_1", "xarray_backends"
    )
    backend_entrypoints = plugins.build_engines([dummy_pkg_entrypoint])

    assert isinstance(backend_entrypoints["cfgrib"], DummyBackendEntrypoint1)
    assert backend_entrypoints["cfgrib"].open_dataset_parameters == (
        "filename_or_obj",
        "decoder",
    )
Example #5
0
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"),
    ]
    backend_entrypoints = plugins.build_engines(dummy_pkg_entrypoints)
    backend_entrypoints = list(backend_entrypoints)

    indices = []
    for be in plugins.STANDARD_BACKENDS_ORDER:
        try:
            index = backend_entrypoints.index(be)
            backend_entrypoints.pop(index)
            indices.append(index)
        except ValueError:
            pass

    assert set(indices) < {0, -1}
    assert list(backend_entrypoints) == sorted(backend_entrypoints)