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