From 0d574490306f66bfd8f65eec01d8ad1a21b696b8 Mon Sep 17 00:00:00 2001 From: Steve Holden Date: Wed, 10 Apr 2024 14:25:17 +0100 Subject: [PATCH] Begin to rationalise test data. Also refactor to silence some CI issues. --- meshtastic/globals.py | 10 +++++++++- meshtastic/tests/test_mesh_interface.py | 14 +++++++------- meshtastic/tests/test_tunnel.py | 3 ++- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/meshtastic/globals.py b/meshtastic/globals.py index fb379c1..58fe76e 100644 --- a/meshtastic/globals.py +++ b/meshtastic/globals.py @@ -15,6 +15,7 @@ with rather more easily once the code is simplified by this change. def reset(): """ + Restore the namespace to pristine condition. """ global args, parser, channel_index, logfile, tunnelInstance, camel_case args = None @@ -25,4 +26,11 @@ def reset(): # TODO: to migrate to camel_case for v1.3 change this value to True camel_case = False -reset() \ No newline at end of file +# These assignments are used instead of calling reset() +# purely to shut pylint up. +args = None +parser = None +channel_index = None +logfile = None +tunnelInstance = None +camel_case = False diff --git a/meshtastic/tests/test_mesh_interface.py b/meshtastic/tests/test_mesh_interface.py index 0667933..791a92a 100644 --- a/meshtastic/tests/test_mesh_interface.py +++ b/meshtastic/tests/test_mesh_interface.py @@ -21,11 +21,12 @@ def test_MeshInterface(capsys): """Test that we can instantiate a MeshInterface""" iface = MeshInterface(noProto=True) - nodes = { - "!9388f81c": { - "num": 2475227164, + NODE_ID = "!9388f81c" + NODE_NUM = 2475227164 + node = { + "num": NODE_NUM, "user": { - "id": "!9388f81c", + "id": NODE_ID, "longName": "Unknown f81c", "shortName": "?1C", "macaddr": "RBeTiPgc", @@ -34,10 +35,9 @@ def test_MeshInterface(capsys): "position": {}, "lastHeard": 1640204888, } - } - iface.nodesByNum = {2475227164: nodes["!9388f81c"]} - iface.nodes = nodes + iface.nodes = {NODE_ID: node} + iface.nodesByNum = {NODE_NUM: node} myInfo = MagicMock() iface.myInfo = myInfo diff --git a/meshtastic/tests/test_tunnel.py b/meshtastic/tests/test_tunnel.py index ea2df71..d4a95fc 100644 --- a/meshtastic/tests/test_tunnel.py +++ b/meshtastic/tests/test_tunnel.py @@ -1,5 +1,4 @@ """Meshtastic unit tests for tunnel.py""" -from meshtastic import globals import logging import re import sys @@ -7,6 +6,8 @@ from unittest.mock import MagicMock, patch import pytest +from meshtastic import globals + from ..tcp_interface import TCPInterface from ..tunnel import Tunnel, onTunnelReceive