"""Regression: dataset YAML files parse and have the expected shape. Bug captured: schema_docs.yaml had values that began with a quote character (e.g. `gender: 'M' or 'F'.`), which YAML treats as a quoted scalar — anything after the closing quote is a parse error. The YAML structure is now flat — tables. is a description string, columns are keyed `table.column`, and relationships are an explicit list. The DDL structure (column types, nullability) lives in extracted_schema.json generated by `make recon`. """ from pathlib import Path import pytest import yaml DATASETS_DIR = Path(__file__).resolve().parent.parent / "api" / "datasets" DATASETS = [p.name for p in DATASETS_DIR.iterdir() if p.is_dir() and not p.name.startswith("_")] @pytest.mark.parametrize("dataset", DATASETS) def test_schema_docs_parses(dataset): docs = yaml.safe_load((DATASETS_DIR / dataset / "schema_docs.yaml").read_text()) assert docs is not None assert "tables" in docs assert isinstance(docs["tables"], dict) and docs["tables"] # New shape: each table value is a description string, not a dict. for name, val in docs["tables"].items(): assert isinstance(val, str), f"tables.{name} should be a string description, got {type(val)}" @pytest.mark.parametrize("dataset", DATASETS) def test_metrics_parses(dataset): metrics = yaml.safe_load((DATASETS_DIR / dataset / "metrics.yaml").read_text()) assert metrics is not None assert "metrics" in metrics assert isinstance(metrics["metrics"], dict) and metrics["metrics"] def test_financial_columns_with_quotes_survive_parse(): """Values containing quoted codes (M, F, OWNER, PRIJEM, ...) must parse without truncation. Columns are flat `table.col` keys now.""" docs = yaml.safe_load( (DATASETS_DIR / "financial" / "schema_docs.yaml").read_text() ) cols = docs["columns"] assert '"M"' in cols["client.gender"] and '"F"' in cols["client.gender"] assert '"OWNER"' in cols["disp.type"] and '"DISPONENT"' in cols["disp.type"] assert '"PRIJEM"' in cols["trans.type"] and '"VYDAJ"' in cols["trans.type"] def test_financial_has_relationships(): docs = yaml.safe_load( (DATASETS_DIR / "financial" / "schema_docs.yaml").read_text() ) rels = docs.get("relationships") or [] assert len(rels) >= 5 # we have 8; assert ≥5 to allow some pruning # all entries have from/to for r in rels: assert "from" in r and "to" in r assert "." in r["from"] and "." in r["to"]