1111from diffpy .utils .diffraction_objects import XQUANTITIES , DiffractionObject
1212
1313params = [
14- ( # Default
15- {},
16- {},
17- True ,
18- ),
1914 ( # Compare same attributes
2015 {
2116 "name" : "same" ,
4136 {
4237 "name" : "something" ,
4338 "scat_quantity" : "" ,
44- "wavelength" : None ,
45- "xtype" : "" ,
39+ "wavelength" : 0.71 ,
40+ "xtype" : "tth " ,
4641 "xarray" : np .empty (0 ),
4742 "yarray" : np .empty (0 ),
4843 "metadata" : {"thing1" : 1 , "thing2" : "thing2" },
4944 },
5045 {
5146 "name" : "something else" ,
5247 "scat_quantity" : "" ,
53- "wavelength" : None ,
54- "xtype" : "" ,
48+ "wavelength" : 0.71 ,
49+ "xtype" : "tth " ,
5550 "xarray" : np .empty (0 ),
5651 "yarray" : np .empty (0 ),
5752 "metadata" : {"thing1" : 1 , "thing2" : "thing2" },
6257 {
6358 "scat_quantity" : "" ,
6459 "wavelength" : 0.71 ,
65- "xtype" : "" ,
60+ "xtype" : "tth " ,
6661 "xarray" : np .empty (0 ),
6762 "yarray" : np .empty (0 ),
6863 "metadata" : {"thing1" : 1 , "thing2" : "thing2" },
6964 },
7065 {
7166 "scat_quantity" : "" ,
72- "wavelength" : None ,
73- "xtype" : "" ,
67+ "wavelength" : 0.42 ,
68+ "xtype" : "tth " ,
7469 "xarray" : np .empty (0 ),
7570 "yarray" : np .empty (0 ),
7671 "metadata" : {"thing1" : 1 , "thing2" : "thing2" },
8176 {
8277 "scat_quantity" : "" ,
8378 "wavelength" : 0.71 ,
84- "xtype" : "" ,
79+ "xtype" : "tth " ,
8580 "xarray" : np .empty (0 ),
8681 "yarray" : np .empty (0 ),
8782 "metadata" : {"thing1" : 1 , "thing2" : "thing2" },
8883 },
8984 {
9085 "scat_quantity" : "" ,
9186 "wavelength" : 0.711 ,
92- "xtype" : "" ,
87+ "xtype" : "tth " ,
9388 "xarray" : np .empty (0 ),
9489 "yarray" : np .empty (0 ),
9590 "metadata" : {"thing1" : 1 , "thing2" : "thing2" },
9994 ( # Different scat_quantity
10095 {
10196 "scat_quantity" : "x-ray" ,
102- "wavelength " : None ,
103- "xtype " : "" ,
97+ "xtype " : "tth" ,
98+ "wavelength " : 0.71 ,
10499 "xarray" : np .empty (0 ),
105100 "yarray" : np .empty (0 ),
106101 "metadata" : {"thing1" : 1 , "thing2" : "thing2" },
107102 },
108103 {
109104 "scat_quantity" : "neutron" ,
110- "wavelength " : None ,
111- "xtype " : "" ,
105+ "xtype " : "tth" ,
106+ "wavelength " : 0.71 ,
112107 "xarray" : np .empty (0 ),
113108 "yarray" : np .empty (0 ),
114109 "metadata" : {"thing1" : 1 , "thing2" : "thing2" },
118113 ( # Different on_q
119114 {
120115 "scat_quantity" : "" ,
121- "wavelength" : None ,
122116 "xtype" : "q" ,
117+ "wavelength" : 0.71 ,
123118 "xarray" : np .array ([1.0 , 2.0 ]),
124119 "yarray" : np .array ([100.0 , 200.0 ]),
125120 "metadata" : {},
126121 },
127122 {
128123 "scat_quantity" : "" ,
129- "wavelength" : None ,
130124 "xtype" : "q" ,
125+ "wavelength" : 0.71 ,
131126 "xarray" : np .array ([3.0 , 4.0 ]),
132127 "yarray" : np .array ([100.0 , 200.0 ]),
133128 "metadata" : {"thing1" : 1 , "thing2" : "thing2" },
137132 ( # Different metadata
138133 {
139134 "scat_quantity" : "" ,
140- "wavelength " : None ,
141- "xtype " : "" ,
135+ "xtype " : "q" ,
136+ "wavelength " : 0.71 ,
142137 "xarray" : np .empty (0 ),
143138 "yarray" : np .empty (0 ),
144139 "metadata" : {"thing1" : 0 , "thing2" : "thing2" },
145140 },
146141 {
147142 "scat_quantity" : "" ,
148- "wavelength " : None ,
149- "xtype " : "" ,
143+ "xtype " : "q" ,
144+ "wavelength " : 0.71 ,
150145 "xarray" : np .empty (0 ),
151146 "yarray" : np .empty (0 ),
152147 "metadata" : {"thing1" : 1 , "thing2" : "thing2" },
@@ -171,15 +166,15 @@ def test_on_xtype():
171166 assert np .allclose (test .on_xtype ("d" ), [np .array ([12.13818 , 6.28319 ]), np .array ([1 , 2 ])])
172167
173168
174- def test_init_invalid_xtype ():
169+ def test_init_invalid_xtype (do_minimal ):
175170 with pytest .raises (
176171 ValueError ,
177172 match = re .escape (
178173 f"I don't know how to handle the xtype, 'invalid_type'. "
179174 f"Please rerun specifying an xtype from { * XQUANTITIES , } "
180175 ),
181176 ):
182- DiffractionObject (xtype = "invalid_type" )
177+ return DiffractionObject (xarray = np . empty ( 0 ), yarray = np . empty ( 0 ), xtype = "invalid_type" , wavelength = 1.54 )
183178
184179
185180params_index = [
@@ -241,40 +236,6 @@ def test_dump(tmp_path, mocker):
241236
242237
243238tc_params = [
244- (
245- {},
246- {
247- "_all_arrays" : np .empty (shape = (0 , 4 )), # instantiate empty
248- "metadata" : {},
249- "_input_xtype" : "" ,
250- "name" : "" ,
251- "scat_quantity" : None ,
252- "qmin" : np .float64 (np .inf ),
253- "qmax" : np .float64 (0.0 ),
254- "tthmin" : np .float64 (np .inf ),
255- "tthmax" : np .float64 (0.0 ),
256- "dmin" : np .float64 (np .inf ),
257- "dmax" : np .float64 (0.0 ),
258- "wavelength" : None ,
259- },
260- ),
261- ( # instantiate just non-array attributes
262- {"name" : "test" , "scat_quantity" : "x-ray" , "metadata" : {"thing" : "1" , "another" : "2" }},
263- {
264- "_all_arrays" : np .empty (shape = (0 , 4 )),
265- "metadata" : {"thing" : "1" , "another" : "2" },
266- "_input_xtype" : "" ,
267- "name" : "test" ,
268- "scat_quantity" : "x-ray" ,
269- "qmin" : np .float64 (np .inf ),
270- "qmax" : np .float64 (0.0 ),
271- "tthmin" : np .float64 (np .inf ),
272- "tthmax" : np .float64 (0.0 ),
273- "dmin" : np .float64 (np .inf ),
274- "dmax" : np .float64 (0.0 ),
275- "wavelength" : None ,
276- },
277- ),
278239 ( # instantiate just array attributes
279240 {
280241 "xarray" : np .array ([0.0 , 90.0 , 180.0 ]),
@@ -293,7 +254,7 @@ def test_dump(tmp_path, mocker):
293254 "metadata" : {},
294255 "_input_xtype" : "tth" ,
295256 "name" : "" ,
296- "scat_quantity" : None ,
257+ "scat_quantity" : "" ,
297258 "qmin" : np .float64 (0.0 ),
298259 "qmax" : np .float64 (1.0 ),
299260 "tthmin" : np .float64 (0.0 ),
@@ -339,6 +300,9 @@ def test_dump(tmp_path, mocker):
339300def test_constructor (inputs , expected ):
340301 actual = DiffractionObject (** inputs ).__dict__
341302 diff = DeepDiff (actual , expected , ignore_order = True , significant_digits = 13 , exclude_paths = "root['_id']" )
303+ print ("Print diff" )
304+ print (diff )
305+ # {'dictionary_item_added': ["root['name']", "root['scat_quantity']"]}
342306 assert diff == {}
343307
344308
@@ -359,8 +323,8 @@ def test_all_array_getter():
359323 assert np .allclose (actual_do .all_arrays , expected_all_arrays )
360324
361325
362- def test_all_array_setter ():
363- actual_do = DiffractionObject ()
326+ def test_all_array_setter (do_minimal ):
327+ actual_do = do_minimal
364328
365329 # Attempt to directly modify the property
366330 with pytest .raises (
@@ -371,21 +335,21 @@ def test_all_array_setter():
371335 actual_do .all_arrays = np .empty ((4 , 4 ))
372336
373337
374- def test_id_getter ():
375- do = DiffractionObject ()
338+ def test_id_getter (do_minimal ):
339+ do = do_minimal
376340 assert hasattr (do , "id" )
377341 assert isinstance (do .id , UUID )
378342 assert len (str (do .id )) == 36
379343
380344
381- def test_id_getter_with_mock (mocker ):
345+ def test_id_getter_with_mock (mocker , do_minimal ):
382346 mocker .patch .object (DiffractionObject , "id" , new_callable = lambda : UUID ("d67b19c6-3016-439f-81f7-cf20a04bee87" ))
383- do = DiffractionObject ()
347+ do = do_minimal
384348 assert do .id == UUID ("d67b19c6-3016-439f-81f7-cf20a04bee87" )
385349
386350
387- def test_id_setter_error ():
388- do = DiffractionObject ()
351+ def test_id_setter_error (do_minimal ):
352+ do = do_minimal
389353
390354 with pytest .raises (
391355 AttributeError ,
@@ -401,18 +365,18 @@ def test_xarray_yarray_length_mismatch():
401365 "Please re-initialize 'DiffractionObject' or re-run the method 'input_data' "
402366 "with 'xarray' and 'yarray' of identical length" ,
403367 ):
404- DiffractionObject (xarray = np .array ([1.0 , 2.0 ]), yarray = np .array ([0.0 , 0.0 , 0.0 ]))
368+ DiffractionObject (
369+ xarray = np .array ([1.0 , 2.0 ]), yarray = np .array ([0.0 , 0.0 , 0.0 ]), xtype = "tth" , wavelength = 1.54
370+ )
405371
406372
407- def test_input_xtype_getter ():
408- do = DiffractionObject ( xtype = "tth" )
373+ def test_input_xtype_getter (do_minimal ):
374+ do = do_minimal
409375 assert do .input_xtype == "tth"
410376
411377
412- def test_input_xtype_setter_error ():
413- do = DiffractionObject (xtype = "tth" )
414-
415- # Attempt to directly modify the property
378+ def test_input_xtype_setter_error (do_minimal ):
379+ do = do_minimal
416380 with pytest .raises (
417381 AttributeError ,
418382 match = "Direct modification of attribute 'input_xtype' is not allowed. "
0 commit comments