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/>.
20 We run this test in a temporary directory for easy cleanup.
25 >>> temp_dir = tempfile.mkdtemp(prefix='tmp-hooke-')
27 >>> from hooke.hooke import Hooke, HookeRunner
31 Add add some commands to the stack.
33 >>> h = r.run_lines(h, ['start_command_capture',
34 ... 'load_playlist test/data/test',
36 ... 'stop_command_capture']) # doctest: +REPORT_UDIFF
45 >>> h = r.run_lines(h, ['get_command_stack']) # doctest: +NORMALIZE_WHITESPACE
46 [<CommandMessage load playlist {input: test/data/test}>,
47 <CommandMessage get curve>]
51 Ensure we'll be saving in our temporary directory.
53 >>> target_dir = os.path.join(temp_dir, 'resources', 'command_stack')
54 >>> h = r.run_lines(h, ['set_config "command_stack plugin" path %s'
58 >>> h = r.run_lines(h, ['get_command_stack']) # doctest: +NORMALIZE_WHITESPACE
59 [<CommandMessage load playlist {input: test/data/test}>,
60 <CommandMessage get curve>]
66 >>> h = r.run_lines(h, ['get_command_stack']) # doctest: +NORMALIZE_WHITESPACE
67 [<CommandMessage load playlist {input: test/data/test}>,
68 <CommandMessage get curve>]
71 >>> h = r.run_lines(h, ['save_command_stack'])
74 >>> os.listdir(temp_dir)
76 >>> os.listdir(target_dir)
78 >>> with open(os.path.join(target_dir, 'default'), 'r') as f:
80 - arguments: {input: !!python/unicode 'test/data/test'}
81 command: load playlist
86 You can also specify the name explicitly.
88 >>> h = r.run_lines(h, ['save_command_stack --output my_stack'])
91 >>> sorted(os.listdir(target_dir))
92 ['default', 'my_stack']
93 >>> with open(os.path.join(target_dir, 'my_stack'), 'r') as f:
95 - arguments: {input: !!python/unicode 'test/data/test'}
96 command: load playlist
101 Further saves overwrite the last save/load path by default.
103 >>> h = r.run_lines(h, ['restart_command_capture',
105 ... 'stop_command_capture']) # doctest: +REPORT_UDIFF
112 >>> h = r.run_lines(h, ['save_command_stack'])
115 >>> with open(os.path.join(target_dir, 'default'), 'r') as f:
117 - arguments: {input: !!python/unicode 'test/data/test'}
118 command: load playlist
122 >>> with open(os.path.join(target_dir, 'my_stack'), 'r') as f:
124 - arguments: {input: !!python/unicode 'test/data/test'}
125 command: load playlist
132 But starting command capture (which clears the stack), reverts the
133 default save name to `default`.
135 >>> h = r.run_lines(h, ['start_command_capture',
137 ... 'stop_command_capture']) # doctest: +REPORT_UDIFF
144 >>> h = r.run_lines(h, ['save_command_stack'])
147 >>> with open(os.path.join(target_dir, 'default'), 'r') as f:
153 Clear the stack so loading behavior is more obvious.
155 >>> h = r.run_lines(h, ['start_command_capture',
156 ... 'stop_command_capture']) # doctest: +REPORT_UDIFF
162 Loading is just the inverse of saving.
164 >>> h = r.run_lines(h, ['load_command_stack'])
167 >>> h = r.run_lines(h, ['get_command_stack'])
168 [<CommandMessage version>]
171 >>> h = r.run_lines(h, ['load_command_stack --input my_stack'])
174 >>> h = r.run_lines(h, ['get_command_stack']) # doctest: +NORMALIZE_WHITESPACE
175 [<CommandMessage load playlist {input: test/data/test}>,
176 <CommandMessage get curve>,
177 <CommandMessage curve info>]
181 Now that the current stack's name is `my_stack`, that will be the
182 default stack loaded if you `load_command_stack` without `--input`.
184 >>> with open(os.path.join(target_dir, 'my_stack'), 'w') as f:
185 ... f.write('\\n'.join([
186 ... '- arguments: {}',
187 ... ' command: debug',
189 >>> h = r.run_lines(h, ['load_command_stack'])
192 >>> h = r.run_lines(h, ['get_command_stack']) # doctest: +NORMALIZE_WHITESPACE
193 [<CommandMessage debug>]
197 Cleanup the temporary directory.
199 >>> shutil.rmtree(temp_dir)