From 0b9ef0cbfe21c49d4d531c1370f799c1b3723202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Ean=20G=C3=BCne=C5=9F?= <180301198+sgunes-wirepas@users.noreply.github.com> Date: Fri, 17 Jan 2025 14:13:10 +0200 Subject: [PATCH] Add missing gateway result codes and add tests for it The test verifies that all of the error codes defined in the currently used protobuf definition can be converted to the internal GateayResultCode enum (in case some of them are forgotten to be added here). --- tests/test_gateway_result_code.py | 15 +++++++++++++++ wirepas_mesh_messaging/gateway_result_code.py | 2 ++ 2 files changed, 17 insertions(+) create mode 100644 tests/test_gateway_result_code.py diff --git a/tests/test_gateway_result_code.py b/tests/test_gateway_result_code.py new file mode 100644 index 0000000..73e446b --- /dev/null +++ b/tests/test_gateway_result_code.py @@ -0,0 +1,15 @@ +# flake8: noqa + +import pytest + +from wirepas_mesh_messaging.proto import ErrorCode +from wirepas_mesh_messaging import GatewayResultCode + +@pytest.mark.parametrize("protobuf_result_code", ErrorCode.items()) +def test_decoding_errors(protobuf_result_code): + name, value = protobuf_result_code + try: + GatewayResultCode(value) + except ValueError as e: + raise ValueError(f"{name} is not defined in GatewayResultCode") from e + diff --git a/wirepas_mesh_messaging/gateway_result_code.py b/wirepas_mesh_messaging/gateway_result_code.py index 738cc14..2d449df 100644 --- a/wirepas_mesh_messaging/gateway_result_code.py +++ b/wirepas_mesh_messaging/gateway_result_code.py @@ -50,3 +50,5 @@ class GatewayResultCode(enum.Enum): GW_RES_INVALID_MAX_HOP_COUNT = INVALID_MAX_HOP_COUNT GW_RES_SINK_OUT_OF_MEMORY = SINK_OUT_OF_MEMORY GW_RES_SINK_TIMEOUT = SINK_TIMEOUT + GW_RES_INVALID_SCRATCHPAD_CHUNK_OFFSET = INVALID_SCRATCHPAD_CHUNK_OFFSET + GW_RES_INVALID_SCRATCHPAD_CHUNK_SIZE = INVALID_SCRATCHPAD_CHUNK_SIZE