diff --git a/tests/test_C/__pycache__/test_launch.cpython-311-pytest-9.1.1.pyc b/tests/test_C/__pycache__/test_launch.cpython-311-pytest-9.1.1.pyc index 4a7fafab7e5933b64392f4600b3db2f9e5a5c503..c13286d39e1df74505a3cce00476351e6c8ccc56 100644 Binary files a/tests/test_C/__pycache__/test_launch.cpython-311-pytest-9.1.1.pyc and b/tests/test_C/__pycache__/test_launch.cpython-311-pytest-9.1.1.pyc differ diff --git a/tests/test_C/__pycache__/test_sweep.cpython-311.pyc b/tests/test_C/__pycache__/test_sweep.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7e02a89e4a1426ca956773ae161beac402198ee5 Binary files /dev/null and b/tests/test_C/__pycache__/test_sweep.cpython-311.pyc differ diff --git a/tests/test_C/test_C.py b/tests/test_C/test_C.py new file mode 100644 index 0000000000000000000000000000000000000000..14f3b72ba8d26def86d9b63337d7e4d3e544689a --- /dev/null +++ b/tests/test_C/test_C.py @@ -0,0 +1,27 @@ +"""Tests for harness/C/__init__.py -- shared config constants.""" + +from pathlib import Path + +from harness import A, B, C + + +def test_input_selections_are_one_shared_vocabulary_with_a_and_b(): + assert B.INPUT_SELECTIONS == A.FRAME_SELECTIONS + + +def test_reuses_harness_a_model_paths_and_generation_protocol(): + assert C.MODEL_PATHS is A.MODEL_PATHS + assert C.MAX_NEW_TOKENS == A.MAX_NEW_TOKENS + assert C.DO_SAMPLE == A.DO_SAMPLE + assert C.TEMPERATURE == A.TEMPERATURE + + +def test_results_dir_defaults_under_root_results(): + assert C.RESULTS_DIR == Path("/root/results/C") + + +def test_depth_and_tracking_reuse_encoder_config_vocabulary(): + from encoder.config import DEPTH_VARIANTS, TRACKING_MODES + + assert C.DEPTH_VARIANTS == DEPTH_VARIANTS + assert C.TRACKING_MODES == TRACKING_MODES diff --git a/tests/test_C/test_overlay.py b/tests/test_C/test_overlay.py new file mode 100644 index 0000000000000000000000000000000000000000..f087058a643d116cd69ea1b72d2cc6cfb457af28 --- /dev/null +++ b/tests/test_C/test_overlay.py @@ -0,0 +1,209 @@ +"""Tests for harness/C/overlay.py -- overlay labels, cache, and stamping.""" + +import json +from pathlib import Path + +import pytest +from PIL import Image + +from harness.C import overlay + +_EXPLICIT_CODE = { + "objects": { + "chair": { + "instances": [ + { + "position": { + "x coordinate": "1.5 m", + "y coordinate": "-2 m", + "height above floor": "0.25 m", + }, + "longest dimension": "0.80 m", + } + ] + }, + "table": { + "instances": [ + { + "position": { + "x coordinate": "3 m", + "y coordinate": "4 m", + "height above floor": "0 m", + }, + "longest dimension": "1.20 m", + } + ] + }, + } +} + + +def test_instance_ids_adds_stable_one_based_labels_without_mutating_input(): + original = {"objects": {"chair": {"instances": [{"position": {}}]}}} + + labeled = overlay.instance_ids(original) + + assert labeled["objects"]["chair"]["instances"][0]["instance id"] == "chair 1" + assert "instance id" not in original["objects"]["chair"]["instances"][0] + + +def test_overlay_spatial_code_path_lives_under_overlay_root(monkeypatch, tmp_path): + monkeypatch.setattr( + overlay.encoder_config, "CODES_ROOT", tmp_path / "data" / "spatial codes" + ) + monkeypatch.setattr(overlay.encoder_config, "MODEL", "sam3+depth-anything-3") + + path = overlay.overlay_spatial_code_path( + "scene", "metric", "uniform", "tracking", 32 + ) + + assert path == ( + tmp_path + / "data" + / "spatial codes" + / "overlay" + / "sam3+depth-anything-3" + / "metric" + / "tracking" + / "uniform" + / "32" + / "explicit" + / "scene.json" + ) + + +def test_load_or_create_overlay_code_saves_missing_file(monkeypatch, tmp_path): + monkeypatch.setattr(overlay.encoder_config, "CODES_ROOT", tmp_path / "codes") + monkeypatch.setattr(overlay.encoder_config, "MODEL", "model") + + code, path = overlay.load_or_create_overlay_code( + _EXPLICIT_CODE, "scene", "metric", "uniform", "tracking", 32 + ) + + path = Path(path) + assert path.is_file() + assert json.loads(path.read_text()) == code + assert code["objects"]["chair"]["instances"][0]["instance id"] == "chair 1" + + +def test_load_or_create_overlay_code_reuses_existing_file(monkeypatch, tmp_path): + monkeypatch.setattr(overlay.encoder_config, "CODES_ROOT", tmp_path / "codes") + monkeypatch.setattr(overlay.encoder_config, "MODEL", "model") + path = overlay.overlay_spatial_code_path( + "scene", "metric", "uniform", "tracking", 32 + ) + path.parent.mkdir(parents=True) + existing = {"objects": {"saved": {"instances": []}}, "sentinel": True} + path.write_text(json.dumps(existing)) + + code, returned = overlay.load_or_create_overlay_code( + _EXPLICIT_CODE, "scene", "metric", "uniform", "tracking", 32 + ) + + assert returned == str(path) + assert code == existing + assert json.loads(path.read_text()) == existing + + +def test_label_positions_parse_meter_strings_in_code_order(): + assert overlay.label_positions(_EXPLICIT_CODE) == [ + ("chair 1", 1.5, -2.0, 0.25, 0.8), + ("table 1", 3.0, 4.0, 0.0, 1.2), + ] + + +def test_load_cached_frames_requires_complete_png_set_and_labels(tmp_path): + assert overlay._load_cached_frames(tmp_path, 2) is None + (tmp_path / "labels.json").write_text(json.dumps([["chair 1"], []])) + Image.new("RGB", (4, 4), "white").save(tmp_path / "0.png") + assert overlay._load_cached_frames(tmp_path, 2) is None + + Image.new("RGB", (4, 4), "black").save(tmp_path / "1.png") + images, visible = overlay._load_cached_frames(tmp_path, 2) + + assert [image.mode for image in images] == ["RGB", "RGB"] + assert visible == [["chair 1"], []] + + +def test_save_cached_frames_writes_pngs_and_labels(tmp_path): + frames = [Image.new("RGB", (2, 2), color) for color in ("white", "black")] + + overlay._save_cached_frames(tmp_path, frames, [["a"], ["b"]]) + + assert (tmp_path / "0.png").is_file() + assert (tmp_path / "1.png").is_file() + assert json.loads((tmp_path / "labels.json").read_text()) == [["a"], ["b"]] + + +def test_stamp_frames_uses_raw_sam3_boxes_and_does_not_mutate_inputs( + monkeypatch, tmp_path +): + monkeypatch.setattr( + overlay, "overlay_frame_cache_dir", lambda *args: tmp_path / "cache" + ) + monkeypatch.setattr( + overlay.perceive, + "cache_or_load", + lambda *args: ({"geometry": "fake"}, "cache"), + ) + monkeypatch.setattr( + overlay.gm, + "instance_source_track_ids", + lambda geometry: {"chair": [[10]], "table": [[20]]}, + ) + monkeypatch.setattr( + overlay, + "_load_raw_sam3_boxes", + lambda *args: { + "chair": {0: {10: (0.10, 0.10, 0.30, 0.30)}}, + "table": {1: {20: (0.50, 0.50, 0.25, 0.25)}}, + }, + ) + frames = [Image.new("RGB", (40, 40), "white"), Image.new("RGB", (40, 40), "white")] + before = frames[0].copy() + + stamped, visible = overlay.stamp_frames( + frames, + _EXPLICIT_CODE, + "scene", + "metric", + "uniform", + "tracking", + 2, + use_cache=True, + ) + + assert visible == [["chair 1"], ["table 1"]] + assert stamped[0].getpixel((8, 8)) != before.getpixel((8, 8)) + assert frames[0].tobytes() == before.tobytes() + cached = overlay._load_cached_frames(tmp_path / "cache", 2) + assert cached is not None + assert cached[1] == visible + + +def test_stamp_frames_serves_complete_cache_without_loading_dependencies( + monkeypatch, tmp_path +): + cache_dir = tmp_path / "cache" + overlay._save_cached_frames( + cache_dir, [Image.new("RGB", (2, 2), "red")], [["cached"]] + ) + monkeypatch.setattr(overlay, "overlay_frame_cache_dir", lambda *args: cache_dir) + monkeypatch.setattr( + overlay.perceive, + "cache_or_load", + lambda *args: pytest.fail("cache hit should not touch perception"), + ) + + stamped, visible = overlay.stamp_frames( + [Image.new("RGB", (2, 2), "white")], + {}, + "scene", + "metric", + "uniform", + "tracking", + 1, + ) + + assert visible == [["cached"]] + assert stamped[0].getpixel((0, 0)) == (255, 0, 0) diff --git a/tests/test_C/test_overlay_launch.py b/tests/test_C/test_overlay_launch.py new file mode 100644 index 0000000000000000000000000000000000000000..3b8ab35c47b74a51b9650679fd5368be8b2e3933 --- /dev/null +++ b/tests/test_C/test_overlay_launch.py @@ -0,0 +1,144 @@ +"""Tests for harness/C/overlay_launch.py -- cache pregeneration orchestration.""" + +import pytest + +from harness.C import overlay_launch + + +def test_available_cpu_count_honors_positive_environment(monkeypatch): + monkeypatch.setenv("VSI_CPU_WORKERS", "3") + assert overlay_launch._available_cpu_count() == 3 + monkeypatch.setenv("VSI_CPU_WORKERS", "0") + with pytest.raises(ValueError, match="positive"): + overlay_launch._available_cpu_count() + + +def test_has_dependencies_requires_spatial_code_and_sam3_cache(monkeypatch, tmp_path): + cache = tmp_path / "sam3.pt" + monkeypatch.setattr( + overlay_launch.spatial_codes, + "load_spatial_code", + lambda *args: ({"objects": {}}, "code.json"), + ) + monkeypatch.setattr( + "encoder.config.sam3_cache_file", + lambda *args: cache, + ) + + assert ( + overlay_launch._has_dependencies("scene", "metric", "uniform", "tracking", 32) + is False + ) + cache.write_text("cache") + assert ( + overlay_launch._has_dependencies("scene", "metric", "uniform", "tracking", 32) + is True + ) + + +def test_has_dependencies_treats_missing_code_as_ineligible(monkeypatch): + def missing(*args): + raise FileNotFoundError("missing code") + + monkeypatch.setattr(overlay_launch.spatial_codes, "load_spatial_code", missing) + assert ( + overlay_launch._has_dependencies("scene", "metric", "uniform", "tracking", 32) + is False + ) + + +def test_launch_skips_missing_and_already_cached_without_pool( + monkeypatch, tmp_path, capsys +): + monkeypatch.setattr( + overlay_launch, + "_has_dependencies", + lambda scene, *args: scene != "missing", + ) + monkeypatch.setattr( + overlay_launch.overlay, + "overlay_frame_cache_dir", + lambda scene, *args: tmp_path / scene, + ) + monkeypatch.setattr( + overlay_launch.overlay, + "_load_cached_frames", + lambda cache_dir, frame_count: ( + ([object()], [[]]) if cache_dir.name == "cached" else None + ), + ) + monkeypatch.setattr( + overlay_launch.overlay, + "overlay_spatial_code_path", + lambda scene, *args: tmp_path / scene / "overlay-code.json", + ) + (tmp_path / "cached").mkdir() + (tmp_path / "cached" / "overlay-code.json").write_text("{}") + monkeypatch.setattr( + overlay_launch.mp, + "get_context", + lambda *_: pytest.fail("no pending scenes should avoid multiprocessing"), + ) + + succeeded, failed, missing = overlay_launch.launch( + "metric", "uniform", "tracking", 32, ["missing", "cached"] + ) + + assert succeeded == [] + assert failed == [] + assert missing == ["missing"] + output = capsys.readouterr().out + assert "missing a code or SAM3 cache" in output + assert "already cached" in output + + +def test_launch_does_not_skip_frames_cache_when_overlay_code_is_missing( + monkeypatch, tmp_path +): + monkeypatch.setattr(overlay_launch, "_has_dependencies", lambda scene, *args: True) + monkeypatch.setattr( + overlay_launch.overlay, + "overlay_frame_cache_dir", + lambda scene, *args: tmp_path / scene, + ) + monkeypatch.setattr( + overlay_launch.overlay, + "_load_cached_frames", + lambda cache_dir, frame_count: ([object()], [[]]), + ) + monkeypatch.setattr( + overlay_launch.overlay, + "overlay_spatial_code_path", + lambda scene, *args: tmp_path / scene / "missing-overlay-code.json", + ) + + calls = [] + + class FakePool: + def __init__(self, workers): + self.workers = workers + + def __enter__(self): + return self + + def __exit__(self, *exc): + return False + + def map(self, fn, tasks): + calls.extend(tasks) + return [(task[0], True, None) for task in tasks] + + class FakeContext: + def Pool(self, workers): + return FakePool(workers) + + monkeypatch.setattr(overlay_launch.mp, "get_context", lambda *_: FakeContext()) + + succeeded, failed, missing = overlay_launch.launch( + "metric", "uniform", "tracking", 32, ["frames_only"], workers=1 + ) + + assert calls == [("frames_only", "metric", "uniform", "tracking", 32)] + assert succeeded == ["frames_only"] + assert failed == [] + assert missing == [] diff --git a/tests/test_C/test_prompts.py b/tests/test_C/test_prompts.py index 367d7e9fc74a647e2831cea149a9907de1b6e660..251c187f39d569f33b8a22ff771f1417e0581453 100644 --- a/tests/test_C/test_prompts.py +++ b/tests/test_C/test_prompts.py @@ -7,7 +7,10 @@ import pytest from harness.A.prompts import MCA_QUESTION_TYPES, NA_QUESTION_TYPES from harness.C import prompts as combined_prompts -_CODE = {"objects": {"chair": {"count": 1}}, "room": {"floor area": "10.0 square meters"}} +_CODE = { + "objects": {"chair": {"count": 1}}, + "room": {"floor area": "10.0 square meters"}, +} def test_pre_prompt_mentions_both_frames_and_spatial_code(): diff --git a/tests/test_C/test_run.py b/tests/test_C/test_run.py index ce07db0739edd0a2936e60dcbc9e3796e7db7bb4..ea93c4f32185eaa83d57910538521c3c41c221f0 100644 --- a/tests/test_C/test_run.py +++ b/tests/test_C/test_run.py @@ -58,22 +58,65 @@ def test_results_dir_for_matches_established_dimension_nesting(): "qwen3.5-4b", "extended", "compact", "metric", "tracking", "uniform", 32 ) assert root == ( - C.RESULTS_DIR / "qwen3.5-4b" / "extended" / "compact" / "metric" / "tracking" - / "uniform" / "32" + C.RESULTS_DIR + / "qwen3.5-4b" + / "extended" + / "compact" + / "metric" + / "tracking" + / "uniform" + / "32" ) def test_results_dir_for_honors_explicit_override(tmp_path): root = harness_run.results_dir_for( - "qwen3.5-4b", "base", "explicit", "relative", "no tracking", "selective", 16, tmp_path + "qwen3.5-4b", + "base", + "explicit", + "relative", + "no tracking", + "selective", + 16, + tmp_path, ) assert root == tmp_path +def test_results_dir_for_places_overlay_under_C_results(): + root = harness_run.results_dir_for( + "qwen3.5-4b", + "extended", + "explicit", + "metric", + "tracking", + "uniform", + 32, + overlay=True, + ) + assert root == ( + C.RESULTS_DIR + / "overlay" + / "qwen3.5-4b" + / "extended" + / "explicit" + / "metric" + / "tracking" + / "uniform" + / "32" + ) + + def test_build_record_carries_both_frame_and_spatial_code_provenance(): record = harness_run._build_record( - _FAKE_ROW, "full prompt text", _FAKE_ANSWER, "MRA:.5:.95:.05", 1.0, - "qwen3.5-4b", "/root/models/qwen3.5-4b", _FAKE_SOURCE_INFO, + _FAKE_ROW, + "full prompt text", + _FAKE_ANSWER, + "MRA:.5:.95:.05", + 1.0, + "qwen3.5-4b", + "/root/models/qwen3.5-4b", + _FAKE_SOURCE_INFO, ) # Spatial-code provenance (shared with harness.B). assert record["spatial_code_format"] == "explicit" @@ -97,14 +140,51 @@ def test_build_record_carries_both_frame_and_spatial_code_provenance(): def test_write_question_result_writes_one_json_file_per_question(tmp_path): path, record = harness_run.write_question_result( - _FAKE_ROW, "full prompt text", _FAKE_ANSWER, "MRA:.5:.95:.05", 1.0, - "qwen3.5-4b", "/root/models/qwen3.5-4b", _FAKE_SOURCE_INFO, results_dir=tmp_path, + _FAKE_ROW, + "full prompt text", + _FAKE_ANSWER, + "MRA:.5:.95:.05", + 1.0, + "qwen3.5-4b", + "/root/models/qwen3.5-4b", + _FAKE_SOURCE_INFO, + results_dir=tmp_path, ) assert path == tmp_path / "scene0001_00" / "7.json" on_disk = json.loads(path.read_text()) assert on_disk == record +def test_write_question_result_routes_overlay_default_to_overlay_tree( + tmp_path, monkeypatch +): + monkeypatch.setattr(harness_run, "RESULTS_DIR", tmp_path) + source_info = {**_FAKE_SOURCE_INFO, "overlay": True} + path, _record = harness_run.write_question_result( + _FAKE_ROW, + "full prompt text", + _FAKE_ANSWER, + "MRA:.5:.95:.05", + 1.0, + "qwen3.5-4b", + "/root/models/qwen3.5-4b", + source_info, + ) + assert path == ( + tmp_path + / "overlay" + / "qwen3.5-4b" + / "extended" + / "explicit" + / "metric" + / "tracking" + / "selective" + / "64" + / "scene0001_00" + / "7.json" + ) + + def test_build_record_carries_reasoning_fields_when_forced(): extended_answer = { **_FAKE_ANSWER, @@ -117,9 +197,17 @@ def test_build_record_carries_reasoning_fields_when_forced(): "forced_input_token_count": 22300, } record = harness_run._build_record( - _FAKE_ROW, "full prompt text", extended_answer, "MRA:.5:.95:.05", 1.0, - "qwen3.5-4b", "/root/models/qwen3.5-4b", _FAKE_SOURCE_INFO, + _FAKE_ROW, + "full prompt text", + extended_answer, + "MRA:.5:.95:.05", + 1.0, + "qwen3.5-4b", + "/root/models/qwen3.5-4b", + _FAKE_SOURCE_INFO, + ) + assert ( + record["reasoning_text"] == "long reasoning about the frames and spatial code" ) - assert record["reasoning_text"] == "long reasoning about the frames and spatial code" assert record["forced"] is True assert record["forced_input_token_count"] == 22300 diff --git a/tests/test_C/test_sweep.py b/tests/test_C/test_sweep.py index e87649c4988eb56674c0ce31ae92face890c1502..f538afe778b0d476b77b3ecb5cff84565272083e 100644 --- a/tests/test_C/test_sweep.py +++ b/tests/test_C/test_sweep.py @@ -8,8 +8,12 @@ from harness.C import sweep def test_build_plan_covers_every_combination(): plan = sweep.build_plan( - ["qwen3.5-2b", "qwen3.5-4b"], ["explicit", "compact"], ["uniform", "selective"], - [16, 32], ["metric"], ["tracking"], + ["qwen3.5-2b", "qwen3.5-4b"], + ["explicit", "compact"], + ["uniform", "selective"], + [16, 32], + ["metric"], + ["tracking"], ) assert len(plan) == 2 * 2 * 2 * 2 assert ("qwen3.5-2b", "explicit", "metric", "tracking", "uniform", 16) in plan @@ -18,8 +22,12 @@ def test_build_plan_covers_every_combination(): def test_build_plan_sweeps_depth_and_tracking_too(): plan = sweep.build_plan( - ["qwen3.5-2b"], ["explicit"], ["uniform"], [16], - ["metric", "relative"], ["tracking", "no tracking"], + ["qwen3.5-2b"], + ["explicit"], + ["uniform"], + [16], + ["metric", "relative"], + ["tracking", "no tracking"], ) assert len(plan) == 4 assert ("qwen3.5-2b", "explicit", "relative", "no tracking", "uniform", 16) in plan @@ -27,22 +35,54 @@ def test_build_plan_sweeps_depth_and_tracking_too(): def test_build_plan_orders_by_frame_count_first(): plan = sweep.build_plan( - ["qwen3.5-2b"], ["explicit"], ["uniform"], [64, 16, 32], ["metric"], ["tracking"] + ["qwen3.5-2b"], + ["explicit"], + ["uniform"], + [64, 16, 32], + ["metric"], + ["tracking"], ) assert [frame_count for *_rest, frame_count in plan] == [16, 32, 64] def test_build_plan_with_all_registered_models(): plan = sweep.build_plan( - list(vlm_models.available_models()), ["explicit"], ["uniform"], [16], - ["metric"], ["tracking"], + list(vlm_models.available_models()), + ["explicit"], + ["uniform"], + [16], + ["metric"], + ["tracking"], ) assert len(plan) == len(vlm_models.available_models()) +def test_sweep_forwards_overlay_to_each_launch(monkeypatch): + calls = [] + monkeypatch.setattr( + sweep.harness_launch, "launch", lambda *args, **kwargs: calls.append(kwargs) + ) + + sweep.sweep( + ["qwen3.5-2b"], + ["explicit"], + ["uniform"], + [32], + ["scene"], + overlay=True, + strip_schema_legend=True, + ) + + assert len(calls) == 1 + assert calls[0]["overlay"] is True + assert calls[0]["results_dir"] is None + + def test_sweep_parser_rejects_unknown_spatial_code_format(): with pytest.raises(ValueError): - sweep._parse_csv_choice("bogus", ("explicit", "compact"), "--spatial-code-formats") + sweep._parse_csv_choice( + "bogus", ("explicit", "compact"), "--spatial-code-formats" + ) def test_sweep_parser_rejects_unknown_depth(): diff --git a/tests/test_D/__pycache__/__init__.cpython-311.pyc b/tests/test_D/__pycache__/__init__.cpython-311.pyc index fe8176ad99e699005a1ce250dcfb381f9c128a0b..d3f76fa6f553a041ca01506d0994022e109f52f2 100644 Binary files a/tests/test_D/__pycache__/__init__.cpython-311.pyc and b/tests/test_D/__pycache__/__init__.cpython-311.pyc differ diff --git a/tests/test_D/__pycache__/test_D.cpython-311-pytest-9.1.1.pyc b/tests/test_D/__pycache__/test_D.cpython-311-pytest-9.1.1.pyc new file mode 100644 index 0000000000000000000000000000000000000000..521dd3b04498f70e9e1871efd55b4efc93d4e292 Binary files /dev/null and b/tests/test_D/__pycache__/test_D.cpython-311-pytest-9.1.1.pyc differ diff --git a/tests/test_D/__pycache__/test_D.cpython-311.pyc b/tests/test_D/__pycache__/test_D.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cac40bbf5ac3e25160a7c74b29bbe2fa53f22610 Binary files /dev/null and b/tests/test_D/__pycache__/test_D.cpython-311.pyc differ diff --git a/tests/test_D/__pycache__/test_init.cpython-311-pytest-9.1.1.pyc b/tests/test_D/__pycache__/test_init.cpython-311-pytest-9.1.1.pyc index ef71292e8553bd9d3fa714b9e49cb537f55135b9..f0d95be44a05c96eceaf3efa0f128bc5892e95d7 100644 Binary files a/tests/test_D/__pycache__/test_init.cpython-311-pytest-9.1.1.pyc and b/tests/test_D/__pycache__/test_init.cpython-311-pytest-9.1.1.pyc differ diff --git a/tests/test_D/__pycache__/test_init.cpython-311.pyc b/tests/test_D/__pycache__/test_init.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5245db56b376b91ffa2cb96565f8ff04e98451d7 Binary files /dev/null and b/tests/test_D/__pycache__/test_init.cpython-311.pyc differ diff --git a/tests/test_D/__pycache__/test_launch.cpython-311-pytest-9.1.1.pyc b/tests/test_D/__pycache__/test_launch.cpython-311-pytest-9.1.1.pyc index 100727b6ec2137834b060b121993222dbeb4db9c..4ee09949616463e30e8c681834b60a493608f80e 100644 Binary files a/tests/test_D/__pycache__/test_launch.cpython-311-pytest-9.1.1.pyc and b/tests/test_D/__pycache__/test_launch.cpython-311-pytest-9.1.1.pyc differ diff --git a/tests/test_D/__pycache__/test_launch.cpython-311.pyc b/tests/test_D/__pycache__/test_launch.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f5d71cae78fd8a2b36e34ded8732f64c6bc7ca8c Binary files /dev/null and b/tests/test_D/__pycache__/test_launch.cpython-311.pyc differ diff --git a/tests/test_D/__pycache__/test_prompts.cpython-311.pyc b/tests/test_D/__pycache__/test_prompts.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5a495715deaa368ae9c077aab83833ad01bdf558 Binary files /dev/null and b/tests/test_D/__pycache__/test_prompts.cpython-311.pyc differ diff --git a/tests/test_D/__pycache__/test_run.cpython-311-pytest-9.1.1.pyc b/tests/test_D/__pycache__/test_run.cpython-311-pytest-9.1.1.pyc index 5809524c51a34293525851ae9e81eeb992d33372..e917bf1629753dce3a449d94e9fcaa7a649d3be7 100644 Binary files a/tests/test_D/__pycache__/test_run.cpython-311-pytest-9.1.1.pyc and b/tests/test_D/__pycache__/test_run.cpython-311-pytest-9.1.1.pyc differ diff --git a/tests/test_D/__pycache__/test_run.cpython-311.pyc b/tests/test_D/__pycache__/test_run.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c6fc49a27d25ea35ba73b33ca50ef4503a2a3f84 Binary files /dev/null and b/tests/test_D/__pycache__/test_run.cpython-311.pyc differ diff --git a/tests/test_D/__pycache__/test_spatial_codes.cpython-311.pyc b/tests/test_D/__pycache__/test_spatial_codes.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..892da44f61f12791b26771546e4bd726a87ae0e9 Binary files /dev/null and b/tests/test_D/__pycache__/test_spatial_codes.cpython-311.pyc differ diff --git a/tests/test_D/__pycache__/test_sweep.cpython-311-pytest-9.1.1.pyc b/tests/test_D/__pycache__/test_sweep.cpython-311-pytest-9.1.1.pyc index 205bfb0b1d98baaafaa9316d212f3df03fe62c18..e230c7571bfb4eead3fea826c4ae771677dcd01f 100644 Binary files a/tests/test_D/__pycache__/test_sweep.cpython-311-pytest-9.1.1.pyc and b/tests/test_D/__pycache__/test_sweep.cpython-311-pytest-9.1.1.pyc differ diff --git a/tests/test_D/__pycache__/test_sweep.cpython-311.pyc b/tests/test_D/__pycache__/test_sweep.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..05e55b34aa8ae692d9e2d297a08c4daf4e14bf7c Binary files /dev/null and b/tests/test_D/__pycache__/test_sweep.cpython-311.pyc differ diff --git a/tests/test_D/__pycache__/test_symbolic_eval.cpython-311-pytest-9.1.1.pyc b/tests/test_D/__pycache__/test_symbolic_eval.cpython-311-pytest-9.1.1.pyc index 01cdfb40ed0a0de23c0c98cee0a7b386d6d15235..f248be596ee4bf0f2d2f32a411f40f72094afe84 100644 Binary files a/tests/test_D/__pycache__/test_symbolic_eval.cpython-311-pytest-9.1.1.pyc and b/tests/test_D/__pycache__/test_symbolic_eval.cpython-311-pytest-9.1.1.pyc differ diff --git a/tests/test_D/test_launch.py b/tests/test_D/test_launch.py index 25e7a91ef811b15b3feb778d3abf3e409f2e0e6a..08f7a5419a82b2e2be3378a1cc2dbf910f863ff8 100644 --- a/tests/test_D/test_launch.py +++ b/tests/test_D/test_launch.py @@ -1,6 +1,5 @@ """Tests for harness/D/launch.py -- multi-GPU scene sharding across workers.""" -from harness.A.run import load_questions as harness_a_load_questions from harness.D import launch @@ -8,14 +7,25 @@ def test_launcher_imports(): assert callable(launch.main) -def test_launch_skips_scene_already_fully_answered(tmp_path, capsys): - scene = "13c3e046d7" - rows = harness_a_load_questions(scene=scene) - assert rows, "fixture scene must have real questions in the VSI-Bench manifest" +class _FakeRun: + rows = [{"id": 2}, {"id": 5}] + + @staticmethod + def results_dir_for(*args, **kwargs): + return args[3] + + @classmethod + def load_questions(cls, scene=None): + return list(cls.rows) + + +def test_launch_skips_scene_already_fully_answered(tmp_path, capsys, monkeypatch): + scene = "scene-d" + monkeypatch.setattr(launch, "_load_run_module", lambda: _FakeRun) scene_dir = tmp_path / scene scene_dir.mkdir() - for row in rows: + for row in _FakeRun.rows: (scene_dir / f"{row['id']}.json").write_text("{}") launch.launch("qwen3.5-2b", "explicit", [scene], results_dir=tmp_path) @@ -26,20 +36,25 @@ def test_launch_skips_scene_already_fully_answered(tmp_path, capsys): def test_launch_rebuild_forces_pending_even_when_answered(tmp_path, monkeypatch): - scene = "13c3e046d7" - rows = harness_a_load_questions(scene=scene) + scene = "scene-d" + monkeypatch.setattr(launch, "_load_run_module", lambda: _FakeRun) scene_dir = tmp_path / scene scene_dir.mkdir() - for row in rows: + for row in _FakeRun.rows: (scene_dir / f"{row['id']}.json").write_text("{}") monkeypatch.setattr(launch, "visible_gpus", lambda: []) monkeypatch.setattr( - launch.mp, "get_context", - lambda *_: (_ for _ in ()).throw(RuntimeError("rebuild correctly reached worker dispatch")), + launch.mp, + "get_context", + lambda *_: (_ for _ in ()).throw( + RuntimeError("rebuild correctly reached worker dispatch") + ), ) try: - launch.launch("qwen3.5-2b", "explicit", [scene], results_dir=tmp_path, rebuild=True) + launch.launch( + "qwen3.5-2b", "explicit", [scene], results_dir=tmp_path, rebuild=True + ) except RuntimeError as exc: assert "rebuild correctly reached worker dispatch" in str(exc) else: @@ -47,9 +62,6 @@ def test_launch_rebuild_forces_pending_even_when_answered(tmp_path, monkeypatch) def test_scenes_is_subset_of_vsi_bench_scenes_with_ground_truth_coverage(monkeypatch): - from harness.A.launch import scenes as vsi_scenes - - all_scenes = set(vsi_scenes()) - monkeypatch.setattr(launch, "ground_truth_scenes", lambda: sorted(all_scenes)) - d_scenes = launch.scenes() - assert set(d_scenes) <= all_scenes + monkeypatch.setattr("harness.A.launch.scenes", lambda: ["a", "b", "c"]) + monkeypatch.setattr(launch, "ground_truth_scenes", lambda: ["b", "c", "z"]) + assert launch.scenes() == ["b", "c"] diff --git a/tests/test_D/test_spatial_codes.py b/tests/test_D/test_spatial_codes.py index 222a89376708db874c1e2c03ca531c779dc975bf..7bfe4b9759c034727417933f4d25e97c96c4e15a 100644 --- a/tests/test_D/test_spatial_codes.py +++ b/tests/test_D/test_spatial_codes.py @@ -14,7 +14,9 @@ def test_load_spatial_code_rejects_unknown_format(): def test_load_spatial_code_raises_clearly_when_missing(tmp_path, monkeypatch): monkeypatch.setattr( - spatial_codes, "ground_truth_spatial_code_path", lambda *a, **k: str(tmp_path / "missing.json") + spatial_codes, + "ground_truth_spatial_code_path", + lambda *a, **k: str(tmp_path / "missing.json"), ) with pytest.raises(FileNotFoundError): spatial_codes.load_spatial_code("scene", "explicit") diff --git a/tests/test_E/__pycache__/__init__.cpython-311.pyc b/tests/test_E/__pycache__/__init__.cpython-311.pyc index 89affc54858b74ee0eb2019caf0101ea20804d5f..9717512241afca94b2de8d794ce03963d40b7049 100644 Binary files a/tests/test_E/__pycache__/__init__.cpython-311.pyc and b/tests/test_E/__pycache__/__init__.cpython-311.pyc differ diff --git a/tests/test_E/__pycache__/test_E.cpython-311-pytest-9.1.1.pyc b/tests/test_E/__pycache__/test_E.cpython-311-pytest-9.1.1.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8fe916aa44e30e66c800a0501af1ee551844687b Binary files /dev/null and b/tests/test_E/__pycache__/test_E.cpython-311-pytest-9.1.1.pyc differ diff --git a/tests/test_E/__pycache__/test_prompts.cpython-311-pytest-9.1.1.pyc b/tests/test_E/__pycache__/test_prompts.cpython-311-pytest-9.1.1.pyc index 3fd31ff84300530b08626f832f85d76eb93461aa..5890c9eaa3efd4b1e480476ae249f87856c4c115 100644 Binary files a/tests/test_E/__pycache__/test_prompts.cpython-311-pytest-9.1.1.pyc and b/tests/test_E/__pycache__/test_prompts.cpython-311-pytest-9.1.1.pyc differ diff --git a/tests/test_calibration/__pycache__/test_report.cpython-311.pyc b/tests/test_calibration/__pycache__/test_report.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5bbf4c3af6853e4f6ce5bd684da583a32ac2f5c8 Binary files /dev/null and b/tests/test_calibration/__pycache__/test_report.cpython-311.pyc differ diff --git a/tests/test_calibration/__pycache__/test_run.cpython-311.pyc b/tests/test_calibration/__pycache__/test_run.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8ccca06fae66fda4649ff398091a4a1e5eae7b35 Binary files /dev/null and b/tests/test_calibration/__pycache__/test_run.cpython-311.pyc differ diff --git a/tests/test_calibration/conftest.py b/tests/test_calibration/conftest.py new file mode 100644 index 0000000000000000000000000000000000000000..8a801f94b60da603c80287f186e31c5d32012e99 --- /dev/null +++ b/tests/test_calibration/conftest.py @@ -0,0 +1,12 @@ +"""Shared import setup for this test package.""" + +from pathlib import Path +import sys + +ROOT = Path(__file__).resolve().parents[2] +if str(ROOT) not in sys.path: + sys.path.insert(0, str(ROOT)) + + +def pytest_configure(config): + config.option.importmode = "importlib" diff --git a/tests/test_calibration/test_calibration.py b/tests/test_calibration/test_calibration.py new file mode 100644 index 0000000000000000000000000000000000000000..0f8fa86b6a7f93f7661ae8fb9965fda2e4ec4b44 --- /dev/null +++ b/tests/test_calibration/test_calibration.py @@ -0,0 +1,18 @@ +"""Tests for calibration package configuration.""" + +import importlib +from pathlib import Path + +import calibration + + +def test_results_dir_defaults_to_root_results(): + assert calibration.RESULTS_DIR == Path("/root/results/calibration") + + +def test_results_dir_can_be_overridden_by_environment(monkeypatch, tmp_path): + monkeypatch.setenv("VSI_CALIBRATION_RESULTS_DIR", str(tmp_path / "calibration")) + reloaded = importlib.reload(calibration) + assert reloaded.RESULTS_DIR == tmp_path / "calibration" + monkeypatch.delenv("VSI_CALIBRATION_RESULTS_DIR") + importlib.reload(calibration) diff --git a/tests/test_calibration/test_run.py b/tests/test_calibration/test_run.py index 2f064fc43f67a8cb778b2d5040d84fdbe589a118..66087deeeb524fc8d8e1a2d80577eaae36ab2d73 100644 --- a/tests/test_calibration/test_run.py +++ b/tests/test_calibration/test_run.py @@ -9,8 +9,13 @@ def test_results_dir_isolates_every_pilot_axis(): base = ("qwen3.5-4b", "explicit", "metric", "tracking", "selective", 32, 512) variants = {calibration_run.results_dir_for(*base)} for index, value in [ - (0, "qwen3.5-2b"), (1, "compact"), (2, "relative"), (3, "no tracking"), - (4, "uniform"), (5, 64), (6, 1024), + (0, "qwen3.5-2b"), + (1, "compact"), + (2, "relative"), + (3, "no tracking"), + (4, "uniform"), + (5, 64), + (6, 1024), ]: changed = list(base) changed[index] = value @@ -39,18 +44,32 @@ def test_run_grid_passes_budget_questions_and_isolated_dir(monkeypatch): launched = [] monkeypatch.setattr(calibration_run, "scenes_for", lambda ids: ["scene_a"]) monkeypatch.setattr( - calibration_run.harness_b_launch, "launch", + calibration_run.harness_b_launch, + "launch", lambda model, fmt, sel, frames, scenes, **kwargs: launched.append( - (model, fmt, kwargs["reasoning_budget"], str(kwargs["results_dir"]), - kwargs["question_ids"], scenes) + ( + model, + fmt, + kwargs["reasoning_budget"], + str(kwargs["results_dir"]), + kwargs["question_ids"], + scenes, + ) ), ) calibration_run.run_grid( - ["qwen3.5-2b"], [256, 512], [1, 2], "compact", - "metric", "tracking", "selective", 64, + ["qwen3.5-2b"], + [256, 512], + [1, 2], + "compact", + "metric", + "tracking", + "selective", + 64, ) assert [(m, f, b) for m, f, b, _, _, _ in launched] == [ - ("qwen3.5-2b", "compact", 256), ("qwen3.5-2b", "compact", 512), + ("qwen3.5-2b", "compact", 256), + ("qwen3.5-2b", "compact", 512), ] assert launched[0][3] != launched[1][3] assert launched[0][4] == {1, 2} @@ -60,9 +79,23 @@ def test_run_grid_passes_budget_questions_and_isolated_dir(monkeypatch): def test_cli_requires_exactly_one_question_source(monkeypatch, capsys): monkeypatch.setattr( "sys.argv", - ["run", "--models", "qwen3.5-2b", "--budgets", "256", - "--spatial-code-format", "explicit", "--depth", "metric", - "--tracking", "tracking", "--input-selection", "selective", "--frames", "32"], + [ + "run", + "--models", + "qwen3.5-2b", + "--budgets", + "256", + "--spatial-code-format", + "explicit", + "--depth", + "metric", + "--tracking", + "tracking", + "--input-selection", + "selective", + "--frames", + "32", + ], ) with pytest.raises(SystemExit): calibration_run.main() @@ -72,9 +105,25 @@ def test_cli_requires_exactly_one_question_source(monkeypatch, capsys): def test_cli_rejects_nonpositive_budget(monkeypatch, capsys): monkeypatch.setattr( "sys.argv", - ["run", "--models", "qwen3.5-2b", "--budgets", "0", "--questions", "1", - "--spatial-code-format", "explicit", "--depth", "metric", - "--tracking", "tracking", "--input-selection", "selective", "--frames", "32"], + [ + "run", + "--models", + "qwen3.5-2b", + "--budgets", + "0", + "--questions", + "1", + "--spatial-code-format", + "explicit", + "--depth", + "metric", + "--tracking", + "tracking", + "--input-selection", + "selective", + "--frames", + "32", + ], ) with pytest.raises(SystemExit): calibration_run.main() diff --git a/tests/test_corruption/__pycache__/test_chimera.cpython-311.pyc b/tests/test_corruption/__pycache__/test_chimera.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d53ce6474de1f189afa3a24096fac001500946bb Binary files /dev/null and b/tests/test_corruption/__pycache__/test_chimera.cpython-311.pyc differ diff --git a/tests/test_corruption/__pycache__/test_empirical.cpython-311.pyc b/tests/test_corruption/__pycache__/test_empirical.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7e0bd863da5c15e146b1acba2bbc6b063a514c1b Binary files /dev/null and b/tests/test_corruption/__pycache__/test_empirical.cpython-311.pyc differ diff --git a/tests/test_corruption/__pycache__/test_launch.cpython-311-pytest-9.1.1.pyc b/tests/test_corruption/__pycache__/test_launch.cpython-311-pytest-9.1.1.pyc index 1b52b5a9873fee12b0565285a8043213d4cb4f56..13265c96fae5a8942bb802aff1420d28f3edc4da 100644 Binary files a/tests/test_corruption/__pycache__/test_launch.cpython-311-pytest-9.1.1.pyc and b/tests/test_corruption/__pycache__/test_launch.cpython-311-pytest-9.1.1.pyc differ diff --git a/tests/test_corruption/__pycache__/test_launch.cpython-311.pyc b/tests/test_corruption/__pycache__/test_launch.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..335f0f454ad78c8f3a96f40b3f05d26b774e9b23 Binary files /dev/null and b/tests/test_corruption/__pycache__/test_launch.cpython-311.pyc differ diff --git a/tests/test_corruption/__pycache__/test_run.cpython-311.pyc b/tests/test_corruption/__pycache__/test_run.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..26c6628c75a144f8c713db143469d5d7e6799be2 Binary files /dev/null and b/tests/test_corruption/__pycache__/test_run.cpython-311.pyc differ diff --git a/tests/test_corruption/__pycache__/test_sample.cpython-311-pytest-9.1.1.pyc b/tests/test_corruption/__pycache__/test_sample.cpython-311-pytest-9.1.1.pyc index 1a9200f188ef605caf51653aeba42ed5a296525d..bc90298942fe97b38d22eec8514d64c9d3a33941 100644 Binary files a/tests/test_corruption/__pycache__/test_sample.cpython-311-pytest-9.1.1.pyc and b/tests/test_corruption/__pycache__/test_sample.cpython-311-pytest-9.1.1.pyc differ diff --git a/tests/test_corruption/__pycache__/test_sample.cpython-311.pyc b/tests/test_corruption/__pycache__/test_sample.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..092c06a69ba68b9b809b7218b620a93518fba77f Binary files /dev/null and b/tests/test_corruption/__pycache__/test_sample.cpython-311.pyc differ diff --git a/tests/test_corruption/__pycache__/test_transforms.cpython-311-pytest-9.1.1.pyc b/tests/test_corruption/__pycache__/test_transforms.cpython-311-pytest-9.1.1.pyc index 68ed29127e1db6d227ca60ddb722578eccb4b977..b9cfe69f8308ecb5b50d5d8936a41788ebdcf0cc 100644 Binary files a/tests/test_corruption/__pycache__/test_transforms.cpython-311-pytest-9.1.1.pyc and b/tests/test_corruption/__pycache__/test_transforms.cpython-311-pytest-9.1.1.pyc differ diff --git a/tests/test_corruption/__pycache__/test_transforms.cpython-311.pyc b/tests/test_corruption/__pycache__/test_transforms.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2d7bb5413f5528caf424610912a8b0e2ec959353 Binary files /dev/null and b/tests/test_corruption/__pycache__/test_transforms.cpython-311.pyc differ diff --git a/tests/test_corruption/conftest.py b/tests/test_corruption/conftest.py new file mode 100644 index 0000000000000000000000000000000000000000..8a801f94b60da603c80287f186e31c5d32012e99 --- /dev/null +++ b/tests/test_corruption/conftest.py @@ -0,0 +1,12 @@ +"""Shared import setup for this test package.""" + +from pathlib import Path +import sys + +ROOT = Path(__file__).resolve().parents[2] +if str(ROOT) not in sys.path: + sys.path.insert(0, str(ROOT)) + + +def pytest_configure(config): + config.option.importmode = "importlib" diff --git a/tests/test_corruption/test_chimera.py b/tests/test_corruption/test_chimera.py index 6b39f387c9a1495fa01250baa3e3df17dea43e4d..6cab03969a07548dd79096173bc70a44cc6128f0 100644 --- a/tests/test_corruption/test_chimera.py +++ b/tests/test_corruption/test_chimera.py @@ -11,7 +11,9 @@ def _instance(x, y, dims=(1.0, 1.0, 1.0), time=0.0): "3D oriented bounding box center coordinates": [x, y, 0.5], "3D oriented bounding box dimensions": list(dims), "3D oriented bounding box orientation unit vectors": [ - [1.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, -1.0, 0.0], + [1.0, 0.0, 0.0], + [0.0, 0.0, 1.0], + [0.0, -1.0, 0.0], ], }, "first visible time": time, @@ -19,7 +21,11 @@ def _instance(x, y, dims=(1.0, 1.0, 1.0), time=0.0): def _code(objects): - return {"spatial code schema": {}, "objects": objects, "room": {"floor boundary polygons": []}} + return { + "spatial code schema": {}, + "objects": objects, + "room": {"floor boundary polygons": []}, + } def test_gt_inventory_keeps_gt_counts_but_takes_perceived_boxes(): @@ -39,7 +45,10 @@ def test_gt_inventory_keeps_gt_counts_but_takes_perceived_boxes(): def test_perceived_inventory_keeps_perceived_counts_but_takes_gt_boxes(): gt = _code({"chair": [_instance(0.0, 0.0, dims=(2.0, 2.0, 2.0))]}) perceived = _code( - {"chair": [_instance(0.4, 0.0), _instance(8.0, 8.0)], "ghost": [_instance(1.0, 1.0)]} + { + "chair": [_instance(0.4, 0.0), _instance(8.0, 8.0)], + "ghost": [_instance(1.0, 1.0)], + } ) hybrid, coverage = chimera.perceived_inventory_gt_geometry(gt, perceived) # Perceived inventory preserved: 2 chairs + the hallucinated "ghost" class. @@ -65,7 +74,10 @@ def test_chimeras_do_not_mutate_inputs(): def test_perturb_single_object_changes_exactly_one_instance(): code = _code( - {"chair": [_instance(0.0, 0.0), _instance(5.0, 5.0)], "table": [_instance(2.0, 2.0)]} + { + "chair": [_instance(0.0, 0.0), _instance(5.0, 5.0)], + "table": [_instance(2.0, 2.0)], + } ) out, info = chimera.perturb_single_object(code, random.Random(0)) changed = 0 diff --git a/tests/test_corruption/test_corruption.py b/tests/test_corruption/test_corruption.py new file mode 100644 index 0000000000000000000000000000000000000000..55573a76f5e670440ec7182c5b89deb5af998d94 --- /dev/null +++ b/tests/test_corruption/test_corruption.py @@ -0,0 +1,19 @@ +"""Tests for corruption package configuration.""" + +import importlib +from pathlib import Path + +import corruption + + +def test_corruption_defaults_are_explicit(): + assert corruption.RESULTS_DIR == Path("/root/results/corruption") + assert corruption.SAMPLE_SEED == 20260725 + + +def test_results_dir_can_be_overridden_by_environment(monkeypatch, tmp_path): + monkeypatch.setenv("VSI_CORRUPTION_RESULTS_DIR", str(tmp_path / "corruption")) + reloaded = importlib.reload(corruption) + assert reloaded.RESULTS_DIR == tmp_path / "corruption" + monkeypatch.delenv("VSI_CORRUPTION_RESULTS_DIR") + importlib.reload(corruption) diff --git a/tests/test_corruption/test_empirical.py b/tests/test_corruption/test_empirical.py index a04a6f24de22c0f9b2b740b7aa48e1db5e1011b0..b8526352da1210c304cd6ba81a358790f115441f 100644 --- a/tests/test_corruption/test_empirical.py +++ b/tests/test_corruption/test_empirical.py @@ -11,7 +11,9 @@ def _instance(x, y, dims=(1.0, 1.0, 1.0)): "3D oriented bounding box center coordinates": [x, y, 0.5], "3D oriented bounding box dimensions": list(dims), "3D oriented bounding box orientation unit vectors": [ - [1.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, -1.0, 0.0], + [1.0, 0.0, 0.0], + [0.0, 0.0, 1.0], + [0.0, -1.0, 0.0], ], }, "first visible time": 0.0, @@ -19,15 +21,21 @@ def _instance(x, y, dims=(1.0, 1.0, 1.0)): def _code(objects): - return {"spatial code schema": {}, "objects": objects, "room": {"floor boundary polygons": []}} + return { + "spatial code schema": {}, + "objects": objects, + "room": {"floor boundary polygons": []}, + } def test_measure_residuals_matches_missed_and_hallucinated(): gt = _code({"chair": [_instance(0.0, 0.0), _instance(5.0, 5.0)]}) - perceived = _code({"chair": [_instance(0.5, 0.0)], "phantom": [_instance(9.0, 9.0)]}) + perceived = _code( + {"chair": [_instance(0.5, 0.0)], "phantom": [_instance(9.0, 9.0)]} + ) residuals = empirical.measure_residuals([(perceived, gt)]) assert residuals["matched"] == 1 - assert residuals["missed"] == 1 # second GT chair unmatched + assert residuals["missed"] == 1 # second GT chair unmatched assert residuals["hallucinated"] == 1 # the phantom class assert residuals["miss_rate"] == 0.5 assert residuals["position_residuals"] == [[0.5, 0.0, 0.0]] @@ -45,8 +53,11 @@ def test_empirical_noise_at_zero_scale_is_identity(): residuals = { "position_residuals": [[0.5, 0.5, 0.0]], "dimension_ratios": [[2.0, 2.0, 2.0]], - "matched": 1, "missed": 1, "hallucinated": 1, - "miss_rate": 0.5, "hallucination_rate": 0.5, + "matched": 1, + "missed": 1, + "hallucinated": 1, + "miss_rate": 0.5, + "hallucination_rate": 0.5, } out = empirical.empirical_noise(code, residuals, random.Random(0), scale=0.0) assert out == code @@ -57,8 +68,11 @@ def test_empirical_noise_applies_sampled_residuals(): residuals = { "position_residuals": [[0.5, -0.5, 0.0]], "dimension_ratios": [[2.0, 1.0, 1.0]], - "matched": 1, "missed": 0, "hallucinated": 0, - "miss_rate": 0.0, "hallucination_rate": 0.0, + "matched": 1, + "missed": 0, + "hallucinated": 0, + "miss_rate": 0.0, + "hallucination_rate": 0.0, } out = empirical.empirical_noise(code, residuals, random.Random(0), scale=1.0) box = out["objects"]["chair"][0]["3D oriented bounding box"] @@ -71,8 +85,11 @@ def test_empirical_noise_is_reproducible(): residuals = { "position_residuals": [[0.5, 0.0, 0.0], [-0.2, 0.1, 0.0]], "dimension_ratios": [[1.1, 0.9, 1.0]], - "matched": 2, "missed": 1, "hallucinated": 1, - "miss_rate": 0.3, "hallucination_rate": 0.3, + "matched": 2, + "missed": 1, + "hallucinated": 1, + "miss_rate": 0.3, + "hallucination_rate": 0.3, } first = empirical.empirical_noise(code, residuals, random.Random(7)) second = empirical.empirical_noise(code, residuals, random.Random(7)) diff --git a/tests/test_corruption/test_launch.py b/tests/test_corruption/test_launch.py index 1016a9469dffdeb36be060fc8b24d87a7bb01c6c..4bba8040e41bf38050f554ac2db568b814715e9d 100644 --- a/tests/test_corruption/test_launch.py +++ b/tests/test_corruption/test_launch.py @@ -12,7 +12,15 @@ def test_launch_imports(): def test_launch_rejects_unknown_transform(monkeypatch, capsys): monkeypatch.setattr( "sys.argv", - ["launch", "--transforms", "not-a-transform", "--magnitudes", "0.5", "--arm", "solver"], + [ + "launch", + "--transforms", + "not-a-transform", + "--magnitudes", + "0.5", + "--arm", + "solver", + ], ) with pytest.raises(SystemExit): launch.main() @@ -32,17 +40,29 @@ def test_launch_vlm_arm_requires_models(monkeypatch, capsys): def test_launch_runs_the_full_grid_through_run_solver(monkeypatch): conditions = [] monkeypatch.setattr( - launch, "run_solver", - lambda transform, magnitude, fmt, **kwargs: conditions.append((transform, magnitude)) or [], + launch, + "run_solver", + lambda transform, magnitude, fmt, **kwargs: conditions.append( + (transform, magnitude) + ) + or [], ) monkeypatch.setattr( "sys.argv", [ - "launch", "--arm", "solver", - "--transforms", "translate,rotate-z", "--magnitudes", "10,90", + "launch", + "--arm", + "solver", + "--transforms", + "translate,rotate-z", + "--magnitudes", + "10,90", ], ) launch.main() assert conditions == [ - ("translate", 10.0), ("translate", 90.0), ("rotate-z", 10.0), ("rotate-z", 90.0), + ("translate", 10.0), + ("translate", 90.0), + ("rotate-z", 10.0), + ("rotate-z", 90.0), ] diff --git a/tests/test_corruption/test_run.py b/tests/test_corruption/test_run.py index b0ed152b22354e1942f148eeaf6dba6a79b71ce3..cefe176074934ca4f277145341195a5536504835 100644 --- a/tests/test_corruption/test_run.py +++ b/tests/test_corruption/test_run.py @@ -1,14 +1,83 @@ -"""Tests for corruption/run.py -- condition orchestration, determinism, and the -certification gate, against real on-disk ground-truth codes.""" +"""Tests for corruption/run.py -- condition orchestration, determinism, and certification.""" + +import copy import pytest from corruption import run as corruption_run +from encoder.geometric import _explicit_from_compact _SCENE = "13c3e046d7" _OTHER_SCENE = "09c1414f1b" +def _box(x, y, z=0.5, dims=(1.0, 1.0, 1.0)): + return { + "3D oriented bounding box center coordinates": [x, y, z], + "3D oriented bounding box dimensions": list(dims), + "3D oriented bounding box orientation unit vectors": [ + [1.0, 0.0, 0.0], + [0.0, 1.0, 0.0], + [0.0, 0.0, 1.0], + ], + } + + +def _compact(offset=0.0): + return { + "spatial code schema": {}, + "objects": { + "chair": [ + { + "3D oriented bounding box": _box(offset, 0.0), + "first visible time": 0.0, + } + ], + "table": [ + { + "3D oriented bounding box": _box(offset + 3.0, 0.0), + "first visible time": 1.0, + } + ], + }, + "room": { + "floor boundary polygons": [ + { + "outer boundary coordinates": [ + [-2.0, -2.0], + [5.0, -2.0], + [5.0, 2.0], + [-2.0, 2.0], + ], + "interior hole boundary coordinates": [], + } + ] + }, + } + + +@pytest.fixture(autouse=True) +def self_contained_ground_truth(monkeypatch): + codes = {_SCENE: _compact(), _OTHER_SCENE: _compact(offset=10.0)} + + def load_compact(scene): + return copy.deepcopy(codes[scene]) + + def load_spatial_code(scene, spatial_code_format): + compact = load_compact(scene) + if spatial_code_format == "compact": + return compact, f"/fixture/{scene}.json" + if spatial_code_format == "explicit": + explicit, _floor_area = _explicit_from_compact(compact) + return explicit, f"/fixture/{scene}.json" + raise ValueError(spatial_code_format) + + monkeypatch.setattr(corruption_run, "load_ground_truth_compact", load_compact) + monkeypatch.setattr( + corruption_run.gt_spatial_codes, "load_spatial_code", load_spatial_code + ) + + def test_seed_is_deterministic_and_condition_specific(): first = corruption_run._seed_for(_SCENE, "position-jitter", 0.25) second = corruption_run._seed_for(_SCENE, "position-jitter", 0.25) @@ -25,7 +94,9 @@ def test_corrupted_code_is_reproducible(): def test_corrupted_explicit_is_derived_from_the_corrupted_compact(): compact = corruption_run.corrupted_code(_SCENE, "position-jitter", 0.25, "compact") - explicit = corruption_run.corrupted_code(_SCENE, "position-jitter", 0.25, "explicit") + explicit = corruption_run.corrupted_code( + _SCENE, "position-jitter", 0.25, "explicit" + ) # Same corruption seed -> the explicit code's per-class counts must match the # corrupted compact's own instance counts (consistency-by-construction). for class_name, items in compact["objects"].items(): @@ -120,7 +191,9 @@ def test_run_solver_respects_the_question_sample(tmp_path): def test_make_code_transform_ignores_the_loaded_code(): hook = corruption_run.make_code_transform("position-jitter", 0.25) out = hook({"not": "used"}, _SCENE, "compact") - assert out == corruption_run.corrupted_code(_SCENE, "position-jitter", 0.25, "compact") + assert out == corruption_run.corrupted_code( + _SCENE, "position-jitter", 0.25, "compact" + ) def test_single_object_info_is_deterministic_and_recomputable(): @@ -141,5 +214,7 @@ def test_single_object_solver_run_writes_perturbation_sidecar(tmp_path): def test_non_probe_runs_write_no_sidecar(tmp_path): - corruption_run.run_solver("position-jitter", 0.0, scenes=[_SCENE], results_dir=tmp_path) + corruption_run.run_solver( + "position-jitter", 0.0, scenes=[_SCENE], results_dir=tmp_path + ) assert not (tmp_path / _SCENE / "_perturbation.json").exists() diff --git a/tests/test_corruption/test_sample.py b/tests/test_corruption/test_sample.py index ae5ffaa2cdb30d911001aebde455f3cc1b1c7db3..848798e3df29196319e8c19c86cf3a856165ca0a 100644 --- a/tests/test_corruption/test_sample.py +++ b/tests/test_corruption/test_sample.py @@ -8,8 +8,14 @@ def _rows(monkeypatch, rows): def test_budget_key_pools_direction_subtypes(): - assert corruption_sample._budget_key("object_rel_direction_easy") == "object_rel_direction" - assert corruption_sample._budget_key("object_rel_direction_hard") == "object_rel_direction" + assert ( + corruption_sample._budget_key("object_rel_direction_easy") + == "object_rel_direction" + ) + assert ( + corruption_sample._budget_key("object_rel_direction_hard") + == "object_rel_direction" + ) assert corruption_sample._budget_key("object_counting") == "object_counting" @@ -29,7 +35,11 @@ def test_draw_sample_is_deterministic_for_the_frozen_seed(monkeypatch): def test_draw_sample_spreads_across_scenes_round_robin(monkeypatch): # 5 scenes x 10 questions each; a 5-question budget must touch 5 DISTINCT scenes. rows = [ - {"id": scene * 100 + i, "scene_name": f"scene{scene}", "question_type": "object_counting"} + { + "id": scene * 100 + i, + "scene_name": f"scene{scene}", + "question_type": "object_counting", + } for scene in range(5) for i in range(10) ] @@ -46,7 +56,9 @@ def test_draw_sample_excludes_unlisted_categories_and_scenes(monkeypatch): {"id": 3, "scene_name": "scene_out", "question_type": "object_counting"}, ] _rows(monkeypatch, rows) - sampled = corruption_sample.draw_sample({"scene_in"}, budgets={"object_counting": 10}) + sampled = corruption_sample.draw_sample( + {"scene_in"}, budgets={"object_counting": 10} + ) assert sampled == [1] diff --git a/tests/test_corruption/test_transforms.py b/tests/test_corruption/test_transforms.py index 0538ce176cc851bfa8885efefd4b759e3e97423f..6c9a0280d77967bf4b6f72d835160b1fc9c07650 100644 --- a/tests/test_corruption/test_transforms.py +++ b/tests/test_corruption/test_transforms.py @@ -15,11 +15,15 @@ def _compact(classes=("chair", "table"), instances_per_class=2): { "3D oriented bounding box": { "3D oriented bounding box center coordinates": [ - float(class_index), float(index), 0.5, + float(class_index), + float(index), + 0.5, ], "3D oriented bounding box dimensions": [1.0, 2.0, 0.5], "3D oriented bounding box orientation unit vectors": [ - [1.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, -1.0, 0.0], + [1.0, 0.0, 0.0], + [0.0, 0.0, 1.0], + [0.0, -1.0, 0.0], ], }, "first visible time": float(index), @@ -31,7 +35,14 @@ def _compact(classes=("chair", "table"), instances_per_class=2): "objects": objects, "room": { "floor boundary polygons": [ - {"outer boundary coordinates": [[0.0, 0.0], [4.0, 0.0], [4.0, 4.0], [0.0, 4.0]]} + { + "outer boundary coordinates": [ + [0.0, 0.0], + [4.0, 0.0], + [4.0, 4.0], + [0.0, 4.0], + ] + } ] }, } @@ -68,7 +79,9 @@ def test_dimension_noise_never_collapses_a_dimension(): code = _compact() out = transforms.dimension_noise(code, 5.0, random.Random(0)) for _name, instance in transforms._instances(out): - for value in instance["3D oriented bounding box"]["3D oriented bounding box dimensions"]: + for value in instance["3D oriented bounding box"][ + "3D oriented bounding box dimensions" + ]: assert value > 0.0 @@ -96,7 +109,9 @@ def test_class_swap_keeps_geometry_but_relabels(): out = transforms.class_swap(code, 1.0, random.Random(0)) # Same set of class names, same total geometry, but at least one class's items moved. assert sorted(out["objects"]) == sorted(code["objects"]) - assert any(out["objects"][name] != code["objects"][name] for name in code["objects"]) + assert any( + out["objects"][name] != code["objects"][name] for name in code["objects"] + ) def test_translate_shifts_centers_and_polygons_together(): @@ -107,7 +122,9 @@ def test_translate_shifts_centers_and_polygons_together(): ] assert center[:2] == [10.0, 10.0] assert center[2] == 0.5 # height untouched - assert out["room"]["floor boundary polygons"][0]["outer boundary coordinates"][0] == [10.0, 10.0] + assert out["room"]["floor boundary polygons"][0]["outer boundary coordinates"][ + 0 + ] == [10.0, 10.0] def test_rotate_z_preserves_pairwise_distances(): @@ -116,16 +133,21 @@ def test_rotate_z_preserves_pairwise_distances(): def centers(c): return [ - instance["3D oriented bounding box"]["3D oriented bounding box center coordinates"] + instance["3D oriented bounding box"][ + "3D oriented bounding box center coordinates" + ] for _name, instance in transforms._instances(c) ] before, after = centers(code), centers(out) for i in range(len(before)): for j in range(i + 1, len(before)): - assert math.dist(before[i], before[j]) == round( - math.dist(after[i], after[j]), 10 - ) or abs(math.dist(before[i], before[j]) - math.dist(after[i], after[j])) < 0.05 + assert ( + math.dist(before[i], before[j]) + == round(math.dist(after[i], after[j]), 10) + or abs(math.dist(before[i], before[j]) - math.dist(after[i], after[j])) + < 0.05 + ) def test_reorder_changes_only_order(): @@ -133,7 +155,9 @@ def test_reorder_changes_only_order(): out = transforms.reorder(code, None, random.Random(3)) assert sorted(out["objects"]) == sorted(code["objects"]) for name in code["objects"]: - assert sorted(map(str, out["objects"][name])) == sorted(map(str, code["objects"][name])) + assert sorted(map(str, out["objects"][name])) == sorted( + map(str, code["objects"][name]) + ) def test_round_precision_rounds_every_geometry_value(): diff --git a/tests/test_encoder/__pycache__/conftest.cpython-311.pyc b/tests/test_encoder/__pycache__/conftest.cpython-311.pyc index 73be4d983113a2ee604b0c36822015e1e659c406..43262b8b18de5d6e14428502349b787aa8b3861d 100644 Binary files a/tests/test_encoder/__pycache__/conftest.cpython-311.pyc and b/tests/test_encoder/__pycache__/conftest.cpython-311.pyc differ diff --git a/tests/test_encoder/__pycache__/test_adapters.cpython-311-pytest-9.1.1.pyc b/tests/test_encoder/__pycache__/test_adapters.cpython-311-pytest-9.1.1.pyc index 57b1480b2d9fbd599c0d03afb34b26b148db1212..e64a6a07975a33bc55a693435370f0bcbbe7e045 100644 Binary files a/tests/test_encoder/__pycache__/test_adapters.cpython-311-pytest-9.1.1.pyc and b/tests/test_encoder/__pycache__/test_adapters.cpython-311-pytest-9.1.1.pyc differ diff --git a/tests/test_encoder/__pycache__/test_adapters.cpython-311.pyc b/tests/test_encoder/__pycache__/test_adapters.cpython-311.pyc index 70e1d7e26f9dd2e0bc5cd5b234c240f85f097ad9..c9e57c3ebf5d28c41839fe6948c7a996a02e1fdf 100644 Binary files a/tests/test_encoder/__pycache__/test_adapters.cpython-311.pyc and b/tests/test_encoder/__pycache__/test_adapters.cpython-311.pyc differ diff --git a/tests/test_encoder/__pycache__/test_config.cpython-311-pytest-9.1.1.pyc b/tests/test_encoder/__pycache__/test_config.cpython-311-pytest-9.1.1.pyc index 2d0017eb83f53ff23e192789a73bc56ec763033f..d6922033e85831fec1416b0a30c2c44d745bc819 100644 Binary files a/tests/test_encoder/__pycache__/test_config.cpython-311-pytest-9.1.1.pyc and b/tests/test_encoder/__pycache__/test_config.cpython-311-pytest-9.1.1.pyc differ diff --git a/tests/test_encoder/__pycache__/test_config.cpython-311.pyc b/tests/test_encoder/__pycache__/test_config.cpython-311.pyc index 330987414e10db54c6ee0674583ef89f5551c791..9dfb374389146890c0d404c14a3fd1e6f9966720 100644 Binary files a/tests/test_encoder/__pycache__/test_config.cpython-311.pyc and b/tests/test_encoder/__pycache__/test_config.cpython-311.pyc differ diff --git a/tests/test_encoder/__pycache__/test_geometric.cpython-311-pytest-9.1.1.pyc b/tests/test_encoder/__pycache__/test_geometric.cpython-311-pytest-9.1.1.pyc index 23c0844c467858d1529e991be01d873ed60f65ad..9d226196eb2bb8707a6de5361bf7ea56a303b7e0 100644 Binary files a/tests/test_encoder/__pycache__/test_geometric.cpython-311-pytest-9.1.1.pyc and b/tests/test_encoder/__pycache__/test_geometric.cpython-311-pytest-9.1.1.pyc differ diff --git a/tests/test_encoder/__pycache__/test_ground_truth.cpython-311-pytest-9.1.1.pyc b/tests/test_encoder/__pycache__/test_ground_truth.cpython-311-pytest-9.1.1.pyc index 79f9543abb9b665353f5c6ee51198db68661f9c8..8958068ecd698addca05efa7a8035f3db1c2fb92 100644 Binary files a/tests/test_encoder/__pycache__/test_ground_truth.cpython-311-pytest-9.1.1.pyc and b/tests/test_encoder/__pycache__/test_ground_truth.cpython-311-pytest-9.1.1.pyc differ diff --git a/tests/test_encoder/__pycache__/test_ground_truth.cpython-311.pyc b/tests/test_encoder/__pycache__/test_ground_truth.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..35db988b681e3990b73f13b49b135a247dc6213d Binary files /dev/null and b/tests/test_encoder/__pycache__/test_ground_truth.cpython-311.pyc differ diff --git a/tests/test_encoder/__pycache__/test_init.cpython-311-pytest-9.1.1.pyc b/tests/test_encoder/__pycache__/test_init.cpython-311-pytest-9.1.1.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5de70b3f7b82311762dccfd2451c16468e1997c8 Binary files /dev/null and b/tests/test_encoder/__pycache__/test_init.cpython-311-pytest-9.1.1.pyc differ diff --git a/tests/test_encoder/__pycache__/test_init.cpython-311.pyc b/tests/test_encoder/__pycache__/test_init.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1d28c974058e6a91b83238067d58924bb1e8803e Binary files /dev/null and b/tests/test_encoder/__pycache__/test_init.cpython-311.pyc differ diff --git a/tests/test_encoder/__pycache__/test_launch.cpython-311-pytest-9.1.1.pyc b/tests/test_encoder/__pycache__/test_launch.cpython-311-pytest-9.1.1.pyc index f6c30928197fb7a2e320bc041840fd62cba8ad0f..37eb5334bb44dd5b495732a97b645ee807aefdf2 100644 Binary files a/tests/test_encoder/__pycache__/test_launch.cpython-311-pytest-9.1.1.pyc and b/tests/test_encoder/__pycache__/test_launch.cpython-311-pytest-9.1.1.pyc differ diff --git a/tests/test_encoder/__pycache__/test_launch.cpython-311.pyc b/tests/test_encoder/__pycache__/test_launch.cpython-311.pyc index 1cf0410260f63788c20d0175cbaf0bd61eb9716e..ee2d8464487e9905dac5463375e1ee0e8326aa9d 100644 Binary files a/tests/test_encoder/__pycache__/test_launch.cpython-311.pyc and b/tests/test_encoder/__pycache__/test_launch.cpython-311.pyc differ diff --git a/tests/test_encoder/__pycache__/test_render.cpython-311-pytest-9.1.1.pyc b/tests/test_encoder/__pycache__/test_render.cpython-311-pytest-9.1.1.pyc index 58bee6c6cce12834a4d50b59363d65c88c2c53df..2d52c2f477e590072d5f828433a73ae3fc077681 100644 Binary files a/tests/test_encoder/__pycache__/test_render.cpython-311-pytest-9.1.1.pyc and b/tests/test_encoder/__pycache__/test_render.cpython-311-pytest-9.1.1.pyc differ diff --git a/tests/test_encoder/__pycache__/test_run.cpython-311.pyc b/tests/test_encoder/__pycache__/test_run.cpython-311.pyc index 7d6688bdbff8a615b95c7258be6490974859a657..cd3a3f1735bb34e842cae4636c174f847bd891f0 100644 Binary files a/tests/test_encoder/__pycache__/test_run.cpython-311.pyc and b/tests/test_encoder/__pycache__/test_run.cpython-311.pyc differ diff --git a/tests/test_encoder/test_adapters.py b/tests/test_encoder/test_adapters.py index 3670aee1dec11cf2b2e5189945d3b8a265eece45..b5bcdebbb32981b327f5ccbb4bbf7efb6115bd15 100644 --- a/tests/test_encoder/test_adapters.py +++ b/tests/test_encoder/test_adapters.py @@ -235,8 +235,7 @@ def test_backproject_resizes_sam3_mask_to_da3_depth_shape(): def test_native_sam3_decodes_prompt_keyed_independent_frames(monkeypatch): - responses = {"chair": [ - {"masks": np.array([[[1, 0], [0, 0]]], dtype=np.uint8)}, {}]} + responses = {"chair": [{"masks": np.array([[[1, 0], [0, 0]]], dtype=np.uint8)}, {}]} monkeypatch.setitem( sys.modules, "torch", @@ -248,8 +247,7 @@ def test_native_sam3_decodes_prompt_keyed_independent_frames(monkeypatch): def test_native_sam3_preserves_tracked_object_ids(monkeypatch): - responses = [{"out_obj_ids": np.array([7]), - "out_binary_masks": np.ones((1, 2, 2))}] + responses = [{"out_obj_ids": np.array([7]), "out_binary_masks": np.ones((1, 2, 2))}] monkeypatch.setitem( sys.modules, "torch", diff --git a/tests/test_encoder/test_geometric.py b/tests/test_encoder/test_geometric.py index 51a55716f58189d5214ef246f71a962e54ba7636..b2e60ce74e62a492fcd023ef32d29c5352037623 100644 --- a/tests/test_encoder/test_geometric.py +++ b/tests/test_encoder/test_geometric.py @@ -54,7 +54,11 @@ def test_explicit_is_a_derivation_of_compact(monkeypatch): """build_explicit_spatial_code() must always build compact FIRST and derive from it -- not measure geometry independently.""" compact_expected = ( - {"spatial code schema": geometric.COMPACT_SPATIAL_CODE_SCHEMA, "objects": {}, "room": {}}, + { + "spatial code schema": geometric.COMPACT_SPATIAL_CODE_SCHEMA, + "objects": {}, + "room": {}, + }, {}, {}, 1, @@ -381,4 +385,3 @@ def test_compact_oriented_box_rejects_one_inconsistent_observation(): ) assert max(box["3D oriented bounding box dimensions"]) < 3.0 - diff --git a/tests/test_encoder/test_ground_truth.py b/tests/test_encoder/test_ground_truth.py index f7d2319fa0522ad6dc6cacff74bcf1406b1bbd03..a0608f0210c06fbcfd541b4a882b592cd3fb7d85 100644 --- a/tests/test_encoder/test_ground_truth.py +++ b/tests/test_encoder/test_ground_truth.py @@ -42,14 +42,18 @@ def _clear_ground_truth_caches(): gt._appearance_order_ranks_by_scene.cache_clear() -def test_load_meta_info_merges_all_three_datasets_and_tags_dataset(tmp_path, monkeypatch): +def test_load_meta_info_merges_all_three_datasets_and_tags_dataset( + tmp_path, monkeypatch +): _write_meta_info( tmp_path, scannet={"scene0001_00": {"room_size": 10.0, "object_bbox": {}}}, arkitscenes={"41000000": {"room_size": 12.0, "object_bbox": {}}}, scannetpp={"abc123": {"room_size": 14.0, "object_bbox": {}}}, ) - monkeypatch.setattr(gt, "META_INFO_DIR", tmp_path / "thinking-in-space" / "data" / "meta_info") + monkeypatch.setattr( + gt, "META_INFO_DIR", tmp_path / "thinking-in-space" / "data" / "meta_info" + ) merged = gt.load_meta_info() assert merged["scene0001_00"]["dataset"] == "scannet" assert merged["41000000"]["dataset"] == "arkitscenes" @@ -75,9 +79,11 @@ def test_floor_level_accounts_for_tilted_box_support(): ] flat_axes = [v for row in axes for v in row] object_bbox = {"box": [_instance([0, 0, 1.0], [1, 2, 2], axes=flat_axes)]} - half_extent_z = (1 / 2) * abs(0) + (2 / 2) * abs(math.sin(math.pi / 4)) + ( - 2 / 2 - ) * abs(math.cos(math.pi / 4)) + half_extent_z = ( + (1 / 2) * abs(0) + + (2 / 2) * abs(math.sin(math.pi / 4)) + + (2 / 2) * abs(math.cos(math.pi / 4)) + ) assert gt._floor_level(object_bbox) == pytest.approx(1.0 - half_extent_z) @@ -107,14 +113,18 @@ def test_gt_oriented_box_renormalizes_orientation_vectors(): def test_gt_floor_boundary_polygon_area_matches_room_size(): - polygons = gt._gt_floor_boundary_polygons(room_size=16.0, room_center=[3.0, -2.0, 0.0]) + polygons = gt._gt_floor_boundary_polygons( + room_size=16.0, room_center=[3.0, -2.0, 0.0] + ) assert len(polygons) == 1 area = geometric._compact_polygon_area(polygons[0]["outer boundary coordinates"]) assert area == pytest.approx(16.0, abs=0.01) assert polygons[0]["interior hole boundary coordinates"] == [] -def test_appearance_order_ranks_topological_across_multiple_questions(tmp_path, monkeypatch): +def test_appearance_order_ranks_topological_across_multiple_questions( + tmp_path, monkeypatch +): jsonl_path = tmp_path / "test.jsonl" questions = [ { @@ -164,7 +174,9 @@ def test_build_compact_ground_truth_spatial_code_uses_ranks_and_nulls_unranked( } }, ) - monkeypatch.setattr(gt, "META_INFO_DIR", tmp_path / "thinking-in-space" / "data" / "meta_info") + monkeypatch.setattr( + gt, "META_INFO_DIR", tmp_path / "thinking-in-space" / "data" / "meta_info" + ) jsonl_path = tmp_path / "test.jsonl" with open(jsonl_path, "w") as stream: stream.write( @@ -186,7 +198,9 @@ def test_build_compact_ground_truth_spatial_code_uses_ranks_and_nulls_unranked( assert code["objects"]["lamp"][0]["first visible time"] == 1.0 -def test_build_compact_ground_truth_spatial_code_nulls_untimed_classes(tmp_path, monkeypatch): +def test_build_compact_ground_truth_spatial_code_nulls_untimed_classes( + tmp_path, monkeypatch +): _write_meta_info( tmp_path, scannet={ @@ -197,7 +211,9 @@ def test_build_compact_ground_truth_spatial_code_nulls_untimed_classes(tmp_path, } }, ) - monkeypatch.setattr(gt, "META_INFO_DIR", tmp_path / "thinking-in-space" / "data" / "meta_info") + monkeypatch.setattr( + gt, "META_INFO_DIR", tmp_path / "thinking-in-space" / "data" / "meta_info" + ) monkeypatch.setattr(config, "JSONL", tmp_path / "empty.jsonl") (tmp_path / "empty.jsonl").write_text("") @@ -205,9 +221,13 @@ def test_build_compact_ground_truth_spatial_code_nulls_untimed_classes(tmp_path, assert code["objects"]["chair"][0]["first visible time"] is None -def test_build_compact_ground_truth_spatial_code_raises_for_unknown_scene(tmp_path, monkeypatch): +def test_build_compact_ground_truth_spatial_code_raises_for_unknown_scene( + tmp_path, monkeypatch +): _write_meta_info(tmp_path) - monkeypatch.setattr(gt, "META_INFO_DIR", tmp_path / "thinking-in-space" / "data" / "meta_info") + monkeypatch.setattr( + gt, "META_INFO_DIR", tmp_path / "thinking-in-space" / "data" / "meta_info" + ) monkeypatch.setattr(config, "JSONL", tmp_path / "empty.jsonl") (tmp_path / "empty.jsonl").write_text("") with pytest.raises(KeyError): @@ -235,16 +255,24 @@ def test_build_explicit_ground_truth_spatial_code_is_derived_from_compact(monkey }, "room": {"floor boundary polygons": []}, } - monkeypatch.setattr(gt, "build_compact_ground_truth_spatial_code", lambda scene: compact_code) + monkeypatch.setattr( + gt, "build_compact_ground_truth_spatial_code", lambda scene: compact_code + ) explicit_code = gt.build_explicit_ground_truth_spatial_code("scene1") - assert explicit_code["spatial code schema"] is geometric.EXPLICIT_SPATIAL_CODE_SCHEMA + assert ( + explicit_code["spatial code schema"] is geometric.EXPLICIT_SPATIAL_CODE_SCHEMA + ) assert explicit_code["objects"]["chair"]["count"] == 1 assert explicit_code["appearance order"] == ["chair"] def test_build_ground_truth_spatial_code_dispatches_by_format(monkeypatch): - monkeypatch.setattr(gt, "build_compact_ground_truth_spatial_code", lambda scene: "compact-code") - monkeypatch.setattr(gt, "build_explicit_ground_truth_spatial_code", lambda scene: "explicit-code") + monkeypatch.setattr( + gt, "build_compact_ground_truth_spatial_code", lambda scene: "compact-code" + ) + monkeypatch.setattr( + gt, "build_explicit_ground_truth_spatial_code", lambda scene: "explicit-code" + ) assert gt.build_ground_truth_spatial_code("scene1", "compact") == "compact-code" assert gt.build_ground_truth_spatial_code("scene1", "explicit") == "explicit-code" @@ -256,7 +284,9 @@ def test_build_ground_truth_spatial_code_rejects_unknown_format(): def test_build_and_write_writes_to_the_ground_truth_path(tmp_path, monkeypatch): monkeypatch.setattr(config, "CODES_ROOT", tmp_path / "codes") - monkeypatch.setattr(gt, "build_ground_truth_spatial_code", lambda scene, fmt: {"objects": {}}) + monkeypatch.setattr( + gt, "build_ground_truth_spatial_code", lambda scene, fmt: {"objects": {}} + ) path = gt.build_and_write("scene1", "explicit") assert path.endswith("codes/ground truth/explicit/scene1.json") assert json.loads(open(path).read()) == {"objects": {}} @@ -268,14 +298,18 @@ def test_scenes_returns_sorted_meta_info_keys(tmp_path, monkeypatch): scannet={"scene0002_00": {}, "scene0001_00": {}}, arkitscenes={"41000000": {}}, ) - monkeypatch.setattr(gt, "META_INFO_DIR", tmp_path / "thinking-in-space" / "data" / "meta_info") + monkeypatch.setattr( + gt, "META_INFO_DIR", tmp_path / "thinking-in-space" / "data" / "meta_info" + ) assert gt.scenes() == ["41000000", "scene0001_00", "scene0002_00"] def test_build_all_writes_every_scene_and_format(tmp_path, monkeypatch): monkeypatch.setattr(config, "CODES_ROOT", tmp_path / "codes") monkeypatch.setattr(gt, "scenes", lambda: ["scene1", "scene2"]) - monkeypatch.setattr(gt, "build_ground_truth_spatial_code", lambda scene, fmt: {"objects": {}}) + monkeypatch.setattr( + gt, "build_ground_truth_spatial_code", lambda scene, fmt: {"objects": {}} + ) written = gt.build_all() assert len(written) == 4 assert (tmp_path / "codes" / "ground truth" / "explicit" / "scene1.json").exists() @@ -284,6 +318,10 @@ def test_build_all_writes_every_scene_and_format(tmp_path, monkeypatch): def test_build_all_respects_explicit_scene_list_and_formats(tmp_path, monkeypatch): monkeypatch.setattr(config, "CODES_ROOT", tmp_path / "codes") - monkeypatch.setattr(gt, "build_ground_truth_spatial_code", lambda scene, fmt: {"objects": {}}) + monkeypatch.setattr( + gt, "build_ground_truth_spatial_code", lambda scene, fmt: {"objects": {}} + ) written = gt.build_all(spatial_code_formats=("compact",), scene_list=["scene9"]) - assert written == [str(tmp_path / "codes" / "ground truth" / "compact" / "scene9.json")] + assert written == [ + str(tmp_path / "codes" / "ground truth" / "compact" / "scene9.json") + ] diff --git a/tests/test_encoder/test_launch.py b/tests/test_encoder/test_launch.py index a85cd4ea4c8ec41bbdf833fa6ee5d1008fc40464..26079d6d11c586198b1103c132f0c9913412de4b 100644 --- a/tests/test_encoder/test_launch.py +++ b/tests/test_encoder/test_launch.py @@ -2,5 +2,6 @@ from encoder import launch + def test_encoder_launcher_imports(): assert callable(launch.main) diff --git a/tests/test_inference/__pycache__/conftest.cpython-311.pyc b/tests/test_inference/__pycache__/conftest.cpython-311.pyc index 0ce250cc1dc0957a6586a541a0111bf1442e4260..887c8c964fa9ab484cada295a72db3335f801664 100644 Binary files a/tests/test_inference/__pycache__/conftest.cpython-311.pyc and b/tests/test_inference/__pycache__/conftest.cpython-311.pyc differ diff --git a/tests/test_inference/__pycache__/test_inference.cpython-311.pyc b/tests/test_inference/__pycache__/test_inference.cpython-311.pyc index 2a399bc653ca018570d9432125174fb00c49ad35..544e43d80bca0cae8e2a54bc842cc25d91f9e3af 100644 Binary files a/tests/test_inference/__pycache__/test_inference.cpython-311.pyc and b/tests/test_inference/__pycache__/test_inference.cpython-311.pyc differ diff --git a/tests/test_inference/__pycache__/test_run.cpython-311.pyc b/tests/test_inference/__pycache__/test_run.cpython-311.pyc index 36486d558d5522e656978c6ee332a462f6113f05..15d35468875464be01dc98a21209dbdb9648c362 100644 Binary files a/tests/test_inference/__pycache__/test_run.cpython-311.pyc and b/tests/test_inference/__pycache__/test_run.cpython-311.pyc differ