Skip to content

Commit f30e506

Browse files
committed
fix tests
1 parent c436bf7 commit f30e506

2 files changed

Lines changed: 37 additions & 23 deletions

File tree

tests/test_cli.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -291,21 +291,20 @@ def test_parameter_analysis():
291291

292292
# Grab the JSON output from cq-cli
293293
jsn = json.loads(out.decode())
294-
295-
# Check to make sure the first parameter was handled properly
296-
assert jsn[0]["type"] == "number"
297-
assert jsn[0]["name"] == "width"
298-
assert jsn[0]["initial"] == 1
299-
300-
# Check to make sure the second parameter was handled properly
301-
assert jsn[1]["type"] == "string"
302-
assert jsn[1]["name"] == "tag_name"
303-
assert jsn[1]["initial"] == "cube"
304-
305-
# Check to make sure the third parameter was handled properly
306-
assert jsn[2]["type"] == "boolean"
307-
assert jsn[2]["name"] == "centered"
308-
assert jsn[2]["initial"] == True
294+
params_by_name = helpers.params_list_to_dict(jsn)
295+
296+
# Check to make sure the parameters were handled properly
297+
assert params_by_name["width"] == {"name": "width", "type": "number", "initial": 1}
298+
assert params_by_name["tag_name"] == {
299+
"name": "tag_name",
300+
"type": "string",
301+
"initial": "cube",
302+
}
303+
assert params_by_name["centered"] == {
304+
"name": "centered",
305+
"type": "boolean",
306+
"initial": True,
307+
}
309308

310309

311310
def test_parameter_file_input_output():
@@ -348,10 +347,10 @@ def test_parameter_file_input_output():
348347
# Modify the parameters file
349348
with open(temp_file, "r") as file:
350349
json_str = file.read()
351-
json_dict = json.loads(json_str)
352-
json_dict[0]["initial"] = 10
350+
json_list = json.loads(json_str)
351+
json_list[1]["initial"] = 10
353352
with open(temp_file, "w") as file:
354-
file.writelines(json.dumps(json_dict))
353+
file.writelines(json.dumps(json_list))
355354

356355
# Run the command with the new parameters
357356
command3 = [
@@ -414,10 +413,11 @@ def test_params_stl_output():
414413
# Make sure that the customizer.json file exists and has what we expect in it
415414
with open(customizer_file_path, "r") as file2:
416415
json_str = file2.read()
417-
json_dict = json.loads(json_str)
418-
assert json_dict[0]["initial"] == 1
419-
assert json_dict[1]["initial"] == "cube"
420-
assert json_dict[2]["initial"] == True
416+
json_list = json.loads(json_str)
417+
params = helpers.params_list_to_dict(json_list)
418+
assert params["width"]["initial"] == 1
419+
assert params["tag_name"]["initial"] == "cube"
420+
assert params["centered"]["initial"] == True
421421

422422
# Write an STL using the default parameters so that we can compare it to what was generated with customized parameters
423423
command = [

tests/test_helpers.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ def cli_call(command):
1515
"""
1616
Makes the operating system process calls to test the CLI properly.
1717
"""
18-
proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,)
18+
proc = subprocess.Popen(
19+
command,
20+
stdout=subprocess.PIPE,
21+
stderr=subprocess.PIPE,
22+
)
1923
out, err = proc.communicate()
2024
return out, err, proc.returncode
25+
26+
27+
def params_list_to_dict(param_list):
28+
"""
29+
Converts a list of params into a dictionary of those params keyed by name.
30+
"""
31+
d = {}
32+
for entry in param_list:
33+
d[entry["name"]] = entry
34+
return d

0 commit comments

Comments
 (0)