source: sasview/test/sasdataloader/test/utest_sesans.py @ 17e257b5

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

Fix the broken unit tests associated with the readers.

  • Property mode set to 100644
File size: 3.5 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_no_version(self):
68        """
69            Confirm that sesans files with no file format version raise an appropriate error
70        """
71        # Warning message sent to logger for files not found.
72        pass
73
74    def test_sesans_future_version(self):
75        """
76            Confirm that sesans files that, according to semantic version, are from a future, backwards-incompatible version of the SES file format throw an exception.
77        """
78        self.assertRaises(
79            FileContentsException,
80            self.loader,
81            "sesans_examples/next_gen.ses")
82
83    def test_sesans_mandatory_headers(self):
84        """
85            Confirm that sesans files throw an exception if one of the mandator headers is missing.
86        """
87        self.assertRaises(
88            FileContentsException,
89            self.loader,
90            "sesans_examples/no_wavelength.ses")
91
92    def test_sesans_columns_match_headers(self):
93        """
94            Confirm that sesans files throw an exception if one of the mandator headers is missing.
95        """
96        self.assertRaises(
97            FileContentsException,
98            self.loader,
99            "sesans_examples/too_many_headers.ses")
100
101if __name__ == "__main__":
102    unittest.main()
Note: See TracBrowser for help on using the repository browser.