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

magnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249unittest-saveload
Last change on this file since f4e2f22 was f4e2f22, checked in by krzywon, 8 months ago

Change unit tests from assertTrue( == ) to assertEqual and change file path separators to os.sep for platform independence.

  • Property mode set to 100644
File size: 3.6 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" + os.sep +
28                                  "sphere2micron.ses"))
29        f = file[0]
30        # self.assertEqual(f, 5)
31        self.assertEqual(len(file), 1)
32        self.assertEqual(len(f.x), 40)
33        self.assertEqual(f.x[0], 391.56)
34        self.assertEqual(f.x[-1], 46099)
35        self.assertEqual(f.y[-1], -0.19956)
36        self.assertEqual(f.x_unit, "A")
37        self.assertEqual(f.y_unit, "A-2 cm-1")
38        self.assertEqual(f.sample.name, "Polystyrene 2 um in 53% H2O, 47% D2O")
39        self.assertEqual(f.sample.thickness, 0.2)
40        self.assertEqual(f.sample.zacceptance, (0.0168, "radians"))
41        self.assertEqual(f.isSesans, True)
42
43    def test_sesans_tof(self):
44        """
45            Test .SES loading on a TOF dataset
46        """
47        file = self.loader(find("sesans_examples" + os.sep + "sphere_isis.ses"))
48        f = file[0]
49        self.assertEqual(len(file), 1)
50        self.assertEqual(len(f.x), 57)
51        self.assertEqual(f.x[-1], 19303.4)
52        self.assertEqual(f.source.wavelength[-1], 13.893668)
53        self.assertEqual(f.source.wavelength[0], 1.612452)
54        self.assertEqual(f.sample.yacceptance, (0.09, "radians"))
55        self.assertEqual(f.sample.zacceptance, (0.09, "radians"))
56        self.assertEqual(f.sample.thickness, 0.2)
57
58    def test_sesans_no_data(self):
59        """
60            Confirm that sesans files with no actual data won't load.
61        """
62        self.assertRaises(
63            FileContentsException,
64            self.loader,
65            find("sesans_examples" + os.sep + "sesans_no_data.ses"))
66
67    def test_sesans_no_spin_echo_unit(self):
68        """
69            Confirm that sesans files with no units from the spin echo length raise an appropriate error
70        """
71        self.assertRaises(
72            FileContentsException,
73            self.loader,
74            find("sesans_examples" + os.sep + "no_spin_echo_unit.ses"))
75
76    def test_sesans_future_version(self):
77        """
78            Confirm that sesans files that, according to semantic version, are from a future, backwards-incompatible version of the SES file format throw an exception.
79        """
80        self.assertRaises(
81            FileContentsException,
82            self.loader,
83            find("sesans_examples" + os.sep + "next_gen.ses"))
84
85    def test_sesans_mandatory_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            find("sesans_examples" + os.sep + "no_wavelength.ses"))
93
94    def test_sesans_columns_match_headers(self):
95        """
96            Confirm that sesans files throw an exception if one of the mandator headers is missing.
97        """
98        self.assertRaises(
99            FileContentsException,
100            self.loader,
101            find("sesans_examples" + os.sep + "too_many_headers.ses"))
102
103if __name__ == "__main__":
104    unittest.main()
Note: See TracBrowser for help on using the repository browser.