source: sasview/test/sasdataloader/test/utest_sesans.py @ a67c494

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since a67c494 was a67c494, checked in by Adam Washington <adam.washington@…>, 3 years ago

Include SESANS unit test that users the full loader infrastructure

We need to be sure that SESANS files load with the correct reader

  • Property mode set to 100644
File size: 3.4 KB
Line 
1"""
2    Unit tests for the SESANS .ses reader
3"""
4
5import unittest
6from sas.sascalc.dataloader.readers.sesans_reader import Reader
7from sas.sascalc.dataloader.loader import  Loader
8
9class sesans_reader(unittest.TestCase):
10
11    def setUp(self):
12        reader = Reader()
13        self.loader = reader.read
14
15    def test_full_load(self):
16        """
17            Test .SES in the full loader to make sure that the file type is correctly accepted
18        """
19        f = Loader().load("sesans_examples/sphere2micron.ses")
20        # self.assertEqual(f, 5)
21        self.assertEqual(len(f.x), 40)
22        self.assertEqual(f.x[0], 391.56)
23        self.assertEqual(f.x[-1], 46099)
24        self.assertEqual(f.y[-1], -0.19956)
25        self.assertEqual(f.x_unit, "A")
26        self.assertEqual(f.y_unit, "A-2 cm-1")
27        self.assertEqual(f.sample.name, "Polystyrene 2 um in 53% H2O, 47% D2O")
28        self.assertEqual(f.sample.thickness, 0.2)
29        self.assertEqual(f.sample.zacceptance, (0.0168, "radians"))
30        self.assertEqual(f.isSesans, True)
31
32    def test_sesans_tof(self):
33        """
34            Test .SES loading on a TOF dataset
35        """
36        f = self.loader("sesans_examples/sphere_isis.ses")
37        self.assertEqual(len(f.x), 57)
38        self.assertEqual(f.x[-1], 19303.4)
39        self.assertEqual(f.source.wavelength[-1], 13.893668)
40        self.assertEqual(f.source.wavelength[0], 1.612452)
41        self.assertEqual(f.sample.yacceptance, (0.09, "radians"))
42        self.assertEqual(f.sample.zacceptance, (0.09, "radians"))
43        self.assertEqual(f.sample.thickness, 0.2)
44
45    def test_sesans_no_data(self):
46        """
47            Confirm that sesans files with no actual data won't load.
48        """
49        self.assertRaises(
50            RuntimeError,
51            self.loader,
52            "sesans_examples/sesans_no_data.ses")
53
54    def test_sesans_no_spin_echo_unit(self):
55        """
56            Confirm that sesans files with no units from the spin echo length raise an appropriate error
57        """
58        self.assertRaises(
59            RuntimeError,
60            self.loader,
61            "sesans_examples/no_spin_echo_unit.ses")
62
63    def test_sesans_no_version(self):
64        """
65            Confirm that sesans files with no file format version raise an appropriate error
66        """
67        self.assertRaises(
68            RuntimeError,
69            self.loader,
70            "sesans_examples/no_version.ses")
71
72    def test_sesans_future_version(self):
73        """
74            Confirm that sesans files that, according to semantic version, are from a future, backwards-incompatible version of the SES file format throw an exception.
75        """
76        self.assertRaises(
77            RuntimeError,
78            self.loader,
79            "sesans_examples/next_gen.ses")
80
81    def test_sesans_mandatory_headers(self):
82        """
83            Confirm that sesans files throw an exception if one of the mandator headers is missing.
84        """
85        self.assertRaises(
86            RuntimeError,
87            self.loader,
88            "sesans_examples/no_wavelength.ses")
89
90    def test_sesans_columns_match_headers(self):
91        """
92            Confirm that sesans files throw an exception if one of the mandator headers is missing.
93        """
94        self.assertRaises(
95            RuntimeError,
96            self.loader,
97            "sesans_examples/too_many_headers.ses")
98
99if __name__ == "__main__":
100    unittest.main()
Note: See TracBrowser for help on using the repository browser.