Spaces:
Running
Running
Download tests/test_repository_schema.py from nikeshn/researchbee: direct link, hf CLI and curl.
- Browser
- Download file 2.61 kB
-
https://huggingface.co/spaces/nikeshn/researchbee/resolve/main/tests/test_repository_schema.py
- Command line
-
hf download hf://spaces/nikeshn/researchbee/tests/test_repository_schema.py
-
curl -L -o test_repository_schema.py https://huggingface.co/spaces/nikeshn/researchbee/resolve/main/tests/test_repository_schema.py
2.61 kB
| from __future__ import annotations | |
| from prompts import REPO_SYSTEM_PROMPT | |
| from repositories import hydrate_deposit_strategy, hydrate_selection | |
| def test_repository_prompt_requires_exact_id_minimal_schema(): | |
| assert '"id": "exact registry id"' in REPO_SYSTEM_PROMPT | |
| assert "Every repositories item MUST contain an exact registry id" in REPO_SYSTEM_PROMPT | |
| assert "id, fit_reason, fit_confidence" in REPO_SYSTEM_PROMPT | |
| def test_hydration_requires_id_and_discards_model_facts(): | |
| selected = [ | |
| { | |
| "id": "zenodo", | |
| "fit_reason": "Good multidisciplinary fallback for these files.", | |
| "fit_confidence": "High", | |
| # All of these must be ignored in favour of the registry. | |
| "name": "Fake Zenodo", | |
| "url": "javascript:alert(1)", | |
| "cost": "Expensive", | |
| "access_model": "Invented", | |
| "licences_supported": "Invented", | |
| }, | |
| {"name": "Figshare", "fit_reason": "Missing id must not hydrate."}, | |
| {"id": "not-in-registry", "fit_reason": "Unknown id must not hydrate."}, | |
| {"id": "zenodo", "fit_reason": "Duplicate must not hydrate twice."}, | |
| ] | |
| hydrated = hydrate_selection(selected) | |
| assert len(hydrated) == 1 | |
| repository = hydrated[0] | |
| assert repository["id"] == "zenodo" | |
| assert repository["name"] == "Zenodo" | |
| assert repository["url"] == "https://zenodo.org" | |
| assert repository["cost"] == "Free" | |
| assert repository["fit_reason"].startswith("Good multidisciplinary") | |
| assert repository["fit_confidence"] == "High" | |
| assert "access_model" not in repository | |
| assert "licences_supported" not in repository | |
| def test_deposit_strategy_resolves_only_hydrated_ids(): | |
| repositories = hydrate_selection([ | |
| {"id": "zenodo", "fit_reason": "Primary", "fit_confidence": "High"}, | |
| {"id": "figshare", "fit_reason": "Secondary", "fit_confidence": "Medium"}, | |
| ]) | |
| strategy = hydrate_deposit_strategy( | |
| { | |
| "primary_repository_id": "zenodo", | |
| "secondary_repository_id": "invented", | |
| "metadata_standard": "Check repository guidance", | |
| "deposit_workflow": ["Review terms", "Deposit files"], | |
| }, | |
| repositories, | |
| ) | |
| assert strategy["primary_repository_id"] == "zenodo" | |
| assert strategy["primary_choice"] == "Zenodo" | |
| # Invalid model id falls back to the next actually hydrated result. | |
| assert strategy["secondary_repository_id"] == "figshare" | |
| assert strategy["secondary_choice"] == "Figshare" | |