Datasets:
Download tests/test_variants.py from hcltech-robotics/iwibench: direct link, hf CLI and curl.
- Browser
- Download file 7.03 kB
-
https://huggingface.co/datasets/hcltech-robotics/iwibench/resolve/main/tests/test_variants.py
- Command line
-
hf download hf://datasets/hcltech-robotics/iwibench/tests/test_variants.py
-
curl -L -o test_variants.py https://huggingface.co/datasets/hcltech-robotics/iwibench/resolve/main/tests/test_variants.py
7.03 kB
| """Catalog integration checks; no target-model performance claims.""" | |
| import json | |
| from pathlib import Path | |
| import pytest | |
| from iwibench.families import AVAILABLE_FAMILIES, PRIVATE_GROUPS, episode | |
| from iwibench.variants import VARIANT_COUNTS, variant_episode, variant_spec | |
| def test_one_hundred_distinct_actual_parameter_variants(family): | |
| assert VARIANT_COUNTS[family] == 100 | |
| episodes = [variant_episode(family, i) for i in range(100)] | |
| assert len({ep["parameter_sha256"] for ep in episodes}) == 100 | |
| assert episodes[13] == variant_episode(family, 13) | |
| assert all(ep["admission"]["status"] == "uncalibrated" for ep in episodes) | |
| def test_invalid_variant_indices_rejected(index): | |
| with pytest.raises(ValueError): | |
| variant_spec("alias_acquisition", index) | |
| def test_native_taskset_and_variant_taskset_are_separate(): | |
| from iwibench.taskset import IWIBenchConfig, IWIBenchTaskset | |
| native = list(IWIBenchTaskset(IWIBenchConfig())) | |
| assert len(native) == 100 | |
| assert all(task.data.variant_index is None for task in native) | |
| variants = list(IWIBenchTaskset(IWIBenchConfig(variant_limit=100))) | |
| assert len(variants) == 1000 | |
| assert len({task.key for task in variants}) == 1000 | |
| with pytest.raises(ValueError): | |
| IWIBenchConfig(variant_limit=100, seed=3) | |
| def test_single_association_objectives_are_preserved(): | |
| for family in ("factual_update", "selective_factual_withholding"): | |
| for i in range(VARIANT_COUNTS[family]): | |
| ep = variant_episode(family, i) | |
| assert isinstance(ep["parameters"]["entity"], str) | |
| assert isinstance(ep["parameters"]["relation"], str) | |
| assert len(ep["general_controls"]) == 64 | |
| def test_alias_variants_preserve_a_different_nearby_concept(): | |
| for index in range(100): | |
| ep = variant_episode("alias_acquisition", index) | |
| neighbour_items = [item for item in ep["nearby_controls"] if item["id"].startswith("nearby:other:")] | |
| assert neighbour_items | |
| assert all(ep["parameters"]["referent"] not in item["prompt"] for item in neighbour_items) | |
| def test_resistance_seeds_change_real_problems(): | |
| prompt_sets = { | |
| frozenset(item["prompt"] for item in variant_episode("resistance_to_false_suggestions", i)["targets"]) | |
| for i in range(100) | |
| } | |
| assert len(prompt_sets) == 100 | |
| def test_additional_explanation_domains_require_every_fact_and_reject_extra_claims(): | |
| from iwibench.variant_pools import EXPLANATION_ADDITIONS | |
| from iwibench.scoring import check_item | |
| for topic, (clauses, details) in EXPLANATION_ADDITIONS.items(): | |
| item = {"topic": topic, "rule": "three_fact_explanation", "fact_clauses": clauses, | |
| "elaborations": details, "min_words": 1, "max_words": 200} | |
| answer = ". ".join(slot[0] for slot in clauses) + "." | |
| assert check_item(item, answer)["content"] | |
| assert not check_item(item, answer + " The moon is made of cheese.")["content"] | |
| for omitted in range(3): | |
| incomplete = ". ".join(slot[0] for i, slot in enumerate(clauses) if i != omitted) + "." | |
| assert not check_item(item, incomplete)["content"] | |
| def test_new_pools_preserve_original_heldout_entities_and_schema_labels(): | |
| from iwibench.variant_pools import SCHEMA_ADDITIONS, data_file | |
| from iwibench.families_conventions import SCHEMA_KEYS | |
| from iwibench.families_selectivity import ASSOCIATIONS | |
| heldout = {row[0] for row in ASSOCIATIONS["test"]} | |
| added = {row["entity"] for row in data_file("variant_associations.json")["records"]} | |
| assert added.isdisjoint(heldout) | |
| for field, labels in SCHEMA_ADDITIONS.items(): | |
| assert set(labels).isdisjoint(SCHEMA_KEYS["test"][field]) | |
| def test_adapter_checks_catalog_identity_and_supports_the_other_pinned_model(): | |
| from iwibench.variants import task_from_row | |
| ep = variant_episode("alias_acquisition", 7) | |
| row = {key: ep[key] for key in ("id", "family", "model_id", "variant_index", "catalog_version", "parameter_sha256")} | |
| task = task_from_row(row, model_id="google/gemma-3-1b-it") | |
| assert task.data.model_id == "google/gemma-3-1b-it" | |
| assert task.data.name.endswith("gemma-3-1b-it") | |
| with pytest.raises(ValueError, match="does not match"): | |
| task_from_row({**row, "parameter_sha256": "0" * 64}) | |
| def test_factual_pool_has_dated_provenance_and_distinct_associations(): | |
| from datetime import date | |
| from iwibench.families import _facts | |
| from iwibench.variant_pools import data_file | |
| additions = data_file("variant_facts.json") | |
| assert len(additions) == 90 | |
| original = _facts() | |
| combined = [fact for fact in original if fact["split"] == "development"] + additions | |
| assert len({fact["id"] for fact in combined}) == 100 | |
| assert len({(fact["entity"].casefold(), fact["relation"].casefold()) for fact in combined}) == 100 | |
| assert {fact["entity"] for fact in additions}.isdisjoint(fact["entity"] for fact in original if fact["split"] == "test") | |
| for fact in additions: | |
| assert fact["source_url"].startswith("https://") | |
| assert date.fromisoformat(fact["source_date"]) <= date(2026, 3, 1) | |
| assert date.fromisoformat(fact["effective_date"]) <= date(2026, 3, 1) | |
| assert fact["stale_candidates"] and fact["nearby_answers"] and fact["answers"] | |
| assert not set(fact["stale_candidates"]) & set(fact["answers"]) | |
| def test_export_roundtrip_and_no_private_payload_in_tasks(tmp_path): | |
| from importlib.util import module_from_spec, spec_from_file_location | |
| root = Path(__file__).resolve().parents[1] | |
| modules = {} | |
| for name in ("build_hf_dataset", "validate_hf_dataset"): | |
| spec = spec_from_file_location(name, root / "scripts" / f"{name}.py") | |
| module = module_from_spec(spec) | |
| spec.loader.exec_module(module) | |
| modules[name] = module | |
| manifest = modules["build_hf_dataset"].build(tmp_path) | |
| assert manifest["num_rows"] == 1000 | |
| assert manifest["shortfall"] == 0 | |
| assert manifest.get("trusted_payloads", True) is False | |
| assert not (tmp_path / "trusted").exists() | |
| assert not any(path.startswith("trusted/") for path in manifest["files"]) | |
| report = modules["validate_hf_dataset"].validate(tmp_path) | |
| assert report["rows"] == 1000 | |
| assert report["model_execution"] is False | |
| from datasets import load_dataset | |
| loaded = load_dataset("parquet", data_files={"train": str(tmp_path / "data/train.parquet")}, | |
| split="train", cache_dir=str(tmp_path / "loader_cache")) | |
| assert len(loaded) == 850 | |
| test = load_dataset("parquet", data_files={"test": str(tmp_path / "data/test.parquet")}, split="test", cache_dir=str(tmp_path / "loader_cache")) | |
| assert len(test) == 150 | |
| assert not set(loaded["id"]) & set(test["id"]) | |
| assert len(set(loaded["id"]) | set(test["id"])) == 1000 | |
| assert set(loaded["family"]) == set(AVAILABLE_FAMILIES) | |