Fix serialization of repeated fields with empty messages (#180)
Extend test config and utils to support exclusion of certain json samples from testing for symetry.
This commit is contained in:
@@ -19,3 +19,10 @@ services = {
|
||||
"example_service",
|
||||
"empty_service",
|
||||
}
|
||||
|
||||
|
||||
# Indicate json sample messages to skip when testing that json (de)serialization
|
||||
# is symmetrical becuase some cases legitimately are not symmetrical.
|
||||
# Each key references the name of the test scenario and the values in the tuple
|
||||
# Are the names of the json files.
|
||||
non_symmetrical_json = {"empty_repeated": ("empty_repeated",)}
|
||||
|
||||
3
tests/inputs/empty_repeated/empty_repeated.json
Normal file
3
tests/inputs/empty_repeated/empty_repeated.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"msg": [{"values":[]}]
|
||||
}
|
||||
9
tests/inputs/empty_repeated/empty_repeated.proto
Normal file
9
tests/inputs/empty_repeated/empty_repeated.proto
Normal file
@@ -0,0 +1,9 @@
|
||||
syntax = "proto3";
|
||||
|
||||
message MessageA {
|
||||
repeated float values = 1;
|
||||
}
|
||||
|
||||
message Test {
|
||||
repeated MessageA msg = 1;
|
||||
}
|
||||
@@ -5,11 +5,11 @@ from tests.util import get_test_case_json_data
|
||||
|
||||
def test_which_count():
|
||||
message = Test()
|
||||
message.from_json(get_test_case_json_data("oneof")[0])
|
||||
message.from_json(get_test_case_json_data("oneof")[0].json)
|
||||
assert betterproto.which_one_of(message, "foo") == ("pitied", 100)
|
||||
|
||||
|
||||
def test_which_name():
|
||||
message = Test()
|
||||
message.from_json(get_test_case_json_data("oneof", "oneof_name.json")[0])
|
||||
message.from_json(get_test_case_json_data("oneof", "oneof_name.json")[0].json)
|
||||
assert betterproto.which_one_of(message, "foo") == ("pitier", "Mr. T")
|
||||
|
||||
@@ -15,7 +15,7 @@ def test_which_one_of_returns_enum_with_default_value():
|
||||
"""
|
||||
message = Test()
|
||||
message.from_json(
|
||||
get_test_case_json_data("oneof_enum", "oneof_enum-enum-0.json")[0]
|
||||
get_test_case_json_data("oneof_enum", "oneof_enum-enum-0.json")[0].json
|
||||
)
|
||||
|
||||
assert message.move == Move(
|
||||
@@ -31,7 +31,7 @@ def test_which_one_of_returns_enum_with_non_default_value():
|
||||
"""
|
||||
message = Test()
|
||||
message.from_json(
|
||||
get_test_case_json_data("oneof_enum", "oneof_enum-enum-1.json")[0]
|
||||
get_test_case_json_data("oneof_enum", "oneof_enum-enum-1.json")[0].json
|
||||
)
|
||||
assert message.move == Move(
|
||||
x=0, y=0
|
||||
@@ -42,7 +42,7 @@ def test_which_one_of_returns_enum_with_non_default_value():
|
||||
|
||||
def test_which_one_of_returns_second_field_when_set():
|
||||
message = Test()
|
||||
message.from_json(get_test_case_json_data("oneof_enum")[0])
|
||||
message.from_json(get_test_case_json_data("oneof_enum")[0].json)
|
||||
assert message.move == Move(x=2, y=3)
|
||||
assert message.signal == Signal.PASS
|
||||
assert betterproto.which_one_of(message, "action") == ("move", Move(x=2, y=3))
|
||||
|
||||
Reference in New Issue
Block a user