Skip to content

Commit e1c5389

Browse files
committed
add unit test for list_boards()
1 parent 0694d22 commit e1c5389

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/test_tycmd.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from pathlib import Path
22
from tempfile import TemporaryDirectory
3+
from unittest.mock import patch
34

45
import pytest
56

@@ -10,6 +11,12 @@
1011
BLINK_HEX = Path(__file__).parent.joinpath("blink.hex").resolve()
1112

1213

14+
@pytest.fixture
15+
def mock_check_output():
16+
with patch("tycmd.check_output") as mock_check_output:
17+
yield mock_check_output
18+
19+
1320
def test_identify():
1421
with TemporaryDirectory() as temp_directory:
1522
firmware_file = Path(temp_directory).joinpath("firmware.hex")
@@ -19,6 +26,27 @@ def test_identify():
1926
assert "Teensy 4.0" in tycmd.identify(BLINK_HEX)
2027

2128

29+
def test_list_boards(mock_check_output):
30+
mock_check_output.return_value = (
31+
'[\n {"action": "add", "tag": "12345678-Teensy", "serial": "12345678", '
32+
'"description": "USB Serial", "model": "Teensy 4.1", "location": "usb-3-3", '
33+
'"capabilities": ["unique", "run", "rtc", "reboot", "serial"], '
34+
'"interfaces": [["Serial", "/dev/ttyACM0"]]}\n]\n'
35+
)
36+
output = tycmd.list_boards()
37+
mock_check_output.assert_called_once_with(
38+
["tycmd", "list", "-O", "json", "-v"], text=True
39+
)
40+
assert isinstance(output, list)
41+
assert isinstance(output[0], dict)
42+
assert output[0]["serial"] == "12345678"
43+
44+
mock_check_output.return_value = "[\n]\n"
45+
output = tycmd.list_boards()
46+
assert isinstance(output, list)
47+
assert len(output) == 0
48+
49+
2250
def test_version():
2351
output = tycmd.version(full=True)
2452
assert isinstance(output, str)

0 commit comments

Comments
 (0)