55
66from diffpy .utils .transforms import d_to_q , d_to_tth , q_to_d , q_to_tth , tth_to_d , tth_to_q
77
8+
89params_q_to_tth = [
910 # UC1: Empty q values, no wavelength, return empty arrays
1011 (None , np .empty ((0 )), np .empty ((0 ))),
2324
2425
2526@pytest .mark .parametrize ("wavelength, q, expected_tth" , params_q_to_tth )
26- def test_q_to_tth (wavelength , q , expected_tth ):
27-
28- wavelength_warning_emsg = (
29- "No wavelength has been specified. You can continue to use the DiffractionObject, but "
30- "some of its powerful features will not be available. "
31- "To specify a wavelength, if you have do = DiffractionObject(xarray, yarray, 'tth'), "
32- "you may set do.wavelength = 1.54 for a wavelength of 1.54 angstroms."
33- )
27+ def test_q_to_tth (wavelength , q , expected_tth , wavelength_warning_msg ):
28+
3429 if wavelength is None :
35- with pytest .warns (UserWarning , match = re .escape (wavelength_warning_emsg )):
30+ with pytest .warns (UserWarning , match = re .escape (wavelength_warning_msg )):
3631 actual_tth = q_to_tth (q , wavelength )
3732 else :
3833 actual_tth = q_to_tth (q , wavelength )
@@ -66,7 +61,7 @@ def test_q_to_tth_bad(q, wavelength, expected_error_type, expected_error_msg):
6661 q_to_tth (wavelength , q )
6762
6863
69- params_tth_to_q = [
64+ test_tth_t_q_params = [
7065 # UC0: User specified empty tth values (without wavelength)
7166 (None , np .array ([]), np .array ([])),
7267 # UC1: User specified empty tth values (with wavelength)
@@ -86,31 +81,38 @@ def test_q_to_tth_bad(q, wavelength, expected_error_type, expected_error_msg):
8681 ),
8782]
8883
89-
90- @pytest .mark .parametrize ("wavelength, tth, expected_q" , params_tth_to_q )
91- def test_tth_to_q (wavelength , tth , expected_q ):
92- actual_q = tth_to_q (tth , wavelength )
84+ @pytest .mark .parametrize ("wavelength, tth, expected_q" , test_tth_t_q_params )
85+ def test_tth_to_q (wavelength , tth , expected_q , wavelength_warning_msg ):
86+ if wavelength is None :
87+ with pytest .warns (UserWarning , match = re .escape (wavelength_warning_msg )):
88+ actual_q = tth_to_q (tth , wavelength )
89+ else :
90+ actual_q = tth_to_q (tth , wavelength )
91+
9392 assert np .allclose (actual_q , expected_q )
9493
95-
96- params_tth_to_q_bad = [
94+ tth_to_q_bad_params = [
9795 # UC0: user specified an invalid tth value of > 180 degrees (without wavelength)
9896 (
99- [None , np .array ([0 , 30 , 60 , 90 , 120 , 181 ])],
100- [ValueError , "Two theta exceeds 180 degrees. Please check the input values for errors." ],
97+ None ,
98+ np .array ([0 , 30 , 60 , 90 , 120 , 181 ]),
99+ ValueError ,
100+ "Two theta exceeds 180 degrees. Please check the input values for errors." ,
101101 ),
102102 # UC1: user specified an invalid tth value of > 180 degrees (with wavelength)
103103 (
104- [4 * np .pi , np .array ([0 , 30 , 60 , 90 , 120 , 181 ])],
105- [ValueError , "Two theta exceeds 180 degrees. Please check the input values for errors." ],
104+ 4 * np .pi ,
105+ np .array ([0 , 30 , 60 , 90 , 120 , 181 ]),
106+ ValueError ,
107+ "Two theta exceeds 180 degrees. Please check the input values for errors." ,
106108 ),
107109]
108110
109111
110- @pytest .mark .parametrize ("inputs, expected " , params_tth_to_q_bad )
111- def test_tth_to_q_bad (inputs , expected ):
112- with pytest .raises (expected [ 0 ] , match = expected [ 1 ] ):
113- tth_to_q (inputs [ 1 ], inputs [ 0 ] )
112+ @pytest .mark .parametrize ("wavelength, tth, expected_error_type, expected_error_msg " , tth_to_q_bad_params )
113+ def test_tth_to_q_bad (wavelength , tth , expected_error_type , expected_error_msg ):
114+ with pytest .raises (expected_error_type , match = expected_error_msg ):
115+ tth_to_q (tth , wavelength )
114116
115117
116118params_q_to_d = [
@@ -212,6 +214,7 @@ def test_tth_to_d_bad(inputs, expected):
212214@pytest .mark .parametrize ("inputs, expected" , params_d_to_tth )
213215def test_d_to_tth (inputs , expected ):
214216 actual = d_to_tth (inputs [1 ], inputs [0 ])
217+
215218 assert np .allclose (expected , actual )
216219
217220
0 commit comments