Skip to content

Commit 32a5abd

Browse files
committed
Add test + news
1 parent 1baaaee commit 32a5abd

File tree

3 files changed

+60
-5
lines changed

3 files changed

+60
-5
lines changed

news/extrap_fix.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+
* Applying a function with no extrapolation no longer produces an error.
20+
21+
**Security:**
22+
23+
* <news item>

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ authors = [
1111
maintainers = [
1212
{ name="Simon J.L. Billinge group", email="simon.billinge@gmail.com" },
1313
]
14-
description = "Python package for manipulating and comparing PDF profiles"
14+
description = "Python package for manipulating and comparing 1D signals."
1515
keywords = ['diffpy', 'pdf', 'data interpretation']
1616
readme = "README.rst"
1717
requires-python = ">=3.11, <3.14"

tests/test_morphstretch.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,16 @@ def test_morphshift_extrapolate(user_filesystem, stretch, wmsg_gen):
101101
y_morph = numpy.sin(x_morph)
102102
x_target = x_morph.copy()
103103
y_target = y_morph.copy()
104-
with pytest.warns() as w:
104+
with pytest.warns() as warning:
105105
morphpy.morph_arrays(
106106
numpy.array([x_morph, y_morph]).T,
107107
numpy.array([x_target, y_target]).T,
108108
stretch=stretch,
109109
apply=True,
110110
)
111-
assert len(w) == 1
112-
assert w[0].category is UserWarning
113-
actual_wmsg = str(w[0].message)
111+
assert len(warning) == 1
112+
assert warning[0].category is UserWarning
113+
actual_wmsg = str(warning[0].message)
114114
expected_wmsg = wmsg_gen([min(x_morph), max(x_morph)])
115115
assert actual_wmsg == expected_wmsg
116116

@@ -131,3 +131,35 @@ def test_morphshift_extrapolate(user_filesystem, stretch, wmsg_gen):
131131
)
132132
with pytest.warns(UserWarning, match=expected_wmsg):
133133
single_morph(parser, opts, pargs, stdout_flag=False)
134+
135+
136+
def test_morphshift_no_warning(user_filesystem):
137+
# Apply a stretch with no extrapolation
138+
# There should be no warning or errors produced
139+
x_morph = numpy.linspace(1, 10, 101)
140+
y_morph = numpy.sin(x_morph)
141+
x_target = x_morph.copy()
142+
y_target = y_morph.copy()
143+
morphpy.morph_arrays(
144+
numpy.array([x_morph, y_morph]).T,
145+
numpy.array([x_target, y_target]).T,
146+
stretch=0,
147+
apply=True,
148+
)
149+
150+
# CLI test
151+
morph_file, target_file = create_morph_data_file(
152+
user_filesystem / "cwd_dir", x_morph, y_morph, x_target, y_target
153+
)
154+
155+
parser = create_option_parser()
156+
(opts, pargs) = parser.parse_args(
157+
[
158+
"--stretch=0",
159+
f"{morph_file.as_posix()}",
160+
f"{target_file.as_posix()}",
161+
"--apply",
162+
"-n",
163+
]
164+
)
165+
single_morph(parser, opts, pargs, stdout_flag=False)

0 commit comments

Comments
 (0)