Added command stack saving and loading.
[hooke.git] / test / command_stack.py
1 # Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
2 #
3 # This file is part of Hooke.
4 #
5 # Hooke is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License as
7 # published by the Free Software Foundation, either version 3 of the
8 # License, or (at your option) any later version.
9 #
10 # Hooke is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
13 # Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with Hooke.  If not, see
17 # <http://www.gnu.org/licenses/>.
18
19 """
20 >>> from hooke.hooke import Hooke, HookeRunner
21 >>> h = Hooke()
22 >>> r = HookeRunner()
23
24 The command stack starts off empty.
25
26 >>> h = r.run_lines(h, ['get_command_stack'])
27 []
28 Success
29 <BLANKLINE>
30
31 And inactive, so you can't stop it.
32
33 >>> h = r.run_lines(h, ['get_command_capture_state'])
34 inactive
35 Success
36 <BLANKLINE>
37 >>> h = r.run_lines(h, ['stop_command_capture'])
38 Failure
39 invalid state change: inactive -> inactive
40
41 Because :meth:`hooke.hooke.HookeRunner.run_lines` spawns and closes
42 its own engine subprocess, we need to run the whole capture session in
43 a single call.  The command stack, on the other hand, will be
44 preserved between calls.
45
46 You can't restart recording.
47
48 >>> h = r.run_lines(h, ['start_command_capture',
49 ...                     'get_command_capture_state',
50 ...                     'start_command_capture',
51 ...                     'restart_command_capture'])  # doctest: +REPORT_UDIFF
52 Success
53 <BLANKLINE>
54 active
55 Success
56 <BLANKLINE>
57 Failure
58 invalid state change: active -> active
59 Failure
60 invalid state change: active -> active
61
62 But you can stop and restart.
63
64 >>> h = r.run_lines(h, ['start_command_capture',
65 ...                     'stop_command_capture',
66 ...                     'restart_command_capture'])  # doctest: +REPORT_UDIFF
67 Success
68 <BLANKLINE>
69 Success
70 <BLANKLINE>
71 Success
72 <BLANKLINE>
73
74 Lets add some commands to the stack.
75
76 >>> h = r.run_lines(h, ['start_command_capture',
77 ...                     'load_playlist test/data/test',
78 ...                     'get_curve',
79 ...                     'stop_command_capture'])  # doctest: +REPORT_UDIFF
80 Success
81 <BLANKLINE>
82 Success
83 <BLANKLINE>
84 Success
85 <BLANKLINE>
86 Success
87 <BLANKLINE>
88 >>> h = r.run_lines(h, ['get_command_stack'])  # doctest: +NORMALIZE_WHITESPACE
89 [<CommandMessage load playlist {input: test/data/test}>,
90  <CommandMessage get curve>]
91 Success
92 <BLANKLINE>
93
94 When capture is stopped, command execution is normal.
95
96 >>> h = r.run_lines(h, ['restart_command_capture',
97 ...                     'curve_info',
98 ...                     'stop_command_capture',
99 ...                     'version',
100 ...                     'restart_command_capture',
101 ...                     'previous_curve',
102 ...                     'stop_command_capture']
103 ...     )  # doctest: +ELLIPSIS, +REPORT_UDIFF
104 Success
105 <BLANKLINE>
106 Success
107 <BLANKLINE>
108 Success
109 <BLANKLINE>
110 Hooke 1.0.0.alpha (Ninken)
111 ...
112 Success
113 <BLANKLINE>
114 Success
115 <BLANKLINE>
116 Success
117 <BLANKLINE>
118
119 You can pop commands regardless of the recording state.
120
121 >>> h = r.run_lines(h, ['pop_command_from_stack'])
122 <CommandMessage previous curve>
123 Success
124 <BLANKLINE>
125 >>> h = r.run_lines(h, ['get_command_stack'])  # doctest: +NORMALIZE_WHITESPACE
126 [<CommandMessage load playlist {input: test/data/test}>,
127  <CommandMessage get curve>,
128  <CommandMessage curve info>]
129 Success
130 <BLANKLINE>
131
132 >>> h = r.run_lines(h, ['restart_command_capture',
133 ...                     'pop_command_from_stack',
134 ...                     'get_command_stack',
135 ...                     'stop_command_capture']
136 ...     )  # doctest: +NORMALIZE_WHITESPACE, +REPORT_UDIFF
137 Success
138 <BLANKLINE>
139 <CommandMessage curve info>
140 Success
141 <BLANKLINE>
142 [<CommandMessage load playlist {input: test/data/test}>,
143  <CommandMessage get curve>]
144 Success
145 <BLANKLINE>
146 Success
147 <BLANKLINE>
148
149 If you start up again (using `start` not `restart`), the stack is cleared.
150
151 >>> h = r.run_lines(h, ['start_command_capture',
152 ...                     'stop_command_capture'])
153 Success
154 <BLANKLINE>
155 Success
156 <BLANKLINE>
157 >>> h = r.run_lines(h, ['get_command_stack'])
158 []
159 Success
160 <BLANKLINE>
161 """