research-link-ai / tests /test_output_structure.py
MHamdan's picture
Deploy Research-Link-AI (Docker Space, offline demo)
a753e74 verified
Raw
History Blame Contribute Delete
1.66 kB
"""Tests for output directory validation."""
import tempfile
from pathlib import Path
from researchlink.validators.output_validator import REQUIRED_FILES, validate_paper_module
def test_missing_directory():
results = validate_paper_module(Path("/nonexistent/path"))
assert any(not r["ok"] for r in results)
def test_empty_directory_has_missing_files():
with tempfile.TemporaryDirectory() as tmpdir:
results = validate_paper_module(Path(tmpdir))
missing = [r for r in results if not r["ok"]]
assert len(missing) > 0
def test_complete_directory_passes():
with tempfile.TemporaryDirectory() as tmpdir:
base = Path(tmpdir)
# Create all required files
for fname in REQUIRED_FILES:
target = base / fname
target.parent.mkdir(parents=True, exist_ok=True)
target.write_text("# test\n", encoding="utf-8")
# Overwrite JSON files with valid JSON
(base / "metadata.json").write_text('{"slug": "test-paper"}', encoding="utf-8")
(base / "sources.json").write_text("[]", encoding="utf-8")
results = validate_paper_module(base)
missing = [r for r in results if not r["ok"]]
assert len(missing) == 0, f"Unexpected missing: {[r['message'] for r in missing]}"
def test_invalid_metadata_json_caught():
with tempfile.TemporaryDirectory() as tmpdir:
base = Path(tmpdir)
(base / "metadata.json").write_text("{not valid json", encoding="utf-8")
results = validate_paper_module(base)
bad = [r for r in results if "metadata.json" in r["message"] and not r["ok"]]
assert len(bad) > 0