Skip to content

Commit aa786c7

Browse files
committed
Fix linting errors and duplicate function
1 parent 23be2d2 commit aa786c7

File tree

2 files changed

+48
-36
lines changed

2 files changed

+48
-36
lines changed

meshtastic/tests/test_main.py

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2713,24 +2713,6 @@ def test_remove_ignored_node():
27132713
main()
27142714

27152715
mocked_node.removeIgnored.assert_called_once_with("!12345678")
2716-
2717-
@pytest.mark.unit
2718-
@pytest.mark.usefixtures("reset_mt_config")
2719-
def test_main_set_owner_short_to_bob(capsys):
2720-
"""Test --set-owner-short bob"""
2721-
sys.argv = ["", "--set-owner-short", "bob"]
2722-
mt_config.args = sys.argv
2723-
2724-
iface = MagicMock(autospec=SerialInterface)
2725-
with patch("meshtastic.serial_interface.SerialInterface", return_value=iface) as mo:
2726-
main()
2727-
out, err = capsys.readouterr()
2728-
assert re.search(r"Connected to radio", out, re.MULTILINE)
2729-
assert re.search(r"Setting device owner short to bob", out, re.MULTILINE)
2730-
assert err == ""
2731-
mo.assert_called()
2732-
2733-
27342716
@pytest.mark.unit
27352717
@pytest.mark.usefixtures("reset_mt_config")
27362718
def test_main_set_owner_whitespace_only(capsys):
@@ -2740,8 +2722,8 @@ def test_main_set_owner_whitespace_only(capsys):
27402722

27412723
with pytest.raises(SystemExit) as excinfo:
27422724
main()
2743-
2744-
out, err = capsys.readouterr()
2725+
2726+
out, _ = capsys.readouterr()
27452727
assert "ERROR: Long Name cannot be empty or contain only whitespace characters" in out
27462728
assert excinfo.value.code == 1
27472729

@@ -2755,8 +2737,8 @@ def test_main_set_owner_empty_string(capsys):
27552737

27562738
with pytest.raises(SystemExit) as excinfo:
27572739
main()
2758-
2759-
out, err = capsys.readouterr()
2740+
2741+
out, _ = capsys.readouterr()
27602742
assert "ERROR: Long Name cannot be empty or contain only whitespace characters" in out
27612743
assert excinfo.value.code == 1
27622744

@@ -2770,8 +2752,8 @@ def test_main_set_owner_short_whitespace_only(capsys):
27702752

27712753
with pytest.raises(SystemExit) as excinfo:
27722754
main()
2773-
2774-
out, err = capsys.readouterr()
2755+
2756+
out, _ = capsys.readouterr()
27752757
assert "ERROR: Short Name cannot be empty or contain only whitespace characters" in out
27762758
assert excinfo.value.code == 1
27772759

@@ -2785,7 +2767,37 @@ def test_main_set_owner_short_empty_string(capsys):
27852767

27862768
with pytest.raises(SystemExit) as excinfo:
27872769
main()
2788-
2789-
out, err = capsys.readouterr()
2770+
2771+
out, _ = capsys.readouterr()
27902772
assert "ERROR: Short Name cannot be empty or contain only whitespace characters" in out
27912773
assert excinfo.value.code == 1
2774+
2775+
2776+
@pytest.mark.unit
2777+
@pytest.mark.usefixtures("reset_mt_config")
2778+
def test_main_set_ham_whitespace_only(capsys):
2779+
"""Test --set-ham with whitespace-only name"""
2780+
sys.argv = ["", "--set-ham", " "]
2781+
mt_config.args = sys.argv
2782+
2783+
with pytest.raises(SystemExit) as excinfo:
2784+
main()
2785+
2786+
out, _ = capsys.readouterr()
2787+
assert "ERROR: Ham radio callsign cannot be empty or contain only whitespace characters" in out
2788+
assert excinfo.value.code == 1
2789+
2790+
2791+
@pytest.mark.unit
2792+
@pytest.mark.usefixtures("reset_mt_config")
2793+
def test_main_set_ham_empty_string(capsys):
2794+
"""Test --set-ham with empty string"""
2795+
sys.argv = ["", "--set-ham", ""]
2796+
mt_config.args = sys.argv
2797+
2798+
with pytest.raises(SystemExit) as excinfo:
2799+
main()
2800+
2801+
out, _ = capsys.readouterr()
2802+
assert "ERROR: Ham radio callsign cannot be empty or contain only whitespace characters" in out
2803+
assert excinfo.value.code == 1

meshtastic/tests/test_node.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,8 +1487,8 @@ def test_setOwner_whitespace_only_long_name(capsys):
14871487

14881488
with pytest.raises(SystemExit) as excinfo:
14891489
anode.setOwner(long_name=" ")
1490-
1491-
out, err = capsys.readouterr()
1490+
1491+
out, _ = capsys.readouterr()
14921492
assert "ERROR: Long Name cannot be empty or contain only whitespace characters" in out
14931493
assert excinfo.value.code == 1
14941494

@@ -1501,8 +1501,8 @@ def test_setOwner_empty_long_name(capsys):
15011501

15021502
with pytest.raises(SystemExit) as excinfo:
15031503
anode.setOwner(long_name="")
1504-
1505-
out, err = capsys.readouterr()
1504+
1505+
out, _ = capsys.readouterr()
15061506
assert "ERROR: Long Name cannot be empty or contain only whitespace characters" in out
15071507
assert excinfo.value.code == 1
15081508

@@ -1515,8 +1515,8 @@ def test_setOwner_whitespace_only_short_name(capsys):
15151515

15161516
with pytest.raises(SystemExit) as excinfo:
15171517
anode.setOwner(short_name=" ")
1518-
1519-
out, err = capsys.readouterr()
1518+
1519+
out, _ = capsys.readouterr()
15201520
assert "ERROR: Short Name cannot be empty or contain only whitespace characters" in out
15211521
assert excinfo.value.code == 1
15221522

@@ -1529,8 +1529,8 @@ def test_setOwner_empty_short_name(capsys):
15291529

15301530
with pytest.raises(SystemExit) as excinfo:
15311531
anode.setOwner(short_name="")
1532-
1533-
out, err = capsys.readouterr()
1532+
1533+
out, _ = capsys.readouterr()
15341534
assert "ERROR: Short Name cannot be empty or contain only whitespace characters" in out
15351535
assert excinfo.value.code == 1
15361536

@@ -1540,10 +1540,10 @@ def test_setOwner_valid_names(caplog):
15401540
"""Test setOwner with valid names"""
15411541
iface = MagicMock(autospec=MeshInterface)
15421542
anode = Node(iface, 123, noProto=True)
1543-
1543+
15441544
with caplog.at_level(logging.DEBUG):
15451545
anode.setOwner(long_name="ValidName", short_name="VN")
1546-
1546+
15471547
# Should not raise any exceptions and should call _sendAdmin
15481548
iface._sendAdmin.assert_called_once()
15491549
assert re.search(r'p.set_owner.long_name:ValidName:', caplog.text, re.MULTILINE)

0 commit comments

Comments
 (0)