diff --git a/packages/essnmx/tests/conftest.py b/packages/essnmx/tests/conftest.py index 8710000b..521ff6fd 100644 --- a/packages/essnmx/tests/conftest.py +++ b/packages/essnmx/tests/conftest.py @@ -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 +""" diff --git a/packages/essnmx/tests/mcstas/loader_test.py b/packages/essnmx/tests/mcstas/loader_test.py index c9d090d3..1f526241 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,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() diff --git a/packages/essnmx/tests/mcstas/mcstas_description_examples.py b/packages/essnmx/tests/mcstas/mcstas_description_examples.py deleted file mode 100644 index 40315ead..00000000 --- a/packages/essnmx/tests/mcstas/mcstas_description_examples.py +++ /dev/null @@ -1,84 +0,0 @@ -# flake8: noqa: E501 - -no_detectors = """ -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 -""" - -two_detectors_two_filenames = """ -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 -""" - -one_detector_no_filename = """ -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 -""" - -two_detectors_same_filename = """ -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 -"""