1 # Copyright (C) 2010-2012 W. Trevor King <wking@drexel.edu>
3 # This file is part of Hooke.
5 # Hooke is free software: you can redistribute it and/or modify it under the
6 # terms of the GNU Lesser General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option) any
10 # Hooke is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with Hooke. If not, see <http://www.gnu.org/licenses/>.
21 >>> from hooke.hooke import Hooke, HookeRunner
25 The command stack starts off empty.
27 >>> h = r.run_lines(h, ['get_command_stack'])
32 And inactive, so you can't stop it.
34 >>> h = r.run_lines(h, ['get_command_capture_state'])
38 >>> h = r.run_lines(h, ['stop_command_capture'])
40 invalid state change: inactive -> inactive
42 Because :meth:`hooke.hooke.HookeRunner.run_lines` spawns and closes
43 its own engine subprocess, we need to run the whole capture session in
44 a single call. The command stack, on the other hand, will be
45 preserved between calls.
47 You can't restart recording.
49 >>> h = r.run_lines(h, ['start_command_capture',
50 ... 'get_command_capture_state',
51 ... 'start_command_capture',
52 ... 'restart_command_capture']) # doctest: +REPORT_UDIFF
59 invalid state change: active -> active
61 invalid state change: active -> active
63 But you can stop and restart.
65 >>> h = r.run_lines(h, ['start_command_capture',
66 ... 'stop_command_capture',
67 ... 'restart_command_capture']) # doctest: +REPORT_UDIFF
75 Lets add some commands to the stack.
77 >>> h = r.run_lines(h, ['start_command_capture',
78 ... 'load_playlist test/data/test',
80 ... 'stop_command_capture']) # doctest: +REPORT_UDIFF
89 >>> h = r.run_lines(h, ['get_command_stack']) # doctest: +NORMALIZE_WHITESPACE
90 [<CommandMessage load playlist {input: test/data/test}>,
91 <CommandMessage get curve>]
95 When capture is stopped, command execution is normal.
97 >>> h = r.run_lines(h, ['restart_command_capture',
99 ... 'stop_command_capture',
101 ... 'restart_command_capture',
102 ... 'previous_curve',
103 ... 'stop_command_capture']
104 ... ) # doctest: +ELLIPSIS, +REPORT_UDIFF
111 Hooke 1.0.0.alpha (Ninken)
120 You can pop commands regardless of the recording state.
122 >>> h = r.run_lines(h, ['pop_command_from_stack'])
123 <CommandMessage previous curve>
126 >>> h = r.run_lines(h, ['get_command_stack']) # doctest: +NORMALIZE_WHITESPACE
127 [<CommandMessage load playlist {input: test/data/test}>,
128 <CommandMessage get curve>,
129 <CommandMessage curve info>]
133 >>> h = r.run_lines(h, ['restart_command_capture',
134 ... 'pop_command_from_stack',
135 ... 'get_command_stack',
136 ... 'stop_command_capture']
137 ... ) # doctest: +NORMALIZE_WHITESPACE, +REPORT_UDIFF
140 <CommandMessage curve info>
143 [<CommandMessage load playlist {input: test/data/test}>,
144 <CommandMessage get curve>]
150 If you start up again (using `start` not `restart`), the stack is cleared.
152 >>> h = r.run_lines(h, ['start_command_capture',
153 ... 'stop_command_capture'])
158 >>> h = r.run_lines(h, ['get_command_stack'])
163 Building command stacks is fun, but its useless if you can't execute
164 them. First, lets repopulate the in-memory stack.
166 >>> h = r.run_lines(h, ['start_command_capture',
167 ... 'debug --attribute config',
169 ... 'stop_command_capture']
170 ... ) # doctest: +REPORT_UDIFF
180 Setup logging so we can check command output in the doctest.
182 >>> log = logging.getLogger('hooke')
183 >>> stdout_handler = logging.StreamHandler(sys.stdout)
184 >>> log.addHandler(stdout_handler)
186 Execute the stack. We use `h.run_command` because `sys.stdout` is
187 replaced by a `doctest._SpoofOut`, and doctest has no way to collect
188 those results from `run_lines`'s engine subprocess.
190 >>> h.run_command('execute command stack', arguments={}
191 ... ) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE, +REPORT_UDIFF
192 engine running internal <CommandMessage execute command stack>
193 engine running internal <CommandMessage debug {attribute: config, ...}>
194 engine message from debug (<type 'instance'>):
195 <hooke.config.HookeConfigParser instance at 0x...>
196 engine message from debug (<class 'hooke.command.Success'>):
197 engine running internal <CommandMessage version {...}>
198 engine message from version (<type 'str'>): Hooke 1.0.0.alpha (Ninken)
201 engine message from version (<class 'hooke.command.Success'>):
202 engine message from execute command stack (<class 'hooke.command.Success'>):