Skip to content
Closed
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
98 changes: 98 additions & 0 deletions packages/essnmx/tests/conftest.py
Copy link
Member

Choose a reason for hiding this comment

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

Can you use more explicit fixture names? no_detectors doesn't say anything about what type of data it contains. And you can use a conftest.py in the mcstas subfolder to give the fixtures a more narrow scope.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point...

Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,101 @@
# Copyright (c) 2024 Scipp contributors (https://github.com/scipp)
# These fixtures cannot be found by pytest,
# if they are not defined in `conftest.py` under `tests` directory.
# flake8: noqa: E501

import pytest


@pytest.fixture
def no_detectors() -> str:
return """
SPLIT 999 COMPONENT Xtal = Single_crystal(
order = 1,
p_transmit=0.001,
reflections = "Rubredoxin.lau",
xwidth = XtalSize_width,
yheight = XtalSize_height,
zdepth = XtalSize_depth,
mosaic = XtalMosaicity,
delta_d_d=1e-4)
AT (0, 0, deltaz) RELATIVE PREVIOUS
ROTATED (XtalPhiX,XtalPhiY, XtalPhiZ) RELATIVE armSample
EXTEND %{
if (!SCATTERED) {ABSORB;}
%}

COMPONENT Sphere = PSD_monitor_4PI(
nx = 360, ny = 360, filename = "4pi", radius = 0.2,
restore_neutron = 1)

AT (0, 0, deltaz) RELATIVE armSample
"""


@pytest.fixture
def two_detectors_two_filenames() -> str:
return """
COMPONENT nD_Mantid_0 = Monitor_nD(
options ="mantid square x limits=[0 0.512] bins=1280 y limits=[0 0.512] bins=1280, neutron pixel min=1 t, list all neutrons",
xmin = 0,
xmax = 0.512,
ymin = 0,
ymax = 0.512,
restore_neutron = 1,
filename = "bank01_events.dat")
AT (-0.25, -0.25, 0.29) RELATIVE armSample
ROTATED (0, 0, 0) RELATIVE armSample

COMPONENT nD_Mantid_1 = Monitor_nD(
options ="mantid square x limits=[0 0.512] bins=1280 y limits=[0 0.512] bins=1280, neutron pixel min=2000000 t, list all neutrons",
xmin = 0,
xmax = 0.512,
ymin = 0,
ymax = 0.512,
restore_neutron = 1,
filename = "bank02_events.dat")
AT (-0.29, -0.25, 0.25) RELATIVE armSample
ROTATED (0, 90, 0) RELATIVE armSample
"""


@pytest.fixture
def one_detector_no_filename() -> str:
return """
COMPONENT nD_Mantid_2 = Monitor_nD(
options ="mantid square x limits=[0 0.512] bins=1280 y limits=[0 0.512] bins=1280, neutron pixel min=2000000 t, list all neutrons",
xmin = 0,
xmax = 0.512,
ymin = 0,
ymax = 0.512,
restore_neutron = 1,
AT (-0.29, -0.25, 0.25) RELATIVE armSample
ROTATED (0, 90, 0) RELATIVE armSample
"""


@pytest.fixture
def two_detectors_same_filename() -> str:
return """
COMPONENT nD_Mantid_0 = Monitor_nD(
options ="mantid square x limits=[0 0.512] bins=1280 y limits=[0 0.512] bins=1280, neutron pixel min=1 t, list all neutrons",
xmin = 0,
xmax = 0.512,
ymin = 0,
ymax = 0.512,
restore_neutron = 1,
filename = "bank01_events.dat")
AT (-0.25, -0.25, 0.29) RELATIVE armSample
ROTATED (0, 0, 0) RELATIVE armSample

COMPONENT nD_Mantid_1 = Monitor_nD(
options ="mantid square x limits=[0 0.512] bins=1280 y limits=[0 0.512] bins=1280, neutron pixel min=2000000 t, list all neutrons",
xmin = 0,
xmax = 0.512,
ymin = 0,
ymax = 0.512,
restore_neutron = 1,
filename = "bank01_events.dat")
AT (-0.29, -0.25, 0.25) RELATIVE armSample
ROTATED (0, 90, 0) RELATIVE armSample
"""
17 changes: 4 additions & 13 deletions packages/essnmx/tests/mcstas/loader_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2024 Scipp contributors (https://github.com/scipp)
import pathlib
import sys
from collections.abc import Generator

import pytest
Expand All @@ -19,14 +18,6 @@
NMXRawEventCountsDataGroup,
)

sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
from mcstas_description_examples import (
no_detectors,
one_detector_no_filename,
two_detectors_same_filename,
two_detectors_two_filenames,
)


def check_nmxdata_properties(
dg: NMXRawEventCountsDataGroup, fast_axis, slow_axis
Expand Down Expand Up @@ -133,24 +124,24 @@ def test_missing_rotation(rotation_mission_tmp_file: FilePath) -> None:
# McStasInstrument is not used due to error in the file.


def test_bank_names_to_detector_names_two_detectors():
def test_bank_names_to_detector_names_two_detectors(two_detectors_two_filenames):
res = bank_names_to_detector_names(two_detectors_two_filenames)
assert len(res) == 2
assert all(len(v) == 1 for v in res.values())


def test_bank_names_to_detector_names_same_filename():
def test_bank_names_to_detector_names_same_filename(two_detectors_same_filename):
res = bank_names_to_detector_names(two_detectors_same_filename)
assert len(res) == 1
assert all(len(v) == 2 for v in res.values())


def test_bank_names_to_detector_names_no_detectors():
def test_bank_names_to_detector_names_no_detectors(no_detectors):
res = bank_names_to_detector_names(no_detectors)
assert len(res) == 0


def test_bank_names_to_detector_names_no_filename():
def test_bank_names_to_detector_names_no_filename(one_detector_no_filename):
res = bank_names_to_detector_names(one_detector_no_filename)
assert len(res) == 1
((bank, (detector,)),) = res.items()
Expand Down
84 changes: 0 additions & 84 deletions packages/essnmx/tests/mcstas/mcstas_description_examples.py

This file was deleted.

Loading