-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathintegration_test.py
130 lines (99 loc) · 4.05 KB
/
integration_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import unittest
import h5py
import numpy as np
from diffpy.fourigui.fourigui import Gui
class TestGui(unittest.TestCase):
def setUp(self):
# set up gui
self.test_gui = Gui()
# set up test data
self.test_sofq = h5py.File("tests/testdata/sofq.h5")["data"]
self.test_sofq_cut_10to40px = h5py.File("tests/testdata/sofq_cut_10to40px.h5")["data"]
self.test_sofq_cut_15to35px = h5py.File("tests/testdata/sofq_cut_15to35px.h5")["data"]
self.test_gofr = h5py.File("tests/testdata/gofr.h5")["data"]
self.test_gofr_cut_10to40px = h5py.File("tests/testdata/gofr_from_sofq_cut_10to40px.h5")["data"]
self.test_gofr_cut_15to35px = h5py.File("tests/testdata/gofr_from_sofq_cut_15to35px.h5")["data"]
def test_load_cube_testdataset1(self):
# given
self.test_gui.filename_entry.delete(0, "end")
self.test_gui.filename_entry.insert(0, "tests/testdata/sofq.h5")
# when
self.test_gui.load_cube()
result = self.test_gui.cube
# then
self.assertTrue(np.allclose(result, self.test_sofq))
def test_load_cube_testdataset2(self):
# given
self.test_gui.filename_entry.delete(0, "end")
self.test_gui.filename_entry.insert(0, "tests/testdata/sofq_cut_10to40px.h5")
# when
self.test_gui.load_cube()
result = self.test_gui.cube
# then
self.assertTrue(np.allclose(np.nan_to_num(result), np.nan_to_num(self.test_sofq_cut_10to40px)))
def test_load_cube_testdataset3(self):
# given
self.test_gui.filename_entry.delete(0, "end")
self.test_gui.filename_entry.insert(0, "tests/testdata/sofq_cut_15to35px.h5")
# when
self.test_gui.load_cube()
result = self.test_gui.cube
# then
self.assertTrue(np.allclose(np.nan_to_num(result), np.nan_to_num(self.test_sofq_cut_15to35px)))
def test_fft_testdataset1(self):
# given
self.test_gui.plot_plane = (
lambda *a, **b: ()
) # overwrite plot_plane which requires not initialized attribute im
self.test_gui.cube = self.test_sofq
# when
self.test_gui.fft()
result = self.test_gui.cube
# then
self.assertTrue(np.allclose(result, self.test_gofr))
def test_fft_testdataset2(self):
# given
self.test_gui.plot_plane = (
lambda *a, **b: ()
) # overwrite plot_plane which requires not initialized attribute im
self.test_gui.cube = self.test_sofq_cut_10to40px
# when
self.test_gui.fft()
result = self.test_gui.cube
# then
self.assertTrue(np.allclose(result, self.test_gofr_cut_10to40px))
def test_fft_testdataset3(self):
# given
self.test_gui.plot_plane = (
lambda *a, **b: ()
) # overwrite plot_plane which requires not initialized attribute im
self.test_gui.cube = self.test_sofq_cut_15to35px
# when
self.test_gui.fft()
result = self.test_gui.cube
# then
self.assertTrue(np.allclose(result, self.test_gofr_cut_15to35px))
def test_applycutoff_range1(self):
# given
self.test_gui.plot_plane = lambda *a, **b: ()
self.test_gui.cube = self.test_sofq
self.test_gui.qminentry.insert(0, "10")
self.test_gui.qmaxentry.insert(0, "40")
# when
self.test_gui.applycutoff()
result = self.test_gui.cube
# then
self.assertTrue(np.allclose(np.nan_to_num(result), np.nan_to_num(self.test_sofq_cut_10to40px)))
def test_applycutoff_range2(self):
# given
self.test_gui.plot_plane = lambda *a, **b: ()
self.test_gui.cube = self.test_sofq
self.test_gui.qminentry.insert(0, "15")
self.test_gui.qmaxentry.insert(0, "35")
# when
self.test_gui.applycutoff()
result = self.test_gui.cube
# then
self.assertTrue(np.allclose(np.nan_to_num(result), np.nan_to_num(self.test_sofq_cut_15to35px)))
if __name__ == "__main__":
unittest.main()