Skip to content
This repository was archived by the owner on Feb 23, 2026. It is now read-only.

Commit 09b9bc4

Browse files
committed
add tests
1 parent 117907a commit 09b9bc4

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

tests/test_json.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,23 @@ class Squid(proto.Message):
121121
)
122122
assert json1 == '{"name":"Steve"}'
123123

124+
json1 = (
125+
Squid.to_json(s, always_print_fields_with_no_presence=False)
126+
.replace(" ", "")
127+
.replace("\n", "")
128+
)
129+
assert json1 == '{"name":"Steve"}'
130+
131+
with pytest.raises(
132+
ValueError,
133+
match="Arguments.*always_print_fields_with_no_presence.*including_default_value_fields.*must match",
134+
):
135+
Squid.to_json(
136+
s,
137+
including_default_value_fields=True,
138+
always_print_fields_with_no_presence=False,
139+
).replace(" ", "").replace("\n", "")
140+
124141
json2 = Squid.to_json(s).replace(" ", "").replace("\n", "")
125142
assert (
126143
json2 == '{"name":"Steve","massKg":0}' or json2 == '{"massKg":0,"name":"Steve"}'

tests/test_message.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,20 @@ class Color(proto.Enum):
267267
expected_dict = {"mass_kg": 20}
268268
assert s_dict_2 == expected_dict
269269

270+
s_dict_2 = Squid.to_dict(s_new_2, always_print_fields_with_no_presence=False)
271+
expected_dict = {"mass_kg": 20}
272+
assert s_dict_2 == expected_dict
273+
274+
with pytest.raises(
275+
ValueError,
276+
match="Arguments.*always_print_fields_with_no_presence.*including_default_value_fields.*must match",
277+
):
278+
s_dict_2 = Squid.to_dict(
279+
s_new_2,
280+
including_default_value_fields=True,
281+
always_print_fields_with_no_presence=False,
282+
)
283+
270284
new_s = Squid(s_dict)
271285
assert new_s == s
272286

0 commit comments

Comments
 (0)