11from pathlib import Path
22from tempfile import TemporaryDirectory
3+ from unittest .mock import patch
34
45import pytest
56
1011BLINK_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+
1320def 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+
2250def test_version ():
2351 output = tycmd .version (full = True )
2452 assert isinstance (output , str )
0 commit comments