test_encode_6400_hex.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from pathlib import Path
  2. import pytest
  3. from tools.encode_6400_hex import Encoder
  4. ROOT = Path(__file__).resolve().parents[2]
  5. def test_target_and_get_match_generated_golden_vectors() -> None:
  6. encoder = Encoder()
  7. golden = encoder.contract["golden_vectors"]["frames"]
  8. assert encoder.set_target("6400-control", 0).hex().upper() == golden["set_target_stop"]
  9. assert encoder.set_target("6400-control", 20).hex().upper() == golden["set_target_20"]
  10. assert encoder.set_target("6400-control", 70).hex().upper() == golden["set_target_70"]
  11. assert encoder.get_snapshot("6400-control").hex().upper() == golden["get_snapshot"]
  12. def test_profile_isolation_and_stimulus_layout() -> None:
  13. encoder = Encoder()
  14. with pytest.raises(ValueError, match="not supported"):
  15. encoder.set_stimulus("6400-control", 1, [0] * 24, [0] * 4, [0] * 4)
  16. result = encoder.set_stimulus(
  17. "6400-identification", 3, list(range(24)), [10, 20, 30, 40], [50, 60, 70, 80]
  18. )
  19. assert result[2:4] == bytes((0x03, 33))
  20. assert result[4] == 3
  21. assert list(result[5:29]) == list(range(24))
  22. assert list(result[29:33]) == [10, 20, 30, 40]
  23. assert list(result[33:37]) == [50, 60, 70, 80]
  24. def test_only_canonical_profile_names_are_accepted() -> None:
  25. encoder = Encoder()
  26. with pytest.raises(ValueError, match="unknown canonical profile"):
  27. encoder.get_snapshot("production")