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
This commit is contained in:
shukari
2025-08-06 23:01:40 +02:00
parent 38b163fa89
commit a79e17a575
2 changed files with 20 additions and 8 deletions

View File

@@ -6,6 +6,7 @@ import os
import platform
import re
import sys
import types
from unittest.mock import mock_open, MagicMock, patch
import pytest
@@ -35,6 +36,12 @@ from ..tcp_interface import TCPInterface
# from ..remote_hardware import onGPIOreceive
# from ..config_pb2 import Config
# create a fake termios for Wwindows, otherwise errors will occur
if sys.platform == "win32":
fake_termios = types.ModuleType("termios")
fake_termios.tcgetattr = lambda fd: None
fake_termios.tcsetattr = lambda fd, when, settings: None
sys.modules["termios"] = fake_termios
@pytest.mark.unit
@pytest.mark.usefixtures("reset_mt_config")
@@ -2676,6 +2683,7 @@ def test_tunnel_no_args(capsys):
assert re.search(r"usage: ", err, re.MULTILINE)
@pytest.mark.skipif(sys.platform == "win32", reason="Linux is forced in test and no termios")
@pytest.mark.unit
@pytest.mark.usefixtures("reset_mt_config")
@patch("meshtastic.util.findPorts", return_value=[])
@@ -2699,6 +2707,7 @@ def test_tunnel_tunnel_arg_with_no_devices(mock_platform_system, caplog, capsys)
assert err == ""
@pytest.mark.skipif(sys.platform == "win32", reason="Linux is forced in test and no termios")
@pytest.mark.unit
@pytest.mark.usefixtures("reset_mt_config")
@patch("meshtastic.util.findPorts", return_value=[])
@@ -2722,6 +2731,7 @@ def test_tunnel_subnet_arg_with_no_devices(mock_platform_system, caplog, capsys)
assert err == ""
@pytest.mark.skipif(sys.platform == "win32", reason="Linux is forced in test and no termios")
@pytest.mark.unit
@pytest.mark.usefixtures("reset_mt_config")
@patch("platform.system")

View File

@@ -672,15 +672,17 @@ def test_getOrCreateByNum(iface_with_nodes):
@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)
try:
with MeshInterface(noProto=True):
raise ValueError("Something went wrong")
except:
assert re.search(
r"An exception of type <class \'ValueError\'> with value Something went wrong has occurred",
caplog.text,
re.MULTILINE,
)
assert re.search(r"Traceback:\n.*in test_exit_with_exception\n {4}raise ValueError\(\"Something went wrong\"\)", caplog.text, re.MULTILINE)
@pytest.mark.unit