test: add pytest coverage for plugin utilities
This commit is contained in:
@@ -19,4 +19,4 @@
|
||||
- Concise, engineering notebook tone.
|
||||
|
||||
## How to verify (tests/commands)
|
||||
- Unknown / needs verification (no test harness yet).
|
||||
- `pytest`
|
||||
|
||||
@@ -8,6 +8,14 @@ authors = [
|
||||
{name = "scawful"}
|
||||
]
|
||||
|
||||
[project.optional-dependencies]
|
||||
test = [
|
||||
"pytest>=7.4"
|
||||
]
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
testpaths = ["tests"]
|
||||
|
||||
[build-system]
|
||||
requires = ["setuptools>=68"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
9
tests/conftest.py
Normal file
9
tests/conftest.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
SRC = ROOT / "src"
|
||||
if str(SRC) not in sys.path:
|
||||
sys.path.insert(0, str(SRC))
|
||||
33
tests/test_config.py
Normal file
33
tests/test_config.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from afs_scawful.config import load_training_paths, load_training_resources
|
||||
|
||||
|
||||
def test_load_training_paths_expands_paths(tmp_path: Path) -> None:
|
||||
config_path = tmp_path / "training_paths.toml"
|
||||
config_path.write_text(
|
||||
"[paths]\n"
|
||||
"training_root = \"~/training\"\n"
|
||||
"datasets = \"~/training/datasets\"\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
data = load_training_paths(config_path=config_path)
|
||||
paths = data["paths"]
|
||||
assert paths["training_root"] == (Path.home() / "training").resolve()
|
||||
assert paths["datasets"] == (Path.home() / "training" / "datasets").resolve()
|
||||
|
||||
|
||||
def test_load_training_resources_expands_roots(tmp_path: Path) -> None:
|
||||
config_path = tmp_path / "training_resources.toml"
|
||||
config_path.write_text(
|
||||
"[resource_discovery]\n"
|
||||
f"resource_roots = [\"{tmp_path}\"]\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
data = load_training_resources(config_path=config_path)
|
||||
roots = data["resource_discovery"]["resource_roots"]
|
||||
assert roots == [tmp_path.resolve()]
|
||||
24
tests/test_registry.py
Normal file
24
tests/test_registry.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from afs_scawful.registry import build_dataset_registry
|
||||
|
||||
|
||||
def test_build_dataset_registry(tmp_path: Path) -> None:
|
||||
datasets_root = tmp_path / "datasets"
|
||||
dataset_dir = datasets_root / "alpha"
|
||||
dataset_dir.mkdir(parents=True)
|
||||
|
||||
(dataset_dir / "train.jsonl").write_text("{}\n", encoding="utf-8")
|
||||
(dataset_dir / "stats.json").write_text("{\"samples\": 1}\n", encoding="utf-8")
|
||||
(dataset_dir / "metadata.json").write_text("{\"source\": \"test\"}\n", encoding="utf-8")
|
||||
|
||||
registry = build_dataset_registry(datasets_root)
|
||||
datasets = registry["datasets"]
|
||||
|
||||
assert len(datasets) == 1
|
||||
entry = datasets[0]
|
||||
assert entry["name"] == "alpha"
|
||||
assert entry["stats"]["samples"] == 1
|
||||
assert entry["metadata"]["source"] == "test"
|
||||
27
tests/test_resource_index.py
Normal file
27
tests/test_resource_index.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from afs_scawful.resource_index import ResourceIndexer
|
||||
|
||||
|
||||
def test_resource_indexer_dedupes(tmp_path: Path) -> None:
|
||||
root = tmp_path / "resources"
|
||||
root.mkdir()
|
||||
|
||||
(root / "a.txt").write_text("same\n", encoding="utf-8")
|
||||
(root / "b.txt").write_text("same\n", encoding="utf-8")
|
||||
(root / "c.md").write_text("diff\n", encoding="utf-8")
|
||||
|
||||
indexer = ResourceIndexer(
|
||||
resource_roots=[root],
|
||||
search_patterns=["**/*.txt", "**/*.md"],
|
||||
exclude_patterns=[],
|
||||
index_path=tmp_path / "index.json",
|
||||
)
|
||||
|
||||
result = indexer.build_index()
|
||||
assert result.total_files == 2
|
||||
assert result.duplicates_found == 1
|
||||
assert result.by_type.get("txt", 0) == 1
|
||||
assert result.by_type.get("md", 0) == 1
|
||||
Reference in New Issue
Block a user