Skip to content

Commit 267923f

Browse files
committed
Add hypothesis fuzzing test for _timeago
1 parent 9ab1b32 commit 267923f

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

meshtastic/tests/test_mesh_interface.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from unittest.mock import MagicMock, patch
66

77
import pytest
8+
from hypothesis import given, strategies as st
89

910
from .. import mesh_pb2, config_pb2, BROADCAST_ADDR, LOCAL_ADDR
1011
from ..mesh_interface import MeshInterface, _timeago
@@ -696,3 +697,9 @@ def test_timeago():
696697
assert _timeago(99999) == "1 day ago"
697698
assert _timeago(9999999) == "3 months ago"
698699
assert _timeago(-999) == "now"
700+
701+
@given(seconds=st.integers())
702+
def test_timeago_fuzz(seconds):
703+
"""Fuzz _timeago to ensure it works with any integer"""
704+
val = _timeago(seconds)
705+
assert re.match(r"(now|\d+ (secs?|mins?|hours?|days?|months?|years?))", val)

0 commit comments

Comments
 (0)