Skip to content

add private function for initating DO #81

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 3 commits into from
Jun 21, 2024
Merged
Changes from 1 commit
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
32 changes: 17 additions & 15 deletions src/diffpy/labpdfproc/tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,29 @@ def test_set_muls_at_angle(inputs, expected):
assert actual_muls_sorted == pytest.approx(expected_muls_sorted, rel=1e-4, abs=1e-6)


def test_compute_cve(mocker):
def _instantiate_test_do(mocker, yarray, name="test", scat_quantity="x-ray"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you pass everything in we don't gain much. Are there cases where you want to vary name="test", scat_quantity="x-ray" etc?

I would make yarray a required arg too to make the code more readable.

Also, is it necessary to pass in mocker? It may be, but if not I don't think it adds much syntatically.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I couldn't find prettier numbers for the yarrays.. they all seem a bit messy.
The name and scat_quantity are for the absorption correction DOs.
I can remove the mocker, it's not needed there.

mocker_xarray = np.array([90, 90.1, 90.2])
mocker.patch("diffpy.labpdfproc.functions.N_POINTS_ON_DIAMETER", 4)
mocker.patch("diffpy.labpdfproc.functions.TTH_GRID", np.array([45, 60, 90]))
input_pattern = Diffraction_object(wavelength=1.54)
input_pattern.insert_scattering_quantity(
np.array([45, 60, 90]),
np.array([2.2, 3, 4]),
mocker.patch("diffpy.labpdfproc.functions.TTH_GRID", mocker_xarray)
test_do = Diffraction_object(wavelength=1.54)
test_do.insert_scattering_quantity(
mocker_xarray,
yarray,
"tth",
scat_quantity="x-ray",
name="test",
scat_quantity=scat_quantity,
name=name,
metadata={"thing1": 1, "thing2": "thing2"},
)
return test_do


def test_compute_cve(mocker):
input_pattern = _instantiate_test_do(mocker, yarray=np.array([1, 1, 1]))
actual_abdo = compute_cve(input_pattern, mud=1, wavelength=1.54)
expected_abdo = Diffraction_object()
expected_abdo.insert_scattering_quantity(
np.array([45, 60, 90]),
np.array([2.54253, 2.52852, 2.49717]),
"tth",
metadata={"thing1": 1, "thing2": "thing2"},
expected_abdo = _instantiate_test_do(
mocker,
yarray=np.array([2.49717, 2.49706, 2.49695]),
name="absorption correction, cve, for test",
wavelength=1.54,
scat_quantity="cve",
)
assert actual_abdo == expected_abdo
Loading