| import importlib.util |
| import json |
| from pathlib import Path |
|
|
|
|
| PATH = Path(__file__).parents[1] / "scripts" / "archive_genre_challenge_v2.py" |
| SPEC = importlib.util.spec_from_file_location("archive_genre_challenge_v2", PATH) |
| MODULE = importlib.util.module_from_spec(SPEC) |
| assert SPEC.loader |
| SPEC.loader.exec_module(MODULE) |
|
|
|
|
| def test_archive_separates_evaluator_payload_from_label_key(tmp_path): |
| dataset = tmp_path / "source.jsonl" |
| rows = [] |
| challenge_rows = [] |
| genres = ["amber_oriental", "citrus_cologne", "floral_woody", "fougere"] |
| for index in range(8): |
| rows.append({"genre": genres[index % 4], "formula_id": f"F{index}", "formula": [ |
| {"cas": f"cas-{index}", "smiles": "CCO", "weight_fraction": 1.0} |
| ]}) |
| challenge_rows.append({"source_index": index, "formula_id": f"F{index}", "genre": genres[index % 4]}) |
| dataset.write_text("".join(json.dumps(row) + "\n" for row in rows)) |
| challenge = tmp_path / "challenge.json" |
| challenge.write_text(json.dumps({"challenge_records": challenge_rows})) |
|
|
| output = tmp_path / "release" |
| result = MODULE.archive(challenge, dataset, output, seed=7) |
| blinded = json.loads((output / "blinded_challenge.json").read_text()) |
| key = json.loads((output / "label_key.json").read_text()) |
|
|
| assert result["records"] == 8 |
| assert result["blocks"] == 2 |
| assert all("genre" not in row and "source_index" not in row and "formula_id" not in row for row in blinded["records"]) |
| assert {row["blind_id"] for row in blinded["records"]} == {row["blind_id"] for row in key["records"]} |
| assert (output / "blinded_challenge.json").stat().st_mode & 0o777 == 0o444 |
| assert (output / "label_key.json").stat().st_mode & 0o777 == 0o400 |
|
|