Skip to content

Commit a79e17a

Browse files
committed
fix test_exit_with_exception test, pytest for windows
- test are now runable on windows, some are ignored and a fake termios for the decorators - test_exit_with_exception with a true exception
1 parent 38b163f commit a79e17a

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

meshtastic/tests/test_main.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import platform
77
import re
88
import sys
9+
import types
910
from unittest.mock import mock_open, MagicMock, patch
1011

1112
import pytest
@@ -35,6 +36,12 @@
3536
# from ..remote_hardware import onGPIOreceive
3637
# from ..config_pb2 import Config
3738

39+
# create a fake termios for Wwindows, otherwise errors will occur
40+
if sys.platform == "win32":
41+
fake_termios = types.ModuleType("termios")
42+
fake_termios.tcgetattr = lambda fd: None
43+
fake_termios.tcsetattr = lambda fd, when, settings: None
44+
sys.modules["termios"] = fake_termios
3845

3946
@pytest.mark.unit
4047
@pytest.mark.usefixtures("reset_mt_config")
@@ -2676,6 +2683,7 @@ def test_tunnel_no_args(capsys):
26762683
assert re.search(r"usage: ", err, re.MULTILINE)
26772684

26782685

2686+
@pytest.mark.skipif(sys.platform == "win32", reason="Linux is forced in test and no termios")
26792687
@pytest.mark.unit
26802688
@pytest.mark.usefixtures("reset_mt_config")
26812689
@patch("meshtastic.util.findPorts", return_value=[])
@@ -2699,6 +2707,7 @@ def test_tunnel_tunnel_arg_with_no_devices(mock_platform_system, caplog, capsys)
26992707
assert err == ""
27002708

27012709

2710+
@pytest.mark.skipif(sys.platform == "win32", reason="Linux is forced in test and no termios")
27022711
@pytest.mark.unit
27032712
@pytest.mark.usefixtures("reset_mt_config")
27042713
@patch("meshtastic.util.findPorts", return_value=[])
@@ -2722,6 +2731,7 @@ def test_tunnel_subnet_arg_with_no_devices(mock_platform_system, caplog, capsys)
27222731
assert err == ""
27232732

27242733

2734+
@pytest.mark.skipif(sys.platform == "win32", reason="Linux is forced in test and no termios")
27252735
@pytest.mark.unit
27262736
@pytest.mark.usefixtures("reset_mt_config")
27272737
@patch("platform.system")

meshtastic/tests/test_mesh_interface.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -672,15 +672,17 @@ def test_getOrCreateByNum(iface_with_nodes):
672672
@pytest.mark.unit
673673
def test_exit_with_exception(caplog):
674674
"""Test __exit__()"""
675-
iface = MeshInterface(noProto=True)
676675
with caplog.at_level(logging.ERROR):
677-
iface.__exit__("foo", "bar", "baz")
678-
assert re.search(
679-
r"An exception of type foo with value bar has occurred",
680-
caplog.text,
681-
re.MULTILINE,
682-
)
683-
assert re.search(r"Traceback: baz", caplog.text, re.MULTILINE)
676+
try:
677+
with MeshInterface(noProto=True):
678+
raise ValueError("Something went wrong")
679+
except:
680+
assert re.search(
681+
r"An exception of type <class \'ValueError\'> with value Something went wrong has occurred",
682+
caplog.text,
683+
re.MULTILINE,
684+
)
685+
assert re.search(r"Traceback:\n.*in test_exit_with_exception\n {4}raise ValueError\(\"Something went wrong\"\)", caplog.text, re.MULTILINE)
684686

685687

686688
@pytest.mark.unit

0 commit comments

Comments
 (0)