#!/usr/bin/env python3 """Conversion round-trips for the Value layer. Plain asserts — run directly.""" import sys from secsgem_client._proto import equipment_pb2 as pb from secsgem_client._values import from_value, to_value def roundtrip(v): return from_value(to_value(v)) def main() -> int: assert roundtrip(2.5) == 2.5 assert roundtrip(7) == 7 assert roundtrip(-3) == -3 assert roundtrip(True) is True # bool BEFORE int: must stay boolean assert roundtrip(False) is False assert to_value(True).WhichOneof("kind") == "boolean" assert to_value(1).WhichOneof("kind") == "integer" assert roundtrip("wafer-17") == "wafer-17" assert roundtrip(b"\x01\x02") == b"\x01\x02" assert roundtrip([1, 2.5, "x", [True]]) == [1, 2.5, "x", [True]] assert from_value(pb.Value()) is None # unset oneof try: to_value(object()) raise SystemExit("expected TypeError for unconvertible type") except TypeError: pass print("values: all conversion checks passed") return 0 if __name__ == "__main__": sys.exit(main())