@@ -468,10 +468,61 @@ def test_dump(tmp_path, mocker):
468
468
469
469
470
470
@pytest .mark .parametrize (
471
- "do_init_args, expected_do_dict, divide_by_zero_warning_expected" ,
471
+ "do_init_args, expected_do_dict, divide_by_zero_warning_expected, wavelength_warning_expected " ,
472
472
[
473
473
# Test __dict__ of DiffractionObject instance initialized with valid arguments
474
- ( # C1: Minimum arguments provided for init, expect all attributes set without None
474
+ ( # C1: Instantiate DO with empty arrays, expect it to be a valid DO, but with everything empty
475
+ {
476
+ "xarray" : np .empty (0 ),
477
+ "yarray" : np .empty (0 ),
478
+ "xtype" : "tth" ,
479
+ },
480
+ {
481
+ "_all_arrays" : np .array ([]),
482
+ "_input_xtype" : "tth" ,
483
+ "metadata" : {},
484
+ "name" : "" ,
485
+ "scat_quantity" : "" ,
486
+ "qmin" : np .float64 (np .inf ),
487
+ "qmax" : np .float64 (0.0 ),
488
+ "tthmin" : np .float64 (np .inf ),
489
+ "tthmax" : np .float64 (0.0 ),
490
+ "dmin" : np .float64 (np .inf ),
491
+ "dmax" : np .float64 (0.0 ),
492
+ "wavelength" : None ,
493
+ },
494
+ False ,
495
+ True ,
496
+ ),
497
+ ( # C2: Instantiate just DO with empty array like in C1 but with wavelength, xtype, name, and metadata
498
+ # expect a valid DO with empty arrays, but with some non-array attributes
499
+ {
500
+ "xarray" : np .empty (0 ),
501
+ "yarray" : np .empty (0 ),
502
+ "xtype" : "tth" ,
503
+ "name" : "test_name" ,
504
+ "wavelength" : 1.54 ,
505
+ "metadata" : {"item_1" : "1" , "item_2" : "2" },
506
+ },
507
+ {
508
+ "_all_arrays" : np .array ([]),
509
+ "_input_xtype" : "tth" ,
510
+ "metadata" : {"item_1" : "1" , "item_2" : "2" },
511
+ "name" : "test_name" ,
512
+ "scat_quantity" : "" ,
513
+ "qmin" : np .float64 (np .inf ),
514
+ "qmax" : np .float64 (0.0 ),
515
+ "tthmin" : np .float64 (np .inf ),
516
+ "tthmax" : np .float64 (0.0 ),
517
+ "dmin" : np .float64 (np .inf ),
518
+ "dmax" : np .float64 (0.0 ),
519
+ "wavelength" : 1.54 ,
520
+ },
521
+ False ,
522
+ False ,
523
+ ),
524
+ ( # C3: Minimum arguments provided for init with non-empty values for xarray and yarray and wavelength
525
+ # expect all attributes set without None
475
526
{
476
527
"xarray" : np .array ([0.0 , 90.0 , 180.0 ]),
477
528
"yarray" : np .array ([1.0 , 2.0 , 3.0 ]),
@@ -499,8 +550,9 @@ def test_dump(tmp_path, mocker):
499
550
"wavelength" : 4.0 * np .pi ,
500
551
},
501
552
True ,
553
+ False ,
502
554
),
503
- ( # C2: Initialize with an optional scat_quantity argument, expect non-empty string for scat_quantity
555
+ ( # C4: Same as C3, but with an optional scat_quantity argument, expect non-empty string for scat_quantity
504
556
{
505
557
"xarray" : np .array ([np .inf , 2 * np .sqrt (2 ) * np .pi , 2 * np .pi ]),
506
558
"yarray" : np .array ([1.0 , 2.0 , 3.0 ]),
@@ -529,13 +581,23 @@ def test_dump(tmp_path, mocker):
529
581
"wavelength" : 4.0 * np .pi ,
530
582
},
531
583
False ,
584
+ False ,
532
585
),
533
586
],
534
587
)
535
- def test_init_valid (do_init_args , expected_do_dict , divide_by_zero_warning_expected ):
588
+ def test_init_valid (
589
+ do_init_args ,
590
+ expected_do_dict ,
591
+ divide_by_zero_warning_expected ,
592
+ wavelength_warning_expected ,
593
+ wavelength_warning_msg ,
594
+ ):
536
595
if divide_by_zero_warning_expected :
537
596
with pytest .warns (RuntimeWarning , match = "divide by zero encountered in divide" ):
538
597
actual_do_dict = DiffractionObject (** do_init_args ).__dict__
598
+ elif wavelength_warning_expected :
599
+ with pytest .warns (UserWarning , match = re .escape (wavelength_warning_msg )):
600
+ actual_do_dict = DiffractionObject (** do_init_args ).__dict__
539
601
else :
540
602
actual_do_dict = DiffractionObject (** do_init_args ).__dict__
541
603
diff = DeepDiff (
0 commit comments