1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 from os import sep
24 from tempfile import mkstemp
25
26
27 from data_store import Relax_data_store; ds = Relax_data_store()
28 from pipe_control import pipes
29 from pipe_control.reset import reset
30 from status import Status; status = Status()
31 from test_suite.unit_tests.base_classes import UnitTestCase
32
33
35 """Base class for the tests of both the 'prompt.state' and 'pipe_control.state' modules.
36
37 This base class also contains shared unit tests.
38 """
39
41 """The unpickling and restoration of the relax data storage singleton.
42
43 This tests the normal operation of the pipe_control.state.load() function.
44 """
45
46
47 self.assertEqual(list(ds.keys()), [])
48 self.assertEqual(pipes.cdp_name(), None)
49 self.assertTrue(not hasattr(ds, 'y'))
50
51
52 self.state.load_state(state='basic_single_pipe', dir=status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'saved_states')
53
54
55 dp = pipes.get_pipe('orig')
56
57
58 self.assertEqual(list(ds.keys()), ['orig'])
59 self.assertEqual(pipes.cdp_name(), 'orig')
60 self.assertEqual(dp.x, 1)
61 self.assertEqual(ds.y, 'Hello')
62
63
65 """The modification of an unpickled and restored relax data storage singleton.
66
67 This tests the normal operation of the pipe_control.state.load() function.
68 """
69
70
71 self.assertEqual(list(ds.keys()), [])
72 self.assertEqual(pipes.cdp_name(), None)
73 self.assertTrue(not hasattr(ds, 'y'))
74
75
76 self.state.load_state(state='basic_single_pipe', dir=status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'saved_states')
77
78
79 ds.add('new', 'jw_mapping')
80 cdp.z = [None, None]
81
82
83 dp_orig = pipes.get_pipe('orig')
84 dp_new = pipes.get_pipe('new')
85
86
87 self.assertTrue('orig' in ds)
88 self.assertTrue('new' in ds)
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 pipe_control.state.load() function.
99 """
100
101
102 self.assertEqual(list(ds.keys()), [])
103 self.assertEqual(pipes.cdp_name(), None)
104 self.assertTrue(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.assertTrue(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 pipe_control.state.save() function.
122 """
123
124
125 ds.tmpfile_handle, ds.tmpfile = mkstemp(suffix='.bz2')
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, force=True)
141