diff --git a/meshtastic/tests/test_util.py b/meshtastic/tests/test_util.py index b7a2aa6..5679d1a 100644 --- a/meshtastic/tests/test_util.py +++ b/meshtastic/tests/test_util.py @@ -8,7 +8,8 @@ import pytest from meshtastic.util import (fixme, stripnl, pskToString, our_exit, support_info, genPSK256, fromStr, fromPSK, quoteBooleans, catchAndIgnore, - remove_keys_from_dict) + remove_keys_from_dict, Timeout, hexstr, + ipstr, readnet_u16) @pytest.mark.unit @@ -174,3 +175,39 @@ def test_remove_keys_from_dict_empty_keys(): def test_remove_keys_from_dict(): """Test remove_keys_from_dict()""" assert remove_keys_from_dict(('b'), {'a':1, 'b':2}) == {'a':1} + + +@pytest.mark.unit +def test_Timeout_not_found(): + """Test Timeout()""" + to = Timeout(0.2) + attrs = ('foo') + to.waitForSet('bar', attrs) + + +@pytest.mark.unit +def test_Timeout_found(): + """Test Timeout()""" + to = Timeout(0.2) + attrs = () + to.waitForSet('bar', attrs) + + +@pytest.mark.unit +def test_hexstr(): + """Test hexstr()""" + assert hexstr(b'123') == '31:32:33' + assert hexstr(b'') == '' + + +@pytest.mark.unit +def test_ipstr(): + """Test ipstr()""" + assert ipstr(b'1234') == '49.50.51.52' + assert ipstr(b'') == '' + + +@pytest.mark.unit +def test_readnet_u16(): + """Test readnet_u16()""" + assert readnet_u16(b'123456', 2) == 13108 diff --git a/meshtastic/util.py b/meshtastic/util.py index 00019f2..0a3fca5 100644 --- a/meshtastic/util.py +++ b/meshtastic/util.py @@ -169,8 +169,7 @@ class DeferredExecution(): o = self.queue.get() o() except: - logging.error( - f"Unexpected error in deferred execution {sys.exc_info()[0]}") + logging.error(f"Unexpected error in deferred execution {sys.exc_info()[0]}") print(traceback.format_exc())