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

Proposed by Sergio Schvezov
Status: Merged
Approved by: Leo Arias
Approved revision: 240
Merged at revision: 240
Proposed branch: lp:~sergiusens/snapcraft/1499424
Merge into: lp:~snappy-dev/snapcraft/core
Diff against target: 64 lines (+25/-5)
2 files modified
snapcraft/__init__.py (+6/-4)
snapcraft/tests/test_base_plugin.py (+19/-1)
To merge this branch: bzr merge lp:~sergiusens/snapcraft/1499424
Reviewer Review Type Date Requested Status
Leo Arias (community) Approve
Review via email: mp+274460@code.launchpad.net

Commit message

Exit cleanly with an error when using the source keyword with a local file

To post a comment you must log in.
Revision history for this message
Leo Arias (elopio) wrote :

Good. Now maybe we need a way to make it clearer that the local source must be a directory?

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'snapcraft/__init__.py'
2--- snapcraft/__init__.py 2015-10-09 17:43:20 +0000
3+++ snapcraft/__init__.py 2015-10-14 20:02:31 +0000
4@@ -131,9 +131,9 @@
5 source_branch=None):
6 try:
7 handler_class = _get_source_handler(source_type, source)
8- except ValueError:
9- logger.error("Unrecognized source '%s' for part '%s'.", source,
10- self.name)
11+ except ValueError as e:
12+ logger.error('Unrecognized source %r for part %r: %s.', source,
13+ self.name, e)
14 snapcraft.common.fatal()
15
16 try:
17@@ -209,6 +209,8 @@
18 elif re.compile(r'.*\.((tar\.(xz|gz|bz2))|tgz)$').match(source):
19 source_type = 'tar'
20 elif snapcraft.common.isurl(source):
21- raise ValueError()
22+ raise ValueError('No handler to manage source')
23+ elif not os.path.isdir(source):
24+ raise ValueError('Local source is not a directory')
25
26 return source_type
27
28=== modified file 'snapcraft/tests/test_base_plugin.py'
29--- snapcraft/tests/test_base_plugin.py 2015-10-02 09:13:00 +0000
30+++ snapcraft/tests/test_base_plugin.py 2015-10-14 20:02:31 +0000
31@@ -17,6 +17,7 @@
32 import fixtures
33 import logging
34 import os
35+import unittest.mock
36
37 import snapcraft
38 from snapcraft import tests
39@@ -43,7 +44,24 @@
40 self.assertEqual(raised.exception.code, 1, 'Wrong exit code returned.')
41 expected = (
42 "Unrecognized source 'unrecognized://test_source' for part "
43- "'test_plugin'.\n")
44+ "'test_plugin': No handler to manage source.\n")
45+ self.assertEqual(expected, fake_logger.output)
46+
47+ @unittest.mock.patch('os.path.isdir')
48+ def test_local_non_dir_source_path_must_raise_error(self, mock_isdir):
49+ fake_logger = fixtures.FakeLogger(level=logging.ERROR)
50+ self.useFixture(fake_logger)
51+
52+ mock_isdir.return_value = False
53+ plugin = snapcraft.BasePlugin('test_plugin', 'dummy_options')
54+ with self.assertRaises(SystemExit) as raised:
55+ plugin.get_source('file')
56+
57+ mock_isdir.assert_called_once_with('file')
58+ self.assertEqual(raised.exception.code, 1, 'Wrong exit code returned.')
59+ expected = (
60+ "Unrecognized source 'file' for part 'test_plugin': "
61+ "Local source is not a directory.\n")
62 self.assertEqual(expected, fake_logger.output)
63
64 def test_makedirs_with_existing_dir(self):

Subscribers

People subscribed via source and target branches