From dd4fccbc779f61971b88f663b17b7005239de4a2 Mon Sep 17 00:00:00 2001 From: Ian McEwen Date: Wed, 5 Jun 2024 19:29:55 -0700 Subject: [PATCH] Add a fairly simple property-based test as a starting point --- .gitignore | 1 + meshtastic/tests/test_util.py | 16 ++++++++++++++++ requirements.txt | 1 + 3 files changed, 18 insertions(+) diff --git a/.gitignore b/.gitignore index f2c823c..578ac95 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ venv/ __pycache__ examples/__pycache__ meshtastic.spec +.hypothesis/ diff --git a/meshtastic/tests/test_util.py b/meshtastic/tests/test_util.py index 32ca3db..4980c76 100644 --- a/meshtastic/tests/test_util.py +++ b/meshtastic/tests/test_util.py @@ -6,6 +6,7 @@ import re from unittest.mock import patch import pytest +from hypothesis import given, strategies as st from meshtastic.supported_device import SupportedDevice from meshtastic.mesh_pb2 import MyNodeInfo @@ -577,3 +578,18 @@ def test_acknowledgement_reset(): assert test_ack_obj.receivedTraceRoute is False assert test_ack_obj.receivedTelemetry is False assert test_ack_obj.receivedPosition is False + +@given(a_string=st.text( + alphabet=st.characters( + codec='ascii', + min_codepoint=0x5F, + max_codepoint=0x7A, + exclude_characters=r'`', + )).filter( + lambda x: x not in [''] and x[0] not in "_" and x[-1] not in '_' and not re.search(r'__', x) + )) +def test_roundtrip_snake_to_camel_camel_to_snake(a_string): + value0 = snake_to_camel(a_string=a_string) + value1 = camel_to_snake(a_string=value0) + assert a_string == value1, (a_string, value1) + diff --git a/requirements.txt b/requirements.txt index b9e5423..000ef87 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,6 +14,7 @@ autopep8 pylint pytest pytest-cov +hypothesis pyyaml pytap2 pdoc3