Skip to content

Commit 468f436

Browse files
docs: improves docstring and test comments
1 parent 36f0cf8 commit 468f436

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def define_arguments():
5656
"name": ["-w", "--wavelength"],
5757
"help": (
5858
"X-ray source wavelength in angstroms. "
59-
"Not needed if the anode-type is specified. "
59+
"Not needed if the anode-type is specified."
6060
),
6161
"type": float,
6262
},
@@ -101,7 +101,7 @@ def define_arguments():
101101
f"The method for computing absorption correction. "
102102
f"Allowed methods: {*CVE_METHODS, }. "
103103
f"Default method is polynomial interpolation "
104-
f"if not specified. "
104+
f"if not specified."
105105
),
106106
"default": "polynomial_interpolation",
107107
},
@@ -118,7 +118,7 @@ def define_arguments():
118118
"For example, facility='NSLS II', "
119119
"'facility=NSLS II', beamline=28ID-2, "
120120
"'beamline'='28ID-2', 'favorite color'=blue, "
121-
"are all valid key=value items. "
121+
"are all valid key=value items."
122122
),
123123
"nargs": "+",
124124
"metavar": "KEY=VALUE",
@@ -128,7 +128,7 @@ def define_arguments():
128128
"help": (
129129
"Username will be loaded from config files. "
130130
"Specify here only if you want to "
131-
"override that behavior at runtime. "
131+
"override that behavior at runtime."
132132
),
133133
"default": None,
134134
},
@@ -137,7 +137,7 @@ def define_arguments():
137137
"help": (
138138
"Email will be loaded from config files. "
139139
"Specify here only if you want to "
140-
"override that behavior at runtime. "
140+
"override that behavior at runtime."
141141
),
142142
"default": None,
143143
},
@@ -146,7 +146,7 @@ def define_arguments():
146146
"help": (
147147
"ORCID will be loaded from config files. "
148148
"Specify here only if you want to "
149-
"override that behavior at runtime. "
149+
"override that behavior at runtime."
150150
),
151151
"default": None,
152152
},

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ def set_input_lists(args):
161161

162162
def set_wavelength(args):
163163
"""Set the wavelength based on the given anode_type or wavelength.
164+
164165
First checks from args. If neither is provided,
165166
it attempts to load from local and then global config file.
166167
@@ -173,7 +174,8 @@ def set_wavelength(args):
173174
------
174175
ValueError
175176
Raised if:
176-
(1) neither is provided, and either mu*D needs to be looked up or
177+
(1) neither wavelength or anode type is provided,
178+
and either mu*D needs to be looked up or
177179
xtype is not the two-theta grid,
178180
(2) both are provided,
179181
(3) anode_type is not one of the known sources,
@@ -186,7 +188,9 @@ def set_wavelength(args):
186188
"""
187189
# first load values from config file
188190
if args.wavelength is None and args.anode_type is None:
189-
if not (args.mud is not None and args.xtype in ANGLEQUANTITIES):
191+
# either mu*D needs to be looked up or
192+
# xtype is not the two-theta grid
193+
if args.mud is None or args.xtype not in ANGLEQUANTITIES:
190194
raise ValueError(
191195
f"Please provide a wavelength or anode type. "
192196
f"Allowed anode types are {*known_sources, }."

Diff for: tests/test_tools.py

+7
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,13 @@ def test_set_wavelength(inputs, expected):
272272
f"Allowed anode types are {*known_sources, }.",
273273
),
274274
( # C3: invalid anode type
275+
# expect error asking to specify a valid anode type
275276
["--anode-type", "invalid"],
276277
f"Anode type not recognized. "
277278
f"Please rerun specifying an anode_type from {*known_sources, }.",
278279
),
279280
( # C4: invalid wavelength
281+
# expect error asking to specify a valid wavelength or anode type
280282
["--wavelength", "0"],
281283
"No valid wavelength. "
282284
"Please rerun specifying a known anode_type "
@@ -506,6 +508,11 @@ def test_load_package_info(mocker):
506508

507509

508510
def test_load_metadata(mocker, user_filesystem):
511+
# Test if the function loads args
512+
# (which will be loaded into the header file).
513+
# Expect to include mu*D, anode type, xtype, cve method,
514+
# user-specified metadata, user info, package info, z-scan file,
515+
# and full paths for current input and output directories.
509516
cwd = Path(user_filesystem)
510517
home_dir = cwd / "home_dir"
511518
mocker.patch("pathlib.Path.home", lambda _: home_dir)

0 commit comments

Comments
 (0)