5
5
import semver
6
6
from datetime import datetime
7
7
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' )
11
8
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 ):
29
10
result = run_command ('help' )
30
11
assert result .ok
31
12
assert result .stderr == ''
32
13
assert 'Usage' in result .stdout
33
14
34
15
35
- def test_command_lib_list ():
16
+ def test_command_lib_list (run_command ):
36
17
"""
37
18
When ouput is empty, nothing is printed out, no matter the output format
38
19
"""
39
20
result = run_command ('lib list' )
40
21
assert result .ok
41
22
assert '' == result .stderr
42
- result = run_command ('lib list' , ' --format json' )
23
+ result = run_command ('lib list --format json' )
43
24
assert '' == result .stdout
44
25
45
26
46
- def test_command_lib_install ():
27
+ def test_command_lib_install (run_command ):
47
28
libs = ['\" AzureIoTProtocol_MQTT\" ' , '\" CMMC MQTT Connector\" ' , '\" WiFiNINA\" ' ]
48
29
# Should be safe to run install multiple times
49
30
result_1 = run_command ('lib install {}' .format (' ' .join (libs )))
50
31
assert result_1 .ok
51
32
result_2 = run_command ('lib install {}' .format (' ' .join (libs )))
52
33
assert result_2 .ok
53
34
54
- def test_command_lib_update_index ():
35
+ def test_command_lib_update_index (run_command ):
55
36
result = run_command ('lib update-index' )
56
37
assert result .ok
57
38
assert 'Updating index: library_index.json downloaded' == result .stdout .splitlines ()[- 1 ].strip ()
58
39
59
- def test_command_lib_remove ():
40
+ def test_command_lib_remove (run_command ):
60
41
libs = ['\" AzureIoTProtocol_MQTT\" ' , '\" CMMC MQTT Connector\" ' , '\" WiFiNINA\" ' ]
61
42
result = run_command ('lib uninstall {}' .format (' ' .join (libs )))
62
43
assert result .ok
63
44
64
45
@pytest .mark .slow
65
- def test_command_lib_search ():
46
+ def test_command_lib_search (run_command ):
66
47
result = run_command ('lib search' )
67
48
assert result .ok
68
49
out_lines = result .stdout .splitlines ()
@@ -81,7 +62,7 @@ def test_command_lib_search():
81
62
assert number_of_libs == number_of_libs_from_json
82
63
83
64
84
- def test_command_board_list ():
65
+ def test_command_board_list (run_command ):
85
66
result = run_command ('board list --format json' )
86
67
assert result .ok
87
68
# check is a valid json and contains a list of ports
@@ -92,13 +73,13 @@ def test_command_board_list():
92
73
assert 'protocol_label' in port
93
74
94
75
95
- def test_command_board_listall ():
76
+ def test_command_board_listall (run_command ):
96
77
result = run_command ('board listall' )
97
78
assert result .ok
98
79
assert ['Board' , 'Name' , 'FQBN' ] == result .stdout .splitlines ()[0 ].strip ().split ()
99
80
100
81
101
- def test_command_version ():
82
+ def test_command_version (run_command ):
102
83
result = run_command ('version --format json' )
103
84
assert result .ok
104
85
parsed_out = json .loads (result .stdout )
0 commit comments