25
25
26
26
27
27
def test_defaults (run_command ):
28
- result = run_command (cmd_string = "" , custom_working_dir = test_data_path .joinpath ("recursive" ))
28
+ result = run_command (cmd = [] , custom_working_dir = test_data_path .joinpath ("recursive" ))
29
29
assert result .ok
30
30
31
31
@@ -40,32 +40,32 @@ def test_compliance(run_command, project_folder, compliance_level):
40
40
if compliance_setting == compliance_level :
41
41
expected_ok = True
42
42
43
- result = run_command (cmd_string = "--compliance {} {}" . format ( compliance_setting , project_path ) )
43
+ result = run_command (cmd = [ "--compliance" , compliance_setting , project_path ] )
44
44
assert result .ok == expected_ok
45
45
46
46
47
47
def test_compliance_invalid (run_command ):
48
- result = run_command (cmd_string = "--compliance foo {}" . format ( test_data_path .joinpath ("ValidSketch" )) )
48
+ result = run_command (cmd = [ "--compliance" , " foo" , test_data_path .joinpath ("ValidSketch" )] )
49
49
assert not result .ok
50
50
51
51
52
52
def test_format (run_command ):
53
53
project_path = test_data_path .joinpath ("ValidSketch" )
54
- result = run_command (cmd_string = "--format text {}" . format ( project_path ) )
54
+ result = run_command (cmd = [ "--format" , " text" , project_path ] )
55
55
assert result .ok
56
56
with pytest .raises (json .JSONDecodeError ):
57
57
json .loads (result .stdout )
58
58
59
- result = run_command (cmd_string = "--format json {}" . format ( project_path ) )
59
+ result = run_command (cmd = [ "--format" , " json" , project_path ] )
60
60
assert result .ok
61
61
json .loads (result .stdout )
62
62
63
- result = run_command (cmd_string = "--format foo {}" . format ( project_path ) )
63
+ result = run_command (cmd = [ "--format" , " foo" , project_path ] )
64
64
assert not result .ok
65
65
66
66
67
67
def test_help (run_command ):
68
- result = run_command (cmd_string = "--help" )
68
+ result = run_command (cmd = [ "--help" ] )
69
69
assert result .ok
70
70
assert "Usage:" in result .stdout
71
71
@@ -82,12 +82,12 @@ def test_help(run_command):
82
82
def test_library_manager (run_command , project_folder , expected_exit_statuses ):
83
83
project_path = test_data_path .joinpath ("library-manager" , project_folder )
84
84
for library_manager_setting , expected_exit_status in expected_exit_statuses .items ():
85
- result = run_command (cmd_string = "--library-manager {} {}" . format ( library_manager_setting , project_path ) )
85
+ result = run_command (cmd = [ "--library-manager" , library_manager_setting , project_path ] )
86
86
assert result .exited == expected_exit_status
87
87
88
88
89
89
def test_library_manager_invalid (run_command ):
90
- result = run_command (cmd_string = "--library-manager foo {}" . format ( test_data_path .joinpath ("ValidSketch" )) )
90
+ result = run_command (cmd = [ "--library-manager" , " foo" , test_data_path .joinpath ("ValidSketch" )] )
91
91
assert not result .ok
92
92
93
93
@@ -103,39 +103,39 @@ def test_library_manager_invalid(run_command):
103
103
def test_project_type (run_command , project_folder , expected_exit_statuses ):
104
104
project_path = test_data_path .joinpath ("project-type" , project_folder )
105
105
for project_type , expected_exit_status in expected_exit_statuses .items ():
106
- result = run_command (cmd_string = "--project-type {} {}" . format ( project_type , project_path ) )
106
+ result = run_command (cmd = [ "--project-type" , project_type , project_path ] )
107
107
assert result .exited == expected_exit_status
108
108
109
109
110
110
def test_project_type_invalid (run_command ):
111
- result = run_command (cmd_string = "--project-type foo {}" . format ( test_data_path .joinpath ("ValidSketch" )) )
111
+ result = run_command (cmd = [ "--project-type" , " foo" , test_data_path .joinpath ("ValidSketch" )] )
112
112
assert not result .ok
113
113
114
114
115
115
def test_recursive (run_command ):
116
116
valid_projects_path = test_data_path .joinpath ("recursive" )
117
- result = run_command (cmd_string = "--recursive true {}" . format ( valid_projects_path ) )
117
+ result = run_command (cmd = [ "--recursive" , " true" , valid_projects_path ] )
118
118
assert result .ok
119
119
120
- result = run_command (cmd_string = "--recursive false {}" . format ( valid_projects_path ) )
120
+ result = run_command (cmd = [ "--recursive" , " false" , valid_projects_path ] )
121
121
assert not result .ok
122
122
123
123
124
124
def test_recursive_invalid (run_command ):
125
- result = run_command (cmd_string = "--recursive foo {}" . format ( test_data_path .joinpath ("ValidSketch" )) )
125
+ result = run_command (cmd = [ "--recursive" , " foo" , test_data_path .joinpath ("ValidSketch" )] )
126
126
assert not result .ok
127
127
128
128
129
129
def test_report_file (run_command , working_dir ):
130
130
project_path = test_data_path .joinpath ("ValidSketch" )
131
131
report_file_name = "report.json"
132
- result = run_command (cmd_string = "--report-file {} {}" . format ( report_file_name , project_path ) )
132
+ result = run_command (cmd = [ "--report-file" , report_file_name , project_path ] )
133
133
assert result .ok
134
134
with pathlib .Path (working_dir , report_file_name ).open () as report_file :
135
135
report = json .load (report_file )
136
136
137
137
assert pathlib .PurePath (report ["configuration" ]["paths" ][0 ]) == project_path
138
- assert report ["configuration" ]["projectType" ] == "any project type "
138
+ assert report ["configuration" ]["projectType" ] == "all "
139
139
assert report ["configuration" ]["recursive" ]
140
140
assert pathlib .PurePath (report ["projects" ][0 ]["path" ]) == project_path
141
141
assert report ["projects" ][0 ]["projectType" ] == "sketch"
@@ -147,30 +147,30 @@ def test_report_file(run_command, working_dir):
147
147
148
148
def test_verbose (run_command ):
149
149
project_path = test_data_path .joinpath ("verbose" , "HasWarnings" )
150
- result = run_command (cmd_string = "--format text {}" . format ( project_path ) )
150
+ result = run_command (cmd = [ "--format" , " text" , project_path ] )
151
151
assert result .ok
152
152
assert "result: pass" not in result .stdout
153
153
assert "result: fail" in result .stdout
154
154
155
- result = run_command (cmd_string = "--format text --verbose {}" . format ( project_path ) )
155
+ result = run_command (cmd = [ "--format" , " text" , " --verbose" , project_path ] )
156
156
assert result .ok
157
157
assert "result: pass" in result .stdout
158
158
159
- result = run_command (cmd_string = "--format json {}" . format ( project_path ) )
159
+ result = run_command (cmd = [ "--format" , " json" , project_path ] )
160
160
assert result .ok
161
161
report = json .loads (result .stdout )
162
162
assert True not in [check .get ("result" ) == "pass" for check in report ["projects" ][0 ]["checks" ]]
163
163
assert True in [check .get ("result" ) == "fail" for check in report ["projects" ][0 ]["checks" ]]
164
164
165
- result = run_command (cmd_string = "--format json --verbose {}" . format ( project_path ) )
165
+ result = run_command (cmd = [ "--format" , " json" , " --verbose" , project_path ] )
166
166
assert result .ok
167
167
report = json .loads (result .stdout )
168
168
assert True in [check .get ("result" ) == "pass" for check in report ["projects" ][0 ]["checks" ]]
169
169
assert True in [check .get ("result" ) == "fail" for check in report ["projects" ][0 ]["checks" ]]
170
170
171
171
172
172
def test_version (run_command ):
173
- result = run_command (cmd_string = "--version" )
173
+ result = run_command (cmd = [ "--version" ] )
174
174
assert result .ok
175
175
output_list = result .stdout .strip ().split (sep = " " )
176
176
assert semver .VersionInfo .isvalid (version = output_list [0 ])
@@ -187,10 +187,15 @@ def run_command(pytestconfig, working_dir):
187
187
188
188
arduino_lint_path = pathlib .Path (pytestconfig .rootdir ).parent / "arduino-lint"
189
189
190
- def _run (cmd_string , custom_working_dir = None , custom_env = None ):
190
+ def _run (cmd , custom_working_dir = None , custom_env = None ):
191
+ if cmd is None :
192
+ cmd = []
191
193
if not custom_working_dir :
192
194
custom_working_dir = working_dir
193
- cli_full_line = '"{}" {}' .format (arduino_lint_path , cmd_string )
195
+ quoted_cmd = []
196
+ for token in cmd :
197
+ quoted_cmd .append (f'"{ token } "' )
198
+ cli_full_line = '"{}" {}' .format (arduino_lint_path , " " .join (quoted_cmd ))
194
199
run_context = invoke .context .Context ()
195
200
# It might happen that we need to change directories between drives on Windows,
196
201
# in that case the "/d" flag must be used otherwise directory wouldn't change
0 commit comments