Skip to content

Commit 861cbf0

Browse files
resolved conflicts and set tmppath
2 parents ad46e97 + 3089e1b commit 861cbf0

File tree

3 files changed

+38
-27
lines changed

3 files changed

+38
-27
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_output_directory, 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: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,40 @@
11
import argparse
2+
import os
3+
import re
24
from pathlib import Path
35

46
import pytest
57

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

810
params1 = [
9-
([None], [Path.cwd().resolve()]),
10-
(["."], [Path.cwd().resolve()]),
11-
(["new_dir"], [Path.cwd().resolve() / "new_dir"]),
12-
(["existing_dir"], [Path.cwd().resolve() / "existing_dir"]),
11+
([None], ["."]),
12+
(["."], ["."]),
13+
(["new_dir"], ["new_dir"]),
14+
(["existing_dir"], ["existing_dir"]),
1315
]
1416

1517

1618
@pytest.mark.parametrize("inputs, expected", params1)
17-
def test_set_output_directory(inputs, expected):
19+
def test_set_output_directory(inputs, expected, tmp_path):
20+
directory = Path(tmp_path)
21+
os.chdir(directory)
22+
1823
existing_dir = Path().cwd().resolve() / "existing_dir"
1924
existing_dir.mkdir(parents=True, exist_ok=True)
2025

21-
expected_output_directory = expected[0]
26+
expected_output_directory = Path.cwd().resolve() / expected[0]
2227
actual_args = argparse.Namespace(output_directory=inputs[0])
2328
actual_args.output_directory = set_output_directory(actual_args)
2429
assert actual_args.output_directory == expected_output_directory
2530
assert Path(actual_args.output_directory).exists()
2631
assert Path(actual_args.output_directory).is_dir()
2732

2833

29-
def test_set_output_directory_bad():
34+
def test_set_output_directory_bad(tmp_path):
35+
directory = Path(tmp_path)
36+
os.chdir(directory)
37+
3038
existing_file = Path().cwd().resolve() / "existing_file.py"
3139
existing_file.touch()
3240

@@ -54,14 +62,17 @@ def test_set_wavelength(inputs, expected):
5462

5563

5664
params3 = [
57-
([None, "invalid"]),
58-
([0, None]),
59-
([-1, "Mo"]),
65+
(
66+
[None, "invalid"],
67+
[f"Anode type not recognized. please rerun specifying an anode_type from {*known_sources, }"],
68+
),
69+
([0, None], ["No valid wavelength. Please rerun specifying a known anode_type or a positive wavelength"]),
70+
([-1, "Mo"], ["No valid wavelength. Please rerun specifying a known anode_type or a positive wavelength"]),
6071
]
6172

6273

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])
74+
@pytest.mark.parametrize("inputs, msg", params3)
75+
def test_set_wavelength_bad(inputs, msg):
76+
actual_args = argparse.Namespace(wavelength=inputs[0], anode_type=inputs[1])
77+
with pytest.raises(ValueError, match=re.escape(msg[0])):
6778
actual_args.wavelength = set_wavelength(actual_args)

src/diffpy/labpdfproc/tools.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ def set_wavelength(args):
4646
4747
"""
4848
if args.wavelength is not None and args.wavelength <= 0:
49-
raise ValueError("Please rerun the program specifying a positive float number.")
49+
raise ValueError(
50+
"No valid wavelength. Please rerun specifying a known anode_type or a positive wavelength"
51+
)
5052
if not args.wavelength and args.anode_type and args.anode_type not in WAVELENGTHS:
5153
raise ValueError(
52-
f"Invalid anode type {args.anode_type}. "
53-
f"Please rerun the program to either specify a wavelength as a positive float number "
54-
f"or specify anode_type as one of {known_sources}."
54+
f"Anode type not recognized. please rerun specifying an anode_type from {*known_sources, }"
5555
)
5656

5757
if args.wavelength:

0 commit comments

Comments
 (0)