Skip to content

Commit c8e6244

Browse files
committed
tests: add Struct roundtrip tests
Signed-off-by: William Woodruff <[email protected]>
1 parent f5a3eee commit c8e6244

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/test_struct.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import json
2+
3+
from betterproto.lib.google.protobuf import Struct
4+
5+
6+
def test_struct_roundtrip():
7+
data = {
8+
"foo": "bar",
9+
"baz": None,
10+
"quux": 123,
11+
"zap": [1, {"two": 3}, "four"],
12+
}
13+
data_json = json.dumps(data)
14+
15+
struct_from_dict = Struct().from_dict(data)
16+
assert struct_from_dict.fields == data
17+
assert struct_from_dict.to_json() == data_json
18+
19+
struct_from_json = Struct().from_json(data_json)
20+
assert struct_from_json.fields == data
21+
assert struct_from_json == struct_from_dict
22+
assert struct_from_json.to_json() == data_json

0 commit comments

Comments
 (0)