Ran update_copyright.py.
[hooke.git] / test / apply_command_stack_to_playlist.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
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 >>> import logging
21 >>> import sys
22 >>> from hooke.command_stack import CommandStack
23 >>> from hooke.engine import CommandMessage
24 >>> from hooke.hooke import Hooke
25 >>> h = Hooke()
26
27 Setup logging so we can check command output in the doctest.
28
29 >>> log = logging.getLogger('hooke')
30 >>> stdout_handler = logging.StreamHandler(sys.stdout)
31 >>> log.addHandler(stdout_handler)
32
33 Setup a playlist to act on.
34
35 >>> h.run_command('load playlist',
36 ...     {'input': 'test/data/vclamp_picoforce/playlist'})  # doctest: +ELLIPSIS
37 engine running internal <CommandMessage load playlist {input: test/data/vclamp_picoforce/playlist}>
38 engine message from load playlist (<class 'hooke.playlist.FilePlaylist'>): <FilePlaylist ...>
39 engine message from load playlist (<class 'hooke.command.Success'>): 
40 >>> stack = CommandStack([
41 ...         CommandMessage('get curve'),
42 ...         CommandMessage('zero surface contact point'),
43 ...         ])
44
45 Test `apply command stack to playlist`.
46
47 >>> h.run_command('apply command stack to playlist',
48 ...     {'commands': stack, 'evaluate': True})  # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE, +REPORT_UDIFF
49 engine running internal <CommandMessage apply command stack to playlist
50   {commands: [<CommandMessage get curve>,
51               <CommandMessage zero surface contact point>],
52    evaluate: True}>
53 loading curve 20071120a_i27_t33.100 with driver ...
54 engine running internal <CommandMessage execute command stack {...}>
55 engine running internal <CommandMessage get curve {stack: True}>
56 engine message from get curve (<class 'hooke.curve.Curve'>): <Curve 20071120a_i27_t33.100>
57 engine message from get curve (<class 'hooke.command.Success'>): 
58 engine running internal <CommandMessage zero surface contact point {...}>
59 engine message from zero surface contact point (<type 'dict'>): {...}
60 engine message from zero surface contact point (<class 'hooke.command.Success'>): 
61 engine message from execute command stack (<class 'hooke.command.Success'>): 
62 loading curve 20071120a_i27_t33.101 with driver ...
63 engine running internal <CommandMessage execute command stack {...}>
64 engine running internal <CommandMessage get curve {stack: True}>
65 engine message from get curve (<class 'hooke.curve.Curve'>): <Curve 20071120a_i27_t33.101>
66 engine message from get curve (<class 'hooke.command.Success'>): 
67 engine running internal <CommandMessage zero surface contact point {...}>
68 engine message from zero surface contact point (<type 'dict'>): {...}
69 engine message from zero surface contact point (<class 'hooke.command.Success'>): 
70 engine message from execute command stack (<class 'hooke.command.Success'>): 
71 loading curve 20071120a_i27_t33.102 with driver ...
72
73 ...
74 loading curve 20071120a_i27_t33.199 with driver ...
75 engine running internal <CommandMessage execute command stack {...}>
76 engine running internal <CommandMessage get curve {stack: True}>
77 engine message from get curve (<class 'hooke.curve.Curve'>): <Curve 20071120a_i27_t33.199>
78 engine message from get curve (<class 'hooke.command.Success'>): 
79 engine running internal <CommandMessage zero surface contact point {...}>
80 engine message from zero surface contact point (<type 'dict'>): {...}
81 engine message from zero surface contact point (<class 'hooke.command.Success'>): 
82 engine message from execute command stack (<class 'hooke.command.Success'>): 
83 loading curve 0x06130001 with driver ...
84 unloading curve 20071120a_i27_t33.100
85 engine running internal <CommandMessage execute command stack
86   {commands: [<CommandMessage get curve>,
87               <CommandMessage zero surface contact point>],
88    curve: ...}>
89 engine running internal <CommandMessage get curve {stack: True}>
90 ...
91 engine message from apply command stack to playlist (<class 'hooke.command.Success'>): 
92 >>> curve = h.playlists.current().current(
93 ...     )  # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
94 loading curve 20071120a_i27_t33.100 with driver ...
95 engine running internal <CommandMessage zero surface contact point
96   {block: None, curve: <Curve 20071120a_i27_t33.100>, ...}>
97 engine message from zero surface contact point (<type 'dict'>): {...}
98 engine message from zero surface contact point (<class 'hooke.command.Success'>): 
99 unloading curve 20071120a_i27_t33.102
100 >>> curve
101 <Curve 20071120a_i27_t33.100>
102 >>> curve.command_stack  # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
103 [<CommandMessage zero surface contact point
104     {block: None, curve: <Curve 20071120a_i27_t33.100>, ...}>]
105
106 Test `apply command stack to playlist` without evaluating.
107
108 >>> stack = CommandStack([
109 ...         CommandMessage('flat filter peaks',
110 ...                        {'block':'retract', 'min points':1}),
111 ...         ])
112 >>> h.run_command('apply command stack to playlist',
113 ...     {'commands': stack, 'evaluate': False}
114 ...     )  # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE, +REPORT_UDIFF
115 engine running internal
116   <CommandMessage apply command stack to playlist {...}>
117 unloading curve 20071120a_i27_t33.100
118 unloading curve 20071120a_i27_t33.101
119 unloading curve 20071120a_i27_t33.102
120 ...
121 unloading curve 20071120a_i27_t33.199
122 unloading curve 0x06130001
123 unloading curve 0x07200000
124 engine message from apply command stack to playlist
125   (<class 'hooke.command.Success'>): 
126 >>> for c in curve.command_stack:
127 ...     print c  # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE, +REPORT_UDIFF
128 <CommandMessage zero surface contact point
129   {..., curve: <Curve 20071120a_i27_t33.100>...}>
130 <CommandMessage flat filter peaks {block: retract, min points: 1}>
131
132 Test `clear curve command stack`.
133
134 >>> h.run_command('clear curve command stack', arguments={})
135 engine running internal <CommandMessage clear curve command stack>
136 engine message from clear curve command stack (<class 'hooke.command.Success'>): 
137 >>> curve.command_stack
138 []
139 """