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, 6 years 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
RevLine 
[2b310602]1"""
2    Unit tests for the SESANS .ses reader
3"""
4
[f53d684]5import os.path
[2b310602]6import unittest
[17e257b5]7from sas.sascalc.dataloader.loader_exceptions import FileContentsException,\
8    DefaultReaderException
[ade1080]9from sas.sascalc.dataloader.readers.sesans_reader import Reader
[a67c494]10from sas.sascalc.dataloader.loader import  Loader
[2b310602]11
[f53d684]12
13def find(filename):
14    return os.path.join(os.path.dirname(__file__), filename)
15
16
[2b310602]17class sesans_reader(unittest.TestCase):
18
19    def setUp(self):
[ade1080]20        reader = Reader()
21        self.loader = reader.read
[2b310602]22
[a67c494]23    def test_full_load(self):
[2b310602]24        """
[a67c494]25            Test .SES in the full loader to make sure that the file type is correctly accepted
[2b310602]26        """
[f4e2f22]27        file = Loader().load(find("sesans_examples" + os.sep +
28                                  "sphere2micron.ses"))
[17e257b5]29        f = file[0]
[2b310602]30        # self.assertEqual(f, 5)
[fe15198]31        self.assertEqual(len(file), 1)
[2b310602]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"))
[bfd34a7]41        self.assertEqual(f.isSesans, True)
[2b310602]42
[ebed4de]43    def test_sesans_tof(self):
44        """
45            Test .SES loading on a TOF dataset
46        """
[f4e2f22]47        file = self.loader(find("sesans_examples" + os.sep + "sphere_isis.ses"))
[17e257b5]48        f = file[0]
[fe15198]49        self.assertEqual(len(file), 1)
[ebed4de]50        self.assertEqual(len(f.x), 57)
51        self.assertEqual(f.x[-1], 19303.4)
52        self.assertEqual(f.source.wavelength[-1], 13.893668)
[7e56311]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)
[ebed4de]57
[a79ab31]58    def test_sesans_no_data(self):
59        """
[10ab40e]60            Confirm that sesans files with no actual data won't load.
[a79ab31]61        """
[ade1080]62        self.assertRaises(
[17e257b5]63            FileContentsException,
[ade1080]64            self.loader,
[f4e2f22]65            find("sesans_examples" + os.sep + "sesans_no_data.ses"))
[ebed4de]66
[5ae40e7]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(
[17e257b5]72            FileContentsException,
[5ae40e7]73            self.loader,
[f4e2f22]74            find("sesans_examples" + os.sep + "no_spin_echo_unit.ses"))
[5ae40e7]75
[a81af92]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(
[17e257b5]81            FileContentsException,
[a81af92]82            self.loader,
[f4e2f22]83            find("sesans_examples" + os.sep + "next_gen.ses"))
[e801a4e]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(
[17e257b5]90            FileContentsException,
[e801a4e]91            self.loader,
[f4e2f22]92            find("sesans_examples" + os.sep + "no_wavelength.ses"))
[e801a4e]93
[35cf5c0]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(
[17e257b5]99            FileContentsException,
[35cf5c0]100            self.loader,
[f4e2f22]101            find("sesans_examples" + os.sep + "too_many_headers.ses"))
[35cf5c0]102
[2b310602]103if __name__ == "__main__":
104    unittest.main()
Note: See TracBrowser for help on using the repository browser.