forked from datahub-project/datahub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ingest): verify dynamic registry types at runtime (datahub-proje…
- Loading branch information
1 parent
1adcc83
commit cefc22a
Showing
10 changed files
with
102 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
from abc import abstractmethod | ||
|
||
|
||
class Closeable: | ||
@abstractmethod | ||
def close(self): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from click.testing import CliRunner | ||
|
||
from datahub.entrypoints import datahub | ||
|
||
|
||
def test_cli_help(): | ||
runner = CliRunner() | ||
result = runner.invoke(datahub, ["--help"]) | ||
assert result.output | ||
|
||
|
||
def test_check_local_docker(): | ||
# This just verifies that it runs without error. | ||
# We don't actually know what environment this will be run in, so | ||
# we can't depend on the output. Eventually, we should mock the docker SDK. | ||
runner = CliRunner() | ||
result = runner.invoke(datahub, ["check", "local-docker"]) | ||
assert result.output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,61 @@ | ||
import pytest | ||
from click.testing import CliRunner | ||
|
||
from datahub.configuration.common import ConfigurationError | ||
from datahub.entrypoints import datahub | ||
from datahub.ingestion.api.registry import Registry | ||
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 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"registry", | ||
[ | ||
source_registry, | ||
sink_registry, | ||
extractor_registry, | ||
], | ||
) | ||
def test_registry_nonempty(registry): | ||
assert len(registry.mapping) > 0 | ||
|
||
|
||
def test_list_all(): | ||
# This just verifies that it runs without error. | ||
runner = CliRunner() | ||
result = runner.invoke(datahub, ["ingest-list-plugins"]) | ||
assert result.exit_code == 0 | ||
|
||
|
||
def test_registry(): | ||
# Make a mini sink registry. | ||
fake_registry = Registry[Sink]() | ||
fake_registry.register("console", ConsoleSink) | ||
fake_registry.register_disabled("disabled", ImportError("disabled sink")) | ||
|
||
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 | ||
) | ||
|
||
with pytest.raises(KeyError, match="key cannot contain '.'"): | ||
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") | ||
|
||
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") |