from pathlib import Path import pytest from tools.encode_6400_hex import Encoder ROOT = Path(__file__).resolve().parents[2] def test_target_and_get_match_generated_golden_vectors() -> None: encoder = Encoder() golden = encoder.contract["golden_vectors"]["frames"] assert encoder.set_target("6400-control", 0).hex().upper() == golden["set_target_stop"] assert encoder.set_target("6400-control", 20).hex().upper() == golden["set_target_20"] assert encoder.set_target("6400-control", 70).hex().upper() == golden["set_target_70"] assert encoder.get_snapshot("6400-control").hex().upper() == golden["get_snapshot"] def test_profile_isolation_and_stimulus_layout() -> None: encoder = Encoder() with pytest.raises(ValueError, match="not supported"): encoder.set_stimulus("6400-control", 1, [0] * 24, [0] * 4, [0] * 4) result = encoder.set_stimulus( "6400-identification", 3, list(range(24)), [10, 20, 30, 40], [50, 60, 70, 80] ) assert result[2:4] == bytes((0x03, 33)) assert result[4] == 3 assert list(result[5:29]) == list(range(24)) assert list(result[29:33]) == [10, 20, 30, 40] assert list(result[33:37]) == [50, 60, 70, 80] def test_only_canonical_profile_names_are_accepted() -> None: encoder = Encoder() with pytest.raises(ValueError, match="unknown canonical profile"): encoder.get_snapshot("production")