Skip to content

Commit 64e7c4d

Browse files
fix: make anode type case insensitive, add related tests
1 parent 703b16a commit 64e7c4d

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

Diff for: src/diffpy/labpdfproc/tools.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,18 @@ def set_wavelength(args):
150150
raise ValueError(
151151
"No valid wavelength. Please rerun specifying a known anode_type or a positive wavelength."
152152
)
153-
if not args.wavelength and args.anode_type and args.anode_type not in WAVELENGTHS:
154-
raise ValueError(
155-
f"Anode type not recognized. Please rerun specifying an anode_type from {*known_sources, }."
156-
)
157-
158-
if args.wavelength:
159-
delattr(args, "anode_type")
160-
elif args.anode_type:
153+
elif not args.wavelength and args.anode_type:
154+
matched_anode_type = next((key for key in WAVELENGTHS if key.lower() == args.anode_type.lower()), None)
155+
if matched_anode_type is None:
156+
raise ValueError(
157+
f"Anode type not recognized. Please rerun specifying an anode_type from {*known_sources, }."
158+
)
159+
args.anode_type = matched_anode_type
161160
args.wavelength = WAVELENGTHS[args.anode_type]
162-
else:
161+
elif not args.wavelength:
163162
args.wavelength = WAVELENGTHS["Mo"]
163+
else:
164+
delattr(args, "anode_type")
164165
return args
165166

166167

Diff for: tests/test_tools.py

+17
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,26 @@ def test_set_output_directory_bad(user_filesystem):
167167
@pytest.mark.parametrize(
168168
"inputs, expected",
169169
[
170+
# C1: nothing passed in, expect default is Mo
170171
([], {"wavelength": 0.71073, "anode_type": "Mo"}),
172+
# C2: only a valid anode type was entered (case independent),
173+
# expect to match the corresponding wavelength and preserve the correct case anode type
174+
(["--anode-type", "Mo"], {"wavelength": 0.71073, "anode_type": "Mo"}),
175+
(["--anode-type", "MoKa1"], {"wavelength": 0.70930, "anode_type": "MoKa1"}),
176+
(["--anode-type", "MoKa1Ka2"], {"wavelength": 0.71073, "anode_type": "MoKa1Ka2"}),
171177
(["--anode-type", "Ag"], {"wavelength": 0.56087, "anode_type": "Ag"}),
178+
(["--anode-type", "AgKa1"], {"wavelength": 0.55941, "anode_type": "AgKa1"}),
179+
(["--anode-type", "AgKa1Ka2"], {"wavelength": 0.56087, "anode_type": "AgKa1Ka2"}),
180+
(["--anode-type", "Cu"], {"wavelength": 1.54184, "anode_type": "Cu"}),
181+
(["--anode-type", "CuKa1"], {"wavelength": 1.54056, "anode_type": "CuKa1"}),
182+
(["--anode-type", "CuKa1Ka2"], {"wavelength": 1.54184, "anode_type": "CuKa1Ka2"}),
183+
(["--anode-type", "moKa1Ka2"], {"wavelength": 0.71073, "anode_type": "MoKa1Ka2"}),
184+
(["--anode-type", "ag"], {"wavelength": 0.56087, "anode_type": "Ag"}),
185+
(["--anode-type", "cuka1"], {"wavelength": 1.54056, "anode_type": "CuKa1"}),
186+
# C3: only a valid wavelength was entered, expect to include the wavelength only and anode type is None
172187
(["--wavelength", "0.25"], {"wavelength": 0.25, "anode_type": None}),
188+
# C4: both valid anode type and wavelength were entered,
189+
# expect to remove the anode type and preserve wavelength only
173190
(["--wavelength", "0.25", "--anode-type", "Ag"], {"wavelength": 0.25, "anode_type": None}),
174191
],
175192
)

0 commit comments

Comments
 (0)