Skip to content

Refactor test-on-xtype test function #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import json
from pathlib import Path

import numpy as np
import pytest

from diffpy.utils.diffraction_objects import DiffractionObject


@pytest.fixture
def user_filesystem(tmp_path):
Expand All @@ -28,3 +31,8 @@ def _load(filename):
return base_path / filename

return _load


@pytest.fixture
def do_minimal_tth():
return DiffractionObject(wavelength=2 * np.pi, xarray=np.array([30, 60]), yarray=np.array([1, 2]), xtype="tth")
20 changes: 14 additions & 6 deletions tests/test_diffraction_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,20 @@ def test_diffraction_objects_equality(inputs1, inputs2, expected):
assert (do_1 == do_2) == expected


def test_on_xtype():
do = DiffractionObject(wavelength=2 * np.pi, xarray=np.array([30, 60]), yarray=np.array([1, 2]), xtype="tth")
assert np.allclose(do.on_xtype("tth"), [np.array([30, 60]), np.array([1, 2])])
assert np.allclose(do.on_xtype("2theta"), [np.array([30, 60]), np.array([1, 2])])
assert np.allclose(do.on_xtype("q"), [np.array([0.51764, 1]), np.array([1, 2])])
assert np.allclose(do.on_xtype("d"), [np.array([12.13818, 6.28319]), np.array([1, 2])])
@pytest.mark.parametrize(
"xtype, expected_xarray",
[
("tth", np.array([30, 60])),
("2theta", np.array([30, 60])),
("q", np.array([0.51764, 1])),
("d", np.array([12.13818, 6.28319])),
],
)
def test_on_xtype(xtype, expected_xarray, do_minimal_tth):
do = do_minimal_tth
actual_xrray, actual_yarray = do.on_xtype(xtype)
assert np.allclose(actual_xrray, expected_xarray)
assert np.allclose(actual_yarray, np.array([1, 2]))


def test_init_invalid_xtype():
Expand Down
Loading