Skip to content

Commit 7ccebe8

Browse files
committed
Add wavelength user behavior back
1 parent de6f12d commit 7ccebe8

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

tests/test_diffraction_objects.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
{
1616
"name": "same",
1717
"scat_quantity": "x-ray",
18-
"wavelength": 0.71,
1918
"xtype": "q",
2019
"xarray": np.array([1.0, 2.0]),
2120
"yarray": np.array([100.0, 200.0]),
@@ -24,7 +23,6 @@
2423
{
2524
"name": "same",
2625
"scat_quantity": "x-ray",
27-
"wavelength": 0.71,
2826
"xtype": "q",
2927
"xarray": np.array([1.0, 2.0]),
3028
"yarray": np.array([100.0, 200.0]),
@@ -35,17 +33,13 @@
3533
( # Different names
3634
{
3735
"name": "something",
38-
"scat_quantity": "",
39-
"wavelength": 0.71,
4036
"xtype": "tth",
4137
"xarray": np.empty(0),
4238
"yarray": np.empty(0),
4339
"metadata": {"thing1": 1, "thing2": "thing2"},
4440
},
4541
{
4642
"name": "something else",
47-
"scat_quantity": "",
48-
"wavelength": 0.71,
4943
"xtype": "tth",
5044
"xarray": np.empty(0),
5145
"yarray": np.empty(0),
@@ -55,15 +49,13 @@
5549
),
5650
( # Different wavelengths
5751
{
58-
"scat_quantity": "",
5952
"wavelength": 0.71,
6053
"xtype": "tth",
6154
"xarray": np.empty(0),
6255
"yarray": np.empty(0),
6356
"metadata": {"thing1": 1, "thing2": "thing2"},
6457
},
6558
{
66-
"scat_quantity": "",
6759
"wavelength": 0.42,
6860
"xtype": "tth",
6961
"xarray": np.empty(0),
@@ -74,15 +66,13 @@
7466
),
7567
( # Different wavelengths
7668
{
77-
"scat_quantity": "",
7869
"wavelength": 0.71,
7970
"xtype": "tth",
8071
"xarray": np.empty(0),
8172
"yarray": np.empty(0),
8273
"metadata": {"thing1": 1, "thing2": "thing2"},
8374
},
8475
{
85-
"scat_quantity": "",
8676
"wavelength": 0.711,
8777
"xtype": "tth",
8878
"xarray": np.empty(0),
@@ -112,15 +102,12 @@
112102
),
113103
( # Different on_q
114104
{
115-
"scat_quantity": "",
116105
"xtype": "q",
117106
"wavelength": 0.71,
118107
"xarray": np.array([1.0, 2.0]),
119108
"yarray": np.array([100.0, 200.0]),
120-
"metadata": {},
121109
},
122110
{
123-
"scat_quantity": "",
124111
"xtype": "q",
125112
"wavelength": 0.71,
126113
"xarray": np.array([3.0, 4.0]),
@@ -131,15 +118,13 @@
131118
),
132119
( # Different metadata
133120
{
134-
"scat_quantity": "",
135121
"xtype": "q",
136122
"wavelength": 0.71,
137123
"xarray": np.empty(0),
138124
"yarray": np.empty(0),
139125
"metadata": {"thing1": 0, "thing2": "thing2"},
140126
},
141127
{
142-
"scat_quantity": "",
143128
"xtype": "q",
144129
"wavelength": 0.71,
145130
"xarray": np.empty(0),
@@ -166,7 +151,7 @@ def test_on_xtype():
166151
assert np.allclose(do.on_xtype("d"), [np.array([12.13818, 6.28319]), np.array([1, 2])])
167152

168153

169-
def test_init_invalid_xtype(do_minimal):
154+
def test_init_invalid_xtype():
170155
with pytest.raises(
171156
ValueError,
172157
match=re.escape(
@@ -387,7 +372,8 @@ def test_dump(tmp_path, mocker):
387372
assert actual == expected
388373

389374

390-
tc_params = [
375+
376+
@pytest.mark.parametrize("init_args, expected_do_dict", [
391377
( # instantiate just array attributes
392378
{
393379
"xarray": np.array([0.0, 90.0, 180.0]),
@@ -445,14 +431,27 @@ def test_dump(tmp_path, mocker):
445431
"wavelength": 4.0 * np.pi,
446432
},
447433
),
448-
]
434+
])
435+
def test_init_valid(init_args, expected_do_dict):
436+
actual_do_dict = DiffractionObject(**init_args).__dict__
437+
diff = DeepDiff(actual_do_dict, expected_do_dict, ignore_order=True, significant_digits=13, exclude_paths="root['_id']")
438+
assert diff == {}
449439

450440

451-
@pytest.mark.parametrize("inputs, expected", tc_params)
452-
def test_constructor(inputs, expected):
453-
actual = DiffractionObject(**inputs).__dict__
454-
diff = DeepDiff(actual, expected, ignore_order=True, significant_digits=13, exclude_paths="root['_id']")
455-
assert diff == {}
441+
442+
@pytest.mark.parametrize("init_args, error_message", [
443+
( # UC1: no arguments provided
444+
{},
445+
"missing 3 required positional arguments: 'xarray', 'yarray', and 'xtype'",
446+
),
447+
( # UC2: only xarray and yarray provided
448+
{"xarray": np.array([0.0, 90.0]), "yarray": np.array([0.0, 90.0])},
449+
"missing 1 required positional argument: 'xtype'",
450+
),
451+
])
452+
def test_init_invalid_args(init_args, error_message):
453+
with pytest.raises(TypeError, match=error_message):
454+
DiffractionObject(**init_args)
456455

457456

458457
def test_all_array_getter():
@@ -473,7 +472,7 @@ def test_all_array_getter():
473472

474473

475474
def test_all_array_setter(do_minimal):
476-
actual_do = do_minimal
475+
do = do_minimal
477476
# Attempt to directly modify the property
478477
with pytest.raises(
479478
AttributeError,

0 commit comments

Comments
 (0)