| import json |
| import math |
|
|
| import pytest |
|
|
| from submission import SubmissionError, build_submission, save_submission_file |
|
|
|
|
| VALID_METRICS = { |
| "Vis": 0.839, |
| "Aud (PQ)": 6.31, |
| "AV": 0.37, |
| "Lip": 5.40, |
| "Text": 41.36, |
| "Face": 49.05, |
| "Music": 11.25, |
| "Speech": 76.49, |
| "Lo-Phy": 3.93, |
| "Hi-Phy": 52.92, |
| "Holistic": 57.45, |
| } |
|
|
|
|
| def _valid_submission(**overrides): |
| data = { |
| "model": "Ovi", |
| "components": "Ovi (Open-source)", |
| "component_type": "Open-source", |
| "contact": "maintainer@example.com", |
| "model_url": "https://example.com/model", |
| "results_url": "https://example.com/results", |
| "notes": "test submission", |
| "metrics": VALID_METRICS, |
| } |
| data.update(overrides) |
| return build_submission(**data) |
|
|
|
|
| def test_build_submission_recomputes_total(): |
| submission = _valid_submission() |
|
|
| assert submission["status"] == "pending_review" |
| assert math.isclose(submission["computed_total"], 52.0174, abs_tol=1e-4) |
|
|
|
|
| def test_build_submission_rejects_out_of_range_metric(): |
| metrics = dict(VALID_METRICS) |
| metrics["Vis"] = 1.2 |
|
|
| with pytest.raises(SubmissionError, match="Vis must be between 0 and 1"): |
| _valid_submission(metrics=metrics) |
|
|
|
|
| def test_build_submission_requires_https_urls(): |
| with pytest.raises(SubmissionError, match="Model or paper URL"): |
| _valid_submission(model_url="example.com/model") |
|
|
|
|
| def test_save_submission_file(tmp_path, monkeypatch): |
| monkeypatch.setenv("PENDING_SUBMISSION_DIR", str(tmp_path)) |
| submission = _valid_submission(model="My Model") |
|
|
| path = save_submission_file(submission) |
|
|
| assert path.exists() |
| assert path.parent == tmp_path |
| assert json.loads(path.read_text(encoding="utf-8"))["model"] == "My Model" |
|
|