Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/datasource_kit/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

import json
from dataclasses import dataclass, field
from importlib.metadata import version
from pathlib import Path
from typing import Any

from .completeness import CompletenessReport

__all__ = ["IngestReport"]

_KIT_VERSION = "0.15.0"
_KIT_VERSION = version("datasource-kit")


@dataclass
Expand Down
40 changes: 14 additions & 26 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

import json
import tomllib
from importlib.metadata import version
from pathlib import Path

import pytest

from datasource_kit.cli import EXAMPLE_ROOT, main
from datasource_kit.providers import builtin_registry
from datasource_kit.report import IngestReport


# ---------------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------------


@pytest.fixture()
Expand Down Expand Up @@ -58,9 +59,7 @@ def demo_batch(tmp_path: Path) -> Path:
return tmp_path


# ---------------------------------------------------------------------------
# validate verb
# ---------------------------------------------------------------------------


def test_validate_demo_scraper_ok(demo_scraper: Path) -> None:
Expand Down Expand Up @@ -90,9 +89,7 @@ def test_validate_unknown_provider_nonzero(tmp_path: Path) -> None:
assert main(["validate", str(tmp_path)]) != 0


# ---------------------------------------------------------------------------
# run verb
# ---------------------------------------------------------------------------


def test_run_writes_json(demo_scraper: Path, tmp_path: Path) -> None:
Expand All @@ -104,6 +101,17 @@ def test_run_writes_json(demo_scraper: Path, tmp_path: Path) -> None:
assert data["source_name"] == "test-scraper"
assert data["windows_processed"] > 0
assert data["records_fetched"] > 0
expected = version("datasource-kit")
project = tomllib.loads((Path(__file__).parents[1] / "pyproject.toml").read_text())
assert data["kit_version"] == expected == project["project"]["version"]
for report, expected_version in (
(IngestReport("test-scraper"), expected), (IngestReport.from_dict({}), expected),
(IngestReport("old", kit_version="0.14.0"), "0.14.0"),
(IngestReport.from_dict({"source_name": "old", "kit_version": "0.14.0"}), "0.14.0"),
):
report.save_json(out)
assert json.loads(out.read_text())["kit_version"] == expected_version
assert IngestReport.load_json(out).as_dict() == report.as_dict()


def test_run_stdout(demo_scraper: Path, capsys: pytest.CaptureFixture) -> None:
Expand All @@ -114,11 +122,6 @@ def test_run_stdout(demo_scraper: Path, capsys: pytest.CaptureFixture) -> None:
assert "source_name" in data


# ---------------------------------------------------------------------------
# coverage report verb
# ---------------------------------------------------------------------------


def test_coverage_report(demo_scraper: Path, tmp_path: Path, capsys: pytest.CaptureFixture) -> None:
out = tmp_path / "report.json"
main(["run", str(demo_scraper), "--out", str(out)])
Expand All @@ -129,11 +132,6 @@ def test_coverage_report(demo_scraper: Path, tmp_path: Path, capsys: pytest.Capt
assert "records_fetched" in captured.out


# ---------------------------------------------------------------------------
# explain verb
# ---------------------------------------------------------------------------


def test_explain(demo_scraper: Path, tmp_path: Path, capsys: pytest.CaptureFixture) -> None:
out = tmp_path / "report.json"
main(["run", str(demo_scraper), "--out", str(out)])
Expand All @@ -145,11 +143,6 @@ def test_explain(demo_scraper: Path, tmp_path: Path, capsys: pytest.CaptureFixtu
assert f"kit_version: {project['project']['version']}" in captured.out


# ---------------------------------------------------------------------------
# examples run verb (shipped demo profiles)
# ---------------------------------------------------------------------------


def test_examples_run_demo_scraper() -> None:
assert EXAMPLE_ROOT.exists(), f"EXAMPLE_ROOT missing: {EXAMPLE_ROOT}"
rc = main(["examples", "run", "demo-scraper"])
Expand Down Expand Up @@ -185,11 +178,6 @@ def test_examples_run_unknown_name_nonzero() -> None:
assert rc != 0


# ---------------------------------------------------------------------------
# Dep-free standalone assertion
# ---------------------------------------------------------------------------


def test_builtin_registry_stdlib_only() -> None:
"""builtin_registry() must not require any third-party package."""
reg = builtin_registry()
Expand Down
Loading