source: sasview/test/sasdataloader/test/utest_sesans.py @ 3a473ef

ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since 3a473ef was 3a473ef, checked in by Piotr Rozyczko <rozyczko@…>, 6 years ago

Manual update of test/ directory with changes on master - SASVIEW-996

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