Files
stack/tests/cli/test_cli.py
kert cda66f8f21
Some checks failed
Deploy / build (push) Failing after 9s
Deploy / scan (push) Has been skipped
Deploy / report-vulns (push) Has been skipped
CI / lint-test (push) Failing after 1m24s
fix 8 tests failing in Gitea Actions CI environment
- cli tests: strip ANSI escape codes from Rich/typer help output
  before asserting keywords (Rich outputs ANSI in no-TTY mode)
- conf/test_connect: skip DuckDB tests when data/aco.duckdb is
  absent (3GB file not present in CI checkout)
- docs/test_docs_build: resolve paths relative to repo root
  (CI may run from a different working directory)
2026-03-23 21:49:07 -04:00

164 lines
5.1 KiB
Python

"""Tests for CLI skeleton — all subcommands are reachable and print stubs."""
from __future__ import annotations
import re
from typer.testing import CliRunner
from cli import app
runner = CliRunner()
_ANSI_RE = re.compile(r"\x1b\[[0-9;]*m")
def _plain(text: str) -> str:
"""Strip ANSI escape codes for assertion matching."""
return _ANSI_RE.sub("", text)
class TestTopLevel:
def test_help(self) -> None:
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
assert "Healthcare data platform CLI" in result.output
def test_no_args_shows_help(self) -> None:
result = runner.invoke(app, [])
assert "Commands" in result.output
class TestRun:
def test_run_help(self) -> None:
result = runner.invoke(app, ["run", "--help"])
assert result.exit_code == 0
assert "target" in result.output
def test_run_unknown_pipeline(self) -> None:
result = runner.invoke(app, ["run", "nonexistent"])
assert result.exit_code != 0
assert "Unknown pipeline" in result.output
def test_run_lists_available(self) -> None:
result = runner.invoke(app, ["run", "nonexistent"])
assert "readmissions" in result.output
class TestLoad:
def test_load_help(self) -> None:
result = runner.invoke(app, ["load", "--help"])
assert result.exit_code == 0
for cmd in ("cclf", "bcda", "seed"):
assert cmd in result.output
def test_load_cclf_requires_path(self) -> None:
result = runner.invoke(app, ["load", "cclf"])
assert result.exit_code != 0
def test_load_bcda_help(self) -> None:
result = runner.invoke(app, ["load", "bcda", "--help"])
assert result.exit_code == 0
assert "ndjson" in result.output
def test_load_seed_help(self) -> None:
result = runner.invoke(app, ["load", "seed", "--help"])
assert result.exit_code == 0
assert "seed" in result.output.lower()
class TestGenerate:
def test_generate_models_help(self) -> None:
result = runner.invoke(app, ["generate", "models", "--help"])
assert result.exit_code == 0
assert "sync" in result.output
class TestBib:
def test_bib_sync_help(self) -> None:
result = runner.invoke(app, ["bib", "sync", "--help"])
assert result.exit_code == 0
assert "dry-run" in _plain(result.output)
def test_bib_tag(self) -> None:
result = runner.invoke(app, ["bib", "tag"])
assert result.exit_code == 0
assert "tags found" in result.output
def test_bib_query(self) -> None:
result = runner.invoke(app, ["bib", "query", "pfs"])
assert result.exit_code == 0
assert "items found" in result.output
class TestLake:
def test_lake_deploy_help(self) -> None:
result = runner.invoke(app, ["lake", "deploy", "--help"])
assert result.exit_code == 0
out = _plain(result.output)
assert "catalog-type" in out
assert "dry-run" in out
def test_lake_load_help(self) -> None:
result = runner.invoke(app, ["lake", "load", "--help"])
assert result.exit_code == 0
out = _plain(result.output)
assert "catalog-type" in out
assert "mode" in out
def test_lake_validate_help(self) -> None:
result = runner.invoke(app, ["lake", "validate", "--help"])
assert result.exit_code == 0
assert "catalog-type" in _plain(result.output)
def test_lake_parity_help(self) -> None:
result = runner.invoke(app, ["lake", "parity", "--help"])
assert result.exit_code == 0
assert "schema" in result.output
class TestDb:
def test_db_comment(self) -> None:
result = runner.invoke(app, ["db", "comment"])
assert result.exit_code == 0
assert "db comment" in result.output
def test_db_inspect(self) -> None:
result = runner.invoke(app, ["db", "inspect"])
assert result.exit_code == 0
assert "db inspect" in result.output
class TestValidate:
def test_validate_single(self) -> None:
result = runner.invoke(app, ["validate", "readmissions"])
assert "readmissions" in result.output.lower()
def test_validate_unknown(self) -> None:
result = runner.invoke(app, ["validate", "nonexistent"])
assert result.exit_code != 0
class TestHealth:
def test_health(self) -> None:
result = runner.invoke(app, ["health"])
assert "duckdb" in result.output
assert "pipelines" in result.output
class TestDocs:
def test_docs_build_help(self) -> None:
result = runner.invoke(app, ["docs", "build", "--help"])
assert result.exit_code == 0
assert "skip-generate" in _plain(result.output)
def test_docs_serve_help(self) -> None:
result = runner.invoke(app, ["docs", "serve", "--help"])
assert result.exit_code == 0
assert "port" in result.output
def test_docs_generate_help(self) -> None:
result = runner.invoke(app, ["docs", "generate", "--help"])
assert result.exit_code == 0
assert "Generate" in result.output