Merge lp:~pwlars/lava-test/bug639930 into lp:lava-test/0.0

Proposed by Paul Larson
Status: Merged
Merged at revision: 29
Proposed branch: lp:~pwlars/lava-test/bug639930
Merge into: lp:lava-test/0.0
Diff against target: 111 lines (+51/-13)
5 files modified
abrek/main.py (+15/-11)
bin/abrek (+1/-1)
tests/__init__.py (+1/-0)
tests/imposters.py (+3/-1)
tests/test_main.py (+31/-0)
To merge this branch: bzr merge lp:~pwlars/lava-test/bug639930
Reviewer Review Type Date Requested Status
James Westby (community) Needs Information
Review via email: mp+35586@code.launchpad.net
To post a comment you must log in.
Revision history for this message
James Westby (james-w) wrote :

Hi,

Looks ok, though NotImplementedError is a bit generic to catch
and give that message. Where in particular does it get thrown?

Thanks,

James

review: Needs Information
Revision history for this message
Paul Larson (pwlars) wrote :

On Wed, 2010-09-15 at 20:54 +0000, James Westby wrote:
> Review: Needs Information
> Hi,
>
> Looks ok, though NotImplementedError is a bit generic to catch
> and give that message. Where in particular does it get thrown?
That was there from before. Mostly I put it there as a trap for if
there was ever a command without run() implemented.

Revision history for this message
James Westby (james-w) wrote :

Ah, I see it. Might it be better to have a split between normal commands
and commands with subcommands? That way this could be dealt with better,
without any loss in functionality, as I have trouble seeing a use for
a command that can have optional subcommands.

That split could either be a class split, or just a check for len(self.subcommands),
depending on how deep the changes go.

Thanks,

James

Revision history for this message
Paul Larson (pwlars) wrote :

That's a good idea, but unless you have a problem with it, I'd like to go ahead and check this in to fix the bug, then revisit that later.

Revision history for this message
James Westby (james-w) wrote :

On Fri, 17 Sep 2010 14:36:15 -0000, Paul Larson <email address hidden> wrote:
> That's a good idea, but unless you have a problem with it, I'd like to go ahead and check this in to fix the bug, then revisit that later.

That sounds ok to me. Please file a bug for that so that we don't
forget.

Thanks,

James

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'abrek/main.py'
2--- abrek/main.py 2010-08-26 20:05:06 +0000
3+++ abrek/main.py 2010-09-15 20:36:12 +0000
4@@ -17,15 +17,19 @@
5 import abrek.command
6
7
8-def main(argv=None):
9- if argv is None:
10- argv = sys.argv[1:]
11- if not argv:
12- argv = ['help']
13- cmd = argv.pop(0)
14- cmd_func = abrek.command.get_command(cmd)
15- if not cmd_func:
16- print "command '%s' not found" % cmd
17- return 1
18- main = cmd_func.main
19+def main(argv):
20+ origargv = argv
21+ argv = argv[1:]
22+ if not argv:
23+ argv = ['help']
24+ cmd = argv.pop(0)
25+ cmd_func = abrek.command.get_command(cmd)
26+ if not cmd_func:
27+ print "command '%s' not found" % cmd
28+ return 1
29+ main = cmd_func.main
30+ try:
31 main(argv)
32+ except NotImplementedError:
33+ print >>sys.stderr, "Unknown usage '%s'" % " ".join(origargv)
34+ print >>sys.stderr, "Use 'abrek help [cmd]' for help"
35
36=== modified file 'bin/abrek'
37--- bin/abrek 2010-08-18 15:33:32 +0000
38+++ bin/abrek 2010-09-15 20:36:12 +0000
39@@ -27,5 +27,5 @@
40 import abrek.main
41
42 if __name__ == '__main__':
43- exit_code = abrek.main.main()
44+ exit_code = abrek.main.main(sys.argv)
45 sys.exit(exit_code)
46
47=== modified file 'tests/__init__.py'
48--- tests/__init__.py 2010-09-10 17:09:14 +0000
49+++ tests/__init__.py 2010-09-15 20:36:12 +0000
50@@ -23,6 +23,7 @@
51 'tests.test_builtins',
52 'tests.test_dashboard',
53 'tests.test_hwprofile',
54+ 'tests.test_main',
55 'tests.test_results',
56 'tests.test_swprofile']
57 loader = unittest.TestLoader()
58
59=== modified file 'tests/imposters.py'
60--- tests/imposters.py 2010-09-10 17:09:14 +0000
61+++ tests/imposters.py 2010-09-15 20:36:12 +0000
62@@ -25,10 +25,12 @@
63 class OutputImposter(object):
64 def setUp(self):
65 self.origstdout = sys.stdout
66- sys.stdout = self.fakestdout = StringIO.StringIO()
67+ self.origstderr = sys.stderr
68+ sys.stdout = sys.stderr = self.fakestdout = StringIO.StringIO()
69
70 def tearDown(self):
71 sys.stdout = self.origstdout
72+ sys.stderr = self.origstderr
73
74 def getvalue(self):
75 return self.fakestdout.getvalue()
76
77=== added file 'tests/test_main.py'
78--- tests/test_main.py 1970-01-01 00:00:00 +0000
79+++ tests/test_main.py 2010-09-15 20:36:12 +0000
80@@ -0,0 +1,31 @@
81+# Copyright (c) 2010 Linaro
82+#
83+# This program is free software: you can redistribute it and/or modify
84+# it under the terms of the GNU General Public License as published by
85+# the Free Software Foundation, either version 3 of the License, or
86+# (at your option) any later version.
87+#
88+# This program is distributed in the hope that it will be useful,
89+# but WITHOUT ANY WARRANTY; without even the implied warranty of
90+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
91+# GNU General Public License for more details.
92+#
93+# You should have received a copy of the GNU General Public License
94+# along with this program. If not, see <http://www.gnu.org/licenses/>.
95+
96+from abrek.main import main
97+from imposters import OutputImposter
98+from fixtures import TestCaseWithFixtures
99+
100+
101+class testMain(TestCaseWithFixtures):
102+ def setUp(self):
103+ super(testMain, self).setUp()
104+ self.out = self.add_fixture(OutputImposter())
105+ self._fixtures = []
106+
107+ def test_bad_subcmd(self):
108+ errmsg = "Unknown usage './abrek results foo'\nUse 'abrek help [cmd]' for help\n"
109+ main(['./abrek', 'results', 'foo'])
110+ self.assertEqual(errmsg, self.out.getvalue())
111+

Subscribers

People subscribed via source and target branches