1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 from os import sep
25 from tempfile import mktemp
26
27
28 from data import Relax_data_store; ds = Relax_data_store()
29 from generic_fns import pipes
30 from generic_fns.reset import reset
31 from status import Status; status = Status()
32 from test_suite.unit_tests.base_classes import UnitTestCase
33
34
36 """Base class for the tests of both the 'prompt.state' and 'generic_fns.state' modules.
37
38 This base class also contains shared unit tests.
39 """
40
42 """The unpickling and restoration of the relax data storage singleton.
43
44 This tests the normal operation of the generic_fns.state.load() function.
45 """
46
47
48 self.assertEqual(list(ds.keys()), [])
49 self.assertEqual(pipes.cdp_name(), None)
50 self.assert_(not hasattr(ds, 'y'))
51
52
53 self.state.load_state(state='basic_single_pipe', dir=status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'saved_states')
54
55
56 dp = pipes.get_pipe('orig')
57
58
59 self.assertEqual(list(ds.keys()), ['orig'])
60 self.assertEqual(pipes.cdp_name(), 'orig')
61 self.assertEqual(dp.x, 1)
62 self.assertEqual(ds.y, 'Hello')
63
64
66 """The modification of an unpickled and restored relax data storage singleton.
67
68 This tests the normal operation of the generic_fns.state.load() function.
69 """
70
71
72 self.assertEqual(list(ds.keys()), [])
73 self.assertEqual(pipes.cdp_name(), None)
74 self.assert_(not hasattr(ds, 'y'))
75
76
77 self.state.load_state(state='basic_single_pipe', dir=status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'saved_states')
78
79
80 ds.add('new', 'jw_mapping')
81 cdp.z = [None, None]
82
83
84 dp_orig = pipes.get_pipe('orig')
85 dp_new = pipes.get_pipe('new')
86
87
88 self.assertEqual(list(ds.keys()).sort(), ['orig', 'new'].sort())
89 self.assertEqual(pipes.cdp_name(), 'new')
90 self.assertEqual(dp_orig.x, 1)
91 self.assertEqual(ds.y, 'Hello')
92 self.assertEqual(dp_new.z, [None, None])
93
94
96 """The resetting of an unpickled and restored relax data storage singleton.
97
98 This tests the normal operation of the generic_fns.state.load() function.
99 """
100
101
102 self.assertEqual(list(ds.keys()), [])
103 self.assertEqual(pipes.cdp_name(), None)
104 self.assert_(not hasattr(ds, 'y'))
105
106
107 self.state.load_state(state='basic_single_pipe', dir=status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'saved_states')
108
109
110 reset()
111
112
113 self.assertEqual(list(ds.keys()), [])
114 self.assertEqual(pipes.cdp_name(), None)
115 self.assert_(not hasattr(ds, 'y'))
116
117
119 """The pickling and saving of the relax data storage singleton.
120
121 This tests the normal operation of the generic_fns.state.save() function.
122 """
123
124
125 ds.tmpfile = mktemp()
126
127
128 ds.add(pipe_name='orig', pipe_type='mf')
129
130
131 dp = pipes.get_pipe('orig')
132
133
134 dp.x = 1
135
136
137 ds.y = 'Hello'
138
139
140 self.state.save_state(state=ds.tmpfile)
141