Skip to content

Commit 3918433

Browse files
authored
Merge pull request #231 from bobleesj/refactor-test-on-xtype
Refactor `test-on-xtype` test function
2 parents 75e0ef8 + 8053d31 commit 3918433

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

Diff for: tests/conftest.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import json
22
from pathlib import Path
33

4+
import numpy as np
45
import pytest
56

7+
from diffpy.utils.diffraction_objects import DiffractionObject
8+
69

710
@pytest.fixture
811
def user_filesystem(tmp_path):
@@ -28,3 +31,8 @@ def _load(filename):
2831
return base_path / filename
2932

3033
return _load
34+
35+
36+
@pytest.fixture
37+
def do_minimal_tth():
38+
return DiffractionObject(wavelength=2 * np.pi, xarray=np.array([30, 60]), yarray=np.array([1, 2]), xtype="tth")

Diff for: tests/test_diffraction_objects.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,20 @@ def test_diffraction_objects_equality(inputs1, inputs2, expected):
163163
assert (do_1 == do_2) == expected
164164

165165

166-
def test_on_xtype():
167-
do = DiffractionObject(wavelength=2 * np.pi, xarray=np.array([30, 60]), yarray=np.array([1, 2]), xtype="tth")
168-
assert np.allclose(do.on_xtype("tth"), [np.array([30, 60]), np.array([1, 2])])
169-
assert np.allclose(do.on_xtype("2theta"), [np.array([30, 60]), np.array([1, 2])])
170-
assert np.allclose(do.on_xtype("q"), [np.array([0.51764, 1]), np.array([1, 2])])
171-
assert np.allclose(do.on_xtype("d"), [np.array([12.13818, 6.28319]), np.array([1, 2])])
166+
@pytest.mark.parametrize(
167+
"xtype, expected_xarray",
168+
[
169+
("tth", np.array([30, 60])),
170+
("2theta", np.array([30, 60])),
171+
("q", np.array([0.51764, 1])),
172+
("d", np.array([12.13818, 6.28319])),
173+
],
174+
)
175+
def test_on_xtype(xtype, expected_xarray, do_minimal_tth):
176+
do = do_minimal_tth
177+
actual_xrray, actual_yarray = do.on_xtype(xtype)
178+
assert np.allclose(actual_xrray, expected_xarray)
179+
assert np.allclose(actual_yarray, np.array([1, 2]))
172180

173181

174182
def test_init_invalid_xtype():

0 commit comments

Comments
 (0)