2
2
3
3
import numpy as np
4
4
import pytest
5
+ from deepdiff import DeepDiff
5
6
from freezegun import freeze_time
6
7
7
8
from diffpy .utils .diffraction_objects import DiffractionObject
@@ -248,7 +249,7 @@ def test_dump(tmp_path, mocker):
248
249
(
249
250
{},
250
251
{
251
- "all_arrays " : np .empty (shape = (0 , 4 )), # instantiate empty
252
+ "_all_arrays " : np .empty (shape = (0 , 4 )), # instantiate empty
252
253
"metadata" : {},
253
254
"input_xtype" : "" ,
254
255
"name" : "" ,
@@ -265,7 +266,7 @@ def test_dump(tmp_path, mocker):
265
266
( # instantiate just non-array attributes
266
267
{"name" : "test" , "scat_quantity" : "x-ray" , "metadata" : {"thing" : "1" , "another" : "2" }},
267
268
{
268
- "all_arrays " : np .empty (shape = (0 , 4 )),
269
+ "_all_arrays " : np .empty (shape = (0 , 4 )),
269
270
"metadata" : {"thing" : "1" , "another" : "2" },
270
271
"input_xtype" : "" ,
271
272
"name" : "test" ,
@@ -287,7 +288,7 @@ def test_dump(tmp_path, mocker):
287
288
"wavelength" : 4.0 * np .pi ,
288
289
},
289
290
{
290
- "all_arrays " : np .array (
291
+ "_all_arrays " : np .array (
291
292
[
292
293
[1.0 , 0.0 , 0.0 , np .float64 (np .inf )],
293
294
[2.0 , 1.0 / np .sqrt (2 ), 90.0 , np .sqrt (2 ) * 2 * np .pi ],
@@ -316,7 +317,7 @@ def test_dump(tmp_path, mocker):
316
317
"scat_quantity" : "x-ray" ,
317
318
},
318
319
{
319
- "all_arrays " : np .array (
320
+ "_all_arrays " : np .array (
320
321
[
321
322
[1.0 , 0.0 , 0.0 , np .float64 (np .inf )],
322
323
[2.0 , 1.0 / np .sqrt (2 ), 90.0 , np .sqrt (2 ) * 2 * np .pi ],
@@ -342,21 +343,26 @@ def test_dump(tmp_path, mocker):
342
343
@pytest .mark .parametrize ("inputs, expected" , tc_params )
343
344
def test_constructor (inputs , expected ):
344
345
actual_do = DiffractionObject (** inputs )
345
- actual_dict = {
346
- "all_arrays" : actual_do .all_arrays ,
347
- "metadata" : actual_do .metadata ,
348
- "input_xtype" : actual_do .input_xtype ,
349
- "name" : actual_do .name ,
350
- "scat_quantity" : actual_do .scat_quantity ,
351
- "qmin" : actual_do .qmin ,
352
- "qmax" : actual_do .qmax ,
353
- "tthmin" : actual_do .tthmin ,
354
- "tthmax" : actual_do .tthmax ,
355
- "dmin" : actual_do .dmin ,
356
- "dmax" : actual_do .dmax ,
357
- "wavelength" : actual_do .wavelength ,
358
- }
359
- compare_dicts (actual_dict , expected )
346
+ diff = DeepDiff (actual_do .__dict__ , expected , ignore_order = True , significant_digits = 4 )
347
+ # Ensure there is no difference
348
+ assert diff == {}
349
+
350
+
351
+ def test_all_array_getter ():
352
+ actual_do = DiffractionObject (
353
+ xarray = np .array ([0.0 , 90.0 , 180.0 ]),
354
+ yarray = np .array ([1.0 , 2.0 , 3.0 ]),
355
+ xtype = "tth" ,
356
+ wavelength = 4.0 * np .pi ,
357
+ )
358
+ expected_all_arrays = np .array (
359
+ [
360
+ [1.0 , 0.0 , 0.0 , np .float64 (np .inf )],
361
+ [2.0 , 1.0 / np .sqrt (2 ), 90.0 , np .sqrt (2 ) * 2 * np .pi ],
362
+ [3.0 , 1.0 , 180.0 , 1.0 * 2 * np .pi ],
363
+ ]
364
+ )
365
+ assert np .array_equal (actual_do .all_arrays , expected_all_arrays )
360
366
361
367
362
368
def test_all_array_setter ():
0 commit comments