diff --git a/README.rst b/README.rst index abab13eb..3a77b607 100644 --- a/README.rst +++ b/README.rst @@ -35,7 +35,7 @@ .. |Tracking| image:: https://img.shields.io/badge/issue_tracking-github-blue :target: https://github.com/diffpy/diffpy.morph/issues -Python package for manipulating and comparing diffraction data +Python package for manipulating and comparing diffraction data. ``diffpy.morph`` is a Python software package designed to increase the insight researchers can obtain from measured data including diffraction data diff --git a/docs/source/index.rst b/docs/source/index.rst index eb981226..59936edd 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -2,7 +2,7 @@ diffpy.morph documentation ########################## -``diffpy.morph`` - Tools for manipulating and comparing PDF profiles +``diffpy.morph`` - Tools for manipulating and comparing 1D signals. | Software version |release| | Last updated |today|. diff --git a/news/error-message.rst b/news/error-message.rst new file mode 100644 index 00000000..aa3db216 --- /dev/null +++ b/news/error-message.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* Program no longer gives SystemExit. Proper errors are assigned to each case. + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/news/save_pdf.rst b/news/save_pdf.rst new file mode 100644 index 00000000..b01e6998 --- /dev/null +++ b/news/save_pdf.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* Default labels for saving are now [x] and [fx] instead of [r] and [gr]. + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/news/squeeze_tests.rst b/news/squeeze_tests.rst new file mode 100644 index 00000000..7d73a2bf --- /dev/null +++ b/news/squeeze_tests.rst @@ -0,0 +1,23 @@ +**Added:** + +* No news: fixing tests, no user-facing changes. + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/src/diffpy/morph/__init__.py b/src/diffpy/morph/__init__.py index 48455828..c2baddb1 100644 --- a/src/diffpy/morph/__init__.py +++ b/src/diffpy/morph/__init__.py @@ -12,7 +12,7 @@ # See LICENSE.rst for license information. # ############################################################################## -"""Python package for manipulating and comparing PDF profiles.""" +"""Python package for manipulating and comparing 1D signals.""" # key used when saving multiple morphs __save_morph_as__ = "save_morph_as" diff --git a/src/diffpy/morph/morph_io.py b/src/diffpy/morph/morph_io.py index b0d80b68..cf194f54 100644 --- a/src/diffpy/morph/morph_io.py +++ b/src/diffpy/morph/morph_io.py @@ -223,7 +223,7 @@ def single_morph_output( path_name = "NO FILE PATH PROVIDED" else: path_name = str(Path(morph_file).resolve()) - header = "# PDF created by diffpy.morph\n" + header = "# Function created by diffpy.morph\n" header += f"# from {path_name}" header_verbose = f"{morphs_in}\n{morphs_out}" @@ -236,7 +236,7 @@ def single_morph_output( print(header_verbose, file=outfile) # Print table with label - print("\n# Labels: [r] [gr]", file=outfile) + print("\n# Labels: [x] [fx]", file=outfile) numpy.savetxt(outfile, numpy.transpose(xy_out)) if stdout_flag: @@ -246,7 +246,7 @@ def single_morph_output( else: # Just print table with label if save is to stdout - print("# Labels: [r] [gr]") + print("# Labels: [x] [fx]") numpy.savetxt(sys.stdout, numpy.transpose(xy_out)) diff --git a/src/diffpy/morph/morphapp.py b/src/diffpy/morph/morphapp.py index 22b6780a..5b03a6ad 100755 --- a/src/diffpy/morph/morphapp.py +++ b/src/diffpy/morph/morphapp.py @@ -41,13 +41,13 @@ class CustomParser(optparse.OptionParser): def __init__(self, *args, **kwargs): super(CustomParser, self).__init__(*args, **kwargs) - def custom_error(self, msg): - """custom_error(msg : string) + def morph_error(self, msg, error): + """morph_error(msg : string) Print a message incorporating 'msg' to stderr and exit. Does not print usage. """ - self.exit(2, "%s: error: %s\n" % (self.get_prog_name(), msg)) + raise error(f"{self.get_prog_name()}: {msg}") parser = CustomParser( usage="\n".join( @@ -507,14 +507,17 @@ def single_morph( parser, opts, pargs, stdout_flag=True, python_wrap=False, pymorphs=None ): if len(pargs) < 2: - parser.error("You must supply MORPHFILE and TARGETFILE.") + parser.morph_error( + "You must supply MORPHFILE and TARGETFILE.", TypeError + ) elif len(pargs) > 2 and not python_wrap: - parser.error( + parser.morph_error( "Too many arguments. Make sure you only supply " - "MORPHFILE and TARGETFILE." + "MORPHFILE and TARGETFILE.", + TypeError, ) elif not (len(pargs) == 2 or len(pargs) == 6) and python_wrap: - parser.error("Python wrapper error.") + parser.morph_error("Python wrapper error.", RuntimeError) # Get the PDFs # If we get from python, we may wrap, which has input size 4 @@ -528,9 +531,9 @@ def single_morph( x_target, y_target = getPDFFromFile(pargs[1]) if y_morph is None: - parser.error(f"No data table found in: {pargs[0]}.") + parser.morph_error(f"No data table found in: {pargs[0]}.", ValueError) if y_target is None: - parser.error(f"No data table found in: {pargs[1]}.") + parser.morph_error(f"No data table found in: {pargs[1]}.", ValueError) # Get tolerance tolerance = 1e-08 @@ -549,8 +552,8 @@ def single_morph( and opts.xmax is not None and opts.xmax <= opts.xmin ): - e = "xmin must be less than xmax" - parser.custom_error(e) + emsg = "xmin must be less than xmax" + parser.morph_error(emsg, ValueError) # Set up the morphs chain = morphs.MorphChain(config) @@ -607,7 +610,9 @@ def single_morph( squeeze_dict_in.update({f"a{idx}": float(coeff)}) idx += 1 except ValueError: - parser.error(f"{coeff} could not be converted to float.") + parser.morph_error( + f"{coeff} could not be converted to float.", ValueError + ) squeeze_poly_deg = len(squeeze_dict_in.keys()) squeeze_morph = morphs.MorphSqueeze() chain.append(squeeze_morph) @@ -727,7 +732,7 @@ def single_morph( # Adjust all parameters refiner.refine(*refpars) except ValueError as e: - parser.custom_error(str(e)) + parser.morph_error(str(e), ValueError) # Smear is not being refined, but baselineslope needs to refined to apply # smear # Note that baselineslope is only added to the refine list if smear is @@ -738,7 +743,7 @@ def single_morph( "baselineslope", baselineslope=config["baselineslope"] ) except ValueError as e: - parser.custom_error(str(e)) + parser.morph_error(str(e), ValueError) else: chain(x_morph, y_morph, x_target, y_target) @@ -827,9 +832,9 @@ def single_morph( stdout_flag=stdout_flag, ) - except (FileNotFoundError, RuntimeError): + except (FileNotFoundError, RuntimeError) as e: save_fail_message = "Unable to save to designated location." - parser.custom_error(save_fail_message) + parser.morph_error(save_fail_message, type(e)) if opts.plot: pairlist = [chain.xy_target_out, chain.xy_morph_out] @@ -871,25 +876,29 @@ def multiple_targets(parser, opts, pargs, stdout_flag=True, python_wrap=False): # Custom error messages since usage is distinct when --multiple tag is # applied if len(pargs) < 2: - parser.custom_error( + parser.morph_error( "You must supply a FILE and DIRECTORY. " - "See --multiple-targets under --help for usage." + "See --multiple-targets under --help for usage.", + TypeError, ) elif len(pargs) > 2: - parser.custom_error( - "Too many arguments. You must only supply a FILE and a DIRECTORY." + parser.morph_error( + "Too many arguments. You must only supply a FILE and a DIRECTORY.", + TypeError, ) # Parse paths morph_file = Path(pargs[0]) if not morph_file.is_file(): - parser.custom_error( - f"{morph_file} is not a file. Go to --help for usage." + parser.morph_error( + f"{morph_file} is not a file. Go to --help for usage.", + FileNotFoundError, ) target_directory = Path(pargs[1]) if not target_directory.is_dir(): - parser.custom_error( - f"{target_directory} is not a directory. Go to --help for usage." + parser.morph_error( + f"{target_directory} is not a directory. Go to --help for usage.", + NotADirectoryError, ) # Get list of files from target directory @@ -926,12 +935,14 @@ def multiple_targets(parser, opts, pargs, stdout_flag=True, python_wrap=False): ) except KeyError: if opts.serfile is not None: - parser.custom_error( - "The requested field was not found in the metadata file." + parser.morph_error( + "The requested field was not found in the metadata file.", + KeyError, ) else: - parser.custom_error( - "The requested field is missing from a file header." + parser.morph_error( + "The requested field is missing from a file header.", + KeyError, ) else: # Default is alphabetical sort @@ -953,9 +964,9 @@ def multiple_targets(parser, opts, pargs, stdout_flag=True, python_wrap=False): save_morphs_here = io.create_morphs_directory(save_directory) # Could not create directory or find names to save morphs as - except (FileNotFoundError, RuntimeError): + except (FileNotFoundError, RuntimeError) as e: save_fail_message = "\nUnable to create directory" - parser.custom_error(save_fail_message) + parser.morph_error(save_fail_message, type(e)) try: save_names = io.get_multisave_names( @@ -964,7 +975,7 @@ def multiple_targets(parser, opts, pargs, stdout_flag=True, python_wrap=False): # Could not create directory or find names to save morphs as except FileNotFoundError: save_fail_message = "\nUnable to read from save names file" - parser.custom_error(save_fail_message) + parser.morph_error(save_fail_message, FileNotFoundError) # Morph morph_file against all other files in target_directory morph_results = {} @@ -1013,9 +1024,9 @@ def multiple_targets(parser, opts, pargs, stdout_flag=True, python_wrap=False): verbose=opts.verbose, stdout_flag=stdout_flag, ) - except (FileNotFoundError, RuntimeError): + except (FileNotFoundError, RuntimeError) as e: save_fail_message = "Unable to save summary to directory." - parser.custom_error(save_fail_message) + parser.morph_error(save_fail_message, type(e)) # Plot the values of some parameter for each target if requested if plot_opt: @@ -1032,8 +1043,9 @@ def multiple_targets(parser, opts, pargs, stdout_flag=True, python_wrap=False): # Not an available parameter to plot or no values found for the # parameter if param_list is None: - parser.custom_error( - "Cannot find specified plot parameter. No plot shown." + parser.morph_error( + "Cannot find specified plot parameter. No plot shown.", + KeyError, ) else: try: @@ -1045,9 +1057,10 @@ def multiple_targets(parser, opts, pargs, stdout_flag=True, python_wrap=False): # i.e. --smear is not selected as an option, but smear is the # plotting parameter except ValueError: - parser.custom_error( + parser.morph_error( "The plot parameter is missing values for at least one " - "morph and target pair. No plot shown." + "morph and target pair. No plot shown.", + ValueError, ) return morph_results @@ -1057,25 +1070,29 @@ def multiple_morphs(parser, opts, pargs, stdout_flag=True, python_wrap=False): # Custom error messages since usage is distinct when --multiple tag is # applied if len(pargs) < 2: - parser.custom_error( + parser.morph_error( "You must supply a DIRECTORY and FILE. " - "See --multiple-morphs under --help for usage." + "See --multiple-morphs under --help for usage.", + TypeError, ) elif len(pargs) > 2: - parser.custom_error( - "Too many arguments. You must only supply a DIRECTORY and FILE." + parser.morph_error( + "Too many arguments. You must only supply a DIRECTORY and FILE.", + TypeError, ) # Parse paths target_file = Path(pargs[1]) if not target_file.is_file(): - parser.custom_error( - f"{target_file} is not a file. Go to --help for usage." + parser.morph_error( + f"{target_file} is not a file. Go to --help for usage.", + FileNotFoundError, ) morph_directory = Path(pargs[0]) if not morph_directory.is_dir(): - parser.custom_error( - f"{morph_directory} is not a directory. Go to --help for usage." + parser.morph_error( + f"{morph_directory} is not a directory. Go to --help for usage.", + NotADirectoryError, ) # Get list of files from morph directory @@ -1112,12 +1129,14 @@ def multiple_morphs(parser, opts, pargs, stdout_flag=True, python_wrap=False): ) except KeyError: if opts.serfile is not None: - parser.custom_error( - "The requested field was not found in the metadata file." + parser.morph_error( + "The requested field was not found in the metadata file.", + KeyError, ) else: - parser.custom_error( - "The requested field is missing from a PDF file header." + parser.morph_error( + "The requested field is missing from a PDF file header.", + KeyError, ) else: # Default is alphabetical sort @@ -1139,9 +1158,9 @@ def multiple_morphs(parser, opts, pargs, stdout_flag=True, python_wrap=False): save_morphs_here = io.create_morphs_directory(save_directory) # Could not create directory or find names to save morphs as - except (FileNotFoundError, RuntimeError): + except (FileNotFoundError, RuntimeError) as e: save_fail_message = "\nUnable to create directory" - parser.custom_error(save_fail_message) + parser.morph_error(save_fail_message, type(e)) try: save_names = io.get_multisave_names( @@ -1150,7 +1169,7 @@ def multiple_morphs(parser, opts, pargs, stdout_flag=True, python_wrap=False): # Could not create directory or find names to save morphs as except FileNotFoundError: save_fail_message = "\nUnable to read from save names file" - parser.custom_error(save_fail_message) + parser.morph_error(save_fail_message, FileNotFoundError) # Morph morph_file against all other files in target_directory morph_results = {} @@ -1200,9 +1219,9 @@ def multiple_morphs(parser, opts, pargs, stdout_flag=True, python_wrap=False): stdout_flag=stdout_flag, mm=True, ) - except (FileNotFoundError, RuntimeError): + except (FileNotFoundError, RuntimeError) as e: save_fail_message = "Unable to save summary to directory." - parser.custom_error(save_fail_message) + parser.morph_error(save_fail_message, type(e)) # Plot the values of some parameter for each target if requested if plot_opt: @@ -1219,8 +1238,9 @@ def multiple_morphs(parser, opts, pargs, stdout_flag=True, python_wrap=False): # Not an available parameter to plot or no values found for the # parameter if param_list is None: - parser.custom_error( - "Cannot find specified plot parameter. No plot shown." + parser.morph_error( + "Cannot find specified plot parameter. No plot shown.", + KeyError, ) else: try: @@ -1232,9 +1252,10 @@ def multiple_morphs(parser, opts, pargs, stdout_flag=True, python_wrap=False): # i.e. --smear is not selected as an option, but smear is the # plotting parameter except ValueError: - parser.custom_error( + parser.morph_error( "The plot parameter is missing values for at least one " - "morph and target pair. No plot shown." + "morph and target pair. No plot shown.", + ValueError, ) return morph_results diff --git a/tests/test_morphapp.py b/tests/test_morphapp.py index b4729d4d..a414e932 100644 --- a/tests/test_morphapp.py +++ b/tests/test_morphapp.py @@ -105,43 +105,40 @@ def test_parser_numerical(self, setup_parser): ) # Check correct value parsed assert len(n_args) == 1 # Check one leftover - def test_parser_systemexits(self, capsys, setup_parser): + def test_parser_errors(self, capsys, setup_parser): # ###Basic tests for any variety of morphing### # Ensure only two pargs given for morphing (opts, pargs) = self.parser.parse_args(["toofewfiles"]) - with pytest.raises(SystemExit): + with pytest.raises(TypeError) as excinfo: single_morph(self.parser, opts, pargs, stdout_flag=False) - _, err = capsys.readouterr() - assert "You must supply MORPHFILE and TARGETFILE." in err - with pytest.raises(SystemExit): + assert "You must supply MORPHFILE and TARGETFILE." in str( + excinfo.value + ) + with pytest.raises(TypeError) as excinfo: multiple_targets(self.parser, opts, pargs, stdout_flag=False) - _, err = capsys.readouterr() - assert "You must supply a FILE and DIRECTORY." in err + assert "You must supply a FILE and DIRECTORY." in str(excinfo.value) (opts, pargs) = self.parser.parse_args(["too", "many", "files"]) - with pytest.raises(SystemExit): + with pytest.raises(TypeError) as excinfo: single_morph(self.parser, opts, pargs, stdout_flag=False) - _, err = capsys.readouterr() assert ( "Too many arguments. Make sure you only supply MORPHFILE and " - "TARGETFILE." in err + "TARGETFILE." in str(excinfo.value) ) - with pytest.raises(SystemExit): + with pytest.raises(TypeError) as excinfo: multiple_targets(self.parser, opts, pargs, stdout_flag=False) - _, err = capsys.readouterr() assert ( "Too many arguments. You must only supply a FILE and a DIRECTORY." - in err + in str(excinfo.value) ) # Make sure xmax greater than xmin (opts, pargs) = self.parser.parse_args( [f"{nickel_PDF}", f"{nickel_PDF}", "--xmin", "10", "--xmax", "1"] ) - with pytest.raises(SystemExit): + with pytest.raises(ValueError) as excinfo: single_morph(self.parser, opts, pargs, stdout_flag=False) - _, err = capsys.readouterr() - assert "xmin must be less than xmax" in err + assert "xmin must be less than xmax" in str(excinfo.value) # ###Tests exclusive to multiple morphs### # Make sure we save to a directory that exists @@ -154,39 +151,36 @@ def test_parser_systemexits(self, capsys, setup_parser): "/nonexisting_directory/no_way_this_exists/nonexisting_path", ] ) - with pytest.raises(SystemExit): + with pytest.raises(FileNotFoundError) as excinfo: single_morph(self.parser, opts, pargs, stdout_flag=False) - _, err = capsys.readouterr() - assert "Unable to save to designated location." in err - with pytest.raises(SystemExit): + assert "Unable to save to designated location." in str(excinfo.value) + with pytest.raises(NotADirectoryError) as excinfo: multiple_targets(self.parser, opts, pargs, stdout_flag=False) - _, err = capsys.readouterr() - assert "is not a directory." in err + assert "is not a directory." in str(excinfo.value) # Ensure first parg is a FILE and second parg is a DIRECTORY (opts, pargs) = self.parser.parse_args( [f"{nickel_PDF}", f"{nickel_PDF}"] ) - with pytest.raises(SystemExit): + with pytest.raises(NotADirectoryError) as excinfo: multiple_targets(self.parser, opts, pargs, stdout_flag=False) (opts, pargs) = self.parser.parse_args( [f"{testsequence_dir}", f"{testsequence_dir}"] ) - _, err = capsys.readouterr() - assert "is not a directory." in err - with pytest.raises(SystemExit): + assert "is not a directory." in str(excinfo.value) + with pytest.raises(FileNotFoundError) as excinfo: multiple_targets(self.parser, opts, pargs, stdout_flag=False) - _, err = capsys.readouterr() - assert "is not a file." in err + assert "is not a file." in str(excinfo.value) # Try sorting by non-existing field (opts, pargs) = self.parser.parse_args( [f"{nickel_PDF}", f"{testsequence_dir}", "--sort-by", "fake_field"] ) - with pytest.raises(SystemExit): + with pytest.raises(KeyError) as excinfo: multiple_targets(self.parser, opts, pargs, stdout_flag=False) - _, err = capsys.readouterr() - assert "The requested field is missing from a file header." in err + assert "The requested field is missing from a file header." in str( + excinfo.value + ) (opts, pargs) = self.parser.parse_args( [ f"{nickel_PDF}", @@ -197,10 +191,12 @@ def test_parser_systemexits(self, capsys, setup_parser): f"{serial_JSON}", ] ) - with pytest.raises(SystemExit): + with pytest.raises(KeyError) as excinfo: multiple_targets(self.parser, opts, pargs, stdout_flag=False) - _, err = capsys.readouterr() - assert "The requested field was not found in the metadata file." in err + assert ( + "The requested field was not found in the metadata file." + in str(excinfo.value) + ) # Try plotting an unknown parameter (opts, pargs) = self.parser.parse_args( @@ -211,10 +207,11 @@ def test_parser_systemexits(self, capsys, setup_parser): "unknown", ] ) - with pytest.raises(SystemExit): + with pytest.raises(KeyError) as excinfo: multiple_targets(self.parser, opts, pargs, stdout_flag=False) - _, err = capsys.readouterr() - assert "Cannot find specified plot parameter. No plot shown." in err + assert "Cannot find specified plot parameter. No plot shown." in str( + excinfo.value + ) # Try plotting an unrefined parameter (opts, pargs) = self.parser.parse_args( @@ -225,13 +222,12 @@ def test_parser_systemexits(self, capsys, setup_parser): "stretch", ] ) - with pytest.raises(SystemExit): + with pytest.raises(ValueError) as excinfo: multiple_targets(self.parser, opts, pargs, stdout_flag=False) - _, err = capsys.readouterr() assert ( "The plot parameter is missing values for at " "least one morph and target pair. " - "No plot shown." in err + "No plot shown." in str(excinfo.value) ) # Pass a non-float list to squeeze @@ -243,10 +239,9 @@ def test_parser_systemexits(self, capsys, setup_parser): "1,a,0", ] ) - with pytest.raises(SystemExit): + with pytest.raises(ValueError) as excinfo: single_morph(self.parser, opts, pargs, stdout_flag=False) - _, err = capsys.readouterr() - assert "a could not be converted to float." in err + assert "a could not be converted to float." in str(excinfo.value) def test_morphsequence(self, setup_morphsequence): # Parse arguments sorting by field diff --git a/tests/test_morphsqueeze.py b/tests/test_morphsqueeze.py index 8a172086..90de2a6c 100644 --- a/tests/test_morphsqueeze.py +++ b/tests/test_morphsqueeze.py @@ -148,11 +148,16 @@ def test_morphsqueeze_extrapolate(user_filesystem, squeeze_coeffs, wmsg_gen): squeeze=coeffs, apply=True, ) - assert len(warning) == 1 - assert warning[0].category is UserWarning - actual_wmsg = str(warning[0].message) - expected_wmsg = wmsg_gen([min(x_squeezed), max(x_squeezed)]) - assert actual_wmsg == expected_wmsg + assert len(warning) >= 1 + expected_wmsg = wmsg_gen([min(x_squeezed), max(x_squeezed)]) + message_found = False + for w in warning: + actual_wmsg = str(w.message) + if actual_wmsg == expected_wmsg: + if w.category is UserWarning: + message_found = True + break + assert message_found # CLI test morph_file, target_file = create_morph_data_file( @@ -272,9 +277,7 @@ def test_squeeze_warnings(user_filesystem, squeeze_coeffs, x_morph): squeeze=squeeze_coeffs, apply=True, ) - assert len(warning) == 1 - assert warning[0].category is UserWarning - actual_wmsg = str(warning[0].message) + assert len(warning) >= 1 expected_wmsg = ( "Warning: The squeeze morph has interpolated your morphed " "function from a non-monotonically increasing grid. " @@ -295,7 +298,14 @@ def test_squeeze_warnings(user_filesystem, squeeze_coeffs, x_morph): "first apply a --hshift and --stretch morph. " "Then, use the hshift parameter for a0 and stretch parameter for a1." ) - assert expected_wmsg in actual_wmsg + message_found = False + for w in warning: + actual_wmsg = str(w.message) + if expected_wmsg in actual_wmsg: + if w.category is UserWarning: + message_found = True + break + assert message_found # call in CLI morph_file, target_file = create_morph_data_file( @@ -314,9 +324,13 @@ def test_squeeze_warnings(user_filesystem, squeeze_coeffs, x_morph): ) with pytest.warns(UserWarning) as warning: single_morph(parser, opts, pargs, stdout_flag=False) - assert len(warning) == 1 - actual_wmsg = str(warning[0].message) - assert expected_wmsg in actual_wmsg + assert len(warning) >= 1 + message_found = False + for w in warning: + actual_wmsg = str(w.message) + if expected_wmsg in actual_wmsg: + message_found = True + assert message_found @pytest.mark.parametrize( diff --git a/tests/test_refine.py b/tests/test_refine.py index b64bccd1..fe9e9937 100644 --- a/tests/test_refine.py +++ b/tests/test_refine.py @@ -231,10 +231,9 @@ def test_refine_grid_bad(self, user_filesystem, capsys): run_cmd.append("-n") parser = create_option_parser() (opts, pargs) = parser.parse_args(run_cmd) - with pytest.raises(SystemExit): + with pytest.raises(ValueError) as excinfo: single_morph(parser, opts, pargs, stdout_flag=False) - _, err = capsys.readouterr() - assert expected_error_message in actual_error_message + assert expected_error_message in str(excinfo.value) # End of class TestRefine diff --git a/tests/testdata/funcy_target.cgr b/tests/testdata/funcy_target.cgr index fa36dc6b..108fde4d 100644 --- a/tests/testdata/funcy_target.cgr +++ b/tests/testdata/funcy_target.cgr @@ -1,4 +1,4 @@ -# PDF created by diffpy.morph +# Function created by diffpy.morph # from NO FILE PATH PROVIDED # Input morphing parameters: @@ -32,7 +32,7 @@ def quadratic(x, y, a0, a1, a2): # Rw = 0.000000 # Pearson = 1.000000 -# Labels: [r] [gr] +# Labels: [x] [fx] 0.000000000000000000e+00 1.000000000000000000e+00 1.000000000000000056e-01 1.229999999999999982e+00 2.000000000000000111e-01 1.520000000000000018e+00 diff --git a/tests/testdata/squeeze_morph.cgr b/tests/testdata/squeeze_morph.cgr index cc7799b9..ee388096 100644 --- a/tests/testdata/squeeze_morph.cgr +++ b/tests/testdata/squeeze_morph.cgr @@ -1,7 +1,7 @@ -# PDF created by diffpy.morph +# Function created by diffpy.morph # from PATH -# Labels: [r] [gr] +# Labels: [x] [fx] 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000056e-01 2.016607210740701817e-01 2.000000000000000111e-01 4.012816425967311584e-01 diff --git a/tests/testdata/squeeze_target.cgr b/tests/testdata/squeeze_target.cgr index 1474409a..e5ab4504 100644 --- a/tests/testdata/squeeze_target.cgr +++ b/tests/testdata/squeeze_target.cgr @@ -1,4 +1,4 @@ -# PDF created by diffpy.morph +# Function created by diffpy.morph # from PATH # Input morphing parameters: @@ -24,7 +24,7 @@ # Rw = 0.000000 # Pearson = 1.000000 -# Labels: [r] [gr] +# Labels: [x] [fx] 0.000000000000000000e+00 -8.357788796904224253e-08 1.000000000000000056e-01 9.983335989539958433e-02 2.000000000000000111e-01 1.986692882755068390e-01 diff --git a/tests/testdata/testsequence/testsaving/succinct/Morphs/mwt_a.cgr b/tests/testdata/testsequence/testsaving/succinct/Morphs/mwt_a.cgr index c1b2cb4c..041f42fa 100644 --- a/tests/testdata/testsequence/testsaving/succinct/Morphs/mwt_a.cgr +++ b/tests/testdata/testsequence/testsaving/succinct/Morphs/mwt_a.cgr @@ -1,7 +1,7 @@ -# PDF created by diffpy.morph +# Function created by diffpy.morph # from PATH -# Labels: [r] [gr] +# Labels: [x] [fx] 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000021e-02 4.042510000000000027e-04 2.000000000000000042e-02 7.817419999999999838e-04 diff --git a/tests/testdata/testsequence/testsaving/succinct/Morphs/mwt_b.cgr b/tests/testdata/testsequence/testsaving/succinct/Morphs/mwt_b.cgr index c1b2cb4c..041f42fa 100644 --- a/tests/testdata/testsequence/testsaving/succinct/Morphs/mwt_b.cgr +++ b/tests/testdata/testsequence/testsaving/succinct/Morphs/mwt_b.cgr @@ -1,7 +1,7 @@ -# PDF created by diffpy.morph +# Function created by diffpy.morph # from PATH -# Labels: [r] [gr] +# Labels: [x] [fx] 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000021e-02 4.042510000000000027e-04 2.000000000000000042e-02 7.817419999999999838e-04 diff --git a/tests/testdata/testsequence/testsaving/succinct/Morphs/mwt_c.cgr b/tests/testdata/testsequence/testsaving/succinct/Morphs/mwt_c.cgr index c1b2cb4c..041f42fa 100644 --- a/tests/testdata/testsequence/testsaving/succinct/Morphs/mwt_c.cgr +++ b/tests/testdata/testsequence/testsaving/succinct/Morphs/mwt_c.cgr @@ -1,7 +1,7 @@ -# PDF created by diffpy.morph +# Function created by diffpy.morph # from PATH -# Labels: [r] [gr] +# Labels: [x] [fx] 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000021e-02 4.042510000000000027e-04 2.000000000000000042e-02 7.817419999999999838e-04 diff --git a/tests/testdata/testsequence/testsaving/succinct/Morphs/mwt_d.cgr b/tests/testdata/testsequence/testsaving/succinct/Morphs/mwt_d.cgr index c1b2cb4c..041f42fa 100644 --- a/tests/testdata/testsequence/testsaving/succinct/Morphs/mwt_d.cgr +++ b/tests/testdata/testsequence/testsaving/succinct/Morphs/mwt_d.cgr @@ -1,7 +1,7 @@ -# PDF created by diffpy.morph +# Function created by diffpy.morph # from PATH -# Labels: [r] [gr] +# Labels: [x] [fx] 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000021e-02 4.042510000000000027e-04 2.000000000000000042e-02 7.817419999999999838e-04 diff --git a/tests/testdata/testsequence/testsaving/succinct/Morphs/mwt_e.cgr b/tests/testdata/testsequence/testsaving/succinct/Morphs/mwt_e.cgr index c1b2cb4c..041f42fa 100644 --- a/tests/testdata/testsequence/testsaving/succinct/Morphs/mwt_e.cgr +++ b/tests/testdata/testsequence/testsaving/succinct/Morphs/mwt_e.cgr @@ -1,7 +1,7 @@ -# PDF created by diffpy.morph +# Function created by diffpy.morph # from PATH -# Labels: [r] [gr] +# Labels: [x] [fx] 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000021e-02 4.042510000000000027e-04 2.000000000000000042e-02 7.817419999999999838e-04 diff --git a/tests/testdata/testsequence/testsaving/succinct/Morphs/mwt_f.cgr b/tests/testdata/testsequence/testsaving/succinct/Morphs/mwt_f.cgr index c1b2cb4c..041f42fa 100644 --- a/tests/testdata/testsequence/testsaving/succinct/Morphs/mwt_f.cgr +++ b/tests/testdata/testsequence/testsaving/succinct/Morphs/mwt_f.cgr @@ -1,7 +1,7 @@ -# PDF created by diffpy.morph +# Function created by diffpy.morph # from PATH -# Labels: [r] [gr] +# Labels: [x] [fx] 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000021e-02 4.042510000000000027e-04 2.000000000000000042e-02 7.817419999999999838e-04 diff --git a/tests/testdata/testsequence/testsaving/succinct/single_succinct_morph.cgr b/tests/testdata/testsequence/testsaving/succinct/single_succinct_morph.cgr index c1b2cb4c..041f42fa 100644 --- a/tests/testdata/testsequence/testsaving/succinct/single_succinct_morph.cgr +++ b/tests/testdata/testsequence/testsaving/succinct/single_succinct_morph.cgr @@ -1,7 +1,7 @@ -# PDF created by diffpy.morph +# Function created by diffpy.morph # from PATH -# Labels: [r] [gr] +# Labels: [x] [fx] 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000021e-02 4.042510000000000027e-04 2.000000000000000042e-02 7.817419999999999838e-04 diff --git a/tests/testdata/testsequence/testsaving/verbose/Morphs/mwt_a.cgr b/tests/testdata/testsequence/testsaving/verbose/Morphs/mwt_a.cgr index 95cba1f9..eed0c27f 100644 --- a/tests/testdata/testsequence/testsaving/verbose/Morphs/mwt_a.cgr +++ b/tests/testdata/testsequence/testsaving/verbose/Morphs/mwt_a.cgr @@ -1,4 +1,4 @@ -# PDF created by diffpy.morph +# Function created by diffpy.morph # from PATH # Input morphing parameters: @@ -15,7 +15,7 @@ # Rw = 0.127100 # Pearson = 0.992111 -# Labels: [r] [gr] +# Labels: [x] [fx] 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000021e-02 4.042510000000000027e-04 2.000000000000000042e-02 7.817419999999999838e-04 diff --git a/tests/testdata/testsequence/testsaving/verbose/Morphs/mwt_b.cgr b/tests/testdata/testsequence/testsaving/verbose/Morphs/mwt_b.cgr index ef8cf023..a41aa616 100644 --- a/tests/testdata/testsequence/testsaving/verbose/Morphs/mwt_b.cgr +++ b/tests/testdata/testsequence/testsaving/verbose/Morphs/mwt_b.cgr @@ -1,4 +1,4 @@ -# PDF created by diffpy.morph +# Function created by diffpy.morph # from PATH # Input morphing parameters: @@ -15,7 +15,7 @@ # Rw = 0.117595 # Pearson = 0.993160 -# Labels: [r] [gr] +# Labels: [x] [fx] 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000021e-02 4.042510000000000027e-04 2.000000000000000042e-02 7.817419999999999838e-04 diff --git a/tests/testdata/testsequence/testsaving/verbose/Morphs/mwt_c.cgr b/tests/testdata/testsequence/testsaving/verbose/Morphs/mwt_c.cgr index 27ebcd00..c53e08c6 100644 --- a/tests/testdata/testsequence/testsaving/verbose/Morphs/mwt_c.cgr +++ b/tests/testdata/testsequence/testsaving/verbose/Morphs/mwt_c.cgr @@ -1,4 +1,4 @@ -# PDF created by diffpy.morph +# Function created by diffpy.morph # from PATH # Input morphing parameters: @@ -15,7 +15,7 @@ # Rw = 0.105918 # Pearson = 0.994409 -# Labels: [r] [gr] +# Labels: [x] [fx] 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000021e-02 4.042510000000000027e-04 2.000000000000000042e-02 7.817419999999999838e-04 diff --git a/tests/testdata/testsequence/testsaving/verbose/Morphs/mwt_d.cgr b/tests/testdata/testsequence/testsaving/verbose/Morphs/mwt_d.cgr index 8a30b321..d77b671d 100644 --- a/tests/testdata/testsequence/testsaving/verbose/Morphs/mwt_d.cgr +++ b/tests/testdata/testsequence/testsaving/verbose/Morphs/mwt_d.cgr @@ -1,4 +1,4 @@ -# PDF created by diffpy.morph +# Function created by diffpy.morph # from PATH # Input morphing parameters: @@ -15,7 +15,7 @@ # Rw = 0.062392 # Pearson = 0.998077 -# Labels: [r] [gr] +# Labels: [x] [fx] 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000021e-02 4.042510000000000027e-04 2.000000000000000042e-02 7.817419999999999838e-04 diff --git a/tests/testdata/testsequence/testsaving/verbose/Morphs/mwt_e.cgr b/tests/testdata/testsequence/testsaving/verbose/Morphs/mwt_e.cgr index 1ad1a45f..b4d00115 100644 --- a/tests/testdata/testsequence/testsaving/verbose/Morphs/mwt_e.cgr +++ b/tests/testdata/testsequence/testsaving/verbose/Morphs/mwt_e.cgr @@ -1,4 +1,4 @@ -# PDF created by diffpy.morph +# Function created by diffpy.morph # from PATH # Input morphing parameters: @@ -15,7 +15,7 @@ # Rw = 0.034859 # Pearson = 0.999424 -# Labels: [r] [gr] +# Labels: [x] [fx] 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000021e-02 4.042510000000000027e-04 2.000000000000000042e-02 7.817419999999999838e-04 diff --git a/tests/testdata/testsequence/testsaving/verbose/Morphs/mwt_f.cgr b/tests/testdata/testsequence/testsaving/verbose/Morphs/mwt_f.cgr index 32ce202b..8e8aa722 100644 --- a/tests/testdata/testsequence/testsaving/verbose/Morphs/mwt_f.cgr +++ b/tests/testdata/testsequence/testsaving/verbose/Morphs/mwt_f.cgr @@ -1,4 +1,4 @@ -# PDF created by diffpy.morph +# Function created by diffpy.morph # from PATH # Input morphing parameters: @@ -15,7 +15,7 @@ # Rw = 0.020141 # Pearson = 0.999810 -# Labels: [r] [gr] +# Labels: [x] [fx] 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000021e-02 4.042510000000000027e-04 2.000000000000000042e-02 7.817419999999999838e-04 diff --git a/tests/testdata/testsequence/testsaving/verbose/single_verbose_morph.cgr b/tests/testdata/testsequence/testsaving/verbose/single_verbose_morph.cgr index 95cba1f9..eed0c27f 100644 --- a/tests/testdata/testsequence/testsaving/verbose/single_verbose_morph.cgr +++ b/tests/testdata/testsequence/testsaving/verbose/single_verbose_morph.cgr @@ -1,4 +1,4 @@ -# PDF created by diffpy.morph +# Function created by diffpy.morph # from PATH # Input morphing parameters: @@ -15,7 +15,7 @@ # Rw = 0.127100 # Pearson = 0.992111 -# Labels: [r] [gr] +# Labels: [x] [fx] 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000021e-02 4.042510000000000027e-04 2.000000000000000042e-02 7.817419999999999838e-04