@@ -198,9 +198,7 @@ def test_set_output_directory_bad(user_filesystem):
198198@pytest .mark .parametrize (
199199 "inputs, expected" ,
200200 [
201- # C1: nothing passed in, expect default is Mo
202- ([], {"wavelength" : 0.71073 , "anode_type" : "Mo" }),
203- # C2: only a valid anode type was entered (case independent),
201+ # C1: only a valid anode type was entered (case independent),
204202 # expect to match the corresponding wavelength
205203 # and preserve the correct case anode type
206204 (["--anode-type" , "Mo" ], {"wavelength" : 0.71073 , "anode_type" : "Mo" }),
@@ -239,45 +237,52 @@ def test_set_output_directory_bad(user_filesystem):
239237 ["--anode-type" , "cuka1" ],
240238 {"wavelength" : 1.54056 , "anode_type" : "CuKa1" },
241239 ),
242- # C3: only a valid wavelength was entered,
240+ # C2: a valid wavelength was entered,
243241 # expect to include the wavelength only and anode type is None
244242 (["--wavelength" , "0.25" ], {"wavelength" : 0.25 , "anode_type" : None }),
245- # C4: both valid anode type and wavelength were entered,
246- # expect to remove the anode type and preserve wavelength only
247- (
248- ["--wavelength" , "0.25" , "--anode-type" , "Ag" ],
249- {"wavelength" : 0.25 , "anode_type" : None },
250- ),
243+ # C3: nothing passed in, but mu*D was provided and xtype is on tth
244+ # expect wavelength and anode type to be None
245+ # and program proceeds without error
246+ ([], {"wavelength" : None , "anode_type" : None }),
251247 ],
252248)
253249def test_set_wavelength (inputs , expected ):
254250 cli_inputs = ["2.5" , "data.xy" ] + inputs
255251 actual_args = get_args (cli_inputs )
256252 actual_args = set_wavelength (actual_args )
257253 assert actual_args .wavelength == expected ["wavelength" ]
258- assert getattr ( actual_args , " anode_type" , None ) == expected ["anode_type" ]
254+ assert actual_args . anode_type == expected ["anode_type" ]
259255
260256
261257@pytest .mark .parametrize (
262258 "inputs, expected_error_msg" ,
263259 [
264- (
260+ ( # C1: nothing passed in, xtype is not on tth
261+ # expect error asking for either wavelength or anode type
262+ ["--xtype" , "q" ],
263+ f"Please provide a wavelength or anode type "
264+ f"because the independent variable axis is not on two-theta. "
265+ f"Allowed anode types are { * known_sources , } ." ,
266+ ),
267+ ( # C2: both wavelength and anode type were specified
268+ # expect error asking not to specify both
269+ ["--wavelength" , "0.7" , "--anode-type" , "Mo" ],
270+ f"Please provide either a wavelength or an anode type, not both. "
271+ f"Allowed anode types are { * known_sources , } ." ,
272+ ),
273+ ( # C3: invalid anode type
274+ # expect error asking to specify a valid anode type
265275 ["--anode-type" , "invalid" ],
266276 f"Anode type not recognized. "
267277 f"Please rerun specifying an anode_type from { * known_sources , } ." ,
268278 ),
269- (
279+ ( # C4: invalid wavelength
280+ # expect error asking to specify a valid wavelength or anode type
270281 ["--wavelength" , "0" ],
271282 "No valid wavelength. "
272283 "Please rerun specifying a known anode_type "
273284 "or a positive wavelength." ,
274285 ),
275- (
276- ["--wavelength" , "-1" , "--anode-type" , "Mo" ],
277- "No valid wavelength. "
278- "Please rerun specifying a known anode_type "
279- "or a positive wavelength." ,
280- ),
281286 ],
282287)
283288def test_set_wavelength_bad (inputs , expected_error_msg ):
@@ -502,6 +507,11 @@ def test_load_package_info(mocker):
502507
503508
504509def test_load_metadata (mocker , user_filesystem ):
510+ # Test if the function loads args
511+ # (which will be loaded into the header file).
512+ # Expect to include mu*D, anode type, xtype, cve method,
513+ # user-specified metadata, user info, package info, z-scan file,
514+ # and full paths for current input and output directories.
505515 cwd = Path (user_filesystem )
506516 home_dir = cwd / "home_dir"
507517 mocker .patch ("pathlib.Path.home" , lambda _ : home_dir )
@@ -515,6 +525,8 @@ def test_load_metadata(mocker, user_filesystem):
515525 cli_inputs = [
516526 "2.5" ,
517527 "." ,
528+ "--anode-type" ,
529+ "Mo" ,
518530 "--user-metadata" ,
519531 "key=value" ,
520532 "--username" ,
0 commit comments