Skip to content
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
1 change: 1 addition & 0 deletions packages/essnmx/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
# 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.

Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2026 Scipp contributors (https://github.com/scipp)
# These fixtures are only for mcstas related tests.
# They are mcstas descriptions to be parsed by essnmx mcstas helper functions.
# flake8: noqa: E501

no_detectors = """
import pytest


@pytest.fixture
def no_detectors_desc() -> str:
return """
SPLIT 999 COMPONENT Xtal = Single_crystal(
order = 1,
p_transmit=0.001,
Expand All @@ -23,7 +32,10 @@
AT (0, 0, deltaz) RELATIVE armSample
"""

two_detectors_two_filenames = """

@pytest.fixture
def two_detectors_two_filenames_desc() -> 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,
Expand All @@ -47,7 +59,10 @@
ROTATED (0, 90, 0) RELATIVE armSample
"""

one_detector_no_filename = """

@pytest.fixture
def one_detector_no_filename_desc() -> 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,
Expand All @@ -59,7 +74,10 @@
ROTATED (0, 90, 0) RELATIVE armSample
"""

two_detectors_same_filename = """

@pytest.fixture
def two_detectors_same_filename_desc() -> 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,
Expand Down
25 changes: 8 additions & 17 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,25 +124,25 @@ 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():
res = bank_names_to_detector_names(two_detectors_two_filenames)
def test_bank_names_to_detector_names_two_detectors(two_detectors_two_filenames_desc):
res = bank_names_to_detector_names(two_detectors_two_filenames_desc)
assert len(res) == 2
assert all(len(v) == 1 for v in res.values())


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


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


def test_bank_names_to_detector_names_no_filename():
res = bank_names_to_detector_names(one_detector_no_filename)
def test_bank_names_to_detector_names_no_filename(one_detector_no_filename_desc):
res = bank_names_to_detector_names(one_detector_no_filename_desc)
assert len(res) == 1
((bank, (detector,)),) = res.items()
assert bank == detector
Loading