From 6ff5b8a053926ed68ad1c182b2491b952c43ef51 Mon Sep 17 00:00:00 2001 From: Adrien Vannson Date: Wed, 13 Nov 2024 11:11:29 +0100 Subject: [PATCH 1/2] Don't repeat tests --- tests/conftest.py | 11 --------- tests/test_inputs.py | 58 +++++++++++++++++++++----------------------- 2 files changed, 28 insertions(+), 41 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index c6b256d3..34c044e0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,17 +4,6 @@ import pytest -def pytest_addoption(parser): - parser.addoption( - "--repeat", type=int, default=1, help="repeat the operation multiple times" - ) - - -@pytest.fixture(scope="session") -def repeat(request): - return request.config.getoption("repeat") - - @pytest.fixture def reset_sys_path(): original = copy.deepcopy(sys.path) diff --git a/tests/test_inputs.py b/tests/test_inputs.py index 2077fffd..de7f776e 100644 --- a/tests/test_inputs.py +++ b/tests/test_inputs.py @@ -174,22 +174,21 @@ def test_message_equality(test_data: TestData) -> None: @pytest.mark.parametrize("test_data", test_cases.messages_with_json, indirect=True) -def test_message_json(repeat, test_data: TestData) -> None: +def test_message_json(test_data: TestData) -> None: plugin_module, _, json_data = test_data - for _ in range(repeat): - for sample in json_data: - if sample.belongs_to(test_input_config.non_symmetrical_json): - continue + for sample in json_data: + if sample.belongs_to(test_input_config.non_symmetrical_json): + continue - message: betterproto.Message = plugin_module.Test() + message: betterproto.Message = plugin_module.Test() - message.from_json(sample.json) - message_json = message.to_json(0) + message.from_json(sample.json) + message_json = message.to_json(0) - assert dict_replace_nans(json.loads(message_json)) == dict_replace_nans( - json.loads(sample.json) - ) + assert dict_replace_nans(json.loads(message_json)) == dict_replace_nans( + json.loads(sample.json) + ) @pytest.mark.parametrize("test_data", test_cases.services, indirect=True) @@ -198,28 +197,27 @@ def test_service_can_be_instantiated(test_data: TestData) -> None: @pytest.mark.parametrize("test_data", test_cases.messages_with_json, indirect=True) -def test_binary_compatibility(repeat, test_data: TestData) -> None: +def test_binary_compatibility(test_data: TestData) -> None: plugin_module, reference_module, json_data = test_data for sample in json_data: reference_instance = Parse(sample.json, reference_module().Test()) reference_binary_output = reference_instance.SerializeToString() - for _ in range(repeat): - plugin_instance_from_json: betterproto.Message = ( - plugin_module.Test().from_json(sample.json) - ) - plugin_instance_from_binary = plugin_module.Test.FromString( - reference_binary_output - ) - - # Generally this can't be relied on, but here we are aiming to match the - # existing Python implementation and aren't doing anything tricky. - # https://developers.google.com/protocol-buffers/docs/encoding#implications - assert bytes(plugin_instance_from_json) == reference_binary_output - assert bytes(plugin_instance_from_binary) == reference_binary_output - - assert plugin_instance_from_json == plugin_instance_from_binary - assert dict_replace_nans( - plugin_instance_from_json.to_dict() - ) == dict_replace_nans(plugin_instance_from_binary.to_dict()) + plugin_instance_from_json: betterproto.Message = ( + plugin_module.Test().from_json(sample.json) + ) + plugin_instance_from_binary = plugin_module.Test.FromString( + reference_binary_output + ) + + # Generally this can't be relied on, but here we are aiming to match the + # existing Python implementation and aren't doing anything tricky. + # https://developers.google.com/protocol-buffers/docs/encoding#implications + assert bytes(plugin_instance_from_json) == reference_binary_output + assert bytes(plugin_instance_from_binary) == reference_binary_output + + assert plugin_instance_from_json == plugin_instance_from_binary + assert dict_replace_nans( + plugin_instance_from_json.to_dict() + ) == dict_replace_nans(plugin_instance_from_binary.to_dict()) From cef0321bc0aa8dd9af0288174216ecca2dc974c7 Mon Sep 17 00:00:00 2001 From: Adrien Vannson Date: Wed, 13 Nov 2024 11:16:01 +0100 Subject: [PATCH 2/2] Format code --- tests/test_inputs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_inputs.py b/tests/test_inputs.py index de7f776e..919bbc8c 100644 --- a/tests/test_inputs.py +++ b/tests/test_inputs.py @@ -204,8 +204,8 @@ def test_binary_compatibility(test_data: TestData) -> None: reference_instance = Parse(sample.json, reference_module().Test()) reference_binary_output = reference_instance.SerializeToString() - plugin_instance_from_json: betterproto.Message = ( - plugin_module.Test().from_json(sample.json) + plugin_instance_from_json: betterproto.Message = plugin_module.Test().from_json( + sample.json ) plugin_instance_from_binary = plugin_module.Test.FromString( reference_binary_output