Skip to content

Commit ed69697

Browse files
committed
Quote commands in integration tests
This is necessary to support paths that contain spaces.
1 parent 1805623 commit ed69697

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

test/test_all.py

+28-23
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626

2727
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"))
2929
assert result.ok
3030

3131

@@ -40,32 +40,32 @@ def test_compliance(run_command, project_folder, compliance_level):
4040
if compliance_setting == compliance_level:
4141
expected_ok = True
4242

43-
result = run_command(cmd_string="--compliance {} {}".format(compliance_setting, project_path))
43+
result = run_command(cmd=["--compliance", compliance_setting, project_path])
4444
assert result.ok == expected_ok
4545

4646

4747
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")])
4949
assert not result.ok
5050

5151

5252
def test_format(run_command):
5353
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])
5555
assert result.ok
5656
with pytest.raises(json.JSONDecodeError):
5757
json.loads(result.stdout)
5858

59-
result = run_command(cmd_string="--format json {}".format(project_path))
59+
result = run_command(cmd=["--format", "json", project_path])
6060
assert result.ok
6161
json.loads(result.stdout)
6262

63-
result = run_command(cmd_string="--format foo {}".format(project_path))
63+
result = run_command(cmd=["--format", "foo", project_path])
6464
assert not result.ok
6565

6666

6767
def test_help(run_command):
68-
result = run_command(cmd_string="--help")
68+
result = run_command(cmd=["--help"])
6969
assert result.ok
7070
assert "Usage:" in result.stdout
7171

@@ -82,12 +82,12 @@ def test_help(run_command):
8282
def test_library_manager(run_command, project_folder, expected_exit_statuses):
8383
project_path = test_data_path.joinpath("library-manager", project_folder)
8484
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])
8686
assert result.exited == expected_exit_status
8787

8888

8989
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")])
9191
assert not result.ok
9292

9393

@@ -103,39 +103,39 @@ def test_library_manager_invalid(run_command):
103103
def test_project_type(run_command, project_folder, expected_exit_statuses):
104104
project_path = test_data_path.joinpath("project-type", project_folder)
105105
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])
107107
assert result.exited == expected_exit_status
108108

109109

110110
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")])
112112
assert not result.ok
113113

114114

115115
def test_recursive(run_command):
116116
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])
118118
assert result.ok
119119

120-
result = run_command(cmd_string="--recursive false {}".format(valid_projects_path))
120+
result = run_command(cmd=["--recursive", "false", valid_projects_path])
121121
assert not result.ok
122122

123123

124124
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")])
126126
assert not result.ok
127127

128128

129129
def test_report_file(run_command, working_dir):
130130
project_path = test_data_path.joinpath("ValidSketch")
131131
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])
133133
assert result.ok
134134
with pathlib.Path(working_dir, report_file_name).open() as report_file:
135135
report = json.load(report_file)
136136

137137
assert pathlib.PurePath(report["configuration"]["paths"][0]) == project_path
138-
assert report["configuration"]["projectType"] == "any project type"
138+
assert report["configuration"]["projectType"] == "all"
139139
assert report["configuration"]["recursive"]
140140
assert pathlib.PurePath(report["projects"][0]["path"]) == project_path
141141
assert report["projects"][0]["projectType"] == "sketch"
@@ -147,30 +147,30 @@ def test_report_file(run_command, working_dir):
147147

148148
def test_verbose(run_command):
149149
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])
151151
assert result.ok
152152
assert "result: pass" not in result.stdout
153153
assert "result: fail" in result.stdout
154154

155-
result = run_command(cmd_string="--format text --verbose {}".format(project_path))
155+
result = run_command(cmd=["--format", "text", "--verbose", project_path])
156156
assert result.ok
157157
assert "result: pass" in result.stdout
158158

159-
result = run_command(cmd_string="--format json {}".format(project_path))
159+
result = run_command(cmd=["--format", "json", project_path])
160160
assert result.ok
161161
report = json.loads(result.stdout)
162162
assert True not in [check.get("result") == "pass" for check in report["projects"][0]["checks"]]
163163
assert True in [check.get("result") == "fail" for check in report["projects"][0]["checks"]]
164164

165-
result = run_command(cmd_string="--format json --verbose {}".format(project_path))
165+
result = run_command(cmd=["--format", "json", "--verbose", project_path])
166166
assert result.ok
167167
report = json.loads(result.stdout)
168168
assert True in [check.get("result") == "pass" for check in report["projects"][0]["checks"]]
169169
assert True in [check.get("result") == "fail" for check in report["projects"][0]["checks"]]
170170

171171

172172
def test_version(run_command):
173-
result = run_command(cmd_string="--version")
173+
result = run_command(cmd=["--version"])
174174
assert result.ok
175175
output_list = result.stdout.strip().split(sep=" ")
176176
assert semver.VersionInfo.isvalid(version=output_list[0])
@@ -187,10 +187,15 @@ def run_command(pytestconfig, working_dir):
187187

188188
arduino_lint_path = pathlib.Path(pytestconfig.rootdir).parent / "arduino-lint"
189189

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 = []
191193
if not custom_working_dir:
192194
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))
194199
run_context = invoke.context.Context()
195200
# It might happen that we need to change directories between drives on Windows,
196201
# in that case the "/d" flag must be used otherwise directory wouldn't change

0 commit comments

Comments
 (0)