@@ -311,15 +311,76 @@ def test_load_wavelength_from_config_file_with_local_conf_file(
311311 assert actual_args .wavelength == expected ["wavelength" ]
312312
313313
314+ @pytest .mark .parametrize (
315+ "local_config, home_config" ,
316+ [
317+ # C1: no config files exist
318+ # expected: raise ValueError
319+ (None , None ),
320+ # C2: local config is empty, no home config
321+ # expected: raise ValueError
322+ ({}, None ),
323+ # C3: no local config, home config is empty
324+ # expected: raise ValueError
325+ (None , {}),
326+ # C4: both config files are empty
327+ # expected: raise ValueError
328+ ({}, {}),
329+ ],
330+ )
331+ def test_load_wavelength_from_config_file_without_conf_files_bad (
332+ mocker ,
333+ user_filesystem ,
334+ local_config ,
335+ home_config ,
336+ ):
337+ # User tries to correct data without specifying wavelength and
338+ # no config files
339+ # with wavelength exist -- expected to raise ValueError
340+ cwd = Path (user_filesystem )
341+ home_dir = cwd / "home_dir"
342+ mocker .patch ("pathlib.Path.home" , return_value = home_dir )
343+ os .chdir (cwd )
344+
345+ local_config_file = cwd / "diffpyconfig.json"
346+ if local_config_file .exists ():
347+ local_config_file .unlink ()
348+ home_config_file = home_dir / "diffpyconfig.json"
349+ if home_config_file .exists ():
350+ home_config_file .unlink ()
351+
352+ if local_config is not None :
353+ with open (local_config_file , "w" ) as f :
354+ json .dump (local_config , f )
355+ if home_config is not None :
356+ with open (home_config_file , "w" ) as f :
357+ json .dump (home_config , f )
358+
359+ cli_inputs = ["mud" , "data.xy" , "2.5" ]
360+ actual_args = get_args_cli (cli_inputs )
361+
362+ msg = re .escape (
363+ "No configuration file was found containing information "
364+ "about the wavelength or anode type. \n "
365+ "You can add the wavelength or anode type "
366+ "to a configuration file on the current computer "
367+ "and it will be automatically associated with "
368+ "subsequent diffpy data by default. \n "
369+ "You will only have to do that once. \n "
370+ "For more information, please refer to www.diffpy.org/"
371+ "diffpy.labpdfproc/examples/toolsexample.html"
372+ )
373+ with pytest .raises (ValueError , match = msg ):
374+ load_wavelength_from_config_file (actual_args )
375+
376+
314377@pytest .mark .parametrize (
315378 "inputs, expected" ,
316379 [
317380 # Test when no config files exist,
318381 # expect to return args without modification.
319382 # This test only checks loading behavior,
320383 # not value validation (which is handled by `set_wavelength`).
321- # C1: no args
322- ([], {"wavelength" : None }),
323384 # C1: wavelength provided
324385 (["--wavelength" , "0.25" ], {"wavelength" : 0.25 }),
325386 # C2: anode type provided
0 commit comments