(repeat, test_data: TestData)
| 199 | |
| 200 | @pytest.mark.parametrize("test_data", test_cases.messages_with_json, indirect=True) |
| 201 | def test_binary_compatibility(repeat, test_data: TestData) -> None: |
| 202 | plugin_module, reference_module, json_data = test_data |
| 203 | |
| 204 | for sample in json_data: |
| 205 | reference_instance = Parse(sample.json, reference_module().Test()) |
| 206 | reference_binary_output = reference_instance.SerializeToString() |
| 207 | |
| 208 | for _ in range(repeat): |
| 209 | plugin_instance_from_json: betterproto.Message = ( |
| 210 | plugin_module.Test().from_json(sample.json) |
| 211 | ) |
| 212 | plugin_instance_from_binary = plugin_module.Test.FromString( |
| 213 | reference_binary_output |
| 214 | ) |
| 215 | |
| 216 | # Generally this can't be relied on, but here we are aiming to match the |
| 217 | # existing Python implementation and aren't doing anything tricky. |
| 218 | # https://developers.google.com/protocol-buffers/docs/encoding#implications |
| 219 | assert bytes(plugin_instance_from_json) == reference_binary_output |
| 220 | assert bytes(plugin_instance_from_binary) == reference_binary_output |
| 221 | |
| 222 | assert plugin_instance_from_json == plugin_instance_from_binary |
| 223 | assert dict_replace_nans( |
| 224 | plugin_instance_from_json.to_dict() |
| 225 | ) == dict_replace_nans(plugin_instance_from_binary.to_dict()) |
nothing calls this directly
no test coverage detected