@@ -115,7 +115,7 @@ def test_set_input_lists(inputs, expected, user_filesystem):
115115 base_dir .resolve () / expected_path for expected_path in expected
116116 ]
117117
118- cli_inputs = [ " 2.5" ] + inputs
118+ cli_inputs = inputs + [ "--mud" , " 2.5" ]
119119 actual_args = get_args (cli_inputs )
120120 actual_args = set_input_lists (actual_args )
121121 assert sorted (actual_args .input_paths ) == sorted (expected_paths )
@@ -161,7 +161,7 @@ def test_set_input_lists(inputs, expected, user_filesystem):
161161def test_set_input_files_bad (inputs , expected_error_msg , user_filesystem ):
162162 base_dir = Path (user_filesystem )
163163 os .chdir (base_dir )
164- cli_inputs = [ " 2.5" ] + inputs
164+ cli_inputs = inputs + [ "--mud" , " 2.5" ]
165165 actual_args = get_args (cli_inputs )
166166 with pytest .raises (FileNotFoundError , match = re .escape (expected_error_msg )):
167167 actual_args = set_input_lists (actual_args )
@@ -179,7 +179,7 @@ def test_set_input_files_bad(inputs, expected_error_msg, user_filesystem):
179179def test_set_output_directory (inputs , expected , user_filesystem ):
180180 os .chdir (user_filesystem )
181181 expected_output_directory = Path (user_filesystem ) / expected [0 ]
182- cli_inputs = ["2.5 " , "data.xy " ] + inputs
182+ cli_inputs = ["data.xy " , "--mud" , "2.5 " ] + inputs
183183 actual_args = get_args (cli_inputs )
184184 actual_args = set_output_directory (actual_args )
185185 assert actual_args .output_directory == expected_output_directory
@@ -189,7 +189,13 @@ def test_set_output_directory(inputs, expected, user_filesystem):
189189
190190def test_set_output_directory_bad (user_filesystem ):
191191 os .chdir (user_filesystem )
192- cli_inputs = ["2.5" , "data.xy" , "--output-directory" , "good_data.chi" ]
192+ cli_inputs = [
193+ "data.xy" ,
194+ "--mud" ,
195+ "2.5" ,
196+ "--output-directory" ,
197+ "good_data.chi" ,
198+ ]
193199 actual_args = get_args (cli_inputs )
194200 with pytest .raises (FileExistsError ):
195201 actual_args = set_output_directory (actual_args )
@@ -374,7 +380,7 @@ def test_load_wavelength_from_config_file_without_conf_files(
374380 ],
375381)
376382def test_set_wavelength (inputs , expected ):
377- cli_inputs = ["2.5 " , "data.xy " ] + inputs
383+ cli_inputs = ["data.xy " , "--mud" , "2.5 " ] + inputs
378384 actual_args = get_args (cli_inputs )
379385 actual_args = set_wavelength (actual_args )
380386 assert actual_args .wavelength == expected ["wavelength" ]
@@ -413,7 +419,7 @@ def test_set_wavelength(inputs, expected):
413419 ],
414420)
415421def test_set_wavelength_bad (inputs , expected_error_msg ):
416- cli_inputs = ["2.5 " , "data.xy " ] + inputs
422+ cli_inputs = ["data.xy " , "--mud" , "2.5 " ] + inputs
417423 actual_args = get_args (cli_inputs )
418424 with pytest .raises (ValueError , match = re .escape (expected_error_msg )):
419425 actual_args = set_wavelength (actual_args )
@@ -429,50 +435,63 @@ def test_set_wavelength_bad(inputs, expected_error_msg):
429435 ],
430436)
431437def test_set_xtype (inputs , expected_xtype ):
432- cli_inputs = ["2.5 " , "data.xy " ] + inputs
438+ cli_inputs = ["data.xy " , "--mud" , "2.5 " ] + inputs
433439 actual_args = get_args (cli_inputs )
434440 actual_args = set_xtype (actual_args )
435441 assert actual_args .xtype == expected_xtype
436442
437443
438444def test_set_xtype_bad ():
439- cli_inputs = ["2.5 " , "data.xy " , "--xtype" , "invalid" ]
445+ cli_inputs = ["data.xy " , "--mud" , "2.5 " , "--xtype" , "invalid" ]
440446 actual_args = get_args (cli_inputs )
441447 with pytest .raises (
442448 ValueError ,
443449 match = re .escape (
444- f"Unknown xtype: invalid. " f" Allowed xtypes are { * XQUANTITIES , } ."
450+ f"Unknown xtype: invalid. Allowed xtypes are { * XQUANTITIES , } ."
445451 ),
446452 ):
447453 actual_args = set_xtype (actual_args )
448454
449455
450- def test_set_mud (user_filesystem ):
451- cli_inputs = ["2.5" , "data.xy" ]
452- actual_args = get_args (cli_inputs )
453- actual_args = set_mud (actual_args )
454- assert actual_args .mud == pytest .approx (2.5 , rel = 1e-4 , abs = 0.1 )
455- assert actual_args .z_scan_file is None
456-
456+ @pytest .mark .parametrize (
457+ "inputs, expected_mud" ,
458+ [
459+ # C1: user enters muD manually, expect to return the same value
460+ (["--mud" , "2.5" ], 2.5 ),
461+ # C2: user provides a z-scan file, expect to estimate through the file
462+ (["--z-scan-file" , "test_dir/testfile.xy" ], 3 ),
463+ ],
464+ )
465+ def test_set_mud (user_filesystem , inputs , expected_mud ):
457466 cwd = Path (user_filesystem )
458- test_dir = cwd / "test_dir"
459467 os .chdir (cwd )
460- inputs = ["--z-scan-file" , "test_dir/testfile.xy" ]
461- expected = [3 , str (test_dir / "testfile.xy" )]
462- cli_inputs = ["2.5" , "data.xy" ] + inputs
468+ cli_inputs = ["data.xy" ] + inputs
463469 actual_args = get_args (cli_inputs )
464470 actual_args = set_mud (actual_args )
465- assert actual_args .mud == pytest .approx (expected [0 ], rel = 1e-4 , abs = 0.1 )
466- assert actual_args .z_scan_file == expected [1 ]
471+ assert actual_args .mud == pytest .approx (expected_mud , rel = 1e-4 , abs = 0.1 )
467472
468473
469- def test_set_mud_bad ():
470- cli_inputs = ["2.5" , "data.xy" , "--z-scan-file" , "invalid file" ]
474+ @pytest .mark .parametrize (
475+ "inputs, expected" ,
476+ [
477+ # C1: user provides an invalid z-scan file,
478+ # expect FileNotFoundError and message to specify a valid file path
479+ (
480+ ["--z-scan-file" , "invalid file" ],
481+ [
482+ FileNotFoundError ,
483+ "Cannot find invalid file. Please specify a valid file path." ,
484+ ],
485+ ),
486+ ],
487+ )
488+ def test_set_mud_bad (user_filesystem , inputs , expected ):
489+ expected_error , expected_error_msg = expected
490+ cwd = Path (user_filesystem )
491+ os .chdir (cwd )
492+ cli_inputs = ["data.xy" ] + inputs
471493 actual_args = get_args (cli_inputs )
472- with pytest .raises (
473- FileNotFoundError ,
474- match = "Cannot find invalid file. " "Please specify a valid file path." ,
475- ):
494+ with pytest .raises (expected_error , match = expected_error_msg ):
476495 actual_args = set_mud (actual_args )
477496
478497
@@ -497,12 +516,12 @@ def test_set_mud_bad():
497516 ],
498517)
499518def test_load_user_metadata (inputs , expected ):
500- expected_args = get_args (["2.5 " , "data.xy " ])
519+ expected_args = get_args (["data.xy " , "--mud" , "2.5 " ])
501520 for expected_pair in expected :
502521 setattr (expected_args , expected_pair [0 ], expected_pair [1 ])
503522 delattr (expected_args , "user_metadata" )
504523
505- cli_inputs = ["2.5 " , "data.xy " ] + inputs
524+ cli_inputs = ["data.xy " , "--mud" , "2.5 " ] + inputs
506525 actual_args = get_args (cli_inputs )
507526 actual_args = load_user_metadata (actual_args )
508527 assert actual_args == expected_args
@@ -538,7 +557,7 @@ def test_load_user_metadata(inputs, expected):
538557 ],
539558)
540559def test_load_user_metadata_bad (inputs , expected_error_msg ):
541- cli_inputs = ["2.5 " , "data.xy " ] + inputs
560+ cli_inputs = ["data.xy " , "--mud" , "2.5 " ] + inputs
542561 actual_args = get_args (cli_inputs )
543562 with pytest .raises (ValueError , match = re .escape (expected_error_msg )):
544563 actual_args = load_user_metadata (actual_args )
@@ -601,8 +620,9 @@ def test_load_user_info(monkeypatch, inputs, expected, user_filesystem):
601620 os .chdir (cwd )
602621
603622 cli_inputs = [
604- "2.5" ,
605623 "data.xy" ,
624+ "--mud" ,
625+ "2.5" ,
606626 "--username" ,
607627 inputs ["username" ],
608628 "--email" ,
@@ -624,7 +644,7 @@ def test_load_package_info(mocker):
624644 "3.3.0" if package_name == "diffpy.utils" else "1.2.3"
625645 ),
626646 )
627- cli_inputs = ["2.5 " , "data.xy " ]
647+ cli_inputs = ["data.xy " , "--mud" , "2.5 " ]
628648 actual_args = get_args (cli_inputs )
629649 actual_args = load_package_info (actual_args )
630650 assert actual_args .package_info == {
@@ -650,8 +670,9 @@ def test_load_metadata(mocker, user_filesystem):
650670 ),
651671 )
652672 cli_inputs = [
653- "2.5" ,
654673 "." ,
674+ "--mud" ,
675+ "2.5" ,
655676 "--anode-type" ,
656677 "Mo" ,
657678 "--user-metadata" ,
0 commit comments