Updated test/ to match the new explicit YAML format.
[hooke.git] / test / tutorial.py
1 # Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
2 #
3 # This file is part of Hooke.
4 #
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.
9 #
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.
14 #
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/>.
18
19 """
20 Test the commands listed in :file:`doc/tutorial.txt`.
21
22 >>> import os
23 >>> import os.path
24 >>> from hooke.hooke import Hooke, HookeRunner
25 >>> h = Hooke()
26 >>> r = HookeRunner()
27
28 *Help*
29
30 >>> h = r.run_lines(h, ['help'])  # doctest: +ELLIPSIS
31 <BLANKLINE>
32 Documented commands (type help <topic>):
33 ========================================
34 ...
35 >>> h = r.run_lines(h, ['help load_playlist'])
36 Command: load_playlist
37 <BLANKLINE>
38 Arguments:
39 <BLANKLINE>
40 help BOOL (bool) Print a help message.
41 stack BOOL (bool) Add this command to appropriate command stacks.
42 output_playlist STRING (string) Name of the new playlist (defaults to
43     an auto-generated name).
44 input FILE (file) File name for the input playlist.
45 drivers DRIVER (driver) Drivers for loading curves.
46 <BLANKLINE>
47 Load a playlist.
48 <BLANKLINE>
49 ----
50 Usage: load_playlist [options] input
51
52 *Creating a playlist*
53
54 >>> h = r.run_lines(h, ['cd --path .'])
55 Success
56 <BLANKLINE>
57 >>> h = r.run_lines(h, ['pwd'])  # doctest: +ELLIPSIS
58 /.../hooke
59 Success
60 <BLANKLINE>
61 >>> h = r.run_lines(h, ['ls'])  # doctest: +ELLIPSIS +REPORT_UDIFF
62 .hg
63 ...
64 AUTHORS
65 ...
66 README
67 ...
68 hooke
69 ...
70 Success
71 <BLANKLINE>
72 >>> h = r.run_lines(h, ['new_playlist --output_playlist mylist'])
73 <FilePlaylist mylist>
74 Success
75 <BLANKLINE>
76 >>> h = r.run_lines(h, ['jump_to_playlist -- -1'])
77 Success
78 <BLANKLINE>
79 >>> h = r.run_lines(h, ['get_playlist'])
80 <FilePlaylist mylist>
81 Success
82 <BLANKLINE>
83 >>> h = r.run_lines(h, ['glob_curves_to_playlist test/data/vclamp_picoforce/*']
84 ...     )  # doctest: +ELLIPSIS
85 <Curve 0x06130001>
86 <Curve 0x07200000>
87 <Curve 20071120a_i27_t33.100>
88 <Curve 20071120a_i27_t33.101>
89 ...
90 <Curve 20071120a_i27_t33.199>
91 Success
92 <BLANKLINE>
93 >>> playlist_already_exists = os.path.exists('mylist.hkp')
94 >>> playlist_already_exists
95 False
96 >>> h = r.run_lines(h, ['save_playlist --output mylist'])
97 Success
98 <BLANKLINE>
99 >>> h = r.run_lines(h, ['name_playlist my_old_list'])
100 <FilePlaylist my_old_list>
101 Success
102 <BLANKLINE>
103 >>> os.path.isfile('mylist.hkp')
104 True
105 >>> h = r.run_lines(h, ['load_playlist mylist.hkp'])
106 <FilePlaylist mylist>
107 Success
108 <BLANKLINE>
109 >>> if playlist_already_exists == False:
110 ...     os.remove('mylist.hkp')
111
112 *Navigating the playlist*
113
114 >>> h = r.run_lines(h, ['get_curve'])
115 <Curve 0x06130001>
116 Success
117 <BLANKLINE>
118 >>> h = r.run_lines(h, ['next_curve'])
119 Success
120 <BLANKLINE>
121 >>> h = r.run_lines(h, ['get_curve'])
122 <Curve 0x07200000>
123 Success
124 <BLANKLINE>
125 >>> h = r.run_lines(h, ['previous_curve'])
126 Success
127 <BLANKLINE>
128 >>> h = r.run_lines(h, ['get_curve'])
129 <Curve 0x06130001>
130 Success
131 <BLANKLINE>
132 >>> h = r.run_lines(h, ['curve_index'])
133 0
134 Success
135 <BLANKLINE>
136 >>> h = r.run_lines(h, ['previous_curve'])
137 Success
138 <BLANKLINE>
139 >>> h = r.run_lines(h, ['get_curve'])
140 <Curve 20071120a_i27_t33.199>
141 Success
142 <BLANKLINE>
143 >>> h = r.run_lines(h, ['curve_index'])
144 101
145 Success
146 <BLANKLINE>
147 >>> h = r.run_lines(h, ['next_curve'])
148 Success
149 <BLANKLINE>
150 >>> h = r.run_lines(h, ['get_curve'])
151 <Curve 0x06130001>
152 Success
153 <BLANKLINE>
154 >>> h = r.run_lines(h, ['curve_index'])
155 0
156 Success
157 <BLANKLINE>
158 >>> h = r.run_lines(h, ['jump_to_curve 14'])
159 Success
160 <BLANKLINE>
161 >>> h = r.run_lines(h, ['get_curve'])
162 <Curve 20071120a_i27_t33.112>
163 Success
164 <BLANKLINE>
165 >>> h = r.run_lines(h, ['curve_index'])
166 14
167 Success
168 <BLANKLINE>
169
170 >>> [p for p in h.playlists]
171 [<FilePlaylist my_old_list>, <FilePlaylist mylist>]
172 >>> h = r.run_lines(h, ['get_playlist'])
173 <FilePlaylist my_old_list>
174 Success
175 <BLANKLINE>
176 >>> h = r.run_lines(h, ['next_playlist'])
177 Success
178 <BLANKLINE>
179 >>> h = r.run_lines(h, ['get_playlist'])
180 <FilePlaylist mylist>
181 Success
182 <BLANKLINE>
183 >>> h = r.run_lines(h, ['previous_playlist'])
184 Success
185 <BLANKLINE>
186 >>> h = r.run_lines(h, ['get_playlist'])
187 <FilePlaylist my_old_list>
188 Success
189 <BLANKLINE>
190 >>> h = r.run_lines(h, ['playlist_index'])
191 0
192 Success
193 <BLANKLINE>
194 >>> h = r.run_lines(h, ['previous_playlist'])
195 Success
196 <BLANKLINE>
197 >>> h = r.run_lines(h, ['get_playlist'])
198 <FilePlaylist mylist>
199 Success
200 <BLANKLINE>
201 >>> h = r.run_lines(h, ['playlist_index'])
202 1
203 Success
204 <BLANKLINE>
205 >>> h = r.run_lines(h, ['next_playlist'])
206 Success
207 <BLANKLINE>
208 >>> h = r.run_lines(h, ['get_playlist'])
209 <FilePlaylist my_old_list>
210 Success
211 <BLANKLINE>
212 >>> h = r.run_lines(h, ['playlist_index'])
213 0
214 Success
215 <BLANKLINE>
216 >>> h = r.run_lines(h, ['jump_to_playlist 1'])
217 Success
218 <BLANKLINE>
219 >>> h = r.run_lines(h, ['get_playlist'])
220 <FilePlaylist mylist>
221 Success
222 <BLANKLINE>
223 >>> h = r.run_lines(h, ['playlist_index'])
224 1
225 Success
226 <BLANKLINE>
227
228 *Taking notes*
229
230 See :file:`note.py`.
231
232 *Exporting curves*
233
234 See :file:`export_block.py`.
235
236 *Measuring distances and forces*
237
238 See :file:`delta.py`.
239
240 *Worm like chain and freely jointed chain fitting*
241
242 *Command stacks*
243
244 See :file:`command_stack.py`,
245 :file:`apply_command_stack_to_playlist.py`, and
246 :file:`command_stack_save_load.py`.
247
248 *Multiple curve analysis*
249
250 See :file:`multiple_curve_analysis`.
251
252 *Configuring Hooke*
253
254 See :file:`config.py`.
255 """