55import semver
66from datetime import datetime
77
8- this_test_path = os .path .dirname (os .path .realpath (__file__ ))
9- # Calculate absolute path of the CLI
10- cli_path = os .path .join (this_test_path , '..' , 'arduino-cli' )
118
12- # Useful reference:
13- # http://docs.pyinvoke.org/en/1.2/api/runners.html#invoke.runners.Result
14-
15-
16- def cli_line (* args ):
17- # Accept a list of arguments cli_line('lib list --format json')
18- # Return a full command line string e.g. 'arduino-cli help --format json'
19- cli_full_line = ' ' .join ([cli_path , ' ' .join (str (arg ) for arg in args )])
20- return cli_full_line
21-
22-
23- def run_command (* args ):
24- result = run (cli_line (* args ), echo = False , hide = True , warn = True )
25- return result
26-
27-
28- def test_command_help ():
9+ def test_command_help (run_command ):
2910 result = run_command ('help' )
3011 assert result .ok
3112 assert result .stderr == ''
3213 assert 'Usage' in result .stdout
3314
3415
35- def test_command_lib_list ():
16+ def test_command_lib_list (run_command ):
3617 """
3718 When ouput is empty, nothing is printed out, no matter the output format
3819 """
3920 result = run_command ('lib list' )
4021 assert result .ok
4122 assert '' == result .stderr
42- result = run_command ('lib list' , ' --format json' )
23+ result = run_command ('lib list --format json' )
4324 assert '' == result .stdout
4425
4526
46- def test_command_lib_install ():
27+ def test_command_lib_install (run_command ):
4728 libs = ['\" AzureIoTProtocol_MQTT\" ' , '\" CMMC MQTT Connector\" ' , '\" WiFiNINA\" ' ]
4829 # Should be safe to run install multiple times
4930 result_1 = run_command ('lib install {}' .format (' ' .join (libs )))
5031 assert result_1 .ok
5132 result_2 = run_command ('lib install {}' .format (' ' .join (libs )))
5233 assert result_2 .ok
5334
54- def test_command_lib_update_index ():
35+ def test_command_lib_update_index (run_command ):
5536 result = run_command ('lib update-index' )
5637 assert result .ok
5738 assert 'Updating index: library_index.json downloaded' == result .stdout .splitlines ()[- 1 ].strip ()
5839
59- def test_command_lib_remove ():
40+ def test_command_lib_remove (run_command ):
6041 libs = ['\" AzureIoTProtocol_MQTT\" ' , '\" CMMC MQTT Connector\" ' , '\" WiFiNINA\" ' ]
6142 result = run_command ('lib uninstall {}' .format (' ' .join (libs )))
6243 assert result .ok
6344
6445@pytest .mark .slow
65- def test_command_lib_search ():
46+ def test_command_lib_search (run_command ):
6647 result = run_command ('lib search' )
6748 assert result .ok
6849 out_lines = result .stdout .splitlines ()
@@ -81,7 +62,7 @@ def test_command_lib_search():
8162 assert number_of_libs == number_of_libs_from_json
8263
8364
84- def test_command_board_list ():
65+ def test_command_board_list (run_command ):
8566 result = run_command ('board list --format json' )
8667 assert result .ok
8768 # check is a valid json and contains a list of ports
@@ -92,13 +73,13 @@ def test_command_board_list():
9273 assert 'protocol_label' in port
9374
9475
95- def test_command_board_listall ():
76+ def test_command_board_listall (run_command ):
9677 result = run_command ('board listall' )
9778 assert result .ok
9879 assert ['Board' , 'Name' , 'FQBN' ] == result .stdout .splitlines ()[0 ].strip ().split ()
9980
10081
101- def test_command_version ():
82+ def test_command_version (run_command ):
10283 result = run_command ('version --format json' )
10384 assert result .ok
10485 parsed_out = json .loads (result .stdout )
0 commit comments