Files
chemenu/tools/chemenu/tests/test_kb_collections.py
T
torben f63a72cb24
CI / verify (push) Successful in 42s
Release / release (push) Successful in 37s
fix: raw_dir-Fixture kappt config.ROOT, private Fixture-Namen ersetzt (2.1.1)
Files changed:
- CHANGES.md
- VERSION
- tools/chemenu/tests/conftest.py
- tools/chemenu/tests/test_corpus_diff.py
- tools/chemenu/tests/test_index_build.py
- tools/chemenu/tests/test_kb_collections.py
- tools/chemenu/tests/test_lint.py
- tools/chemenu/tests/test_migrate_cmd.py
- tools/chemenu/tests/test_new_page.py
- tools/chemenu/tests/test_page_ops.py
- tools/chemenu/tests/test_provenance.py
- tools/chemenu/tests/test_search.py
- tools/chemenu/tests/test_touch.py
2026-09-01 17:03:51 +02:00

68 lines
2.5 KiB
Python

from pathlib import Path
import pytest
from chemenu import config, kb_collections
@pytest.fixture
def repo(tmp_path: Path, monkeypatch) -> Path:
"""A repo skeleton with two collections, plus the non-collection stages."""
kb = tmp_path / "kb"
for name in ("entities", "concepts"):
(kb / name).mkdir(parents=True)
(kb / name / "COLLECTION.md").write_text(f"# kb/{name}/\n", encoding="utf-8")
(kb / "entities" / "systems").mkdir()
(kb / "README.md").write_text("# KB Routing\n", encoding="utf-8")
(tmp_path / "raw").mkdir()
(tmp_path / "types").mkdir()
monkeypatch.setattr(config, "ROOT", tmp_path)
monkeypatch.setattr(config, "KB_DIR", kb)
return tmp_path
def test_collections_are_discovered_by_contract_presence(repo):
assert [p.name for p in kb_collections.iter_kb_collections()] == ["concepts", "entities"]
def test_directory_without_a_contract_is_not_a_collection(repo):
(repo / "kb" / "drafts").mkdir()
assert "drafts" not in [p.name for p in kb_collections.iter_kb_collections()]
def test_area_resolves_to_its_enclosing_collection(repo):
page = repo / "kb" / "entities" / "systems" / "gateway.md"
assert kb_collections.kb_collection_of(page) == repo / "kb" / "entities"
def test_path_outside_kb_has_no_collection(repo):
assert kb_collections.kb_collection_of(repo / "raw" / "notes" / "x.md") is None
def test_nested_contract_is_stray(repo):
nested = repo / "kb" / "entities" / "systems" / "COLLECTION.md"
nested.write_text("# nope\n", encoding="utf-8")
assert kb_collections.stray_collection_contracts() == [nested]
def test_contract_outside_kb_is_stray(repo):
"""`raw/`, `types/` and `reports/` are pipeline stages, not collections.
Without this check the word 'collection' widens back out to 'any directory
with a contract in it'."""
outside = repo / "raw" / "COLLECTION.md"
outside.write_text("# nope\n", encoding="utf-8")
assert kb_collections.stray_collection_contracts() == [outside]
def test_vendored_commonplace_contracts_are_ignored(repo):
"""commonplace/ is a read-only vendored KB with its own collection tree and
is not governed by this repo's layout."""
vendored = repo / "commonplace" / "kb" / "notes"
vendored.mkdir(parents=True)
(vendored / "COLLECTION.md").write_text("# vendored\n", encoding="utf-8")
assert kb_collections.stray_collection_contracts() == []
def test_a_clean_tree_has_no_strays(repo):
assert kb_collections.stray_collection_contracts() == []