@@ -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
311310def 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 = [
@@ -544,3 +544,27 @@ def test_multiple_outfiles():
544544 ]
545545 out , err , exitcode = helpers .cli_call (command )
546546 assert exitcode == 0
547+
548+
549+ def test_file_variable_is_set ():
550+ """
551+ Tests that cq-cli sets the __file__ variable for the model script.
552+ """
553+ test_file = helpers .get_test_file_location ("file_var.py" )
554+
555+ temp_dir = tempfile .gettempdir ()
556+ out_path = os .path .join (temp_dir , "temp_test_file_variable.stl" )
557+
558+ command = [
559+ "python" ,
560+ "src/cq_cli/main.py" ,
561+ "--codec" ,
562+ "stl" ,
563+ "--infile" ,
564+ test_file ,
565+ "--outfile" ,
566+ out_path ,
567+ ]
568+ out , err , exitcode = helpers .cli_call (command )
569+ assert exitcode == 0
570+ assert "__file__=" in out .decode ()
0 commit comments