Skip to content

Commit

Permalink
fix: Ensure all expected tap parameters are passed to SQLTap initia…
Browse files Browse the repository at this point in the history
…lizer (#1842)
  • Loading branch information
edgarrmondragon authored Jul 19, 2023
1 parent e655386 commit e36da21
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
28 changes: 4 additions & 24 deletions singer_sdk/tap_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/samples/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}

Expand Down
21 changes: 21 additions & 0 deletions tests/samples/test_tap_sqlite.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"]
Expand Down

0 comments on commit e36da21

Please sign in to comment.