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

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 a78a02f was a78a02f, checked in by krzywon, 3 years ago

Make suggested changes for unit test fixes.

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