X-Git-Url: http://git.tremily.us/?p=hooke.git;a=blobdiff_plain;f=test%2Fcommand_stack.py;fp=test%2Fcommand_stack.py;h=48ef4d16c5dda6e556a6a7b1fdf879e3f5ff3328;hp=0000000000000000000000000000000000000000;hb=a078c0a31187b85ce426eba9e1745d179ad8ed02;hpb=47ad41b1dead39fa836f5e5d45ce759a4f930066 diff --git a/test/command_stack.py b/test/command_stack.py new file mode 100644 index 0000000..48ef4d1 --- /dev/null +++ b/test/command_stack.py @@ -0,0 +1,161 @@ +# Copyright (C) 2010 W. Trevor King +# +# This file is part of Hooke. +# +# Hooke is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# Hooke is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General +# Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with Hooke. If not, see +# . + +""" +>>> from hooke.hooke import Hooke, HookeRunner +>>> h = Hooke() +>>> r = HookeRunner() + +The command stack starts off empty. + +>>> h = r.run_lines(h, ['get_command_stack']) +[] +Success + + +And inactive, so you can't stop it. + +>>> h = r.run_lines(h, ['get_command_capture_state']) +inactive +Success + +>>> h = r.run_lines(h, ['stop_command_capture']) +Failure +invalid state change: inactive -> inactive + +Because :meth:`hooke.hooke.HookeRunner.run_lines` spawns and closes +its own engine subprocess, we need to run the whole capture session in +a single call. The command stack, on the other hand, will be +preserved between calls. + +You can't restart recording. + +>>> h = r.run_lines(h, ['start_command_capture', +... 'get_command_capture_state', +... 'start_command_capture', +... 'restart_command_capture']) # doctest: +REPORT_UDIFF +Success + +active +Success + +Failure +invalid state change: active -> active +Failure +invalid state change: active -> active + +But you can stop and restart. + +>>> h = r.run_lines(h, ['start_command_capture', +... 'stop_command_capture', +... 'restart_command_capture']) # doctest: +REPORT_UDIFF +Success + +Success + +Success + + +Lets add some commands to the stack. + +>>> h = r.run_lines(h, ['start_command_capture', +... 'load_playlist test/data/test', +... 'get_curve', +... 'stop_command_capture']) # doctest: +REPORT_UDIFF +Success + +Success + +Success + +Success + +>>> h = r.run_lines(h, ['get_command_stack']) # doctest: +NORMALIZE_WHITESPACE +[, + ] +Success + + +When capture is stopped, command execution is normal. + +>>> h = r.run_lines(h, ['restart_command_capture', +... 'curve_info', +... 'stop_command_capture', +... 'version', +... 'restart_command_capture', +... 'previous_curve', +... 'stop_command_capture'] +... ) # doctest: +ELLIPSIS, +REPORT_UDIFF +Success + +Success + +Success + +Hooke 1.0.0.alpha (Ninken) +... +Success + +Success + +Success + + +You can pop commands regardless of the recording state. + +>>> h = r.run_lines(h, ['pop_command_from_stack']) + +Success + +>>> h = r.run_lines(h, ['get_command_stack']) # doctest: +NORMALIZE_WHITESPACE +[, + , + ] +Success + + +>>> h = r.run_lines(h, ['restart_command_capture', +... 'pop_command_from_stack', +... 'get_command_stack', +... 'stop_command_capture'] +... ) # doctest: +NORMALIZE_WHITESPACE, +REPORT_UDIFF +Success + + +Success + +[, + ] +Success + +Success + + +If you start up again (using `start` not `restart`), the stack is cleared. + +>>> h = r.run_lines(h, ['start_command_capture', +... 'stop_command_capture']) +Success + +Success + +>>> h = r.run_lines(h, ['get_command_stack']) +[] +Success + +"""