Download tools/test_recording_reference_view.py from maxwellinked/time-lapse-artifacts: direct link, hf CLI and curl.
- Browser
- Download file 3.16 kB
-
https://huggingface.co/datasets/maxwellinked/time-lapse-artifacts/resolve/refs%2Fpr%2F113/tools/test_recording_reference_view.py
- Command line
-
hf download hf://datasets/maxwellinked/time-lapse-artifacts@refs/pr/113/tools/test_recording_reference_view.py
-
curl -L -o test_recording_reference_view.py https://huggingface.co/datasets/maxwellinked/time-lapse-artifacts/resolve/refs%2Fpr%2F113/tools/test_recording_reference_view.py
3.16 kB
| """Migration safety checks. Full source-bound data validation runs during generation.""" | |
| from pathlib import Path | |
| import csv | |
| import json | |
| import subprocess | |
| import sys | |
| import tempfile | |
| import unittest | |
| import pyarrow as pa | |
| import build_selected_front_projection as view | |
| class ProjectionMigrationTests(unittest.TestCase): | |
| def test_csv_retains_null_empty_and_numeric_values_without_image_bytes(self): | |
| table = pa.table({"file_name": ["a.mp4", "b.mp4"], | |
| "image": pa.array([{"bytes": b"opaque", "path": "work.jpg"}, None], | |
| type=pa.struct([("bytes", pa.binary()), ("path", pa.string())])), | |
| "work_id": ["tlaw-a", ""], | |
| "Source photograph URL": ["https://example.invalid/source", None], | |
| "display_width_px": pa.array([100, None], type=pa.int64())}) | |
| with tempfile.TemporaryDirectory() as d: | |
| path = Path(d)/"scalar.csv" | |
| result = view.write_scalar_csv(table, path) | |
| self.assertTrue(result["typed_scalar_roundtrip_exact"]) | |
| with path.open(newline="") as f: rows = list(csv.DictReader(f)) | |
| self.assertNotIn("image", rows[0]) | |
| self.assertEqual(rows[1]["work_id"], "") | |
| self.assertEqual(rows[1]["Source photograph URL"], view.CSV_NULL) | |
| self.assertEqual(rows[1]["display_width_px"], view.CSV_NULL) | |
| def test_legacy_cli_fails_without_writing_even_if_output_is_preexisting(self): | |
| script = Path(__file__).with_name("build_recording_reference_view.py") | |
| with tempfile.TemporaryDirectory() as d: | |
| root = Path(d); output = root/"recording_physical_references.csv" | |
| output.write_bytes(b"preserved existing export") | |
| result = subprocess.run([sys.executable, str(script), "--root", str(root), | |
| "--source-revision", view.BASE_REVISION, "--output", str(output)], | |
| capture_output=True) | |
| self.assertNotEqual(result.returncode, 0) | |
| self.assertEqual(output.read_bytes(), b"preserved existing export") | |
| def test_source_url_requires_exact_manifest_work_hash_and_path(self): | |
| item = {"work_id": "tlaw-a", "source_photograph_sha256": "1"*64, | |
| "existing_main_source_path": "Physical_References/Photographs/images/tlaw-a/a.jpg"} | |
| with self.assertRaises(ValueError): view.original_url(item, {}, view.BASE_REVISION) | |
| wrong = {("tlaw-a", "1"*64): [{"image_path": "Physical_References/Photographs/images/tlaw-a/b.jpg"}]} | |
| with self.assertRaises(ValueError): view.original_url(item, wrong, view.BASE_REVISION) | |
| self.assertEqual(view.original_url({"existing_main_source_path": None}, {}, view.BASE_REVISION), (None, None)) | |
| def test_csv_null_token_collision_is_rejected(self): | |
| table = pa.table({"image": [None], "work_id": [view.CSV_NULL]}) | |
| with tempfile.TemporaryDirectory() as d: | |
| with self.assertRaises(ValueError): view.write_scalar_csv(table, Path(d)/"bad.csv") | |
| if __name__ == "__main__": | |
| unittest.main() | |