Merge lp:~elopio/snapcraft/makedirs into lp:~snappy-dev/snapcraft/core

Proposed by Leo Arias
Status: Merged
Approved by: Leo Arias
Approved revision: 121
Merged at revision: 124
Proposed branch: lp:~elopio/snapcraft/makedirs
Merge into: lp:~snappy-dev/snapcraft/core
Diff against target: 184 lines (+61/-42)
3 files modified
debian/control (+1/-1)
snapcraft/plugin.py (+13/-26)
snapcraft/tests/test_plugin.py (+47/-15)
To merge this branch: bzr merge lp:~elopio/snapcraft/makedirs
Reviewer Review Type Date Requested Status
Michael Terry (community) Approve
Review via email: mp+266979@code.launchpad.net

Commit message

Refactored the plugin makedirs, with tests. Added python3 >= 3.2 as a dependency, needed by makedirs exist_ok argument.

To post a comment you must log in.
Revision history for this message
Michael Terry (mterry) wrote :

LGTM, thanks Leo!

review: Approve
Revision history for this message
Snappy Tarmac (snappydevtarmac) wrote :

The attempt to merge lp:~elopio/snapcraft/makedirs into lp:snapcraft failed. Below is the output from the failed tests.

wget -c http://0.0.0.0:46923/test.tar

parts:
cp --preserve=all zzz /tmp/tmpwbwvn8c3/parts/copy/install/zzz
cp --preserve=all src /tmp/tmp548v9y6s/parts/copy/install/dst
cp --preserve=all src /tmp/tmp7m_60hbh/parts/copy/install/dir/dst

.........--2015-08-05 14:20:49-- http://0.0.0.0:46923/test.tar
Connecting to 0.0.0.0:46923... connected.
HTTP request sent, awaiting response... 200 OK
Length: 22 [text/html]
Saving to: ‘test.tar’

     0K 100% 313M=0s

2015-08-05 14:20:49 (313 MB/s) - ‘test.tar’ saved [22/22]

....Warning: unable to find "test_relexepath" in the path
...........EE....EE.......
======================================================================
ERROR: test_makedirs_with_existing_dirs (snapcraft.tests.test_plugin.PluginMakedirsTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/tarmac/branch.Edc9Te/snapcraft/tests/test_plugin.py", line 205, in test_makedirs_with_existing_dirs
    p.makedirs()
  File "/tmp/tarmac/branch.Edc9Te/snapcraft/plugin.py", line 133, in makedirs
    os.makedirs(d, exists_ok=True)
TypeError: makedirs() got an unexpected keyword argument 'exists_ok'

======================================================================
ERROR: test_makedirs_with_existing_dirs (snapcraft.tests.test_plugin.PluginMakedirsTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/tarmac/branch.Edc9Te/snapcraft/tests/test_plugin.py", line 205, in test_makedirs_with_existing_dirs
    p.makedirs()
  File "/tmp/tarmac/branch.Edc9Te/snapcraft/plugin.py", line 133, in makedirs
    os.makedirs(d, exists_ok=True)
TypeError: makedirs() got an unexpected keyword argument 'exists_ok'

======================================================================
ERROR: test_is_dirty (snapcraft.tests.test_plugin.PluginTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/tarmac/branch.Edc9Te/snapcraft/tests/test_plugin.py", line 61, in test_is_dirty
    p.pull()
  File "/tmp/tarmac/branch.Edc9Te/snapcraft/plugin.py", line 165, in pull
    self.makedirs()
  File "/tmp/tarmac/branch.Edc9Te/snapcraft/plugin.py", line 133, in makedirs
    os.makedirs(d, exists_ok=True)
TypeError: makedirs() got an unexpected keyword argument 'exists_ok'

======================================================================
ERROR: test_is_dirty (snapcraft.tests.test_plugin.PluginTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.4/unittest/case.py", line 57, in testPartExecutor
    yield
  File "/usr/lib/python3.4/unittest/case.py", line 615, in doCleanups
    function(*args, **kwargs)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpjmz3ufkk'

----------------------------------------------------------------------
Ran 38 tests in 0.698s

FAILED (errors=4)

lp:~elopio/snapcraft/makedirs updated
121. By Leo Arias

Fixed typo on the exist argument.

Revision history for this message
Leo Arias (elopio) wrote :

Sorry, a typo. It's exist_ok instead of exists_ok. I must have done something stupid when running the tests after the last push.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/control'
--- debian/control 2015-08-04 21:37:07 +0000
+++ debian/control 2015-08-05 14:26:20 +0000
@@ -11,7 +11,7 @@
11 pep8,11 pep8,
12 plainbox,12 plainbox,
13 pyflakes,13 pyflakes,
14 python3,14 python3 (>= 3.2),
15 python3-apt,15 python3-apt,
16 python3-fixtures,16 python3-fixtures,
17 python3-setuptools,17 python3-setuptools,
1818
=== modified file 'snapcraft/plugin.py'
--- snapcraft/plugin.py 2015-07-24 16:55:44 +0000
+++ snapcraft/plugin.py 2015-08-05 14:26:20 +0000
@@ -54,12 +54,13 @@
54 self.deps = []54 self.deps = []
55 self.plugin_name = name55 self.plugin_name = name
5656
57 self.sourcedir = os.path.join(os.getcwd(), "parts", part_name, "src")57 parts_dir = os.path.join(os.getcwd(), 'parts')
58 self.builddir = os.path.join(os.getcwd(), "parts", part_name, "build")58 self.sourcedir = os.path.join(parts_dir, part_name, 'src')
59 self.installdir = os.path.join(os.getcwd(), "parts", part_name, "install")59 self.builddir = os.path.join(parts_dir, part_name, 'build')
60 self.stagedir = os.path.join(os.getcwd(), "stage")60 self.installdir = os.path.join(parts_dir, part_name, 'install')
61 self.snapdir = os.path.join(os.getcwd(), "snap")61 self.stagedir = os.path.join(os.getcwd(), 'stage')
62 self.statefile = os.path.join(os.getcwd(), "parts", part_name, "state")62 self.snapdir = os.path.join(os.getcwd(), 'snap')
63 self.statefile = os.path.join(parts_dir, part_name, 'state')
6364
64 try:65 try:
65 if load_config:66 if load_config:
@@ -124,26 +125,12 @@
124 return self.part_names[0]125 return self.part_names[0]
125126
126 def makedirs(self):127 def makedirs(self):
127 try:128 dirs = [
128 os.makedirs(self.sourcedir)129 self.sourcedir, self.builddir, self.installdir, self.stagedir,
129 except FileExistsError:130 self.snapdir
130 pass131 ]
131 try:132 for d in dirs:
132 os.makedirs(self.builddir)133 os.makedirs(d, exist_ok=True)
133 except FileExistsError:
134 pass
135 try:
136 os.makedirs(self.installdir)
137 except FileExistsError:
138 pass
139 try:
140 os.makedirs(self.stagedir)
141 except FileExistsError:
142 pass
143 try:
144 os.makedirs(self.snapdir)
145 except FileExistsError:
146 pass
147134
148 def is_valid(self):135 def is_valid(self):
149 return self.valid136 return self.valid
150137
=== modified file 'snapcraft/tests/test_plugin.py'
--- snapcraft/tests/test_plugin.py 2015-07-23 18:30:21 +0000
+++ snapcraft/tests/test_plugin.py 2015-08-05 14:26:20 +0000
@@ -32,27 +32,28 @@
32from snapcraft.tests import mock_plugin32from snapcraft.tests import mock_plugin
3333
3434
35class TestPlugin(tests.TestCase):35def get_test_plugin(name='mock', part_name='mock-part',
3636 properties=None, load_code=False, load_config=False):
37 def get_test_plugin(self, name='mock', part_name='mock-part',37 if properties is None:
38 properties=None, load_code=False, load_config=False):38 properties = {}
39 if properties is None:39 return plugin.PluginHandler(
40 properties = {}40 name, part_name, properties, load_code=load_code,
41 return plugin.PluginHandler(41 load_config=load_config)
42 name, part_name, properties, load_code=load_code,42
43 load_config=load_config)43
44class PluginTestCase(tests.TestCase):
4445
45 def test_init_unknown_plugin_must_log_error(self):46 def test_init_unknown_plugin_must_log_error(self):
46 fake_logger = fixtures.FakeLogger(level=logging.ERROR)47 fake_logger = fixtures.FakeLogger(level=logging.ERROR)
47 self.useFixture(fake_logger)48 self.useFixture(fake_logger)
4849
49 self.get_test_plugin('test_unexisting_name', load_config=True)50 get_test_plugin('test_unexisting_name', load_config=True)
5051
51 self.assertEqual(52 self.assertEqual(
52 'Unknown plugin: test_unexisting_name\n', fake_logger.output)53 'Unknown plugin: test_unexisting_name\n', fake_logger.output)
5354
54 def test_is_dirty(self):55 def test_is_dirty(self):
55 p = self.get_test_plugin()56 p = get_test_plugin()
56 p.statefile = tempfile.NamedTemporaryFile().name57 p.statefile = tempfile.NamedTemporaryFile().name
57 self.addCleanup(os.remove, p.statefile)58 self.addCleanup(os.remove, p.statefile)
58 p.code = Mock()59 p.code = Mock()
@@ -65,7 +66,7 @@
65 self.assertFalse(p.code.pull.called)66 self.assertFalse(p.code.pull.called)
6667
67 def test_collect_snap_files(self):68 def test_collect_snap_files(self):
68 p = self.get_test_plugin()69 p = get_test_plugin()
6970
70 tmpdirObject = tempfile.TemporaryDirectory()71 tmpdirObject = tempfile.TemporaryDirectory()
71 self.addCleanup(tmpdirObject.cleanup)72 self.addCleanup(tmpdirObject.cleanup)
@@ -116,7 +117,7 @@
116 fake_logger = fixtures.FakeLogger(level=logging.INFO)117 fake_logger = fixtures.FakeLogger(level=logging.INFO)
117 self.useFixture(fake_logger)118 self.useFixture(fake_logger)
118119
119 p = self.get_test_plugin()120 p = get_test_plugin()
120 p.notify_stage('test stage')121 p.notify_stage('test stage')
121122
122 self.assertEqual('test stage mock-part\n', fake_logger.output)123 self.assertEqual('test stage mock-part\n', fake_logger.output)
@@ -145,7 +146,7 @@
145 "mock", "mock-part", {}, load_config=False, load_code=True)146 "mock", "mock-part", {}, load_config=False, load_code=True)
146147
147 def test_collect_snap_files_with_absolute_includes_must_raise_error(self):148 def test_collect_snap_files_with_absolute_includes_must_raise_error(self):
148 p = self.get_test_plugin()149 p = get_test_plugin()
149 with self.assertRaises(plugin.PluginError) as raised:150 with self.assertRaises(plugin.PluginError) as raised:
150 p.collect_snap_files(includes=['rel', '/abs/include'], excludes=[])151 p.collect_snap_files(includes=['rel', '/abs/include'], excludes=[])
151152
@@ -153,7 +154,7 @@
153 "path '/abs/include' must be relative", str(raised.exception))154 "path '/abs/include' must be relative", str(raised.exception))
154155
155 def test_collect_snap_files_with_absolute_excludes_must_raise_error(self):156 def test_collect_snap_files_with_absolute_excludes_must_raise_error(self):
156 p = self.get_test_plugin()157 p = get_test_plugin()
157 with self.assertRaises(plugin.PluginError) as raised:158 with self.assertRaises(plugin.PluginError) as raised:
158 p.collect_snap_files(includes=[], excludes=['rel', '/abs/exclude'])159 p.collect_snap_files(includes=[], excludes=['rel', '/abs/exclude'])
159160
@@ -173,3 +174,34 @@
173 'Unknown plugin: test_unexisting_name\n'174 'Unknown plugin: test_unexisting_name\n'
174 'Could not load part test_unexisting_name\n',175 'Could not load part test_unexisting_name\n',
175 fake_logger.output)176 fake_logger.output)
177
178
179class PluginMakedirsTestCase(tests.TestCase):
180
181 scenarios = [
182 ('existing_dirs', {'make_dirs': True}),
183 ('unexisting_dirs', {'make_dirs': False})
184 ]
185
186 def get_plugin_dirs(self, part_name):
187 parts_dir = os.path.join(self.path, 'parts')
188 return [
189 os.path.join(parts_dir, part_name, 'src'),
190 os.path.join(parts_dir, part_name, 'build'),
191 os.path.join(parts_dir, part_name, 'install'),
192 os.path.join(self.path, 'stage'),
193 os.path.join(self.path, 'snap')
194 ]
195
196 def test_makedirs_with_existing_dirs(self):
197 part_name = 'test_part'
198 dirs = self.get_plugin_dirs(part_name)
199 if self.make_dirs:
200 os.makedirs(os.path.join('parts', part_name))
201 for d in dirs:
202 os.mkdir(d)
203
204 p = get_test_plugin(part_name=part_name)
205 p.makedirs()
206 for d in dirs:
207 self.assertTrue(os.path.exists(d), '{} does not exist'.format(d))

Subscribers

People subscribed via source and target branches

to all changes: