source: sasview/test/sascalculator/test/utest_sas_gen.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@…>, 14 months ago

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

  • Property mode set to 100644
File size: 1.8 KB
Line 
1"""
2Unit tests for the sas_gen
3"""
4
5import os.path
6import warnings
7warnings.simplefilter("ignore")
8
9import unittest
10import numpy as np
11
12from sas.sascalc.calculator import sas_gen
13
14
15def find(filename):
16    return os.path.join(os.path.dirname(__file__), filename)
17
18
19class sas_gen_test(unittest.TestCase):
20
21    def setUp(self):
22        self.sldloader = sas_gen.SLDReader()
23        self.pdbloader = sas_gen.PDBReader()
24        self.omfloader = sas_gen.OMFReader()
25
26    def test_sldreader(self):
27        """
28        Test .sld file loaded
29        """
30        f = self.sldloader.read(find("sld_file.sld"))
31        self.assertEqual(f.pos_x[0], -40.5)
32        self.assertEqual(f.pos_y[0], -13.5)
33        self.assertEqual(f.pos_z[0], -13.5)
34
35    def test_pdbreader(self):
36        """
37        Test .pdb file loaded
38        """
39        f = self.pdbloader.read(find("c60.pdb"))
40        self.assertEqual(f.pos_x[0], -0.733)
41        self.assertEqual(f.pos_y[0], -1.008)
42        self.assertEqual(f.pos_z[0], 3.326)
43
44    def test_omfreader(self):
45        """
46        Test .omf file loaded
47        """
48        f = self.omfloader.read(find("A_Raw_Example-1.omf"))
49        output = sas_gen.OMF2SLD()
50        output.set_data(f)
51        self.assertEqual(f.mx[0], 0)
52        self.assertEqual(f.my[0], 0)
53        self.assertEqual(f.mz[0], 0)
54        self.assertEqual(output.pos_x[0], 0.0)
55        self.assertEqual(output.pos_y[0], 0.0)
56        self.assertEqual(output.pos_z[0], 0.0)
57
58    def test_calculator(self):
59        """
60        Test that the calculator calculates.
61        """
62        f = self.omfloader.read(find("A_Raw_Example-1.omf"))
63        omf2sld = sas_gen.OMF2SLD()
64        omf2sld.set_data(f)
65        model = sas_gen.GenSAS()
66        model.set_sld_data(omf2sld.output)
67        x = np.linspace(0, 0.1, 11)[1:]
68        model.runXY([x, x])
69
70
71if __name__ == '__main__':
72    unittest.main()
73
Note: See TracBrowser for help on using the repository browser.