1
1
from invoke import run , Responder
2
2
import os
3
3
import json
4
+ import pytest
4
5
5
6
this_test_path = os .path .dirname (os .path .realpath (__file__ ))
6
7
# Calculate absolute path of the CLI
@@ -14,12 +15,11 @@ def cli_line(*args):
14
15
# Accept a list of arguments cli_line('lib list --format json')
15
16
# Return a full command line string e.g. 'arduino-cli help --format json'
16
17
cli_full_line = ' ' .join ([cli_path , ' ' .join (str (arg ) for arg in args )])
17
- # print(cli_full_line)
18
18
return cli_full_line
19
19
20
20
21
21
def run_command (* args ):
22
- result = run (cli_line (* args ), echo = False , hide = 'out' )
22
+ result = run (cli_line (* args ), echo = False , hide = True )
23
23
return result
24
24
25
25
@@ -28,7 +28,6 @@ def test_command_help():
28
28
assert result .ok
29
29
assert result .stderr == ''
30
30
assert 'Usage' in result .stdout
31
- # result.out
32
31
33
32
34
33
def test_command_lib_list ():
@@ -50,6 +49,24 @@ def test_command_lib_install():
50
49
def test_command_lib_remove ():
51
50
libs = ['\" AzureIoTProtocol_MQTT\" ' , '\" CMMC MQTT Connector\" ' , '\" WiFiNINA\" ' ]
52
51
result = run_command ('lib uninstall {}' .format (' ' .join (libs )))
52
+ assert result .ok
53
+
54
+ @pytest .mark .slow
55
+ def test_command_lib_search ():
56
+ result = run_command ('lib search' )
57
+ out_lines = result .stdout .splitlines ()
58
+ libs = []
59
+ # Create an array with just the name of the vars
60
+ for line in out_lines :
61
+ if 'Name: ' in line :
62
+ libs .append (line .split ()[1 ].strip ('\" ' ))
63
+ number_of_libs = len (libs )
64
+ # It would be strange to have less than 2000 Arduino Libs published
65
+ assert number_of_libs > 2000
66
+ result = run_command ('lib search --format json' )
67
+ libs_found_from_json = json .loads (result .stdout )
68
+ number_of_libs_from_json = len (libs_found_from_json .get ('libraries' ))
69
+ assert number_of_libs == number_of_libs_from_json
53
70
54
71
55
72
def test_command_board_list ():
@@ -65,3 +82,12 @@ def test_command_board_list():
65
82
def test_command_board_listall ():
66
83
result = run_command ('board listall' )
67
84
assert ['Board' , 'Name' , 'FQBN' ] == result .stdout .splitlines ()[0 ].strip ().split ()
85
+
86
+ def test_command_version ():
87
+ result = run_command ('version --format json' )
88
+ parsed_out = json .loads (result .stdout )
89
+
90
+ assert parsed_out .get ('command' , False ) == 'arduino-cli'
91
+ assert parsed_out .get ('version' , False )
92
+ assert parsed_out .get ('commit' , False )
93
+ assert parsed_out .get ('build_date' , False )
0 commit comments