mirror of
https://github.com/meshtastic/python.git
synced 2025-12-30 03:17:54 -05:00
figured out how to unit test --set with invalid field
This commit is contained in:
@@ -658,3 +658,35 @@ def test_main_set_valid(capsys):
|
||||
assert re.search(r'Set wifi_ssid to foo', out, re.MULTILINE)
|
||||
assert err == ''
|
||||
mo.assert_called()
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_main_set_with_invalid(capsys):
|
||||
"""Test --set with invalid field"""
|
||||
sys.argv = ['', '--set', 'foo', 'foo']
|
||||
args = sys.argv
|
||||
parser = None
|
||||
parser = argparse.ArgumentParser()
|
||||
our_globals = Globals.getInstance()
|
||||
our_globals.set_parser(parser)
|
||||
our_globals.set_args(args)
|
||||
our_globals.set_target_node(None)
|
||||
|
||||
mocked_user_prefs = MagicMock()
|
||||
mocked_user_prefs.DESCRIPTOR.fields_by_name.get.return_value = None
|
||||
|
||||
mocked_node = MagicMock(autospec=Node)
|
||||
mocked_node.radioConfig.preferences = ( mocked_user_prefs )
|
||||
|
||||
iface = MagicMock(autospec=SerialInterface)
|
||||
iface.getNode.return_value = mocked_node
|
||||
|
||||
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
|
||||
main()
|
||||
out, err = capsys.readouterr()
|
||||
print('out:', out)
|
||||
print('err:', err)
|
||||
assert re.search(r'Connected to radio', out, re.MULTILINE)
|
||||
assert re.search(r'does not have an attribute called foo', out, re.MULTILINE)
|
||||
assert err == ''
|
||||
mo.assert_called()
|
||||
|
||||
Reference in New Issue
Block a user