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/>.
19 We run this test in a temporary directory for easy cleanup.
24 >>> temp_dir = tempfile.mkdtemp(prefix='tmp-hooke-')
26 >>> from hooke.hooke import Hooke, HookeRunner
30 Add add some commands to the stack.
32 >>> h = r.run_lines(h, ['start_command_capture',
33 ... 'load_playlist test/data/test',
35 ... 'stop_command_capture']) # doctest: +REPORT_UDIFF
44 >>> h = r.run_lines(h, ['get_command_stack']) # doctest: +NORMALIZE_WHITESPACE
45 [<CommandMessage load playlist {input: test/data/test}>,
46 <CommandMessage get curve>]
50 Ensure we'll be saving in our temporary directory.
52 >>> target_dir = os.path.join(temp_dir, 'resources', 'command_stack')
53 >>> h = r.run_lines(h, ['set_config "command_stack plugin" path %s'
57 >>> h = r.run_lines(h, ['get_command_stack']) # doctest: +NORMALIZE_WHITESPACE
58 [<CommandMessage load playlist {input: test/data/test}>,
59 <CommandMessage get curve>]
65 >>> h = r.run_lines(h, ['get_command_stack']) # doctest: +NORMALIZE_WHITESPACE
66 [<CommandMessage load playlist {input: test/data/test}>,
67 <CommandMessage get curve>]
70 >>> h = r.run_lines(h, ['save_command_stack'])
73 >>> os.listdir(temp_dir)
75 >>> os.listdir(target_dir)
77 >>> with open(os.path.join(target_dir, 'default'), 'r') as f:
79 - arguments: {input: test/data/test}
80 command: load playlist
85 You can also specify the name explicitly.
87 >>> h = r.run_lines(h, ['save_command_stack --output my_stack'])
90 >>> sorted(os.listdir(target_dir))
91 ['default', 'my_stack']
92 >>> with open(os.path.join(target_dir, 'my_stack'), 'r') as f:
94 - arguments: {input: test/data/test}
95 command: load playlist
100 Further saves overwrite the last save/load path by default.
102 >>> h = r.run_lines(h, ['restart_command_capture',
104 ... 'stop_command_capture']) # doctest: +REPORT_UDIFF
111 >>> h = r.run_lines(h, ['save_command_stack'])
114 >>> with open(os.path.join(target_dir, 'default'), 'r') as f:
116 - arguments: {input: test/data/test}
117 command: load playlist
121 >>> with open(os.path.join(target_dir, 'my_stack'), 'r') as f:
123 - arguments: {input: test/data/test}
124 command: load playlist
131 But starting command capture (which clears the stack), reverts the
132 default save name to `default`.
134 >>> h = r.run_lines(h, ['start_command_capture',
136 ... 'stop_command_capture']) # doctest: +REPORT_UDIFF
143 >>> h = r.run_lines(h, ['save_command_stack'])
146 >>> with open(os.path.join(target_dir, 'default'), 'r') as f:
152 Clear the stack so loading behavior is more obvious.
154 >>> h = r.run_lines(h, ['start_command_capture',
155 ... 'stop_command_capture']) # doctest: +REPORT_UDIFF
161 Loading is just the inverse of saving.
163 >>> h = r.run_lines(h, ['load_command_stack'])
166 >>> h = r.run_lines(h, ['get_command_stack'])
167 [<CommandMessage version>]
170 >>> h = r.run_lines(h, ['load_command_stack --input my_stack'])
173 >>> h = r.run_lines(h, ['get_command_stack']) # doctest: +NORMALIZE_WHITESPACE
174 [<CommandMessage load playlist {input: test/data/test}>,
175 <CommandMessage get curve>,
176 <CommandMessage curve info>]
180 Now that the current stack's name is `my_stack`, that will be the
181 default stack loaded if you `load_command_stack` without `--input`.
183 >>> with open(os.path.join(target_dir, 'my_stack'), 'w') as f:
184 ... f.write('\\n'.join([
185 ... '- arguments: {}',
186 ... ' command: debug',
188 >>> h = r.run_lines(h, ['load_command_stack'])
191 >>> h = r.run_lines(h, ['get_command_stack']) # doctest: +NORMALIZE_WHITESPACE
192 [<CommandMessage debug>]
196 Cleanup the temporary directory.
198 >>> shutil.rmtree(temp_dir)