From 8b6321ce7f52c83e9adb5c3fe04c9ffcc52e9942 Mon Sep 17 00:00:00 2001 From: Mike Kinney Date: Sat, 1 Jan 2022 15:21:53 -0800 Subject: [PATCH] add a few more tests --- meshtastic/mesh_interface.py | 3 +-- meshtastic/tests/test_mesh_interface.py | 28 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/meshtastic/mesh_interface.py b/meshtastic/mesh_interface.py index 19a59b3..decb5fb 100644 --- a/meshtastic/mesh_interface.py +++ b/meshtastic/mesh_interface.py @@ -68,8 +68,7 @@ class MeshInterface: def __exit__(self, exc_type, exc_value, traceback): if exc_type is not None and exc_value is not None: - logging.error( - f'An exception of type {exc_type} with value {exc_value} has occurred') + logging.error(f'An exception of type {exc_type} with value {exc_value} has occurred') if traceback is not None: logging.error(f'Traceback: {traceback}') self.close() diff --git a/meshtastic/tests/test_mesh_interface.py b/meshtastic/tests/test_mesh_interface.py index c0a0135..462e25b 100644 --- a/meshtastic/tests/test_mesh_interface.py +++ b/meshtastic/tests/test_mesh_interface.py @@ -560,3 +560,31 @@ def test_getOrCreateByNum(capsys, reset_globals, iface_with_nodes): iface.myInfo.my_node_num = 2475227164 tmp = iface._getOrCreateByNum(2475227164) assert tmp['num'] == 2475227164 + + +@pytest.mark.unit +def test_enter(): + """Test __enter__()""" + iface = MeshInterface(noProto=True) + assert iface == iface.__enter__() + + +@pytest.mark.unit +def test_exit_with_exception(caplog): + """Test __exit__()""" + iface = MeshInterface(noProto=True) + with caplog.at_level(logging.ERROR): + iface.__exit__('foo', 'bar', 'baz') + assert re.search(r'An exception of type foo with value bar has occurred', caplog.text, re.MULTILINE) + assert re.search(r'Traceback: baz', caplog.text, re.MULTILINE) + + +@pytest.mark.unit +def test_showNodes_exclude_self(capsys, caplog, reset_globals, iface_with_nodes): + """Test that we hit that continue statement""" + with caplog.at_level(logging.DEBUG): + iface = iface_with_nodes + iface.localNode.nodeNum = 2475227164 + iface.showNodes() + iface.showNodes(includeSelf=False) + capsys.readouterr()