generated from coulomb/repo-seed
fixture-repository coverage for the testing strategy
This commit is contained in:
1
tests/__init__.py
Normal file
1
tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
41
tests/fixtures.py
Normal file
41
tests/fixtures.py
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
def write_readme_only_repo(root: Path) -> Path:
|
||||||
|
repo = root / "readme-only"
|
||||||
|
repo.mkdir()
|
||||||
|
(repo / "README.md").write_text(
|
||||||
|
"# Readme Only\n\nThis repository describes a planned interface.\n",
|
||||||
|
encoding="utf-8",
|
||||||
|
)
|
||||||
|
return repo
|
||||||
|
|
||||||
|
|
||||||
|
def write_python_cli_repo(root: Path) -> Path:
|
||||||
|
repo = root / "python-cli"
|
||||||
|
repo.mkdir()
|
||||||
|
(repo / "README.md").write_text("# Python CLI\n", encoding="utf-8")
|
||||||
|
(repo / "requirements.txt").write_text("click\npytest\n", encoding="utf-8")
|
||||||
|
(repo / "cli.py").write_text(
|
||||||
|
"import click\n\n"
|
||||||
|
"@click.command()\n"
|
||||||
|
"def main():\n"
|
||||||
|
" click.echo('ok')\n",
|
||||||
|
encoding="utf-8",
|
||||||
|
)
|
||||||
|
(repo / "tests").mkdir()
|
||||||
|
(repo / "tests" / "test_cli.py").write_text(
|
||||||
|
"def test_cli(): pass\n",
|
||||||
|
encoding="utf-8",
|
||||||
|
)
|
||||||
|
return repo
|
||||||
|
|
||||||
|
|
||||||
|
def write_misleading_docs_repo(root: Path) -> Path:
|
||||||
|
repo = root / "misleading-docs"
|
||||||
|
repo.mkdir()
|
||||||
|
(repo / "README.md").write_text(
|
||||||
|
"# Misleading Docs\n\nClaims to provide payments and search, but has no code.\n",
|
||||||
|
encoding="utf-8",
|
||||||
|
)
|
||||||
|
return repo
|
||||||
@@ -1,4 +1,9 @@
|
|||||||
from repo_registry.repo_scanning.scanner import DeterministicScanner
|
from repo_registry.repo_scanning.scanner import DeterministicScanner
|
||||||
|
from tests.fixtures import (
|
||||||
|
write_misleading_docs_repo,
|
||||||
|
write_python_cli_repo,
|
||||||
|
write_readme_only_repo,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_deterministic_scanner_extracts_structural_facts(tmp_path):
|
def test_deterministic_scanner_extracts_structural_facts(tmp_path):
|
||||||
@@ -34,3 +39,35 @@ def test_deterministic_scanner_extracts_structural_facts(tmp_path):
|
|||||||
|
|
||||||
languages = {fact.name: fact.metadata["file_count"] for fact in result.facts if fact.kind == "language"}
|
languages = {fact.name: fact.metadata["file_count"] for fact in result.facts if fact.kind == "language"}
|
||||||
assert languages == {"Python": 2}
|
assert languages == {"Python": 2}
|
||||||
|
|
||||||
|
|
||||||
|
def test_scanner_readme_only_fixture_records_docs_without_interfaces(tmp_path):
|
||||||
|
repo = write_readme_only_repo(tmp_path)
|
||||||
|
|
||||||
|
result = DeterministicScanner().scan(repo)
|
||||||
|
|
||||||
|
facts = {(fact.kind, fact.name, fact.path) for fact in result.facts}
|
||||||
|
assert ("documentation", "README", "README.md") in facts
|
||||||
|
assert {fact.kind for fact in result.facts} == {"documentation"}
|
||||||
|
|
||||||
|
|
||||||
|
def test_scanner_python_cli_fixture_records_cli_and_framework_hints(tmp_path):
|
||||||
|
repo = write_python_cli_repo(tmp_path)
|
||||||
|
|
||||||
|
result = DeterministicScanner().scan(repo)
|
||||||
|
|
||||||
|
facts = {(fact.kind, fact.name, fact.path) for fact in result.facts}
|
||||||
|
assert ("framework", "Click", "requirements.txt") in facts
|
||||||
|
assert ("framework", "pytest", "requirements.txt") in facts
|
||||||
|
assert ("interface", "python CLI command decorator", "cli.py") in facts
|
||||||
|
assert ("test", "test_cli.py", "tests/test_cli.py") in facts
|
||||||
|
|
||||||
|
|
||||||
|
def test_scanner_misleading_docs_fixture_stays_observational(tmp_path):
|
||||||
|
repo = write_misleading_docs_repo(tmp_path)
|
||||||
|
|
||||||
|
result = DeterministicScanner().scan(repo)
|
||||||
|
|
||||||
|
assert [(fact.kind, fact.name, fact.path) for fact in result.facts] == [
|
||||||
|
("documentation", "README", "README.md")
|
||||||
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user