Fix linting errors and duplicate function

This commit is contained in:
Crank-Git
2025-06-08 19:51:21 -04:00
parent 23be2d2189
commit aa786c7ebd
2 changed files with 48 additions and 36 deletions

View File

@@ -2713,24 +2713,6 @@ def test_remove_ignored_node():
main()
mocked_node.removeIgnored.assert_called_once_with("!12345678")
@pytest.mark.unit
@pytest.mark.usefixtures("reset_mt_config")
def test_main_set_owner_short_to_bob(capsys):
"""Test --set-owner-short bob"""
sys.argv = ["", "--set-owner-short", "bob"]
mt_config.args = sys.argv
iface = MagicMock(autospec=SerialInterface)
with patch("meshtastic.serial_interface.SerialInterface", return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r"Connected to radio", out, re.MULTILINE)
assert re.search(r"Setting device owner short to bob", out, re.MULTILINE)
assert err == ""
mo.assert_called()
@pytest.mark.unit
@pytest.mark.usefixtures("reset_mt_config")
def test_main_set_owner_whitespace_only(capsys):
@@ -2740,8 +2722,8 @@ def test_main_set_owner_whitespace_only(capsys):
with pytest.raises(SystemExit) as excinfo:
main()
out, err = capsys.readouterr()
out, _ = capsys.readouterr()
assert "ERROR: Long Name cannot be empty or contain only whitespace characters" in out
assert excinfo.value.code == 1
@@ -2755,8 +2737,8 @@ def test_main_set_owner_empty_string(capsys):
with pytest.raises(SystemExit) as excinfo:
main()
out, err = capsys.readouterr()
out, _ = capsys.readouterr()
assert "ERROR: Long Name cannot be empty or contain only whitespace characters" in out
assert excinfo.value.code == 1
@@ -2770,8 +2752,8 @@ def test_main_set_owner_short_whitespace_only(capsys):
with pytest.raises(SystemExit) as excinfo:
main()
out, err = capsys.readouterr()
out, _ = capsys.readouterr()
assert "ERROR: Short Name cannot be empty or contain only whitespace characters" in out
assert excinfo.value.code == 1
@@ -2785,7 +2767,37 @@ def test_main_set_owner_short_empty_string(capsys):
with pytest.raises(SystemExit) as excinfo:
main()
out, err = capsys.readouterr()
out, _ = capsys.readouterr()
assert "ERROR: Short Name cannot be empty or contain only whitespace characters" in out
assert excinfo.value.code == 1
@pytest.mark.unit
@pytest.mark.usefixtures("reset_mt_config")
def test_main_set_ham_whitespace_only(capsys):
"""Test --set-ham with whitespace-only name"""
sys.argv = ["", "--set-ham", " "]
mt_config.args = sys.argv
with pytest.raises(SystemExit) as excinfo:
main()
out, _ = capsys.readouterr()
assert "ERROR: Ham radio callsign cannot be empty or contain only whitespace characters" in out
assert excinfo.value.code == 1
@pytest.mark.unit
@pytest.mark.usefixtures("reset_mt_config")
def test_main_set_ham_empty_string(capsys):
"""Test --set-ham with empty string"""
sys.argv = ["", "--set-ham", ""]
mt_config.args = sys.argv
with pytest.raises(SystemExit) as excinfo:
main()
out, _ = capsys.readouterr()
assert "ERROR: Ham radio callsign cannot be empty or contain only whitespace characters" in out
assert excinfo.value.code == 1

View File

@@ -1487,8 +1487,8 @@ def test_setOwner_whitespace_only_long_name(capsys):
with pytest.raises(SystemExit) as excinfo:
anode.setOwner(long_name=" ")
out, err = capsys.readouterr()
out, _ = capsys.readouterr()
assert "ERROR: Long Name cannot be empty or contain only whitespace characters" in out
assert excinfo.value.code == 1
@@ -1501,8 +1501,8 @@ def test_setOwner_empty_long_name(capsys):
with pytest.raises(SystemExit) as excinfo:
anode.setOwner(long_name="")
out, err = capsys.readouterr()
out, _ = capsys.readouterr()
assert "ERROR: Long Name cannot be empty or contain only whitespace characters" in out
assert excinfo.value.code == 1
@@ -1515,8 +1515,8 @@ def test_setOwner_whitespace_only_short_name(capsys):
with pytest.raises(SystemExit) as excinfo:
anode.setOwner(short_name=" ")
out, err = capsys.readouterr()
out, _ = capsys.readouterr()
assert "ERROR: Short Name cannot be empty or contain only whitespace characters" in out
assert excinfo.value.code == 1
@@ -1529,8 +1529,8 @@ def test_setOwner_empty_short_name(capsys):
with pytest.raises(SystemExit) as excinfo:
anode.setOwner(short_name="")
out, err = capsys.readouterr()
out, _ = capsys.readouterr()
assert "ERROR: Short Name cannot be empty or contain only whitespace characters" in out
assert excinfo.value.code == 1
@@ -1540,10 +1540,10 @@ def test_setOwner_valid_names(caplog):
"""Test setOwner with valid names"""
iface = MagicMock(autospec=MeshInterface)
anode = Node(iface, 123, noProto=True)
with caplog.at_level(logging.DEBUG):
anode.setOwner(long_name="ValidName", short_name="VN")
# Should not raise any exceptions and should call _sendAdmin
iface._sendAdmin.assert_called_once()
assert re.search(r'p.set_owner.long_name:ValidName:', caplog.text, re.MULTILINE)