From e36da21d7fd05824de727228041bb2b19c0b4b82 Mon Sep 17 00:00:00 2001 From: "Edgar R. M" Date: Tue, 18 Jul 2023 18:01:55 -0600 Subject: [PATCH] fix: Ensure all expected tap parameters are passed to `SQLTap` initializer (#1842) --- singer_sdk/tap_base.py | 28 ++++------------------------ tests/samples/conftest.py | 2 +- tests/samples/test_tap_sqlite.py | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/singer_sdk/tap_base.py b/singer_sdk/tap_base.py index 95800925c..08ce6f3ad 100644 --- a/singer_sdk/tap_base.py +++ b/singer_sdk/tap_base.py @@ -612,37 +612,17 @@ class SQLTap(Tap): # Stream class used to initialize new SQL streams from their catalog declarations. default_stream_class: type[SQLStream] - def __init__( - self, - *, - config: dict | PurePath | str | list[PurePath | str] | None = None, - catalog: PurePath | str | dict | None = None, - state: PurePath | str | dict | None = None, - parse_env_config: bool = False, - validate_config: bool = True, - ) -> None: + def __init__(self, *args: t.Any, **kwargs: t.Any) -> None: """Initialize the SQL tap. The SQLTap initializer additionally creates a cache variable for _catalog_dict. Args: - config: Tap configuration. Can be a dictionary, a single path to a - configuration file, or a list of paths to multiple configuration - files. - catalog: Tap catalog. Can be a dictionary or a path to the catalog file. - state: Tap state. Can be dictionary or a path to the state file. - parse_env_config: Whether to look for configuration values in environment - variables. - validate_config: True to require validation of config settings. + *args: Positional arguments for the Tap initializer. + **kwargs: Keyword arguments for the Tap initializer. """ self._catalog_dict: dict | None = None - super().__init__( - config=config, - catalog=catalog, - state=state, - parse_env_config=parse_env_config, - validate_config=validate_config, - ) + super().__init__(*args, **kwargs) @property def catalog_dict(self) -> dict: diff --git a/tests/samples/conftest.py b/tests/samples/conftest.py index 60f277412..29560a330 100644 --- a/tests/samples/conftest.py +++ b/tests/samples/conftest.py @@ -73,7 +73,7 @@ def path_to_sample_data_db(tmp_path: Path) -> Path: @pytest.fixture -def sqlite_sample_db_config(path_to_sample_data_db: str) -> dict: +def sqlite_sample_db_config(path_to_sample_data_db: Path) -> dict: """Get configuration dictionary for target-csv.""" return {"path_to_db": str(path_to_sample_data_db)} diff --git a/tests/samples/test_tap_sqlite.py b/tests/samples/test_tap_sqlite.py index 5e1349f94..bceaa34b1 100644 --- a/tests/samples/test_tap_sqlite.py +++ b/tests/samples/test_tap_sqlite.py @@ -1,7 +1,11 @@ from __future__ import annotations +import json import typing as t +from click.testing import CliRunner + +from samples.sample_tap_sqlite import SQLiteTap from samples.sample_target_csv.csv_target import SampleTargetCSV from singer_sdk import SQLStream from singer_sdk._singerlib import MetadataMapping, StreamMetadata @@ -24,6 +28,23 @@ def _discover_and_select_all(tap: SQLTap) -> None: catalog_entry["metadata"] = md.to_list() +def test_tap_sqlite_cli(sqlite_sample_db_config: dict[str, t.Any], tmp_path: Path): + runner = CliRunner() + filepath = tmp_path / "config.json" + + with filepath.open("w") as f: + json.dump(sqlite_sample_db_config, f) + + result = runner.invoke( + SQLiteTap.cli, + ["--discover", "--config", str(filepath)], + ) + assert result.exit_code == 0 + + catalog = json.loads(result.stdout) + assert "streams" in catalog + + def test_sql_metadata(sqlite_sample_tap: SQLTap): stream = t.cast(SQLStream, sqlite_sample_tap.streams["main-t1"]) detected_metadata = stream.catalog_entry["metadata"]