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

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

Make suggested changes for unit test fixes.

  • Property mode set to 100644
File size: 3.3 KB
RevLine 
[2b310602]1"""
2    Unit tests for the SESANS .ses reader
3"""
4
5import unittest
[17e257b5]6from sas.sascalc.dataloader.loader_exceptions import FileContentsException,\
7    DefaultReaderException
[ade1080]8from sas.sascalc.dataloader.readers.sesans_reader import Reader
[a67c494]9from sas.sascalc.dataloader.loader import  Loader
[2b310602]10
11class sesans_reader(unittest.TestCase):
12
13    def setUp(self):
[ade1080]14        reader = Reader()
15        self.loader = reader.read
[2b310602]16
[a67c494]17    def test_full_load(self):
[2b310602]18        """
[a67c494]19            Test .SES in the full loader to make sure that the file type is correctly accepted
[2b310602]20        """
[17e257b5]21        file = Loader().load("sesans_examples/sphere2micron.ses")
22        f = file[0]
[2b310602]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"))
[bfd34a7]33        self.assertEqual(f.isSesans, True)
[2b310602]34
[ebed4de]35    def test_sesans_tof(self):
36        """
37            Test .SES loading on a TOF dataset
38        """
[17e257b5]39        file = self.loader("sesans_examples/sphere_isis.ses")
40        f = file[0]
[ebed4de]41        self.assertEqual(len(f.x), 57)
42        self.assertEqual(f.x[-1], 19303.4)
43        self.assertEqual(f.source.wavelength[-1], 13.893668)
[7e56311]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)
[ebed4de]48
[a79ab31]49    def test_sesans_no_data(self):
50        """
[10ab40e]51            Confirm that sesans files with no actual data won't load.
[a79ab31]52        """
[ade1080]53        self.assertRaises(
[17e257b5]54            FileContentsException,
[ade1080]55            self.loader,
56            "sesans_examples/sesans_no_data.ses")
[ebed4de]57
[5ae40e7]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(
[17e257b5]63            FileContentsException,
[5ae40e7]64            self.loader,
65            "sesans_examples/no_spin_echo_unit.ses")
66
[a81af92]67    def test_sesans_future_version(self):
68        """
69            Confirm that sesans files that, according to semantic version, are from a future, backwards-incompatible version of the SES file format throw an exception.
70        """
71        self.assertRaises(
[17e257b5]72            FileContentsException,
[a81af92]73            self.loader,
74            "sesans_examples/next_gen.ses")
[e801a4e]75
76    def test_sesans_mandatory_headers(self):
77        """
78            Confirm that sesans files throw an exception if one of the mandator headers is missing.
79        """
80        self.assertRaises(
[17e257b5]81            FileContentsException,
[e801a4e]82            self.loader,
83            "sesans_examples/no_wavelength.ses")
84
[35cf5c0]85    def test_sesans_columns_match_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,
[35cf5c0]91            self.loader,
92            "sesans_examples/too_many_headers.ses")
93
[2b310602]94if __name__ == "__main__":
95    unittest.main()
Note: See TracBrowser for help on using the repository browser.