Skip to content

Commit 0bcda10

Browse files
committed
Add tests
1 parent ebd8700 commit 0bcda10

File tree

3 files changed

+64
-8
lines changed

3 files changed

+64
-8
lines changed

news/allow_none.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* <news item>
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* In morphpy, when a parameter is set to None, it will not be used as an option.
20+
21+
**Security:**
22+
23+
* <news item>

src/diffpy/morph/morphpy.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@ def get_args(parser, params, kwargs):
2727

2828

2929
def __get_morph_opts__(parser, scale, stretch, smear, plot, **kwargs):
30-
# Check for Python-specific options
31-
python_morphs = ["funcy", "funcx", "funcxy"]
32-
pymorphs = {}
33-
for pmorph in python_morphs:
34-
if pmorph in kwargs:
35-
pmorph_value = kwargs.pop(pmorph)
36-
pymorphs.update({pmorph: pmorph_value})
37-
3830
# Special handling of parameters with dashes
3931
kwargs_copy = kwargs.copy()
4032
kwargs = {}
@@ -44,6 +36,15 @@ def __get_morph_opts__(parser, scale, stretch, smear, plot, **kwargs):
4436
new_key = key.replace("_", "-")
4537
kwargs.update({new_key: kwargs_copy[key]})
4638

39+
# Check for Python-specific options
40+
python_morphs = ["funcy", "funcx", "funcxy"]
41+
pymorphs = {}
42+
for pmorph in python_morphs:
43+
if pmorph in kwargs:
44+
pmorph_value = kwargs.pop(pmorph)
45+
if pmorph_value is not None:
46+
pymorphs.update({pmorph: pmorph_value})
47+
4748
# Special handling of store_true and store_false parameters
4849
opts_storing_values = [
4950
"verbose",

tests/test_morphpy.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,38 @@ def test_morph_opts(self, setup_morph):
116116
else:
117117
assert getattr(opts, opt)
118118

119+
# Check that morphs can be set as None
120+
kwargs = {
121+
"hshift": None,
122+
"vshift": None,
123+
"squeeze": None,
124+
"funcx": None,
125+
"funcy": None,
126+
"funcxy": None,
127+
"verbose": None,
128+
"addpearson": None,
129+
"apply": None,
130+
"exclude": None,
131+
"reverse": None,
132+
"get_diff": None,
133+
"multiple_morphs": None,
134+
"multiple_targets": None,
135+
}
136+
kwargs_copy = kwargs.copy()
137+
opts, pymorphs = __get_morph_opts__(
138+
self.parser,
139+
scale=1,
140+
stretch=0,
141+
smear=0,
142+
plot=False,
143+
**kwargs_copy,
144+
)
145+
for opt in kwargs:
146+
try:
147+
assert not getattr(opts, opt)
148+
except AttributeError:
149+
pass
150+
119151
def test_morph(self, setup_morph):
120152
morph_results = {}
121153
morph_file = self.testfiles[0]

0 commit comments

Comments
 (0)