From 267923fdc5a7418254150904af6dc6f8a1461e35 Mon Sep 17 00:00:00 2001 From: Ian McEwen Date: Tue, 25 Jun 2024 18:14:07 -0700 Subject: [PATCH] Add hypothesis fuzzing test for _timeago --- meshtastic/tests/test_mesh_interface.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/meshtastic/tests/test_mesh_interface.py b/meshtastic/tests/test_mesh_interface.py index 810138c..5e8441c 100644 --- a/meshtastic/tests/test_mesh_interface.py +++ b/meshtastic/tests/test_mesh_interface.py @@ -5,6 +5,7 @@ import re from unittest.mock import MagicMock, patch import pytest +from hypothesis import given, strategies as st from .. import mesh_pb2, config_pb2, BROADCAST_ADDR, LOCAL_ADDR from ..mesh_interface import MeshInterface, _timeago @@ -696,3 +697,9 @@ def test_timeago(): assert _timeago(99999) == "1 day ago" assert _timeago(9999999) == "3 months ago" assert _timeago(-999) == "now" + +@given(seconds=st.integers()) +def test_timeago_fuzz(seconds): + """Fuzz _timeago to ensure it works with any integer""" + val = _timeago(seconds) + assert re.match(r"(now|\d+ (secs?|mins?|hours?|days?|months?|years?))", val)