1 | """ |
---|
2 | Unit tests for the sas_gen |
---|
3 | """ |
---|
4 | |
---|
5 | import os.path |
---|
6 | import warnings |
---|
7 | warnings.simplefilter("ignore") |
---|
8 | |
---|
9 | import unittest |
---|
10 | import numpy as np |
---|
11 | |
---|
12 | from sas.sascalc.calculator import sas_gen |
---|
13 | |
---|
14 | |
---|
15 | def find(filename): |
---|
16 | return os.path.join(os.path.dirname(__file__), filename) |
---|
17 | |
---|
18 | |
---|
19 | class 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("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 | |
---|
71 | if __name__ == '__main__': |
---|
72 | unittest.main() |
---|
73 | |
---|