diff --git a/packages/essnmx/tests/conftest.py b/packages/essnmx/tests/conftest.py index 8710000b..b968fce6 100644 --- a/packages/essnmx/tests/conftest.py +++ b/packages/essnmx/tests/conftest.py @@ -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. + diff --git a/packages/essnmx/tests/mcstas/mcstas_description_examples.py b/packages/essnmx/tests/mcstas/conftest.py similarity index 82% rename from packages/essnmx/tests/mcstas/mcstas_description_examples.py rename to packages/essnmx/tests/mcstas/conftest.py index 40315ead..1cac3ffc 100644 --- a/packages/essnmx/tests/mcstas/mcstas_description_examples.py +++ b/packages/essnmx/tests/mcstas/conftest.py @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/packages/essnmx/tests/mcstas/loader_test.py b/packages/essnmx/tests/mcstas/loader_test.py index c9d090d3..803c09eb 100644 --- a/packages/essnmx/tests/mcstas/loader_test.py +++ b/packages/essnmx/tests/mcstas/loader_test.py @@ -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 @@ -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 @@ -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