]> git.99rst.org Git - openwrt-packages.git/commitdiff
python-protobuf: add test script
authorAlexandru Ardelean <redacted>
Sun, 9 Aug 2026 09:14:15 +0000 (12:14 +0300)
committerAlexandru Ardelean <redacted>
Sun, 9 Aug 2026 17:00:40 +0000 (20:00 +0300)
Add a CI test.sh that imports google.protobuf and round-trips the
Timestamp and Struct well-known types through SerializeToString and
ParseFromString, covering the descriptor pool, encoder and decoder
without needing a compiled .proto. Modelled on python-rpds-py's test.

Signed-off-by: Alexandru Ardelean <redacted>
lang/python/python-protobuf/test.sh [new file with mode: 0755]

diff --git a/lang/python/python-protobuf/test.sh b/lang/python/python-protobuf/test.sh
new file mode 100755 (executable)
index 0000000..04da292
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+[ "$1" = python3-protobuf ] || exit 0
+
+python3 - << 'EOF'
+
+from google.protobuf import struct_pb2, timestamp_pb2
+
+# Well-known types exercise the descriptor pool, encoder and decoder without
+# needing a compiled .proto: serialize a scalar message and a map-backed one,
+# then parse the bytes back and confirm the fields survive the round-trip.
+ts = timestamp_pb2.Timestamp(seconds=1710000000, nanos=123)
+back = timestamp_pb2.Timestamp()
+back.ParseFromString(ts.SerializeToString())
+assert back.seconds == 1710000000 and back.nanos == 123
+
+s = struct_pb2.Struct()
+s["name"] = "openwrt"
+s["count"] = 3
+s2 = struct_pb2.Struct()
+s2.ParseFromString(s.SerializeToString())
+assert s2["name"] == "openwrt" and s2["count"] == 3
+
+EOF
git clone https://git.99rst.org/PROJECT