test_requirements_section.py

tests/test_requirements_section.py

One top-level `requirements:` section, read by the index, the gate and the wiki (R5-CFG F6-F8/F14).

test_a_path_alone_is_the_file

None test_requirements_section.test_a_path_alone_is_the_file(Path tmp_path)

String shorthand.

tests/test_requirements_section.py:53

Checks

  • assert get_requirements(load_config(root / ".clew.yaml"))["file"] == "cat.yaml"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-012measuredtest_a_path_alone_is_the_file → load_config
REQ-DDB-GUARD-024inferredtest_a_path_alone_is_the_file → load_config → apply_opt_in_languages
Source · 9 lines
def test_a_path_alone_is_the_file(tmp_path: Path) -> None:
    """`requirements: cat.yaml` — the 1.x top-level form — stays the short way to say `file:`.

    @brief String shorthand.
    """
    root = _repo(tmp_path, "requirements: cat.yaml\n")
    assert get_requirements(load_config(root / ".clew.yaml"))["file"] == "cat.yaml"

Activity · 2 steps
lines 58–58root = _repo(tmp_path, "requirements: cat.yaml\n")lines 59–59assert get_requirements(load_config(root / ".clew.yaml"))["file"] == "cat.yaml"

test_an_old_location_is_refused_with_a_pointer

None test_requirements_section.test_an_old_location_is_refused_with_a_pointer(Path tmp_path, str text, str pointer)

Moved keys point at their new home.

tests/test_requirements_section.py:84

Show on the map →

Called by none

Calls _repo, load_config

Checks

  • assert pointer in " ".join(exc.value.problems), exc.value.problems

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-012measuredtest_an_old_location_is_refused_with_a_pointer → load_config
REQ-DDB-GUARD-014measured
REQ-DDB-GUARD-024inferredtest_an_old_location_is_refused_with_a_pointer → load_config → apply_opt_in_languages
Source · 11 lines
def test_an_old_location_is_refused_with_a_pointer(tmp_path: Path, text: str, pointer: str) -> None:
    """Refused by name with where the key went, not as "unknown" — the key was right in 1.x.

    @brief Moved keys point at their new home.
    """
    root = _repo(tmp_path, text)
    with pytest.raises(ConfigError) as exc:
        load_config(root / ".clew.yaml")
    assert pointer in " ".join(exc.value.problems), exc.value.problems

Activity · 4 steps
lines 89–89root = _repo(tmp_path, text)lines 90–90with pytest.raises(ConfigError) as exclines 91–91load_config(root / ".clew.yaml")lines 92–92assert pointer in " ".join(exc.value.problems), exc.value.problems

test_an_unknown_requirements_key_is_refused

None test_requirements_section.test_an_unknown_requirements_key_is_refused(Path tmp_path)

A misspelled catalog key is refused by name.

tests/test_requirements_section.py:62

Show on the map →

Called by none

Calls _repo, load_config

Checks

  • assert "id_colum" in " ".join(exc.value.problems)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-012measuredtest_an_unknown_requirements_key_is_refused → load_config
REQ-DDB-GUARD-014measured
REQ-DDB-GUARD-024inferredtest_an_unknown_requirements_key_is_refused → load_config → apply_opt_in_languages
Source · 22 lines
def test_an_unknown_requirements_key_is_refused(tmp_path: Path) -> None:
    """@brief A misspelled catalog key is refused by name."""
    root = _repo(tmp_path, "requirements:\n  file: cat.yaml\n  id_colum: rid\n")
    with pytest.raises(ConfigError) as exc:
        load_config(root / ".clew.yaml")
    assert "id_colum" in " ".join(exc.value.problems)


@pytest.mark.parametrize(
    ("text", "pointer"),
    [
        ("guard:\n  impact:\n    requirements: {file: cat.yaml}\n", "requirements:"),
        (
            "guard:\n  validate:\n    version_gate: {version_field: v}\n",
            "requirements.version_field",
        ),
        (
            "guard:\n  validate:\n    version_gate: {current_version: '1.0'}\n",
            "validate.current_version",
        ),
    ],
)

test_external_and_needs_reach_the_wiki_from_the_requirements_section

None test_requirements_section.test_external_and_needs_reach_the_wiki_from_the_requirements_section(Path tmp_path)

The wiki's catalogs come from `requirements.external`.

tests/test_requirements_section.py:128

Show on the map →

Called by none

Calls _repo, load_wiki_config

Checks

  • assert not problems, problems
  • assert [(s.name, s.repo, s.pin, s.catalog) for s in config.catalogs] == [
  • assert config.needs == "docs/needs.json"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-012measuredtest_external_and_needs_reach_the_wiki_from_the_requirements_section → load_wiki_config → _requirements_section → read_requirements_section
REQ-DDB-WIKI-054inferredtest_external_and_needs_reach_the_wiki_from_the_requirements_section → load_wiki_config → _comments → all
Source · 18 lines
def test_external_and_needs_reach_the_wiki_from_the_requirements_section(tmp_path: Path) -> None:
    """F6: one pinned-catalog shape, `{repo, rev, path, name}`; the wiki reads it from here.

    @brief The wiki's catalogs come from `requirements.external`.
    """
    from clew.wiki.config import load_wiki_config

    root = _repo(
        tmp_path,
        "requirements:\n  file: cat.yaml\n  needs: docs/needs.json\n"
        "  external:\n    - {repo: ../kv, rev: v1.2.0, path: req.yaml, name: kv}\n",
    )
    config, problems = load_wiki_config(root)
    assert not problems, problems
    assert [(s.name, s.repo, s.pin, s.catalog) for s in config.catalogs] == [
        ("kv", "../kv", "v1.2.0", "req.yaml")
    ]
    assert config.needs == "docs/needs.json"

1 more lines, not shown

Activity · 6 steps
lines 133–133from clew.wiki.config import load_wiki_configlines 135–139root = _repo( tmp_path, "requirements:\n file: cat.yaml\n needs: docs/needs.json\n" " external:\n - {repo: ../kv, rev: v1.2.0, path: req.yaml, name: kv}\n", )lines 140–140config, problems = load_wiki_config(root)lines 141–141assert not problems, problemslines 142–144assert [(s.name, s.repo, s.pin, s.catalog) for s in config.catalogs] == [ ("kv", "../kv", "v1.2.0", "req.yaml") ]lines 145–145assert config.needs == "docs/needs.json"

test_one_default_column_pair_for_every_reader

None test_requirements_section.test_one_default_column_pair_for_every_reader()

One default pair.

tests/test_requirements_section.py:115

Checks

  • assert resolve_catalog_columns(None) == (REQUIREMENTS_ID_COLUMN_DEFAULT, REQUIREMENTS_NAME_COLUMN_DEFAULT, )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_one_default_column_pair_for_every_reader → resolve_catalog_columns
Source · 13 lines
def test_one_default_column_pair_for_every_reader() -> None:
    """F8: an undeclared flat catalog is read with the same id/name keys by gate and index.

    @brief One default pair.
    """
    from clew.guard.config import REQUIREMENTS_ID_COLUMN_DEFAULT, REQUIREMENTS_NAME_COLUMN_DEFAULT

    assert resolve_catalog_columns(None) == (
        REQUIREMENTS_ID_COLUMN_DEFAULT,
        REQUIREMENTS_NAME_COLUMN_DEFAULT,
    )

Activity · 2 steps
lines 120–120from clew.guard.config import REQUIREMENTS_ID_COLUMN_DEFAULT, REQUIREMENTS_NAME_COLUMN_DEFAULTlines 122–125assert resolve_catalog_columns(None) == ( REQUIREMENTS_ID_COLUMN_DEFAULT, REQUIREMENTS_NAME_COLUMN_DEFAULT, )

test_the_current_version_is_read_from_its_new_key

None test_requirements_section.test_the_current_version_is_read_from_its_new_key(Path tmp_path)

`validate.current_version` is the release the version gate compares against.

tests/test_requirements_section.py:95

Show on the map →

Called by none

Calls _repo, load_config

Checks

  • assert load_config(root / ".clew.yaml")["validate"]["current_version"] == "2.0.0"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-012measuredtest_the_current_version_is_read_from_its_new_key → load_config
REQ-DDB-GUARD-024measuredtest_the_current_version_is_read_from_its_new_key → load_config → apply_opt_in_languages
Source · 9 lines
def test_the_current_version_is_read_from_its_new_key(tmp_path: Path) -> None:
    """@brief `validate.current_version` is the release the version gate compares against."""
    root = _repo(tmp_path, "guard:\n  validate:\n    current_version: '2.0.0'\n")
    assert load_config(root / ".clew.yaml")["validate"]["current_version"] == "2.0.0"


@pytest.mark.parametrize(
    ("key", "pointer"), [("catalogs", "requirements.external"), ("needs", "requirements.needs")]
)

test_the_gate_and_the_index_read_the_same_top_level_section

None test_requirements_section.test_the_gate_and_the_index_read_the_same_top_level_section(Path tmp_path)

One section, both readers.

tests/test_requirements_section.py:40

Checks

  • assert gate["file"] == "cat.yaml" and gate["id_column"] == "rid"
  • assert resolve_catalog_path(index_cfg, root) == (root / "cat.yaml").resolve()
  • assert resolve_catalog_columns(index_cfg) == ("rid", "label")

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_the_gate_and_the_index_read_the_same_top_level_section → load_guard_config
REQ-DDB-GUARD-012measuredtest_the_gate_and_the_index_read_the_same_top_level_section → load_config
REQ-DDB-GUARD-024inferredtest_the_gate_and_the_index_read_the_same_top_level_section → load_config → apply_opt_in_languages
REQ-DDB-SCHEMA-006measuredtest_the_gate_and_the_index_read_the_same_top_level_section → resolve_catalog_path
Source · 13 lines
def test_the_gate_and_the_index_read_the_same_top_level_section(tmp_path: Path) -> None:
    """With NO `guard:` section at all: the catalog is the repo's, not the gate's.

    @brief One section, both readers.
    """
    root = _repo(tmp_path, _SECTION)
    gate = get_requirements(load_config(root / ".clew.yaml"))
    assert gate["file"] == "cat.yaml" and gate["id_column"] == "rid"
    index_cfg = load_guard_config(root)
    assert resolve_catalog_path(index_cfg, root) == (root / "cat.yaml").resolve()
    assert resolve_catalog_columns(index_cfg) == ("rid", "label")

Activity · 6 steps
lines 45–45root = _repo(tmp_path, _SECTION)lines 46–46gate = get_requirements(load_config(root / ".clew.yaml"))lines 47–47assert gate["file"] == "cat.yaml" and gate["id_column"] == "rid"lines 48–48index_cfg = load_guard_config(root)lines 49–49assert resolve_catalog_path(index_cfg, root) == (root / "cat.yaml").resolve()lines 50–50assert resolve_catalog_columns(index_cfg) == ("rid", "label")

test_the_wiki_catalog_keys_point_at_the_requirements_section

None test_requirements_section.test_the_wiki_catalog_keys_point_at_the_requirements_section(Path tmp_path, str key, str pointer)

`wiki.catalogs` / `wiki.needs` moved to `requirements:`.

tests/test_requirements_section.py:104

Show on the map →

Called by none

Calls _repo, load_wiki_config

Checks

  • assert any(pointer in p for p in problems), problems

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-012measuredtest_the_wiki_catalog_keys_point_at_the_requirements_section → load_wiki_config → _requirements_section → read_requirements_section
REQ-DDB-WIKI-054inferredtest_the_wiki_catalog_keys_point_at_the_requirements_section → load_wiki_config → _comments → all
Source · 11 lines
def test_the_wiki_catalog_keys_point_at_the_requirements_section(
    tmp_path: Path, key: str, pointer: str
) -> None:
    """@brief `wiki.catalogs` / `wiki.needs` moved to `requirements:`."""
    from clew.wiki.config import load_wiki_config

    root = _repo(tmp_path, f"wiki:\n  {key}: []\n")
    _config, problems = load_wiki_config(root)
    assert any(pointer in p for p in problems), problems

Activity · 4 steps
lines 108–108from clew.wiki.config import load_wiki_configlines 110–110root = _repo(tmp_path, f"wiki:\n {key}: []\n")lines 111–111_config, problems = load_wiki_config(root)lines 112–112assert any(pointer in p for p in problems), problems