mirror of
https://github.com/meshtastic/python.git
synced 2026-01-02 12:57:56 -05:00
added --test2 unit test; wip on --info
This commit is contained in:
@@ -13,6 +13,7 @@ import pyqrcode
|
||||
import pkg_resources
|
||||
import meshtastic.util
|
||||
import meshtastic.test
|
||||
from meshtastic.serial_interface import SerialInterface
|
||||
from .serial_interface import SerialInterface
|
||||
from .tcp_interface import TCPInterface
|
||||
from .ble_interface import BLEInterface
|
||||
|
||||
@@ -4,10 +4,11 @@ import sys
|
||||
import argparse
|
||||
import re
|
||||
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import patch, MagicMock
|
||||
import pytest
|
||||
|
||||
from meshtastic.__main__ import initParser, main, Globals
|
||||
#from meshtastic.serial_interface import SerialInterface
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@@ -165,7 +166,7 @@ def test_main_test_one_port(patched_find_ports):
|
||||
@patch('meshtastic.test.testAll', return_value=True)
|
||||
@patch('meshtastic.util.findPorts', return_value=['/dev/ttyFake1', '/dev/ttyFake2'])
|
||||
def test_main_test_two_ports_success(patched_find_ports, patched_test_all):
|
||||
"""Test --test two fake ports"""
|
||||
"""Test --test two fake ports and testAll() is a simulated success"""
|
||||
sys.argv = ['', '--test']
|
||||
args = sys.argv
|
||||
parser = None
|
||||
@@ -179,3 +180,51 @@ def test_main_test_two_ports_success(patched_find_ports, patched_test_all):
|
||||
assert pytest_wrapped_e.value.code == 0
|
||||
# TODO: why does this fail? patched_find_ports.assert_called()
|
||||
patched_test_all.assert_called()
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@patch('meshtastic.test.testAll', return_value=False)
|
||||
@patch('meshtastic.util.findPorts', return_value=['/dev/ttyFake1', '/dev/ttyFake2'])
|
||||
def test_main_test_two_ports_fails(patched_find_ports, patched_test_all):
|
||||
"""Test --test two fake ports and testAll() is a simulated failure"""
|
||||
sys.argv = ['', '--test']
|
||||
args = sys.argv
|
||||
parser = None
|
||||
parser = argparse.ArgumentParser()
|
||||
our_globals = Globals.getInstance()
|
||||
our_globals.set_parser(parser)
|
||||
our_globals.set_args(args)
|
||||
with pytest.raises(SystemExit) as pytest_wrapped_e:
|
||||
main()
|
||||
assert pytest_wrapped_e.type == SystemExit
|
||||
assert pytest_wrapped_e.value.code == 1
|
||||
# TODO: why does this fail? patched_find_ports.assert_called()
|
||||
patched_test_all.assert_called()
|
||||
#
|
||||
#
|
||||
#@pytest.mark.unit
|
||||
#@patch('meshtastic.stream_interface.StreamInterface.__init__')
|
||||
#@patch('serial.Serial')
|
||||
#@patch('meshtastic.serial_interface.SerialInterface')
|
||||
#@patch('meshtastic.util.findPorts', return_value=['/dev/ttyFake1'])
|
||||
#def test_main_info_one_port(patched_find_ports, patched_serial_interface,
|
||||
# patched_serial_serial, patched_stream_interface_constructor):
|
||||
# """Test --info one fake port"""
|
||||
# iface = MagicMock()
|
||||
# patched_serial_interface.return_value = iface
|
||||
# astream = MagicMock()
|
||||
# patched_serial_serial = astream
|
||||
# siface = MagicMock()
|
||||
# patched_stream_interface_constructor = siface
|
||||
# sys.argv = ['', '--info']
|
||||
# args = sys.argv
|
||||
# parser = None
|
||||
# parser = argparse.ArgumentParser()
|
||||
# our_globals = Globals.getInstance()
|
||||
# our_globals.set_parser(parser)
|
||||
# our_globals.set_args(args)
|
||||
# main()
|
||||
# patched_find_ports.assert_called()
|
||||
# patched_serial_interface.assert_called()
|
||||
# patched_serial_serial.assert_called()
|
||||
# patched_stream_interface_constructor
|
||||
|
||||
Reference in New Issue
Block a user