r""" Function rfactor_compute. Test the cases that will cause the function to fail.
()
| 160 | |
| 161 | |
| 162 | def test_rfactor_compute_fail(): |
| 163 | r""" |
| 164 | Function rfactor_compute. Test the cases that will cause the function to fail. |
| 165 | """ |
| 166 | |
| 167 | n_pts, n_refs, n_spec = 100, 5, 3 |
| 168 | |
| 169 | # There will be no computations performed, so all zeros are good enough |
| 170 | ref_spectra = np.zeros(shape=[n_pts, n_refs]) |
| 171 | fit_results = np.zeros(shape=[n_refs]) |
| 172 | spectrum = np.zeros(shape=[n_pts]) |
| 173 | |
| 174 | fit_results_2D = np.zeros(shape=[n_refs, n_spec]) |
| 175 | spectrum_2D = np.zeros(shape=[n_pts, n_spec]) |
| 176 | |
| 177 | # For testing of wrong dimensionality of the arrays, otherwise |
| 178 | # those are meaningless arrays |
| 179 | ref_spectra_3D = np.zeros(shape=[n_pts, n_refs, n_refs]) |
| 180 | spectrum_3D = np.zeros(shape=[n_pts, n_spec, n_spec]) |
| 181 | |
| 182 | # Wrong dimensions of parameter 'spectrum' |
| 183 | with pytest.raises(AssertionError, match="spectrum' must be 1D or 2D array"): |
| 184 | rfactor_compute(spectrum_3D, fit_results, ref_spectra) |
| 185 | |
| 186 | # No match between dimensions of 'spectrum' and 'fit_results' dimensionality |
| 187 | with pytest.raises( |
| 188 | AssertionError, match="Spectrum data .+ and fitting results .+ must have the same number of dimensions" |
| 189 | ): |
| 190 | rfactor_compute(spectrum, fit_results_2D, ref_spectra) |
| 191 | |
| 192 | # Wrong dimensions of parameter 'ref_spectra' |
| 193 | with pytest.raises(AssertionError, match="'ref_spectra' must be 2D array"): |
| 194 | rfactor_compute(spectrum, fit_results, ref_spectra_3D) |
| 195 | |
| 196 | # Mismatch between the number of data points |
| 197 | with pytest.raises(AssertionError, match="must have the same number of data points"): |
| 198 | rfactor_compute(np.delete(spectrum, -1), fit_results, ref_spectra) |
| 199 | with pytest.raises(AssertionError, match="must have the same number of data points"): |
| 200 | rfactor_compute(np.delete(spectrum_2D, -1, axis=0), fit_results_2D, ref_spectra) |
| 201 | |
| 202 | # Mismatch between the number of spectrum points |
| 203 | with pytest.raises(AssertionError, match="must have the same number of spectrum points"): |
| 204 | rfactor_compute(spectrum, np.delete(fit_results, -1), ref_spectra) |
| 205 | with pytest.raises(AssertionError, match="must have the same number of spectrum points"): |
| 206 | rfactor_compute(spectrum_2D, np.delete(fit_results_2D, -1, axis=0), ref_spectra) |
| 207 | |
| 208 | # Mismatch between the number of columns in 'fit_results' and 'spectrum' |
| 209 | with pytest.raises(AssertionError, match="must have the same number of columns"): |
| 210 | rfactor_compute(spectrum_2D, np.delete(fit_results_2D, -1, axis=1), ref_spectra) |
| 211 | |
| 212 | |
| 213 | # fmt: off |
nothing calls this directly
no test coverage detected