IDEAL-FT / tools /test_oxt_validation_names.py
Alan0928's picture
Align IDEAL-FT data with FTP-1 submission conventions
24b5890 verified
Raw History Blame Contribute Delete
3.79 kB
"""Regression tests for documented portable episode-directory names."""
import unittest
import numpy as np
from validate_oxt_export import Checks, episode_name_matches, gripper_check, scan_rgb_rows
class EpisodeNameTests(unittest.TestCase):
original = "Mon_Oct_12_19:18:09_2026"
def test_original_name_is_accepted(self):
self.assertTrue(episode_name_matches(self.original, self.original))
def test_only_colons_replaced_by_hyphens_is_accepted(self):
self.assertTrue(episode_name_matches(self.original, "Mon_Oct_12_19-18-09_2026"))
def test_different_timestamp_is_rejected(self):
for candidate in ("Mon_Oct_12_19:18:10_2026", "Mon_Oct_12_19-18-10_2026",
"Mon_Oct_13_19-18-09_2026"):
with self.subTest(candidate=candidate):
self.assertFalse(episode_name_matches(self.original, candidate))
def test_arbitrary_or_partial_normalization_is_rejected(self):
for candidate in ("Mon-Oct-12-19-18-09-2026", "Mon_Oct_12_19_18_09_2026",
"Mon_Oct_12_19-18:09_2026", "mon_Oct_12_19-18-09_2026",
"Mon_Oct_12_19-18-09_2026 ", "prefix_Mon_Oct_12_19-18-09_2026", ""):
with self.subTest(candidate=candidate):
self.assertFalse(episode_name_matches(self.original, candidate))
class RGBScanTests(unittest.TestCase):
def test_both_cameras_read_every_row_including_partial_final_batch(self):
class RecordingRGBArray:
# Actual exports have one frame per storage chunk. The scanner must
# still request larger slices and cover the complete episode span.
chunks = (1, 360, 640, 3)
def __init__(self):
self.requests = []
self.frame = np.zeros((1, 360, 640, 3), dtype=np.uint8)
def __getitem__(self, selection):
self.requests.append(selection)
return np.broadcast_to(self.frame, (selection.stop - selection.start, 360, 640, 3))
for count in (33, 65):
for camera in ("camera_main", "right_wrist_camera"):
with self.subTest(count=count, camera=camera):
source = RecordingRGBArray()
checks = Checks()
span = slice(7, 7 + count)
self.assertEqual(scan_rgb_rows(source, span, checks, camera), count)
self.assertEqual(checks.errors, [])
read_rows = [i for request in source.requests for i in range(request.start, request.stop)]
self.assertEqual(read_rows, list(range(span.start, span.stop)))
self.assertEqual([request.stop - request.start for request in source.requests],
[32] * (count // 32) + [count % 32])
self.assertEqual(source.requests[-1].stop, span.stop)
class GripperOpeningTests(unittest.TestCase):
def test_inverted_opening_passes_and_legacy_closure_fails(self):
native = np.array([0., .25, .5, .75, 1.])
checks = Checks()
gripper_check(np.array([[1.], [.75], [.5], [.25], [0.]]), native, checks)
self.assertEqual(checks.errors, [])
gripper_check(native[:, None], native, checks)
self.assertTrue(any("1 - native closure" in error for error in checks.errors))
def test_out_of_range_and_nonfinite_values_fail(self):
for native in (np.array([-0.1, 1.1]), np.array([np.nan])):
with self.subTest(native=native):
checks = Checks()
gripper_check((1 - native)[:, None], native, checks)
self.assertTrue(any("within [0, 1]" in error for error in checks.errors))
if __name__ == "__main__":
unittest.main()