Spaces:
Running
Running
| from datetime import datetime, timezone | |
| from app.services.submissions import ( | |
| validate_submission, | |
| build_request_entry, | |
| count_user_submissions_this_month, | |
| monthly_quota_exceeded, | |
| ) | |
| def _valid_payload(**overrides): | |
| p = { | |
| "model_cls": "braindecode.models.BIOT", | |
| "model_name": "BIOT-frozen", | |
| "organization": "braindecode", | |
| "hub_repo": "braindecode/biot-weights", | |
| "finetuning_strategies": ["frozen"], | |
| "heads": ["linear_head"], | |
| "datasets": ["bcic2a", "physionet"], | |
| "n_seeds": 3, | |
| "visibility": "Public", | |
| } | |
| p.update(overrides) | |
| return p | |
| def test_valid_payload_has_no_errors(): | |
| assert validate_submission(_valid_payload()) == [] | |
| def test_model_cls_required(): | |
| errs = validate_submission(_valid_payload(model_cls="")) | |
| assert any("model_cls" in e for e in errs) | |
| def test_model_cls_must_be_dotted_path(): | |
| errs = validate_submission(_valid_payload(model_cls="notdotted")) | |
| assert any("dotted import path" in e for e in errs) | |
| def test_weights_source_required(): | |
| errs = validate_submission(_valid_payload(hub_repo="", checkpoint_url="")) | |
| assert any("weights source" in e for e in errs) | |
| def test_only_one_weights_source(): | |
| errs = validate_submission(_valid_payload(checkpoint_url="https://x/w.pth")) | |
| assert any("only one weights source" in e for e in errs) | |
| def test_peft_strategy_requires_target_modules(): | |
| errs = validate_submission(_valid_payload(finetuning_strategies=["lora"])) | |
| assert any("peft_target_modules" in e for e in errs) | |
| def test_ia3_requires_ff_modules(): | |
| errs = validate_submission(_valid_payload( | |
| finetuning_strategies=["ia3"], peft_target_modules=["to_q"])) | |
| assert any("peft_ff_modules" in e for e in errs) | |
| def test_unknown_strategy_rejected(): | |
| errs = validate_submission(_valid_payload(finetuning_strategies=["magic"])) | |
| assert any("finetuning strategies" in e for e in errs) | |
| def test_unknown_dataset_rejected(): | |
| errs = validate_submission(_valid_payload(datasets=["not_a_dataset"])) | |
| assert any("datasets" in e for e in errs) | |
| def test_bad_email_rejected(): | |
| errs = validate_submission(_valid_payload(contact_email="nope")) | |
| assert any("email" in e for e in errs) | |
| def test_n_seeds_must_be_positive_int(): | |
| errs = validate_submission(_valid_payload(n_seeds=0)) | |
| assert any("n_seeds" in e for e in errs) | |
| def test_build_request_entry_shape(): | |
| now = datetime(2026, 6, 15, 12, 0, 0, tzinfo=timezone.utc) | |
| entry = build_request_entry(_valid_payload(), "alice", now=now) | |
| assert entry["framework"] == "open-eeg-bench" | |
| assert entry["status"] == "PENDING" | |
| assert entry["submitter"] == "alice" | |
| assert entry["submitted_time"] == "2026-06-15T12:00:00Z" | |
| assert entry["benchmark_kwargs"]["model_cls"] == "braindecode.models.BIOT" | |
| assert entry["benchmark_kwargs"]["hub_repo"] == "braindecode/biot-weights" | |
| assert entry["benchmark_kwargs"]["checkpoint_url"] is None | |
| assert entry["benchmark_kwargs"]["finetuning_strategies"] == ["frozen"] | |
| def test_monthly_count_and_quota(): | |
| entries = [ | |
| {"submitter": "alice", "submitted_time": "2026-06-01T00:00:00Z"}, | |
| {"submitter": "alice", "submitted_time": "2026-06-09T00:00:00Z"}, | |
| {"submitter": "bob", "submitted_time": "2026-06-09T00:00:00Z"}, | |
| {"submitter": "alice", "submitted_time": "2026-05-30T00:00:00Z"}, | |
| ] | |
| now = datetime(2026, 6, 15, tzinfo=timezone.utc) | |
| assert count_user_submissions_this_month(entries, "alice", now=now) == 2 | |
| assert monthly_quota_exceeded(entries, "alice", now=now) is False | |
| five = entries + [{"submitter": "alice", "submitted_time": "2026-06-1%dT00:00:00Z" % d} for d in range(3, 6)] | |
| assert monthly_quota_exceeded(five, "alice", now=now) is True | |