Skip to content

Commit

Permalink
docs: improves docstring and test comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yucongalicechen committed Feb 3, 2025
1 parent 36f0cf8 commit 468f436
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/diffpy/labpdfproc/labpdfprocapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def define_arguments():
"name": ["-w", "--wavelength"],
"help": (
"X-ray source wavelength in angstroms. "
"Not needed if the anode-type is specified. "
"Not needed if the anode-type is specified."
),
"type": float,
},
Expand Down Expand Up @@ -101,7 +101,7 @@ def define_arguments():
f"The method for computing absorption correction. "
f"Allowed methods: {*CVE_METHODS, }. "
f"Default method is polynomial interpolation "
f"if not specified. "
f"if not specified."
),
"default": "polynomial_interpolation",
},
Expand All @@ -118,7 +118,7 @@ def define_arguments():
"For example, facility='NSLS II', "
"'facility=NSLS II', beamline=28ID-2, "
"'beamline'='28ID-2', 'favorite color'=blue, "
"are all valid key=value items. "
"are all valid key=value items."
),
"nargs": "+",
"metavar": "KEY=VALUE",
Expand All @@ -128,7 +128,7 @@ def define_arguments():
"help": (
"Username will be loaded from config files. "
"Specify here only if you want to "
"override that behavior at runtime. "
"override that behavior at runtime."
),
"default": None,
},
Expand All @@ -137,7 +137,7 @@ def define_arguments():
"help": (
"Email will be loaded from config files. "
"Specify here only if you want to "
"override that behavior at runtime. "
"override that behavior at runtime."
),
"default": None,
},
Expand All @@ -146,7 +146,7 @@ def define_arguments():
"help": (
"ORCID will be loaded from config files. "
"Specify here only if you want to "
"override that behavior at runtime. "
"override that behavior at runtime."
),
"default": None,
},
Expand Down
8 changes: 6 additions & 2 deletions src/diffpy/labpdfproc/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def set_input_lists(args):

def set_wavelength(args):
"""Set the wavelength based on the given anode_type or wavelength.
First checks from args. If neither is provided,
it attempts to load from local and then global config file.
Expand All @@ -173,7 +174,8 @@ def set_wavelength(args):
------
ValueError
Raised if:
(1) neither is provided, and either mu*D needs to be looked up or
(1) neither wavelength or anode type is provided,
and either mu*D needs to be looked up or
xtype is not the two-theta grid,
(2) both are provided,
(3) anode_type is not one of the known sources,
Expand All @@ -186,7 +188,9 @@ def set_wavelength(args):
"""
# first load values from config file
if args.wavelength is None and args.anode_type is None:
if not (args.mud is not None and args.xtype in ANGLEQUANTITIES):
# either mu*D needs to be looked up or
# xtype is not the two-theta grid
if args.mud is None or args.xtype not in ANGLEQUANTITIES:
raise ValueError(
f"Please provide a wavelength or anode type. "
f"Allowed anode types are {*known_sources, }."
Expand Down
7 changes: 7 additions & 0 deletions tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,13 @@ def test_set_wavelength(inputs, expected):
f"Allowed anode types are {*known_sources, }.",
),
( # C3: invalid anode type
# expect error asking to specify a valid anode type
["--anode-type", "invalid"],
f"Anode type not recognized. "
f"Please rerun specifying an anode_type from {*known_sources, }.",
),
( # C4: invalid wavelength
# expect error asking to specify a valid wavelength or anode type
["--wavelength", "0"],
"No valid wavelength. "
"Please rerun specifying a known anode_type "
Expand Down Expand Up @@ -506,6 +508,11 @@ def test_load_package_info(mocker):


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

0 comments on commit 468f436

Please sign in to comment.