Skip to content

Commit de74af7

Browse files
save progress, resolve conflicts
2 parents 42ad689 + 3089e1b commit de74af7

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

src/diffpy/labpdfproc/labpdfprocapp.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@
33
from pathlib import Path
44

55
from diffpy.labpdfproc.functions import apply_corr, compute_cve
6-
from diffpy.labpdfproc.tools import load_user_metadata, set_wavelength
6+
from diffpy.labpdfproc.tools import known_sources, load_user_metadata, set_wavelength
77
from diffpy.utils.parsers.loaddata import loadData
88
from diffpy.utils.scattering_objects.diffraction_objects import XQUANTITIES, Diffraction_object
99

10-
WAVELENGTHS = {"Mo": 0.71, "Ag": 0.59, "Cu": 1.54}
11-
known_sources = [key for key in WAVELENGTHS.keys()]
12-
1310

1411
def get_args():
1512
p = ArgumentParser()
1613
p.add_argument("mud", help="Value of mu*D for your " "sample. Required.", type=float)
1714
p.add_argument("-i", "--input-file", help="The filename of the " "datafile to load")
1815
p.add_argument(
19-
"-a", "--anode-type", help=f"X-ray source, allowed " f"values: {*[known_sources], }", default="Mo"
16+
"-a",
17+
"--anode-type",
18+
help=f"The type of the x-ray source. Allowed values are "
19+
f"{*[known_sources], }. Either specify a known x-ray source or specify wavelength",
20+
default="Mo",
2021
)
2122
p.add_argument(
2223
"-w",
2324
"--wavelength",
24-
help="X-ray source wavelength. Not needed if the anode-type "
25-
"is specified. This will override the wavelength if anode "
26-
"type is specified",
25+
help="X-ray source wavelength in angstroms. Not needed if the anode-type "
26+
"is specified. This wavelength will override the anode wavelength if both are specified",
2727
default=None,
2828
type=float,
2929
)

src/diffpy/labpdfproc/tests/test_tools.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import argparse
2+
import re
23
from argparse import ArgumentParser
34

45
import pytest
56

6-
from diffpy.labpdfproc.tools import load_user_metadata, set_wavelength
7+
from diffpy.labpdfproc.tools import known_sources, load_user_metadata, set_wavelength
78

89
params2 = [
910
([None, None], [0.71]),
@@ -22,16 +23,19 @@ def test_set_wavelength(inputs, expected):
2223

2324

2425
params3 = [
25-
([None, "invalid"]),
26-
([0, None]),
27-
([-1, "Mo"]),
26+
(
27+
[None, "invalid"],
28+
[f"Anode type not recognized. please rerun specifying an anode_type from {*known_sources, }"],
29+
),
30+
([0, None], ["No valid wavelength. Please rerun specifying a known anode_type or a positive wavelength"]),
31+
([-1, "Mo"], ["No valid wavelength. Please rerun specifying a known anode_type or a positive wavelength"]),
2832
]
2933

3034

31-
@pytest.mark.parametrize("inputs", params3)
32-
def test_set_wavelength_bad(inputs):
33-
with pytest.raises(ValueError):
34-
actual_args = argparse.Namespace(wavelength=inputs[0], anode_type=inputs[1])
35+
@pytest.mark.parametrize("inputs, msg", params3)
36+
def test_set_wavelength_bad(inputs, msg):
37+
actual_args = argparse.Namespace(wavelength=inputs[0], anode_type=inputs[1])
38+
with pytest.raises(ValueError, match=re.escape(msg[0])):
3539
actual_args.wavelength = set_wavelength(actual_args)
3640

3741

src/diffpy/labpdfproc/tools.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ def set_wavelength(args):
2020
2121
"""
2222
if args.wavelength is not None and args.wavelength <= 0:
23-
raise ValueError("Please rerun the program specifying a positive float number.")
23+
raise ValueError(
24+
"No valid wavelength. Please rerun specifying a known anode_type or a positive wavelength"
25+
)
2426
if not args.wavelength and args.anode_type and args.anode_type not in WAVELENGTHS:
2527
raise ValueError(
26-
f"Invalid anode type {args.anode_type}. "
27-
f"Please rerun the program to either specify a wavelength as a positive float number "
28-
f"or specify anode_type as one of {known_sources}."
28+
f"Anode type not recognized. please rerun specifying an anode_type from {*known_sources, }"
2929
)
3030

3131
if args.wavelength:
@@ -67,3 +67,6 @@ def load_user_metadata(args):
6767
# question 2: more than one =?
6868
# if i have key is hello, value is hello=world, then i can have hello=hello=world to process okay
6969
# if i have = in key then it's still processing as value => would this be an issue?
70+
71+
72+
# user specified the same key: same key we defined, same key they defined

0 commit comments

Comments
 (0)