2021-04-01 12:15:05 -07:00
|
|
|
import pytest
|
2021-03-11 16:41:05 -05:00
|
|
|
|
2021-04-01 12:15:05 -07:00
|
|
|
from datahub.configuration.common import ConfigurationError
|
2021-10-25 17:10:24 -04:00
|
|
|
from datahub.ingestion.api.registry import PluginRegistry
|
2021-04-01 12:15:05 -07:00
|
|
|
from datahub.ingestion.api.sink import Sink
|
|
|
|
from datahub.ingestion.extractor.extractor_registry import extractor_registry
|
|
|
|
from datahub.ingestion.sink.console import ConsoleSink
|
|
|
|
from datahub.ingestion.sink.sink_registry import sink_registry
|
|
|
|
from datahub.ingestion.source.source_registry import source_registry
|
2021-10-25 17:10:24 -04:00
|
|
|
from datahub.ingestion.transformer.transform_registry import transform_registry
|
2022-02-08 14:26:44 -08:00
|
|
|
|
|
|
|
# from tests.test_helpers.click_helpers import run_datahub_cmd
|
2021-04-01 12:15:05 -07:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"registry",
|
|
|
|
[
|
|
|
|
source_registry,
|
|
|
|
sink_registry,
|
|
|
|
extractor_registry,
|
2021-10-25 17:10:24 -04:00
|
|
|
transform_registry,
|
2021-04-01 12:15:05 -07:00
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_registry_nonempty(registry):
|
|
|
|
assert len(registry.mapping) > 0
|
2021-03-11 16:41:05 -05:00
|
|
|
|
|
|
|
|
2022-02-08 14:26:44 -08:00
|
|
|
# TODO: Restore this test. This test causes loading interference with test mocks.
|
|
|
|
# @pytest.mark.parametrize(
|
|
|
|
# "verbose",
|
|
|
|
# [False, True],
|
|
|
|
# )
|
|
|
|
# def test_list_all(verbose: bool) -> None:
|
|
|
|
# # This just verifies that it runs without error.
|
|
|
|
# args = ["check", "plugins"]
|
|
|
|
# if verbose:
|
|
|
|
# args.append("--verbose")
|
|
|
|
# result = run_datahub_cmd(args)
|
|
|
|
# assert len(result.output.splitlines()) > 20
|
2021-04-01 12:15:05 -07:00
|
|
|
|
|
|
|
|
|
|
|
def test_registry():
|
|
|
|
# Make a mini sink registry.
|
2021-10-25 17:10:24 -04:00
|
|
|
fake_registry = PluginRegistry[Sink]()
|
2021-04-01 12:15:05 -07:00
|
|
|
fake_registry.register("console", ConsoleSink)
|
2021-05-05 14:05:16 -07:00
|
|
|
fake_registry.register_disabled("disabled", ModuleNotFoundError("disabled sink"))
|
2021-10-25 17:10:24 -04:00
|
|
|
fake_registry.register_disabled(
|
|
|
|
"disabled-exception", Exception("second disabled sink")
|
|
|
|
)
|
2021-04-01 12:15:05 -07:00
|
|
|
|
|
|
|
class DummyClass:
|
|
|
|
pass
|
|
|
|
|
|
|
|
assert len(fake_registry.mapping) > 0
|
|
|
|
assert fake_registry.is_enabled("console")
|
|
|
|
assert fake_registry.get("console") == ConsoleSink
|
|
|
|
assert (
|
|
|
|
fake_registry.get("datahub.ingestion.sink.console.ConsoleSink") == ConsoleSink
|
|
|
|
)
|
|
|
|
|
2021-10-25 17:10:24 -04:00
|
|
|
# Test lazy-loading capabilities.
|
|
|
|
fake_registry.register_lazy(
|
|
|
|
"lazy-console", "datahub.ingestion.sink.console:ConsoleSink"
|
|
|
|
)
|
|
|
|
assert fake_registry.get("lazy-console") == ConsoleSink
|
|
|
|
|
|
|
|
fake_registry.register_lazy("lazy-error", "thisdoesnot.exist")
|
|
|
|
with pytest.raises(ConfigurationError, match="disabled"):
|
|
|
|
fake_registry.get("lazy-error")
|
|
|
|
|
|
|
|
# Test error-checking on keys.
|
|
|
|
with pytest.raises(KeyError, match="special characters"):
|
2021-04-01 12:15:05 -07:00
|
|
|
fake_registry.register("thisdoesnotexist.otherthing", ConsoleSink)
|
|
|
|
with pytest.raises(KeyError, match="in use"):
|
|
|
|
fake_registry.register("console", ConsoleSink)
|
|
|
|
with pytest.raises(KeyError, match="not find"):
|
|
|
|
fake_registry.get("thisdoesnotexist")
|
|
|
|
|
2021-10-25 17:10:24 -04:00
|
|
|
# Test error-checking on registered types.
|
2021-04-01 12:15:05 -07:00
|
|
|
with pytest.raises(ValueError, match="abstract"):
|
|
|
|
fake_registry.register("thisdoesnotexist", Sink) # type: ignore
|
|
|
|
with pytest.raises(ValueError, match="derived"):
|
|
|
|
fake_registry.register("thisdoesnotexist", DummyClass) # type: ignore
|
|
|
|
with pytest.raises(ConfigurationError, match="disabled"):
|
|
|
|
fake_registry.get("disabled")
|
2021-10-25 17:10:24 -04:00
|
|
|
with pytest.raises(ConfigurationError, match="disabled"):
|
|
|
|
fake_registry.get("disabled-exception")
|
|
|
|
|
|
|
|
# This just verifies that it runs without error. The formatting should be manually checked.
|
|
|
|
assert len(fake_registry.summary(verbose=False).splitlines()) >= 5
|
|
|
|
assert len(fake_registry.summary(verbose=True).splitlines()) >= 5
|