@@ -223,30 +223,31 @@ def test_tth_to_d_invalid(wavelength, tth, expected_error_type, expected_error_m
223223
224224
225225@pytest .mark .parametrize (
226- "wavelength, d, expected_tth" ,
226+ "wavelength, d, expected_tth, divide_by_zero_warning_expected " ,
227227 [
228228 # UC1: Empty d values, no wavelength, return empty arrays
229- (None , np .empty ((0 )), np .empty ((0 ))),
229+ (None , np .empty ((0 )), np .empty ((0 )), False ),
230230 # UC2: Empty d values, wavelength specified, return empty arrays
231- (4 * np .pi , np .empty ((0 )), np .empty (0 )),
231+ (4 * np .pi , np .empty ((0 )), np .empty (0 ), False ),
232232 # UC3: User specified valid d values, no wavelength, return empty arrays
233- (
234- None ,
235- np .array ([1 , 0.8 , 0.6 , 0.4 , 0.2 , 0 ]),
236- np .array ([0 , 1 , 2 , 3 , 4 , 5 ]),
237- ),
233+ (None , np .array ([1 , 0.8 , 0.6 , 0.4 , 0.2 , 0 ]), np .array ([0 , 1 , 2 , 3 , 4 , 5 ]), True ),
238234 # UC4: User specified valid d values (with wavelength)
239235 (
240236 4 * np .pi ,
241237 np .array ([4 * np .pi , 4 / np .sqrt (2 ) * np .pi , 4 / np .sqrt (3 ) * np .pi ]),
242238 np .array ([60.0 , 90.0 , 120.0 ]),
239+ False
243240 ),
244241 ],
245242)
246- def test_d_to_tth (wavelength , d , expected_tth , wavelength_warning_msg ):
247- if wavelength is None :
243+ def test_d_to_tth (wavelength , d , expected_tth , divide_by_zero_warning_expected , wavelength_warning_msg ):
244+ if wavelength is None and not divide_by_zero_warning_expected :
248245 with pytest .warns (UserWarning , match = re .escape (wavelength_warning_msg )):
249246 actual_tth = d_to_tth (d , wavelength )
247+ elif wavelength is None and divide_by_zero_warning_expected :
248+ with pytest .warns (UserWarning , match = re .escape (wavelength_warning_msg )):
249+ with pytest .warns (RuntimeWarning , match = "divide by zero encountered in divide" ):
250+ actual_tth = d_to_tth (d , wavelength )
250251 else :
251252 actual_tth = d_to_tth (d , wavelength )
252253
@@ -259,7 +260,7 @@ def test_d_to_tth(wavelength, d, expected_tth, wavelength_warning_msg):
259260 # UC1: user specified invalid d values that result in tth > 180 degrees
260261 (4 * np .pi , np .array ([1.2 , 1 , 0.8 , 0.6 , 0.4 , 0.2 ]), ValueError ),
261262 # UC2: user specified a wrong wavelength that result in tth > 180 degrees
262- (100 , np .array ([1 , 0.8 , 0.6 , 0.4 , 0.2 , 0 ]), ValueError ),
263+ (100 , np .array ([1.2 , 1 , 0.8 , 0.6 , 0.4 , 0.2 ]), ValueError ),
263264 ],
264265)
265266def test_d_to_tth_bad (wavelength , d , expected_error_type , invalid_q_or_d_or_wavelength_error_msg ):
0 commit comments