88
99from diffpy .morph .morph_helpers .transformpdftordf import TransformXtalPDFtoRDF
1010from diffpy .morph .morph_helpers .transformrdftopdf import TransformXtalRDFtoPDF
11+ from diffpy .morph .morphapp import create_option_parser , single_morph
1112from diffpy .morph .morphs .morphchain import MorphChain
1213from diffpy .morph .morphs .morphfuncx import MorphFuncx
1314from diffpy .morph .morphs .morphrgrid import MorphRGrid
@@ -181,7 +182,7 @@ def stretch(x, y, stretch):
181182
182183 assert res < err
183184
184- def test_refine_grid_bad (self , user_filesystem ):
185+ def test_refine_grid_bad (self , user_filesystem , capsys ):
185186 grid = numpy .arange (2 )
186187 func = numpy .sin (grid )
187188 grid1 , func1 , grid2 , func2 = grid , func , grid , func
@@ -208,9 +209,7 @@ def test_refine_grid_bad(self, user_filesystem):
208209 actual_error_message = str (error .value )
209210 assert actual_error_message == expected_error_message
210211
211- # call from command line
212- import subprocess
213-
212+ # Test from command line
214213 data_dir_path = user_filesystem / "cwd_dir"
215214 morph_file = data_dir_path / "morph_data"
216215 morph_data_text = [
@@ -224,18 +223,18 @@ def test_refine_grid_bad(self, user_filesystem):
224223 ]
225224 target_data_text = "\n " .join (target_data_text )
226225 target_file .write_text (target_data_text )
227- run_cmd = ["diffpy.morph" ]
226+ run_cmd = []
228227 for key , value in config .items ():
229228 run_cmd .append (f"--{ key } " )
230229 run_cmd .append (f"{ value } " )
231230 run_cmd .extend ([str (morph_file ), str (target_file )])
232231 run_cmd .append ("-n" )
233- result = subprocess . run ( run_cmd , capture_output = True , text = True )
234- expected_error_message = (
235- "diffpy.morph: error: " + expected_error_message
236- )
237- actual_error_message = result . stderr . strip ()
238- assert actual_error_message == expected_error_message
232+ parser = create_option_parser ( )
233+ ( opts , pargs ) = parser . parse_args ( run_cmd )
234+ with pytest . raises ( SystemExit ):
235+ single_morph ( parser , opts , pargs , stdout_flag = False )
236+ _ , err = capsys . readouterr ()
237+ assert expected_error_message in actual_error_message
239238
240239
241240# End of class TestRefine
0 commit comments