| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,23 @@ | |||
| 1 | + **Added:** | ||
| 2 | + | ||
| 3 | + * Error thrown when squeeze morph given improper inputs. | ||
| 4 | + | ||
| 5 | + **Changed:** | ||
| 6 | + | ||
| 7 | + * Squeeze morph now removes duplicate/repeated and trailing commas before parsing. | ||
| 8 | + | ||
| 9 | + **Deprecated:** | ||
| 10 | + | ||
| 11 | + * <news item> | ||
| 12 | + | ||
| 13 | + **Removed:** | ||
| 14 | + | ||
| 15 | + * <news item> | ||
| 16 | + | ||
| 17 | + **Fixed:** | ||
| 18 | + | ||
| 19 | + * <news item> | ||
| 20 | + | ||
| 21 | + **Security:** | ||
| 22 | + | ||
| 23 | + * <news item> | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -188,6 +188,7 @@ def custom_error(self, msg): | |||
| 188 | 188 | "a0+a1*x+a2*x^2+...a_n*x^n." | |
| 189 | 189 | "n is dependent on the number of values in the " | |
| 190 | 190 | "user-inputted comma-separated list. " | |
| 191 | + "Repeated and trailing commas are removed before parsing." | ||
| 191 | 192 | "When this option is enabled, --hshift is disabled. " | |
| 192 | 193 | "When n>1, --stretch is disabled. " | |
| 193 | 194 | "See online documentation for more information." | |
@@ -522,6 +523,7 @@ def single_morph( | |||
| 522 | 523 | ||
| 523 | 524 | # Squeeze | |
| 524 | 525 | squeeze_poly_deg = -1 | |
| 526 | + squeeze_dict_in = {} | ||
| 525 | 527 | if opts.squeeze is not None: | |
| 526 | 528 | # Handles both list and csv input | |
| 527 | 529 | if ( | |
@@ -537,12 +539,19 @@ def single_morph( | |||
| 537 | 539 | ): | |
| 538 | 540 | opts.squeeze = opts.squeeze[1:-1] | |
| 539 | 541 | squeeze_coeffs = opts.squeeze.strip().split(",") | |
| 540 | - squeeze_dict_in = {} | ||
| 541 | - for idx, coeff in enumerate(squeeze_coeffs): | ||
| 542 | - squeeze_dict_in.update({f"a{idx}": float(coeff)}) | ||
| 543 | - squeeze_poly_deg = len(squeeze_coeffs) - 1 | ||
| 542 | + idx = 0 | ||
| 543 | + for _, coeff in enumerate(squeeze_coeffs): | ||
| 544 | + if coeff.strip() != "": | ||
| 545 | + try: | ||
| 546 | + squeeze_dict_in.update({f"a{idx}": float(coeff)}) | ||
| 547 | + idx += 1 | ||
| 548 | + except ValueError: | ||
| 549 | + parser.error(f"{coeff} could not be converted to float.") | ||
| 550 | + squeeze_poly_deg = len(squeeze_dict_in.keys()) | ||
| 544 | 551 | chain.append(morphs.MorphSqueeze()) | |
| 545 | 552 | config["squeeze"] = squeeze_dict_in | |
| 553 | + # config["extrap_index_low"] = None | ||
| 554 | + # config["extrap_index_high"] = None | ||
| 546 | 555 | refpars.append("squeeze") | |
| 547 | 556 | # Scale | |
| 548 | 557 | if opts.scale is not None: | |
@@ -679,10 +688,7 @@ def single_morph( | |||
| 679 | 688 | morph_inputs.update({"hshift": hshift_in, "vshift": vshift_in}) | |
| 680 | 689 | # More complex input morph parameters are only displayed conditionally | |
| 681 | 690 | if opts.squeeze is not None: | |
| 682 | - squeeze_coeffs = opts.squeeze.strip().split(",") | ||
| 683 | - squeeze_dict = {} | ||
| 684 | - for idx, coeff in enumerate(squeeze_coeffs): | ||
| 685 | - squeeze_dict.update({f"a{idx}": float(coeff)}) | ||
| 691 | + squeeze_dict = squeeze_dict_in.copy() | ||
| 686 | 692 | for idx, _ in enumerate(squeeze_dict): | |
| 687 | 693 | morph_inputs.update({f"squeeze a{idx}": squeeze_dict[f"a{idx}"]}) | |
| 688 | 694 | if pymorphs is not None: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -105,27 +105,43 @@ def test_parser_numerical(self, setup_parser): | |||
| 105 | 105 | ) # Check correct value parsed | |
| 106 | 106 | assert len(n_args) == 1 # Check one leftover | |
| 107 | 107 | ||
| 108 | - def test_parser_systemexits(self, setup_parser): | ||
| 108 | + def test_parser_systemexits(self, capsys, setup_parser): | ||
| 109 | 109 | # ###Basic tests for any variety of morphing### | |
| 110 | 110 | ||
| 111 | 111 | # Ensure only two pargs given for morphing | |
| 112 | 112 | (opts, pargs) = self.parser.parse_args(["toofewfiles"]) | |
| 113 | 113 | with pytest.raises(SystemExit): | |
| 114 | 114 | single_morph(self.parser, opts, pargs, stdout_flag=False) | |
| 115 | + _, err = capsys.readouterr() | ||
| 116 | + assert "You must supply FILE1 and FILE2." in err | ||
| 115 | 117 | with pytest.raises(SystemExit): | |
| 116 | 118 | multiple_targets(self.parser, opts, pargs, stdout_flag=False) | |
| 119 | + _, err = capsys.readouterr() | ||
| 120 | + assert "You must supply FILE and DIRECTORY." in err | ||
| 117 | 121 | (opts, pargs) = self.parser.parse_args(["too", "many", "files"]) | |
| 118 | 122 | with pytest.raises(SystemExit): | |
| 119 | 123 | single_morph(self.parser, opts, pargs, stdout_flag=False) | |
| 124 | + _, err = capsys.readouterr() | ||
| 125 | + assert ( | ||
| 126 | + "Too many arguments. Make sure you only supply FILE1 and FILE2." | ||
| 127 | + in err | ||
| 128 | + ) | ||
| 120 | 129 | with pytest.raises(SystemExit): | |
| 121 | 130 | multiple_targets(self.parser, opts, pargs, stdout_flag=False) | |
| 131 | + _, err = capsys.readouterr() | ||
| 132 | + assert ( | ||
| 133 | + "Too many arguments. You must only supply a FILE and a DIRECTORY." | ||
| 134 | + in err | ||
| 135 | + ) | ||
| 122 | 136 | ||
| 123 | 137 | # Make sure rmax greater than rmin | |
| 124 | 138 | (opts, pargs) = self.parser.parse_args( | |
| 125 | 139 | [f"{nickel_PDF}", f"{nickel_PDF}", "--rmin", "10", "--rmax", "1"] | |
| 126 | 140 | ) | |
| 127 | 141 | with pytest.raises(SystemExit): | |
| 128 | 142 | single_morph(self.parser, opts, pargs, stdout_flag=False) | |
| 143 | + _, err = capsys.readouterr() | ||
| 144 | + assert "rmin must be less than rmax" in err | ||
| 129 | 145 | ||
| 130 | 146 | # ###Tests exclusive to multiple morphs### | |
| 131 | 147 | # Make sure we save to a directory that exists | |
@@ -140,8 +156,12 @@ def test_parser_systemexits(self, setup_parser): | |||
| 140 | 156 | ) | |
| 141 | 157 | with pytest.raises(SystemExit): | |
| 142 | 158 | single_morph(self.parser, opts, pargs, stdout_flag=False) | |
| 159 | + _, err = capsys.readouterr() | ||
| 160 | + assert "Unable to save to designated location." in err | ||
| 143 | 161 | with pytest.raises(SystemExit): | |
| 144 | 162 | multiple_targets(self.parser, opts, pargs, stdout_flag=False) | |
| 163 | + _, err = capsys.readouterr() | ||
| 164 | + assert "is not a directory." in err | ||
| 145 | 165 | ||
| 146 | 166 | # Ensure first parg is a FILE and second parg is a DIRECTORY | |
| 147 | 167 | (opts, pargs) = self.parser.parse_args( | |
@@ -152,15 +172,21 @@ def test_parser_systemexits(self, setup_parser): | |||
| 152 | 172 | (opts, pargs) = self.parser.parse_args( | |
| 153 | 173 | [f"{testsequence_dir}", f"{testsequence_dir}"] | |
| 154 | 174 | ) | |
| 175 | + _, err = capsys.readouterr() | ||
| 176 | + assert "is not a directory." in err | ||
| 155 | 177 | with pytest.raises(SystemExit): | |
| 156 | 178 | multiple_targets(self.parser, opts, pargs, stdout_flag=False) | |
| 179 | + _, err = capsys.readouterr() | ||
| 180 | + assert "is not a file." in err | ||
| 157 | 181 | ||
| 158 | 182 | # Try sorting by non-existing field | |
| 159 | 183 | (opts, pargs) = self.parser.parse_args( | |
| 160 | 184 | [f"{nickel_PDF}", f"{testsequence_dir}", "--sort-by", "fake_field"] | |
| 161 | 185 | ) | |
| 162 | 186 | with pytest.raises(SystemExit): | |
| 163 | 187 | multiple_targets(self.parser, opts, pargs, stdout_flag=False) | |
| 188 | + _, err = capsys.readouterr() | ||
| 189 | + assert "The requested field is missing from a PDF file header." in err | ||
| 164 | 190 | (opts, pargs) = self.parser.parse_args( | |
| 165 | 191 | [ | |
| 166 | 192 | f"{nickel_PDF}", | |
@@ -173,6 +199,8 @@ def test_parser_systemexits(self, setup_parser): | |||
| 173 | 199 | ) | |
| 174 | 200 | with pytest.raises(SystemExit): | |
| 175 | 201 | multiple_targets(self.parser, opts, pargs, stdout_flag=False) | |
| 202 | + _, err = capsys.readouterr() | ||
| 203 | + assert "The requested field was not found in the metadata file." in err | ||
| 176 | 204 | ||
| 177 | 205 | # Try plotting an unknown parameter | |
| 178 | 206 | (opts, pargs) = self.parser.parse_args( | |
@@ -185,6 +213,8 @@ def test_parser_systemexits(self, setup_parser): | |||
| 185 | 213 | ) | |
| 186 | 214 | with pytest.raises(SystemExit): | |
| 187 | 215 | multiple_targets(self.parser, opts, pargs, stdout_flag=False) | |
| 216 | + _, err = capsys.readouterr() | ||
| 217 | + assert "Cannot find specified plot parameter. No plot shown." in err | ||
| 188 | 218 | ||
| 189 | 219 | # Try plotting an unrefined parameter | |
| 190 | 220 | (opts, pargs) = self.parser.parse_args( | |
@@ -197,6 +227,26 @@ def test_parser_systemexits(self, setup_parser): | |||
| 197 | 227 | ) | |
| 198 | 228 | with pytest.raises(SystemExit): | |
| 199 | 229 | multiple_targets(self.parser, opts, pargs, stdout_flag=False) | |
| 230 | + _, err = capsys.readouterr() | ||
| 231 | + assert ( | ||
| 232 | + "The plot parameter is missing values for at " | ||
| 233 | + "least one morph and target pair. " | ||
| 234 | + "No plot shown." in err | ||
| 235 | + ) | ||
| 236 | + | ||
| 237 | + # Pass a non-float list to squeeze | ||
| 238 | + (opts, pargs) = self.parser.parse_args( | ||
| 239 | + [ | ||
| 240 | + f"{nickel_PDF}", | ||
| 241 | + f"{nickel_PDF}", | ||
| 242 | + "--squeeze", | ||
| 243 | + "1,a,0", | ||
| 244 | + ] | ||
| 245 | + ) | ||
| 246 | + with pytest.raises(SystemExit): | ||
| 247 | + single_morph(self.parser, opts, pargs, stdout_flag=False) | ||
| 248 | + _, err = capsys.readouterr() | ||
| 249 | + assert "a could not be converted to float." in err | ||
| 200 | 250 | ||
| 201 | 251 | def test_morphsequence(self, setup_morphsequence): | |
| 202 | 252 | # Parse arguments sorting by field | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -163,7 +163,9 @@ def test_morphsqueeze_outputs(self, setup, tmp_path): | |||
| 163 | 163 | "--scale", | |
| 164 | 164 | "2", | |
| 165 | 165 | "--squeeze", | |
| 166 | - "0,-0.001,-0.0001,0.0001", | ||
| 166 | + # Ignore duplicate commas and trailing commas | ||
| 167 | + # Handle spaces and non-spaces | ||
| 168 | + "0,, ,-0.001, -0.0001,0.0001,", | ||
| 167 | 169 | "--stretch", | |
| 168 | 170 | "1", | |
| 169 | 171 | "--hshift", | |
| Back | FazBrowse Home | New Git URL |
0 commit comments