|
| 1 | +# Mantid Repository : https://github.com/mantidproject/mantid |
| 2 | +# |
| 3 | +# Copyright © 2025 ISIS Rutherford Appleton Laboratory UKRI, |
| 4 | +# NScD Oak Ridge National Laboratory, European Spallation Source, |
| 5 | +# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS |
| 6 | +# SPDX - License - Identifier: GPL - 3.0 + |
| 7 | + |
| 8 | +import unittest |
| 9 | +from unittest.mock import patch |
| 10 | + |
| 11 | +from SANS import SANSadd2 |
| 12 | +from SANS.sans.common.enums import SampleShape |
| 13 | +from mantid.simpleapi import Load |
| 14 | + |
| 15 | + |
| 16 | +class TestSANSAddSampleMetadata(unittest.TestCase): |
| 17 | + def test_raw_files_get_correct_sample_info(self): |
| 18 | + result = SANSadd2.add_runs(("LOQ54432", "LOQ54432"), "LOQ", ".raw") |
| 19 | + assert result.startswith("The following file has been created:") |
| 20 | + assert result.endswith("LOQ54432-add.nxs") |
| 21 | + |
| 22 | + # load the output file and verify it has the sample information |
| 23 | + ws = Load("LOQ54432-add.nxs") |
| 24 | + sample = ws.sample() |
| 25 | + self.assertEqual(3, sample.getGeometryFlag()) |
| 26 | + self.assertEqual(8.0, sample.getHeight()) |
| 27 | + self.assertEqual(8.0, sample.getWidth()) |
| 28 | + self.assertAlmostEqual(1.035, sample.getThickness()) |
| 29 | + |
| 30 | + def test_raw_files_collect_sample_info_using_alg(self): |
| 31 | + with patch("SANS.SANSadd2.LoadSampleDetailsFromRaw") as mocked_load_sample: |
| 32 | + SANSadd2.add_runs(("LOQ54432", "LOQ54432"), "LOQ", ".raw") |
| 33 | + self.assertEqual(2, mocked_load_sample.call_count) |
| 34 | + |
| 35 | + def test_isis_neuxs_files_get_correct_sample_info(self): |
| 36 | + result = SANSadd2.add_runs(["74014"], "LOQ", ".nxs", rawTypes=(".add", ".raw", ".s*"), lowMem=False) |
| 37 | + assert result.startswith("The following file has been created:") |
| 38 | + assert result.endswith("LOQ74014-add.nxs") |
| 39 | + |
| 40 | + # load the output file and verify it has the sample information |
| 41 | + ws = Load("LOQ74014-add.nxs") |
| 42 | + sample = ws.sample() |
| 43 | + self.assertEqual(3, sample.getGeometryFlag()) |
| 44 | + self.assertEqual(10.0, sample.getHeight()) |
| 45 | + self.assertEqual(10.0, sample.getWidth()) |
| 46 | + self.assertEqual(1.0, sample.getThickness()) |
| 47 | + |
| 48 | + def test_isis_nexus_get_sample_info_using_file_information(self): |
| 49 | + with patch("SANS.SANSadd2.get_geometry_information_isis_nexus") as mocked_get_geo_info: |
| 50 | + mocked_get_geo_info.return_value = (8.0, 8.0, 2.0, SampleShape.DISC) |
| 51 | + SANSadd2.add_runs(("74014", "74014"), "LOQ", ".nxs", rawTypes=(".add", ".raw", ".s*"), lowMem=False) |
| 52 | + self.assertEqual(1, mocked_get_geo_info.call_count) |
0 commit comments