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