1+ import subprocess
2+
13import numpy as np
24import pytest
35from 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