Skip to content

Commit e165b41

Browse files
committed
test: add CLI test for extrapolation warning
1 parent 026984a commit e165b41

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

tests/test_morphsqueeze.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import subprocess
2+
13
import numpy as np
24
import pytest
35
from numpy.polynomial import Polynomial
@@ -117,7 +119,7 @@ def test_morphsqueeze(x_morph, x_target, squeeze_coeffs):
117119
),
118120
],
119121
)
120-
def test_morphsqueeze_extrapolate(squeeze_coeffs, wmsg_gen):
122+
def test_morphsqueeze_extrapolate(user_filesystem, squeeze_coeffs, wmsg_gen):
121123
x_morph = np.linspace(0, 10, 101)
122124
y_morph = np.sin(x_morph)
123125
x_target = x_morph
@@ -136,3 +138,32 @@ def test_morphsqueeze_extrapolate(squeeze_coeffs, wmsg_gen):
136138
actual_wmsg = str(w[0].message)
137139
expected_wmsg = wmsg_gen([min(x_squeezed), max(x_squeezed)])
138140
assert actual_wmsg == expected_wmsg
141+
142+
# CLI test
143+
morph_file, target_file = create_morph_data_file(
144+
user_filesystem / "cwd_dir", x_morph, y_morph, x_target, y_target
145+
)
146+
run_cmd = ["diffpy.morph"]
147+
run_cmd.extend(["--squeeze=" + ",".join(map(str, coeffs))])
148+
run_cmd.extend([str(morph_file), str(target_file)])
149+
run_cmd.append("-n")
150+
result = subprocess.run(run_cmd, capture_output=True, text=True)
151+
assert expected_wmsg in result.stderr
152+
153+
154+
def create_morph_data_file(
155+
data_dir_path, x_morph, y_morph, x_target, y_target
156+
):
157+
morph_file = data_dir_path / "morph_data"
158+
morph_data_text = [
159+
str(x_morph[i]) + " " + str(y_morph[i]) for i in range(len(x_morph))
160+
]
161+
morph_data_text = "\n".join(morph_data_text)
162+
morph_file.write_text(morph_data_text)
163+
target_file = data_dir_path / "target_data"
164+
target_data_text = [
165+
str(x_target[i]) + " " + str(y_target[i]) for i in range(len(x_target))
166+
]
167+
target_data_text = "\n".join(target_data_text)
168+
target_file.write_text(target_data_text)
169+
return morph_file, target_file

0 commit comments

Comments
 (0)