1 # Copyright (C) 2010 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
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.
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.
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/>.
22 >>> from hooke.hooke import Hooke, HookeRunner
26 The command stack starts off empty.
28 >>> h = r.run_lines(h, ['get_command_stack'])
33 And inactive, so you can't stop it.
35 >>> h = r.run_lines(h, ['get_command_capture_state'])
39 >>> h = r.run_lines(h, ['stop_command_capture'])
41 invalid state change: inactive -> inactive
43 Because :meth:`hooke.hooke.HookeRunner.run_lines` spawns and closes
44 its own engine subprocess, we need to run the whole capture session in
45 a single call. The command stack, on the other hand, will be
46 preserved between calls.
48 You can't restart recording.
50 >>> h = r.run_lines(h, ['start_command_capture',
51 ... 'get_command_capture_state',
52 ... 'start_command_capture',
53 ... 'restart_command_capture']) # doctest: +REPORT_UDIFF
60 invalid state change: active -> active
62 invalid state change: active -> active
64 But you can stop and restart.
66 >>> h = r.run_lines(h, ['start_command_capture',
67 ... 'stop_command_capture',
68 ... 'restart_command_capture']) # doctest: +REPORT_UDIFF
76 Lets add some commands to the stack.
78 >>> h = r.run_lines(h, ['start_command_capture',
79 ... 'load_playlist test/data/test',
81 ... 'stop_command_capture']) # doctest: +REPORT_UDIFF
90 >>> h = r.run_lines(h, ['get_command_stack']) # doctest: +NORMALIZE_WHITESPACE
91 [<CommandMessage load playlist {input: test/data/test}>,
92 <CommandMessage get curve>]
96 When capture is stopped, command execution is normal.
98 >>> h = r.run_lines(h, ['restart_command_capture',
100 ... 'stop_command_capture',
102 ... 'restart_command_capture',
103 ... 'previous_curve',
104 ... 'stop_command_capture']
105 ... ) # doctest: +ELLIPSIS, +REPORT_UDIFF
112 Hooke 1.0.0.alpha (Ninken)
121 You can pop commands regardless of the recording state.
123 >>> h = r.run_lines(h, ['pop_command_from_stack'])
124 <CommandMessage previous curve>
127 >>> h = r.run_lines(h, ['get_command_stack']) # doctest: +NORMALIZE_WHITESPACE
128 [<CommandMessage load playlist {input: test/data/test}>,
129 <CommandMessage get curve>,
130 <CommandMessage curve info>]
134 >>> h = r.run_lines(h, ['restart_command_capture',
135 ... 'pop_command_from_stack',
136 ... 'get_command_stack',
137 ... 'stop_command_capture']
138 ... ) # doctest: +NORMALIZE_WHITESPACE, +REPORT_UDIFF
141 <CommandMessage curve info>
144 [<CommandMessage load playlist {input: test/data/test}>,
145 <CommandMessage get curve>]
151 If you start up again (using `start` not `restart`), the stack is cleared.
153 >>> h = r.run_lines(h, ['start_command_capture',
154 ... 'stop_command_capture'])
159 >>> h = r.run_lines(h, ['get_command_stack'])
164 Building command stacks is fun, but its useless if you can't execute
165 them. First, lets repopulate the in-memory stack.
167 >>> h = r.run_lines(h, ['start_command_capture',
168 ... 'debug --attribute config',
170 ... 'stop_command_capture']
171 ... ) # doctest: +REPORT_UDIFF
181 Setup logging so we can check command output in the doctest.
183 >>> log = logging.getLogger('hooke')
184 >>> stdout_handler = logging.StreamHandler(sys.stdout)
185 >>> log.addHandler(stdout_handler)
187 Execute the stack. We use `h.run_command` because `sys.stdout` is
188 replaced by a `doctest._SpoofOut`, and doctest has no way to collect
189 those results from `run_lines`'s engine subprocess.
191 >>> h.run_command('execute command stack', arguments={}
192 ... ) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE, +REPORT_UDIFF
193 engine running internal <CommandMessage execute command stack>
194 engine running internal <CommandMessage debug {attribute: config, ...}>
195 engine message from debug (<type 'instance'>):
196 <hooke.config.HookeConfigParser instance at 0x...>
197 engine message from debug (<class 'hooke.command.Success'>):
198 engine running internal <CommandMessage version {...}>
199 engine message from version (<type 'str'>): Hooke 1.0.0.alpha (Ninken)
202 engine message from version (<class 'hooke.command.Success'>):
203 engine message from execute command stack (<class 'hooke.command.Success'>):