Merge lp:~mwhudson/lava-test/help-command-subcommand into lp:lava-test/0.0
- help-command-subcommand
- Merge into trunk
Proposed by
Michael Hudson-Doyle
Status: | Merged | ||||||||
---|---|---|---|---|---|---|---|---|---|
Merged at revision: | 46 | ||||||||
Proposed branch: | lp:~mwhudson/lava-test/help-command-subcommand | ||||||||
Merge into: | lp:lava-test/0.0 | ||||||||
Diff against target: |
887 lines (+333/-249) 10 files modified
abrek/builtins.py (+17/-9) abrek/command.py (+55/-22) abrek/dashboard.py (+82/-84) abrek/main.py (+1/-8) abrek/results.py (+81/-84) tests/test_abrekcmd.py (+45/-20) tests/test_builtins.py (+28/-0) tests/test_dashboard.py (+8/-8) tests/test_main.py (+4/-2) tests/test_results.py (+12/-12) |
||||||||
To merge this branch: | bzr merge lp:~mwhudson/lava-test/help-command-subcommand | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Paul Larson (community) | Approve | ||
Review via email: mp+38176@code.launchpad.net |
Commit message
Description of the change
Hi Paul,
I wanted to fix the bug I reported about 'abrek help dashboard put' not being useful and ended up rewriting how subcommands work to a moderate extent :-) Hope that's OK. The changes are I hope reasonably clear and I think I added tests for everything.
Cheers,
mwh
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'abrek/builtins.py' | |||
2 | --- abrek/builtins.py 2010-10-01 14:45:24 +0000 | |||
3 | +++ abrek/builtins.py 2010-10-12 02:45:55 +0000 | |||
4 | @@ -13,7 +13,6 @@ | |||
5 | 13 | # You should have received a copy of the GNU General Public License | 13 | # You should have received a copy of the GNU General Public License |
6 | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
7 | 15 | 15 | ||
8 | 16 | import json | ||
9 | 17 | import os | 16 | import os |
10 | 18 | import sys | 17 | import sys |
11 | 19 | from optparse import make_option | 18 | from optparse import make_option |
12 | @@ -38,21 +37,30 @@ | |||
13 | 38 | If the command name is ommited, calling the help command will return a | 37 | If the command name is ommited, calling the help command will return a |
14 | 39 | list of valid commands. | 38 | list of valid commands. |
15 | 40 | """ | 39 | """ |
17 | 41 | arglist = ['command'] | 40 | arglist = ['command', 'subcommand'] |
18 | 42 | def run(self): | 41 | def run(self): |
20 | 43 | if len(self.args) != 1: | 42 | if len(self.args) < 1: |
21 | 44 | print "Available commands:" | 43 | print "Available commands:" |
22 | 45 | for cmd in abrek.command.get_all_cmds(): | 44 | for cmd in abrek.command.get_all_cmds(): |
23 | 46 | print " %s" % cmd | 45 | print " %s" % cmd |
24 | 47 | 46 | ||
25 | 48 | print "To access extended help on a command use 'abrek help " \ | 47 | print "To access extended help on a command use 'abrek help " \ |
26 | 49 | "[command]'" | 48 | "[command]'" |
33 | 50 | else: | 49 | return |
34 | 51 | cmd = abrek.command.get_command(self.args[0]) | 50 | command_name = self.args.pop(0) |
35 | 52 | if cmd: | 51 | cmd = abrek.command.get_command(command_name) |
36 | 53 | print cmd.help() | 52 | if not cmd: |
37 | 54 | else: | 53 | print "No command found for '%s'" % command_name |
38 | 55 | print "No command found for '%s'" % self.args[0] | 54 | return |
39 | 55 | while self.args: | ||
40 | 56 | subcommand_name = self.args.pop(0) | ||
41 | 57 | cmd = cmd.get_subcommand(subcommand_name) | ||
42 | 58 | if not cmd: | ||
43 | 59 | print "No sub-command of '%s' found for '%s'" % ( | ||
44 | 60 | command_name, subcommand_name) | ||
45 | 61 | return | ||
46 | 62 | command_name += ' ' + subcommand_name | ||
47 | 63 | print cmd.help() | ||
48 | 56 | 64 | ||
49 | 57 | 65 | ||
50 | 58 | class cmd_install(abrek.command.AbrekCmd): | 66 | class cmd_install(abrek.command.AbrekCmd): |
51 | 59 | 67 | ||
52 | === modified file 'abrek/command.py' | |||
53 | --- abrek/command.py 2010-09-03 14:49:59 +0000 | |||
54 | +++ abrek/command.py 2010-10-12 02:45:55 +0000 | |||
55 | @@ -53,27 +53,25 @@ | |||
56 | 53 | """ | 53 | """ |
57 | 54 | options = [] | 54 | options = [] |
58 | 55 | arglist = [] | 55 | arglist = [] |
59 | 56 | subcmds = {} | ||
60 | 57 | 56 | ||
62 | 58 | def __init__(self): | 57 | def __init__(self, name_prefix=''): |
63 | 58 | self._name_prefix = name_prefix | ||
64 | 59 | self.parser = _AbrekOptionParser(usage=self._usage(), | 59 | self.parser = _AbrekOptionParser(usage=self._usage(), |
65 | 60 | epilog=self._desc()) | 60 | epilog=self._desc()) |
66 | 61 | for opt in self.options: | 61 | for opt in self.options: |
67 | 62 | self.parser.add_option(opt) | 62 | self.parser.add_option(opt) |
68 | 63 | 63 | ||
69 | 64 | def main(self, argv): | 64 | def main(self, argv): |
75 | 65 | if len(argv) and argv[0] in self.subcmds.keys(): | 65 | (self.opts, self.args) = self.parser.parse_args(argv) |
76 | 66 | return self.subcmds[argv[0]].main(argv[1:]) | 66 | return self.run() |
72 | 67 | else: | ||
73 | 68 | (self.opts, self.args) = self.parser.parse_args(argv) | ||
74 | 69 | return self.run() | ||
77 | 70 | 67 | ||
78 | 71 | def name(self): | 68 | def name(self): |
80 | 72 | return _convert_command_name(self.__class__.__name__) | 69 | return self._name_prefix + _convert_command_name(self.__class__.__name__) |
81 | 73 | 70 | ||
82 | 74 | def run(self): | 71 | def run(self): |
83 | 75 | raise NotImplementedError("%s: command defined but not implemented!" % | 72 | raise NotImplementedError("%s: command defined but not implemented!" % |
84 | 76 | self.name()) | 73 | self.name()) |
85 | 74 | |||
86 | 77 | def _usage(self): | 75 | def _usage(self): |
87 | 78 | usagestr = "Usage: abrek %s" % self.name() | 76 | usagestr = "Usage: abrek %s" % self.name() |
88 | 79 | for arg in self.arglist: | 77 | for arg in self.arglist: |
89 | @@ -81,7 +79,6 @@ | |||
90 | 81 | usagestr += " %s" % arg[1:].upper() | 79 | usagestr += " %s" % arg[1:].upper() |
91 | 82 | else: | 80 | else: |
92 | 83 | usagestr += " [%s]" % arg.upper() | 81 | usagestr += " [%s]" % arg.upper() |
93 | 84 | usagestr += self._list_subcmds() | ||
94 | 85 | return usagestr | 82 | return usagestr |
95 | 86 | 83 | ||
96 | 87 | def _desc(self): | 84 | def _desc(self): |
97 | @@ -93,29 +90,67 @@ | |||
98 | 93 | description += docstr + "\n" | 90 | description += docstr + "\n" |
99 | 94 | return description | 91 | return description |
100 | 95 | 92 | ||
101 | 96 | def _list_subcmds(self): | ||
102 | 97 | str = "" | ||
103 | 98 | if self.subcmds: | ||
104 | 99 | str = "\n\nSub-Commands:" | ||
105 | 100 | for cmd in self.subcmds.keys(): | ||
106 | 101 | str += "\n " + cmd | ||
107 | 102 | return str | ||
108 | 103 | |||
109 | 104 | def help(self): | 93 | def help(self): |
110 | 105 | #For some reason, format_help includes an extra \n | 94 | #For some reason, format_help includes an extra \n |
111 | 106 | return self.parser.format_help()[:-1] | 95 | return self.parser.format_help()[:-1] |
112 | 107 | 96 | ||
113 | 97 | def get_subcommand(self, name): | ||
114 | 98 | return None | ||
115 | 99 | |||
116 | 100 | |||
117 | 101 | class AbrekCmdWithSubcommands(AbrekCmd): | ||
118 | 102 | |||
119 | 103 | arglist = ['subcommand'] | ||
120 | 104 | |||
121 | 105 | def main(self, argv): | ||
122 | 106 | if not argv: | ||
123 | 107 | print "Missing sub-command." + self._list_subcmds() | ||
124 | 108 | else: | ||
125 | 109 | subcmd = self.get_subcommand(argv[0]) | ||
126 | 110 | if subcmd is None: | ||
127 | 111 | # This line might print the help and raise SystemExit if | ||
128 | 112 | # --help is passed or if an invalid option was passed. | ||
129 | 113 | opts, args = self.parser.parse_args(argv) | ||
130 | 114 | # If it didn't, complain. | ||
131 | 115 | print "'%s' not found as a sub-command of '%s'" % ( | ||
132 | 116 | args[0], self.name()) + self._list_subcmds() | ||
133 | 117 | else: | ||
134 | 118 | return subcmd.main(argv[1:]) | ||
135 | 119 | |||
136 | 120 | def get_subcommand(self, name): | ||
137 | 121 | subcmd_cls = getattr(self, 'cmd_' + name.replace('_', '-'), None) | ||
138 | 122 | if subcmd_cls is None: | ||
139 | 123 | return None | ||
140 | 124 | return subcmd_cls(self.name() + ' ') | ||
141 | 125 | |||
142 | 126 | def _usage(self): | ||
143 | 127 | usagestr = AbrekCmd._usage(self) | ||
144 | 128 | usagestr += self._list_subcmds() | ||
145 | 129 | return usagestr | ||
146 | 130 | |||
147 | 131 | def _list_subcmds(self): | ||
148 | 132 | subcmds = [] | ||
149 | 133 | for attrname in self.__class__.__dict__.keys(): | ||
150 | 134 | if attrname.startswith('cmd_'): | ||
151 | 135 | subcmds.append(_convert_command_name(attrname)) | ||
152 | 136 | if not subcmds: | ||
153 | 137 | return '' | ||
154 | 138 | return "\n\nAvailable sub-commands:\n " + "\n ".join(subcmds) | ||
155 | 139 | |||
156 | 140 | |||
157 | 108 | def _convert_command_name(cmd): | 141 | def _convert_command_name(cmd): |
158 | 109 | return cmd[4:].replace('_','-') | 142 | return cmd[4:].replace('_','-') |
159 | 110 | 143 | ||
160 | 144 | |||
161 | 111 | def _find_commands(module): | 145 | def _find_commands(module): |
162 | 112 | cmds = {} | 146 | cmds = {} |
163 | 113 | for name, func in module.__dict__.iteritems(): | 147 | for name, func in module.__dict__.iteritems(): |
164 | 114 | if name.startswith("cmd_"): | 148 | if name.startswith("cmd_"): |
165 | 115 | real_name = _convert_command_name(name) | 149 | real_name = _convert_command_name(name) |
167 | 116 | cmds[real_name] = func | 150 | cmds[real_name] = func() |
168 | 117 | return cmds | 151 | return cmds |
169 | 118 | 152 | ||
170 | 153 | |||
171 | 119 | def get_all_cmds(): | 154 | def get_all_cmds(): |
172 | 120 | from abrek import builtins, dashboard, results | 155 | from abrek import builtins, dashboard, results |
173 | 121 | cmds = _find_commands(builtins) | 156 | cmds = _find_commands(builtins) |
174 | @@ -123,9 +158,7 @@ | |||
175 | 123 | cmds.update(_find_commands(results)) | 158 | cmds.update(_find_commands(results)) |
176 | 124 | return cmds | 159 | return cmds |
177 | 125 | 160 | ||
178 | 161 | |||
179 | 126 | def get_command(cmd_name): | 162 | def get_command(cmd_name): |
180 | 127 | cmds = get_all_cmds() | 163 | cmds = get_all_cmds() |
185 | 128 | try: | 164 | return cmds.get(cmd_name) |
182 | 129 | return cmds[cmd_name]() | ||
183 | 130 | except KeyError: | ||
184 | 131 | return None | ||
186 | 132 | 165 | ||
187 | === modified file 'abrek/dashboard.py' | |||
188 | --- abrek/dashboard.py 2010-10-07 19:34:16 +0000 | |||
189 | +++ abrek/dashboard.py 2010-10-12 02:45:55 +0000 | |||
190 | @@ -24,7 +24,7 @@ | |||
191 | 24 | from getpass import getpass | 24 | from getpass import getpass |
192 | 25 | from optparse import make_option | 25 | from optparse import make_option |
193 | 26 | 26 | ||
195 | 27 | from abrek.command import AbrekCmd | 27 | from abrek.command import AbrekCmd, AbrekCmdWithSubcommands |
196 | 28 | from abrek.config import get_config | 28 | from abrek.config import get_config |
197 | 29 | from abrek.testdef import testloader | 29 | from abrek.testdef import testloader |
198 | 30 | 30 | ||
199 | @@ -92,82 +92,87 @@ | |||
200 | 92 | self.dashboardconf.write(fd) | 92 | self.dashboardconf.write(fd) |
201 | 93 | 93 | ||
202 | 94 | 94 | ||
279 | 95 | class subcmd_dashboard_setup(AbrekCmd): | 95 | class cmd_dashboard(AbrekCmdWithSubcommands): |
280 | 96 | """ | 96 | """ |
281 | 97 | Configure information needed to push results to the dashboard | 97 | Connect to the Launch-control dashboard |
282 | 98 | """ | 98 | """ |
283 | 99 | options = [make_option("-u", "--user", dest="user"), | 99 | |
284 | 100 | make_option("-p", "--password", dest="password")] | 100 | class cmd_setup(AbrekCmd): |
285 | 101 | arglist = ["*server"] | 101 | """ |
286 | 102 | 102 | Configure information needed to push results to the dashboard | |
287 | 103 | def run(self): | 103 | """ |
288 | 104 | if len(self.args) != 1: | 104 | options = [make_option("-u", "--user", dest="user"), |
289 | 105 | print "You must specify a server" | 105 | make_option("-p", "--password", dest="password")] |
290 | 106 | sys.exit(1) | 106 | arglist = ["*server"] |
291 | 107 | config = DashboardConfig() | 107 | |
292 | 108 | if self.opts.user: | 108 | def run(self): |
293 | 109 | user = self.opts.user | 109 | if len(self.args) != 1: |
294 | 110 | else: | 110 | print "You must specify a server" |
295 | 111 | user = raw_input("Username: ") | 111 | sys.exit(1) |
296 | 112 | if self.opts.password: | 112 | config = DashboardConfig() |
297 | 113 | password = self.opts.password | 113 | if self.opts.user: |
298 | 114 | else: | 114 | user = self.opts.user |
299 | 115 | password = getpass() | 115 | else: |
300 | 116 | config.host = self.args[0] | 116 | user = raw_input("Username: ") |
301 | 117 | config.user = user | 117 | if self.opts.password: |
302 | 118 | config.password = password | 118 | password = self.opts.password |
303 | 119 | config.write() | 119 | else: |
304 | 120 | 120 | password = getpass() | |
305 | 121 | 121 | config.host = self.args[0] | |
306 | 122 | class subcmd_dashboard_put(AbrekCmd): | 122 | config.user = user |
307 | 123 | """ | 123 | config.password = password |
308 | 124 | Push the results from a test to the server | 124 | config.write() |
309 | 125 | The stream name must include slashes (e.g. /anonymous/foo/) | 125 | |
310 | 126 | """ | 126 | |
311 | 127 | arglist = ["*stream", "*result"] | 127 | class cmd_put(AbrekCmd): |
312 | 128 | 128 | """ | |
313 | 129 | def run(self): | 129 | Push the results from a test to the server |
314 | 130 | if len(self.args) != 2: | 130 | The stream name must include slashes (e.g. /anonymous/foo/) |
315 | 131 | print "You must specify a stream and a result" | 131 | """ |
316 | 132 | sys.exit(1) | 132 | arglist = ["*stream", "*result"] |
317 | 133 | stream_name = self.args[0] | 133 | |
318 | 134 | result_name = self.args[1] | 134 | def run(self): |
319 | 135 | bundle = generate_bundle(result_name) | 135 | if len(self.args) != 2: |
320 | 136 | db_config = DashboardConfig() | 136 | print "You must specify a stream and a result" |
321 | 137 | hosturl = urllib.basejoin(db_config.host, "xml-rpc/") | 137 | sys.exit(1) |
322 | 138 | try: | 138 | stream_name = self.args[0] |
323 | 139 | server = xmlrpclib.Server(hosturl) | 139 | result_name = self.args[1] |
324 | 140 | except IOError: | 140 | bundle = generate_bundle(result_name) |
325 | 141 | print "Error connecting to server, please run 'abrek " \ | 141 | db_config = DashboardConfig() |
326 | 142 | "dashboard setup [host]'" | 142 | hosturl = urllib.basejoin(db_config.host, "xml-rpc/") |
327 | 143 | sys.exit(1) | 143 | try: |
328 | 144 | try: | 144 | server = xmlrpclib.Server(hosturl) |
329 | 145 | result = server.put(json.dumps(bundle, indent=2), result_name, | 145 | except IOError: |
330 | 146 | stream_name) | 146 | print "Error connecting to server, please run 'abrek " \ |
331 | 147 | print "Bundle successfully uploaded to id: %s" % result | 147 | "dashboard setup [host]'" |
332 | 148 | except xmlrpclib.Fault as strerror: | 148 | sys.exit(1) |
333 | 149 | print "Error uploading bundle: %s" % strerror.faultString | 149 | try: |
334 | 150 | sys.exit(1) | 150 | result = server.put(json.dumps(bundle, indent=2), result_name, |
335 | 151 | except socket.error as strerror: | 151 | stream_name) |
336 | 152 | print "Unable to connect to host: %s" % strerror | 152 | print "Bundle successfully uploaded to id: %s" % result |
337 | 153 | sys.exit(1) | 153 | except xmlrpclib.Fault as strerror: |
338 | 154 | except xmlrpclib.ProtocolError as strerror: | 154 | print "Error uploading bundle: %s" % strerror.faultString |
339 | 155 | print "Connection error: %s" % strerror | 155 | sys.exit(1) |
340 | 156 | sys.exit(1) | 156 | except socket.error as strerror: |
341 | 157 | 157 | print "Unable to connect to host: %s" % strerror | |
342 | 158 | 158 | sys.exit(1) | |
343 | 159 | class subcmd_dashboard_bundle(AbrekCmd): | 159 | except xmlrpclib.ProtocolError as strerror: |
344 | 160 | """ | 160 | print "Connection error: %s" % strerror |
345 | 161 | Print JSON output that can be imported into the dashboard | 161 | sys.exit(1) |
346 | 162 | """ | 162 | |
347 | 163 | arglist = ["*result"] | 163 | |
348 | 164 | 164 | class cmd_bundle(AbrekCmd): | |
349 | 165 | def run(self): | 165 | """ |
350 | 166 | if len(self.args) != 1: | 166 | Print JSON output that can be imported into the dashboard |
351 | 167 | print "You must specify a result" | 167 | """ |
352 | 168 | sys.exit(1) | 168 | arglist = ["*result"] |
353 | 169 | bundle = generate_bundle(self.args[0]) | 169 | |
354 | 170 | print json.dumps(bundle, indent=2) | 170 | def run(self): |
355 | 171 | if len(self.args) != 1: | ||
356 | 172 | print "You must specify a result" | ||
357 | 173 | sys.exit(1) | ||
358 | 174 | bundle = generate_bundle(self.args[0]) | ||
359 | 175 | print json.dumps(bundle, indent=2) | ||
360 | 171 | 176 | ||
361 | 172 | 177 | ||
362 | 173 | def generate_bundle(result): | 178 | def generate_bundle(result): |
363 | @@ -188,10 +193,3 @@ | |||
364 | 188 | return testdata | 193 | return testdata |
365 | 189 | 194 | ||
366 | 190 | 195 | ||
367 | 191 | class cmd_dashboard(AbrekCmd): | ||
368 | 192 | """ | ||
369 | 193 | Connect to the Launch-control dashboard | ||
370 | 194 | """ | ||
371 | 195 | subcmds = {'bundle':subcmd_dashboard_bundle(), | ||
372 | 196 | 'put':subcmd_dashboard_put(), | ||
373 | 197 | 'setup':subcmd_dashboard_setup()} | ||
374 | 198 | 196 | ||
375 | === modified file 'abrek/main.py' | |||
376 | --- abrek/main.py 2010-09-15 20:32:29 +0000 | |||
377 | +++ abrek/main.py 2010-10-12 02:45:55 +0000 | |||
378 | @@ -13,12 +13,10 @@ | |||
379 | 13 | # You should have received a copy of the GNU General Public License | 13 | # You should have received a copy of the GNU General Public License |
380 | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
381 | 15 | 15 | ||
382 | 16 | import sys | ||
383 | 17 | import abrek.command | 16 | import abrek.command |
384 | 18 | 17 | ||
385 | 19 | 18 | ||
386 | 20 | def main(argv): | 19 | def main(argv): |
387 | 21 | origargv = argv | ||
388 | 22 | argv = argv[1:] | 20 | argv = argv[1:] |
389 | 23 | if not argv: | 21 | if not argv: |
390 | 24 | argv = ['help'] | 22 | argv = ['help'] |
391 | @@ -27,9 +25,4 @@ | |||
392 | 27 | if not cmd_func: | 25 | if not cmd_func: |
393 | 28 | print "command '%s' not found" % cmd | 26 | print "command '%s' not found" % cmd |
394 | 29 | return 1 | 27 | return 1 |
401 | 30 | main = cmd_func.main | 28 | return cmd_func.main(argv) |
396 | 31 | try: | ||
397 | 32 | main(argv) | ||
398 | 33 | except NotImplementedError: | ||
399 | 34 | print >>sys.stderr, "Unknown usage '%s'" % " ".join(origargv) | ||
400 | 35 | print >>sys.stderr, "Use 'abrek help [cmd]' for help" | ||
402 | 36 | 29 | ||
403 | === modified file 'abrek/results.py' | |||
404 | --- abrek/results.py 2010-09-28 18:53:14 +0000 | |||
405 | +++ abrek/results.py 2010-10-12 02:45:55 +0000 | |||
406 | @@ -18,94 +18,91 @@ | |||
407 | 18 | import sys | 18 | import sys |
408 | 19 | from optparse import make_option | 19 | from optparse import make_option |
409 | 20 | 20 | ||
411 | 21 | from abrek.command import AbrekCmd | 21 | from abrek.command import AbrekCmd, AbrekCmdWithSubcommands |
412 | 22 | from abrek.config import get_config | 22 | from abrek.config import get_config |
413 | 23 | from abrek.utils import read_file | 23 | from abrek.utils import read_file |
414 | 24 | 24 | ||
415 | 25 | 25 | ||
495 | 26 | class subcmd_results_list(AbrekCmd): | 26 | class cmd_results(AbrekCmdWithSubcommands): |
417 | 27 | """ | ||
418 | 28 | List results of previous runs | ||
419 | 29 | """ | ||
420 | 30 | def run(self): | ||
421 | 31 | config = get_config() | ||
422 | 32 | print "Saved results:" | ||
423 | 33 | try: | ||
424 | 34 | for dir in os.listdir(config.resultsdir): | ||
425 | 35 | print dir | ||
426 | 36 | except OSError: | ||
427 | 37 | print "No results found" | ||
428 | 38 | |||
429 | 39 | |||
430 | 40 | class subcmd_results_show(AbrekCmd): | ||
431 | 41 | """ | ||
432 | 42 | Display the output from a previous test run | ||
433 | 43 | """ | ||
434 | 44 | arglist = ['*result'] | ||
435 | 45 | def run(self): | ||
436 | 46 | if len(self.args) != 1: | ||
437 | 47 | print "please specify the name of the result dir" | ||
438 | 48 | sys.exit(1) | ||
439 | 49 | config = get_config() | ||
440 | 50 | resultsdir = os.path.join(config.resultsdir, self.args[0]) | ||
441 | 51 | testoutput = os.path.join(resultsdir, "testoutput.log") | ||
442 | 52 | if not os.path.exists(testoutput): | ||
443 | 53 | print "No result found for '%s'" % self.args[0] | ||
444 | 54 | sys.exit(1) | ||
445 | 55 | print(read_file(testoutput)) | ||
446 | 56 | |||
447 | 57 | |||
448 | 58 | class subcmd_results_remove(AbrekCmd): | ||
449 | 59 | """ | ||
450 | 60 | Remove the results of a previous test run | ||
451 | 61 | """ | ||
452 | 62 | arglist = ['*result'] | ||
453 | 63 | options = [make_option('-f', '--force', action='store_true', | ||
454 | 64 | dest='force')] | ||
455 | 65 | def run(self): | ||
456 | 66 | if len(self.args) != 1: | ||
457 | 67 | print "please specify the name of the result dir" | ||
458 | 68 | sys.exit(1) | ||
459 | 69 | config = get_config() | ||
460 | 70 | resultsdir = os.path.join(config.resultsdir, self.args[0]) | ||
461 | 71 | if not os.path.exists(resultsdir): | ||
462 | 72 | print "No result found for '%s'" % self.args[0] | ||
463 | 73 | sys.exit(1) | ||
464 | 74 | if not self.opts.force: | ||
465 | 75 | print "Delete result '%s' for good? [Y/N]" % self.args[0], | ||
466 | 76 | response = raw_input() | ||
467 | 77 | if response[0].upper() != 'Y': | ||
468 | 78 | sys.exit(0) | ||
469 | 79 | shutil.rmtree(resultsdir) | ||
470 | 80 | |||
471 | 81 | |||
472 | 82 | class subcmd_results_rename(AbrekCmd): | ||
473 | 83 | """ | ||
474 | 84 | Rename the results from a previous test run | ||
475 | 85 | """ | ||
476 | 86 | arglist = ['*source', '*destination'] | ||
477 | 87 | |||
478 | 88 | def run(self): | ||
479 | 89 | if len(self.args) != 2: | ||
480 | 90 | print "please specify the name of the result, and the new name" | ||
481 | 91 | sys.exit(1) | ||
482 | 92 | config = get_config() | ||
483 | 93 | srcdir = os.path.join(config.resultsdir, self.args[0]) | ||
484 | 94 | destdir = os.path.join(config.resultsdir, self.args[1]) | ||
485 | 95 | if not os.path.exists(srcdir): | ||
486 | 96 | print "Result directory not found" | ||
487 | 97 | sys.exit(1) | ||
488 | 98 | if os.path.exists(destdir): | ||
489 | 99 | print "Destination result name already exists" | ||
490 | 100 | sys.exit(1) | ||
491 | 101 | shutil.move(srcdir, destdir) | ||
492 | 102 | |||
493 | 103 | |||
494 | 104 | class cmd_results(AbrekCmd): | ||
496 | 105 | """ | 27 | """ |
497 | 106 | Operate on results of previous test runs stored locally | 28 | Operate on results of previous test runs stored locally |
498 | 107 | """ | 29 | """ |
503 | 108 | subcmds = {'list':subcmd_results_list(), | 30 | |
504 | 109 | 'rm':subcmd_results_remove(), | 31 | class cmd_list(AbrekCmd): |
505 | 110 | 'rename':subcmd_results_rename(), | 32 | """ |
506 | 111 | 'show':subcmd_results_show()} | 33 | List results of previous runs |
507 | 34 | """ | ||
508 | 35 | def run(self): | ||
509 | 36 | config = get_config() | ||
510 | 37 | print "Saved results:" | ||
511 | 38 | try: | ||
512 | 39 | for dir in os.listdir(config.resultsdir): | ||
513 | 40 | print dir | ||
514 | 41 | except OSError: | ||
515 | 42 | print "No results found" | ||
516 | 43 | |||
517 | 44 | |||
518 | 45 | class cmd_show(AbrekCmd): | ||
519 | 46 | """ | ||
520 | 47 | Display the output from a previous test run | ||
521 | 48 | """ | ||
522 | 49 | arglist = ['*result'] | ||
523 | 50 | def run(self): | ||
524 | 51 | if len(self.args) != 1: | ||
525 | 52 | print "please specify the name of the result dir" | ||
526 | 53 | sys.exit(1) | ||
527 | 54 | config = get_config() | ||
528 | 55 | resultsdir = os.path.join(config.resultsdir, self.args[0]) | ||
529 | 56 | testoutput = os.path.join(resultsdir, "testoutput.log") | ||
530 | 57 | if not os.path.exists(testoutput): | ||
531 | 58 | print "No result found for '%s'" % self.args[0] | ||
532 | 59 | sys.exit(1) | ||
533 | 60 | print(read_file(testoutput)) | ||
534 | 61 | |||
535 | 62 | |||
536 | 63 | class cmd_remove(AbrekCmd): | ||
537 | 64 | """ | ||
538 | 65 | Remove the results of a previous test run | ||
539 | 66 | """ | ||
540 | 67 | arglist = ['*result'] | ||
541 | 68 | options = [make_option('-f', '--force', action='store_true', | ||
542 | 69 | dest='force')] | ||
543 | 70 | def run(self): | ||
544 | 71 | if len(self.args) != 1: | ||
545 | 72 | print "please specify the name of the result dir" | ||
546 | 73 | sys.exit(1) | ||
547 | 74 | config = get_config() | ||
548 | 75 | resultsdir = os.path.join(config.resultsdir, self.args[0]) | ||
549 | 76 | if not os.path.exists(resultsdir): | ||
550 | 77 | print "No result found for '%s'" % self.args[0] | ||
551 | 78 | sys.exit(1) | ||
552 | 79 | if not self.opts.force: | ||
553 | 80 | print "Delete result '%s' for good? [Y/N]" % self.args[0], | ||
554 | 81 | response = raw_input() | ||
555 | 82 | if response[0].upper() != 'Y': | ||
556 | 83 | sys.exit(0) | ||
557 | 84 | shutil.rmtree(resultsdir) | ||
558 | 85 | |||
559 | 86 | |||
560 | 87 | class cmd_rename(AbrekCmd): | ||
561 | 88 | """ | ||
562 | 89 | Rename the results from a previous test run | ||
563 | 90 | """ | ||
564 | 91 | arglist = ['*source', '*destination'] | ||
565 | 92 | |||
566 | 93 | def run(self): | ||
567 | 94 | if len(self.args) != 2: | ||
568 | 95 | print "please specify the name of the result, and the new name" | ||
569 | 96 | sys.exit(1) | ||
570 | 97 | config = get_config() | ||
571 | 98 | srcdir = os.path.join(config.resultsdir, self.args[0]) | ||
572 | 99 | destdir = os.path.join(config.resultsdir, self.args[1]) | ||
573 | 100 | if not os.path.exists(srcdir): | ||
574 | 101 | print "Result directory not found" | ||
575 | 102 | sys.exit(1) | ||
576 | 103 | if os.path.exists(destdir): | ||
577 | 104 | print "Destination result name already exists" | ||
578 | 105 | sys.exit(1) | ||
579 | 106 | shutil.move(srcdir, destdir) | ||
580 | 107 | |||
581 | 108 | |||
582 | 112 | 109 | ||
583 | === modified file 'tests/test_abrekcmd.py' | |||
584 | --- tests/test_abrekcmd.py 2010-09-10 17:09:14 +0000 | |||
585 | +++ tests/test_abrekcmd.py 2010-10-12 02:45:55 +0000 | |||
586 | @@ -15,7 +15,12 @@ | |||
587 | 15 | 15 | ||
588 | 16 | import unittest | 16 | import unittest |
589 | 17 | from optparse import make_option | 17 | from optparse import make_option |
591 | 18 | from abrek.command import AbrekCmd, get_command, get_all_cmds | 18 | from abrek.command import ( |
592 | 19 | AbrekCmd, | ||
593 | 20 | AbrekCmdWithSubcommands, | ||
594 | 21 | get_command, | ||
595 | 22 | get_all_cmds, | ||
596 | 23 | ) | ||
597 | 19 | 24 | ||
598 | 20 | 25 | ||
599 | 21 | class testAbrekCmd(unittest.TestCase): | 26 | class testAbrekCmd(unittest.TestCase): |
600 | @@ -72,40 +77,60 @@ | |||
601 | 72 | self.assertTrue(expected_str in cmd.help()) | 77 | self.assertTrue(expected_str in cmd.help()) |
602 | 73 | 78 | ||
603 | 74 | def test_subcmds(self): | 79 | def test_subcmds(self): |
607 | 75 | expected_str = 'Sub-Commands:\n foo' | 80 | expected_str = 'Available sub-commands:\n foo' |
605 | 76 | class subcmd_test(AbrekCmd): | ||
606 | 77 | pass | ||
608 | 78 | 81 | ||
612 | 79 | class cmd_test_subcmds(AbrekCmd): | 82 | class cmd_test_subcmds(AbrekCmdWithSubcommands): |
613 | 80 | subcmds = {'foo':subcmd_test()} | 83 | """Help for test-subcmds.""" |
614 | 81 | pass | 84 | class cmd_foo(AbrekCmd): |
615 | 85 | pass | ||
616 | 82 | cmd = cmd_test_subcmds() | 86 | cmd = cmd_test_subcmds() |
618 | 83 | self.assertTrue(expected_str in cmd.help()) | 87 | self.assertTrue( |
619 | 88 | expected_str in cmd.help() | ||
620 | 89 | and 'Help for test-subcmds.' in cmd.help()) | ||
621 | 84 | 90 | ||
622 | 85 | def test_subcmds_run(self): | 91 | def test_subcmds_run(self): |
623 | 86 | expected_str = "subcmd test str" | 92 | expected_str = "subcmd test str" |
624 | 87 | class subcmd_test(AbrekCmd): | ||
625 | 88 | def run(self): | ||
626 | 89 | return expected_str | ||
627 | 90 | 93 | ||
631 | 91 | class cmd_test_subcmds(AbrekCmd): | 94 | class cmd_test_subcmds(AbrekCmdWithSubcommands): |
632 | 92 | subcmds = {'foo':subcmd_test()} | 95 | class cmd_foo(AbrekCmd): |
633 | 93 | pass | 96 | def run(self): |
634 | 97 | return expected_str | ||
635 | 94 | cmd = cmd_test_subcmds() | 98 | cmd = cmd_test_subcmds() |
636 | 95 | argv = ['foo'] | 99 | argv = ['foo'] |
637 | 96 | self.assertEqual(expected_str, cmd.main(argv)) | 100 | self.assertEqual(expected_str, cmd.main(argv)) |
638 | 97 | 101 | ||
639 | 102 | def test_subcmds_name(self): | ||
640 | 103 | expected_str = "subcmd test str" | ||
641 | 104 | |||
642 | 105 | class cmd_test_subcmds(AbrekCmdWithSubcommands): | ||
643 | 106 | class cmd_foo(AbrekCmd): | ||
644 | 107 | def run(self): | ||
645 | 108 | return expected_str | ||
646 | 109 | cmd = cmd_test_subcmds().get_subcommand('foo') | ||
647 | 110 | self.assertEqual('test-subcmds foo', cmd.name()) | ||
648 | 111 | |||
649 | 112 | def test_subcmds_help(self): | ||
650 | 113 | expected_str = "subcmd test str" | ||
651 | 114 | |||
652 | 115 | class cmd_test_subcmds(AbrekCmdWithSubcommands): | ||
653 | 116 | class cmd_foo(AbrekCmd): | ||
654 | 117 | """Help for foo.""" | ||
655 | 118 | def run(self): | ||
656 | 119 | return expected_str | ||
657 | 120 | cmd = cmd_test_subcmds().get_subcommand('foo') | ||
658 | 121 | self.assertTrue( | ||
659 | 122 | 'test-subcmds foo' in cmd.help() | ||
660 | 123 | and 'Help for foo.' in cmd.help()) | ||
661 | 124 | |||
662 | 98 | def test_subcmd_strip_argv(self): | 125 | def test_subcmd_strip_argv(self): |
663 | 99 | """ | 126 | """ |
664 | 100 | Make sure that the argv list is stripped after calling the subcmd | 127 | Make sure that the argv list is stripped after calling the subcmd |
665 | 101 | """ | 128 | """ |
666 | 102 | class subcmd_test(AbrekCmd): | ||
667 | 103 | def main(self, argv): | ||
668 | 104 | return len(argv) | ||
669 | 105 | 129 | ||
673 | 106 | class cmd_test_subcmds(AbrekCmd): | 130 | class cmd_test_subcmds(AbrekCmdWithSubcommands): |
674 | 107 | subcmds = {'foo':subcmd_test()} | 131 | class cmd_foo(AbrekCmd): |
675 | 108 | pass | 132 | def main(self, argv): |
676 | 133 | return len(argv) | ||
677 | 109 | cmd = cmd_test_subcmds() | 134 | cmd = cmd_test_subcmds() |
678 | 110 | argv = ['foo'] | 135 | argv = ['foo'] |
679 | 111 | self.assertEqual(0, cmd.main(argv)) | 136 | self.assertEqual(0, cmd.main(argv)) |
680 | 112 | 137 | ||
681 | === modified file 'tests/test_builtins.py' | |||
682 | --- tests/test_builtins.py 2010-09-10 17:09:14 +0000 | |||
683 | +++ tests/test_builtins.py 2010-10-12 02:45:55 +0000 | |||
684 | @@ -36,3 +36,31 @@ | |||
685 | 36 | cmd = abrek.builtins.cmd_list_installed() | 36 | cmd = abrek.builtins.cmd_list_installed() |
686 | 37 | cmd.run() | 37 | cmd.run() |
687 | 38 | self.assertTrue(test_name in out.getvalue()) | 38 | self.assertTrue(test_name in out.getvalue()) |
688 | 39 | |||
689 | 40 | class TestHelp(TestCaseWithFixtures): | ||
690 | 41 | |||
691 | 42 | def test_command_help(self): | ||
692 | 43 | out = self.add_fixture(OutputImposter()) | ||
693 | 44 | abrek.builtins.cmd_help().main(['results']) | ||
694 | 45 | self.assertEqual( | ||
695 | 46 | abrek.results.cmd_results().help() + '\n', out.getvalue()) | ||
696 | 47 | |||
697 | 48 | def test_subcommand_help(self): | ||
698 | 49 | out = self.add_fixture(OutputImposter()) | ||
699 | 50 | abrek.builtins.cmd_help().main(['results', 'list']) | ||
700 | 51 | self.assertEqual( | ||
701 | 52 | abrek.results.cmd_results().get_subcommand('list').help() + '\n', | ||
702 | 53 | out.getvalue()) | ||
703 | 54 | |||
704 | 55 | def test_bad_command(self): | ||
705 | 56 | out = self.add_fixture(OutputImposter()) | ||
706 | 57 | abrek.builtins.cmd_help().main(['foo']) | ||
707 | 58 | self.assertEqual( | ||
708 | 59 | "No command found for 'foo'\n", out.getvalue()) | ||
709 | 60 | |||
710 | 61 | def test_bad_subcommand(self): | ||
711 | 62 | out = self.add_fixture(OutputImposter()) | ||
712 | 63 | abrek.builtins.cmd_help().main(['results', 'foo']) | ||
713 | 64 | self.assertEqual( | ||
714 | 65 | "No sub-command of 'results' found for 'foo'\n", | ||
715 | 66 | out.getvalue()) | ||
716 | 39 | 67 | ||
717 | === modified file 'tests/test_dashboard.py' | |||
718 | --- tests/test_dashboard.py 2010-10-07 17:11:55 +0000 | |||
719 | +++ tests/test_dashboard.py 2010-10-12 02:45:55 +0000 | |||
720 | @@ -16,10 +16,10 @@ | |||
721 | 16 | import json | 16 | import json |
722 | 17 | import os | 17 | import os |
723 | 18 | from uuid import uuid1 | 18 | from uuid import uuid1 |
728 | 19 | from abrek.dashboard import (DashboardConfig, | 19 | from abrek.dashboard import ( |
729 | 20 | cmd_dashboard, | 20 | DashboardConfig, |
730 | 21 | subcmd_dashboard_bundle, | 21 | cmd_dashboard, |
731 | 22 | subcmd_dashboard_setup) | 22 | ) |
732 | 23 | from imposters import ConfigImposter, OutputImposter | 23 | from imposters import ConfigImposter, OutputImposter |
733 | 24 | from fixtures import TestCaseWithFixtures | 24 | from fixtures import TestCaseWithFixtures |
734 | 25 | 25 | ||
735 | @@ -44,7 +44,7 @@ | |||
736 | 44 | 44 | ||
737 | 45 | def test_dashboard_setup_noserver(self): | 45 | def test_dashboard_setup_noserver(self): |
738 | 46 | errmsg = "You must specify a server" | 46 | errmsg = "You must specify a server" |
740 | 47 | cmd = subcmd_dashboard_setup() | 47 | cmd = cmd_dashboard.cmd_setup() |
741 | 48 | self.assertRaises(SystemExit, cmd.main, argv=[]) | 48 | self.assertRaises(SystemExit, cmd.main, argv=[]) |
742 | 49 | self.assertEqual(errmsg, self.out.getvalue().strip()) | 49 | self.assertEqual(errmsg, self.out.getvalue().strip()) |
743 | 50 | 50 | ||
744 | @@ -56,13 +56,13 @@ | |||
745 | 56 | 56 | ||
746 | 57 | def test_dashboard_bundle_badresult(self): | 57 | def test_dashboard_bundle_badresult(self): |
747 | 58 | errmsg = "Result directory not found" | 58 | errmsg = "Result directory not found" |
749 | 59 | cmd = subcmd_dashboard_bundle() | 59 | cmd = cmd_dashboard.cmd_bundle() |
750 | 60 | self.assertRaises(SystemExit, cmd.main, argv=['badresult']) | 60 | self.assertRaises(SystemExit, cmd.main, argv=['badresult']) |
751 | 61 | self.assertEqual(errmsg, self.out.getvalue().strip()) | 61 | self.assertEqual(errmsg, self.out.getvalue().strip()) |
752 | 62 | 62 | ||
753 | 63 | def test_dashboard_bundle_noresult(self): | 63 | def test_dashboard_bundle_noresult(self): |
754 | 64 | errmsg = "You must specify a result" | 64 | errmsg = "You must specify a result" |
756 | 65 | cmd = subcmd_dashboard_bundle() | 65 | cmd = cmd_dashboard.cmd_bundle() |
757 | 66 | self.assertRaises(SystemExit, cmd.main, argv=[]) | 66 | self.assertRaises(SystemExit, cmd.main, argv=[]) |
758 | 67 | self.assertEqual(errmsg, self.out.getvalue().strip()) | 67 | self.assertEqual(errmsg, self.out.getvalue().strip()) |
759 | 68 | 68 | ||
760 | @@ -73,7 +73,7 @@ | |||
761 | 73 | self.out = self.add_fixture(OutputImposter()) | 73 | self.out = self.add_fixture(OutputImposter()) |
762 | 74 | 74 | ||
763 | 75 | def test_dashboard_bundle_good(self): | 75 | def test_dashboard_bundle_good(self): |
765 | 76 | cmd = subcmd_dashboard_bundle() | 76 | cmd = cmd_dashboard.cmd_bundle() |
766 | 77 | (testname, testuuid) = make_stream_result(self.config) | 77 | (testname, testuuid) = make_stream_result(self.config) |
767 | 78 | expected_dict = { | 78 | expected_dict = { |
768 | 79 | "test_runs": [{ | 79 | "test_runs": [{ |
769 | 80 | 80 | ||
770 | === modified file 'tests/test_main.py' | |||
771 | --- tests/test_main.py 2010-09-18 04:07:37 +0000 | |||
772 | +++ tests/test_main.py 2010-10-12 02:45:55 +0000 | |||
773 | @@ -24,7 +24,9 @@ | |||
774 | 24 | self.out = self.add_fixture(OutputImposter()) | 24 | self.out = self.add_fixture(OutputImposter()) |
775 | 25 | 25 | ||
776 | 26 | def test_bad_subcmd(self): | 26 | def test_bad_subcmd(self): |
778 | 27 | errmsg = "Unknown usage './abrek results foo'\nUse 'abrek help [cmd]' for help\n" | 27 | # Running a subcommand that does not exist of a command that does |
779 | 28 | # gives a nice error message. | ||
780 | 29 | errmsg = "'foo' not found as a sub-command of 'results'" | ||
781 | 28 | main(['./abrek', 'results', 'foo']) | 30 | main(['./abrek', 'results', 'foo']) |
783 | 29 | self.assertEqual(errmsg, self.out.getvalue()) | 31 | self.assertEqual(errmsg, self.out.getvalue().splitlines()[0]) |
784 | 30 | 32 | ||
785 | 31 | 33 | ||
786 | === modified file 'tests/test_results.py' | |||
787 | --- tests/test_results.py 2010-09-10 17:09:14 +0000 | |||
788 | +++ tests/test_results.py 2010-10-12 02:45:55 +0000 | |||
789 | @@ -15,7 +15,7 @@ | |||
790 | 15 | 15 | ||
791 | 16 | import os | 16 | import os |
792 | 17 | 17 | ||
794 | 18 | import abrek.results | 18 | from abrek.results import cmd_results |
795 | 19 | from abrek.utils import write_file | 19 | from abrek.utils import write_file |
796 | 20 | from imposters import ConfigImposter, OutputImposter | 20 | from imposters import ConfigImposter, OutputImposter |
797 | 21 | from fixtures import TestCaseWithFixtures | 21 | from fixtures import TestCaseWithFixtures |
798 | @@ -30,13 +30,13 @@ | |||
799 | 30 | def test_results_list(self): | 30 | def test_results_list(self): |
800 | 31 | result_name = "test_results_list000" | 31 | result_name = "test_results_list000" |
801 | 32 | os.makedirs(os.path.join(self.config.resultsdir, result_name)) | 32 | os.makedirs(os.path.join(self.config.resultsdir, result_name)) |
803 | 33 | cmd = abrek.results.subcmd_results_list() | 33 | cmd = cmd_results.cmd_list() |
804 | 34 | cmd.run() | 34 | cmd.run() |
805 | 35 | self.assertTrue(result_name in self.out.getvalue()) | 35 | self.assertTrue(result_name in self.out.getvalue()) |
806 | 36 | 36 | ||
807 | 37 | def test_results_list_nodir(self): | 37 | def test_results_list_nodir(self): |
808 | 38 | errmsg = "No results found" | 38 | errmsg = "No results found" |
810 | 39 | cmd = abrek.results.subcmd_results_list() | 39 | cmd = cmd_results.cmd_list() |
811 | 40 | cmd.run() | 40 | cmd.run() |
812 | 41 | self.assertTrue(errmsg in self.out.getvalue()) | 41 | self.assertTrue(errmsg in self.out.getvalue()) |
813 | 42 | 42 | ||
814 | @@ -47,20 +47,20 @@ | |||
815 | 47 | os.makedirs(result_dir) | 47 | os.makedirs(result_dir) |
816 | 48 | outputfile = os.path.join(result_dir, 'testoutput.log') | 48 | outputfile = os.path.join(result_dir, 'testoutput.log') |
817 | 49 | write_file(result_output, outputfile) | 49 | write_file(result_output, outputfile) |
819 | 50 | cmd = abrek.results.subcmd_results_show() | 50 | cmd = cmd_results.cmd_show() |
820 | 51 | cmd.main(argv=[result_name]) | 51 | cmd.main(argv=[result_name]) |
821 | 52 | self.assertEqual(result_output, self.out.getvalue().strip()) | 52 | self.assertEqual(result_output, self.out.getvalue().strip()) |
822 | 53 | 53 | ||
823 | 54 | def test_results_show_noarg(self): | 54 | def test_results_show_noarg(self): |
824 | 55 | errmsg = "please specify the name of the result dir" | 55 | errmsg = "please specify the name of the result dir" |
826 | 56 | cmd = abrek.results.subcmd_results_show() | 56 | cmd = cmd_results.cmd_show() |
827 | 57 | self.assertRaises(SystemExit, cmd.main, argv=[]) | 57 | self.assertRaises(SystemExit, cmd.main, argv=[]) |
828 | 58 | self.assertEqual(errmsg, self.out.getvalue().strip()) | 58 | self.assertEqual(errmsg, self.out.getvalue().strip()) |
829 | 59 | 59 | ||
830 | 60 | def test_results_show_nodir(self): | 60 | def test_results_show_nodir(self): |
831 | 61 | testname = "foo" | 61 | testname = "foo" |
832 | 62 | errmsg = "No result found for '%s'" % testname | 62 | errmsg = "No result found for '%s'" % testname |
834 | 63 | cmd = abrek.results.subcmd_results_show() | 63 | cmd = cmd_results.cmd_show() |
835 | 64 | self.assertRaises(SystemExit, cmd.main, argv=[testname]) | 64 | self.assertRaises(SystemExit, cmd.main, argv=[testname]) |
836 | 65 | self.assertEqual(errmsg, self.out.getvalue().strip()) | 65 | self.assertEqual(errmsg, self.out.getvalue().strip()) |
837 | 66 | 66 | ||
838 | @@ -68,20 +68,20 @@ | |||
839 | 68 | result_name = "test_results_remove000" | 68 | result_name = "test_results_remove000" |
840 | 69 | result_dir = os.path.join(self.config.resultsdir, result_name) | 69 | result_dir = os.path.join(self.config.resultsdir, result_name) |
841 | 70 | os.makedirs(result_dir) | 70 | os.makedirs(result_dir) |
843 | 71 | cmd = abrek.results.subcmd_results_remove() | 71 | cmd = cmd_results.cmd_remove() |
844 | 72 | cmd.main(argv=[result_name, '-f']) | 72 | cmd.main(argv=[result_name, '-f']) |
845 | 73 | self.assertFalse(os.path.exists(result_dir)) | 73 | self.assertFalse(os.path.exists(result_dir)) |
846 | 74 | 74 | ||
847 | 75 | def test_results_remove_noarg(self): | 75 | def test_results_remove_noarg(self): |
848 | 76 | errmsg = "please specify the name of the result dir" | 76 | errmsg = "please specify the name of the result dir" |
850 | 77 | cmd = abrek.results.subcmd_results_remove() | 77 | cmd = cmd_results.cmd_remove() |
851 | 78 | self.assertRaises(SystemExit, cmd.main, argv=[]) | 78 | self.assertRaises(SystemExit, cmd.main, argv=[]) |
852 | 79 | self.assertEqual(errmsg, self.out.getvalue().strip()) | 79 | self.assertEqual(errmsg, self.out.getvalue().strip()) |
853 | 80 | 80 | ||
854 | 81 | def test_results_remove_nodir(self): | 81 | def test_results_remove_nodir(self): |
855 | 82 | testname = "foo" | 82 | testname = "foo" |
856 | 83 | errmsg = "No result found for '%s'" % testname | 83 | errmsg = "No result found for '%s'" % testname |
858 | 84 | cmd = abrek.results.subcmd_results_remove() | 84 | cmd = cmd_results.cmd_remove() |
859 | 85 | self.assertRaises(SystemExit, cmd.main, argv=[testname]) | 85 | self.assertRaises(SystemExit, cmd.main, argv=[testname]) |
860 | 86 | self.assertEqual(errmsg, self.out.getvalue().strip()) | 86 | self.assertEqual(errmsg, self.out.getvalue().strip()) |
861 | 87 | 87 | ||
862 | @@ -91,7 +91,7 @@ | |||
863 | 91 | result_srcdir = os.path.join(self.config.resultsdir, result_src) | 91 | result_srcdir = os.path.join(self.config.resultsdir, result_src) |
864 | 92 | result_destdir = os.path.join(self.config.resultsdir, result_dest) | 92 | result_destdir = os.path.join(self.config.resultsdir, result_dest) |
865 | 93 | os.makedirs(result_srcdir) | 93 | os.makedirs(result_srcdir) |
867 | 94 | cmd = abrek.results.subcmd_results_rename() | 94 | cmd = cmd_results.cmd_rename() |
868 | 95 | cmd.main(argv=[result_src, result_dest]) | 95 | cmd.main(argv=[result_src, result_dest]) |
869 | 96 | self.assertFalse(os.path.exists(result_srcdir)) | 96 | self.assertFalse(os.path.exists(result_srcdir)) |
870 | 97 | self.assertTrue(os.path.exists(result_destdir)) | 97 | self.assertTrue(os.path.exists(result_destdir)) |
871 | @@ -100,7 +100,7 @@ | |||
872 | 100 | errmsg = "Result directory not found" | 100 | errmsg = "Result directory not found" |
873 | 101 | result_src = "test_results_old" | 101 | result_src = "test_results_old" |
874 | 102 | result_dest = "test_results_new" | 102 | result_dest = "test_results_new" |
876 | 103 | cmd = abrek.results.subcmd_results_rename() | 103 | cmd = cmd_results.cmd_rename() |
877 | 104 | self.assertRaises(SystemExit, cmd.main, argv=[result_src, result_dest]) | 104 | self.assertRaises(SystemExit, cmd.main, argv=[result_src, result_dest]) |
878 | 105 | self.assertEqual(errmsg, self.out.getvalue().strip()) | 105 | self.assertEqual(errmsg, self.out.getvalue().strip()) |
879 | 106 | 106 | ||
880 | @@ -112,6 +112,6 @@ | |||
881 | 112 | result_destdir = os.path.join(self.config.resultsdir, result_dest) | 112 | result_destdir = os.path.join(self.config.resultsdir, result_dest) |
882 | 113 | os.makedirs(result_srcdir) | 113 | os.makedirs(result_srcdir) |
883 | 114 | os.makedirs(result_destdir) | 114 | os.makedirs(result_destdir) |
885 | 115 | cmd = abrek.results.subcmd_results_rename() | 115 | cmd = cmd_results.cmd_rename() |
886 | 116 | self.assertRaises(SystemExit, cmd.main, argv=[result_src, result_dest]) | 116 | self.assertRaises(SystemExit, cmd.main, argv=[result_src, result_dest]) |
887 | 117 | self.assertEqual(errmsg, self.out.getvalue().strip()) | 117 | self.assertEqual(errmsg, self.out.getvalue().strip()) |
I like it, much nicer. Thanks a lot Michael!