Merge lp:~sergiusens/snapcraft/1510954 into lp:~snappy-dev/snapcraft/core

Proposed by Sergio Schvezov
Status: Merged
Approved by: Daniel Holbach
Approved revision: 255
Merged at revision: 256
Proposed branch: lp:~sergiusens/snapcraft/1510954
Merge into: lp:~snappy-dev/snapcraft/core
Diff against target: 66 lines (+44/-7)
2 files modified
snapcraft/help.py (+6/-7)
snapcraft/tests/test_help.py (+38/-0)
To merge this branch: bzr merge lp:~sergiusens/snapcraft/1510954
Reviewer Review Type Date Requested Status
Daniel Holbach (community) Approve
Review via email: mp+276013@code.launchpad.net

Commit message

Listing plugins on help should not raise an exception

To post a comment you must log in.
Revision history for this message
Daniel Holbach (dholbach) wrote :

Good work. Thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'snapcraft/help.py'
2--- snapcraft/help.py 2015-10-27 20:21:36 +0000
3+++ snapcraft/help.py 2015-10-28 15:24:34 +0000
4@@ -61,13 +61,12 @@
5 try:
6 module = importlib.import_module(
7 'snapcraft.plugins.{}'.format(module_name))
8+ if module.__doc__ and devel:
9+ help(module)
10+ elif module.__doc__:
11+ print(module.__doc__)
12+ else:
13+ print('The plugin has no documentation')
14 except ImportError:
15 logger.error('The plugin does not exist. Use one of the following:')
16 cmds.list_plugins()
17-
18- if module.__doc__ and devel:
19- help(module)
20- elif module.__doc__:
21- print(module.__doc__)
22- else:
23- print('The plugin has no documentation')
24
25=== added file 'snapcraft/tests/test_help.py'
26--- snapcraft/tests/test_help.py 1970-01-01 00:00:00 +0000
27+++ snapcraft/tests/test_help.py 2015-10-28 15:24:34 +0000
28@@ -0,0 +1,38 @@
29+# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
30+#
31+# Copyright (C) 2015 Canonical Ltd
32+#
33+# This program is free software: you can redistribute it and/or modify
34+# it under the terms of the GNU General Public License version 3 as
35+# published by the Free Software Foundation.
36+#
37+# This program is distributed in the hope that it will be useful,
38+# but WITHOUT ANY WARRANTY; without even the implied warranty of
39+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40+# GNU General Public License for more details.
41+#
42+# You should have received a copy of the GNU General Public License
43+# along with this program. If not, see <http://www.gnu.org/licenses/>.
44+
45+import fixtures
46+
47+from unittest import mock
48+
49+from snapcraft import help
50+from snapcraft import tests
51+
52+
53+class CommonTestCase(tests.TestCase):
54+
55+ @mock.patch('snapcraft.cmds.list_plugins')
56+ def test_topic_and_plugin_not_found_lists_plugins(self, mock_list):
57+ fake_logger = fixtures.FakeLogger()
58+ self.useFixture(fake_logger)
59+
60+ class Args:
61+ topic = 'does-not-exist'
62+ devel = False
63+
64+ help.topic(Args())
65+ self.assertTrue(mock_list.called)
66+ self.assertEqual(mock_list.call_count, 1)

Subscribers

People subscribed via source and target branches