Skip to content

Commit bab35d3

Browse files
authored
Merge branch 'main' into output_dir
2 parents ad46e97 + bc138c0 commit bab35d3

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
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 set_output_directory, set_wavelength
6+
from diffpy.labpdfproc.tools import known_sources, set_wavelength, set_output_directory
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: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pytest
55

6-
from diffpy.labpdfproc.tools import set_output_directory, set_wavelength
6+
from diffpy.labpdfproc.tools import set_output_directory, set_wavelength, known_sources
77

88
params1 = [
99
([None], [Path.cwd().resolve()]),
@@ -54,14 +54,17 @@ def test_set_wavelength(inputs, expected):
5454

5555

5656
params3 = [
57-
([None, "invalid"]),
58-
([0, None]),
59-
([-1, "Mo"]),
57+
(
58+
[None, "invalid"],
59+
[f"Anode type not recognized. please rerun specifying an anode_type from {*known_sources, }"],
60+
),
61+
([0, None], ["No valid wavelength. Please rerun specifying a known anode_type or a positive wavelength"]),
62+
([-1, "Mo"], ["No valid wavelength. Please rerun specifying a known anode_type or a positive wavelength"]),
6063
]
6164

6265

63-
@pytest.mark.parametrize("inputs", params3)
64-
def test_set_wavelength_bad(inputs):
65-
with pytest.raises(ValueError):
66-
actual_args = argparse.Namespace(wavelength=inputs[0], anode_type=inputs[1])
66+
@pytest.mark.parametrize("inputs, msg", params3)
67+
def test_set_wavelength_bad(inputs, msg):
68+
actual_args = argparse.Namespace(wavelength=inputs[0], anode_type=inputs[1])
69+
with pytest.raises(ValueError, match=msg[0]):
6770
actual_args.wavelength = set_wavelength(actual_args)

0 commit comments

Comments
 (0)