summaryrefslogtreecommitdiffstats
path: root/tests/test_struct.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-07-29 09:40:12 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-07-29 09:40:12 +0000
commit14b40ec77a4bf8605789cc3aff0eb87625510a41 (patch)
tree4064d27144d6deaabfcd96df01bd996baa8b51a0 /tests/test_struct.py
parentInitial commit. (diff)
downloadpython-aristaproto-upstream.tar.xz
python-aristaproto-upstream.zip
Adding upstream version 1.2+20240521.upstream/1.2+20240521upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--tests/test_struct.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/test_struct.py b/tests/test_struct.py
new file mode 100644
index 0000000..c562763
--- /dev/null
+++ b/tests/test_struct.py
@@ -0,0 +1,36 @@
+import json
+
+from aristaproto.lib.google.protobuf import Struct
+from aristaproto.lib.pydantic.google.protobuf import Struct as StructPydantic
+
+
+def test_struct_roundtrip():
+ data = {
+ "foo": "bar",
+ "baz": None,
+ "quux": 123,
+ "zap": [1, {"two": 3}, "four"],
+ }
+ data_json = json.dumps(data)
+
+ struct_from_dict = Struct().from_dict(data)
+ assert struct_from_dict.fields == data
+ assert struct_from_dict.to_dict() == data
+ assert struct_from_dict.to_json() == data_json
+
+ struct_from_json = Struct().from_json(data_json)
+ assert struct_from_json.fields == data
+ assert struct_from_json.to_dict() == data
+ assert struct_from_json == struct_from_dict
+ assert struct_from_json.to_json() == data_json
+
+ struct_pyd_from_dict = StructPydantic(fields={}).from_dict(data)
+ assert struct_pyd_from_dict.fields == data
+ assert struct_pyd_from_dict.to_dict() == data
+ assert struct_pyd_from_dict.to_json() == data_json
+
+ struct_pyd_from_dict = StructPydantic(fields={}).from_json(data_json)
+ assert struct_pyd_from_dict.fields == data
+ assert struct_pyd_from_dict.to_dict() == data
+ assert struct_pyd_from_dict == struct_pyd_from_dict
+ assert struct_pyd_from_dict.to_json() == data_json