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
1=== modified file 'debian/control'
2--- debian/control 2015-08-04 21:37:07 +0000
3+++ debian/control 2015-08-05 14:26:20 +0000
4@@ -11,7 +11,7 @@
5 pep8,
6 plainbox,
7 pyflakes,
8- python3,
9+ python3 (>= 3.2),
10 python3-apt,
11 python3-fixtures,
12 python3-setuptools,
13
14=== modified file 'snapcraft/plugin.py'
15--- snapcraft/plugin.py 2015-07-24 16:55:44 +0000
16+++ snapcraft/plugin.py 2015-08-05 14:26:20 +0000
17@@ -54,12 +54,13 @@
18 self.deps = []
19 self.plugin_name = name
20
21- self.sourcedir = os.path.join(os.getcwd(), "parts", part_name, "src")
22- self.builddir = os.path.join(os.getcwd(), "parts", part_name, "build")
23- self.installdir = os.path.join(os.getcwd(), "parts", part_name, "install")
24- self.stagedir = os.path.join(os.getcwd(), "stage")
25- self.snapdir = os.path.join(os.getcwd(), "snap")
26- self.statefile = os.path.join(os.getcwd(), "parts", part_name, "state")
27+ parts_dir = os.path.join(os.getcwd(), 'parts')
28+ self.sourcedir = os.path.join(parts_dir, part_name, 'src')
29+ self.builddir = os.path.join(parts_dir, part_name, 'build')
30+ self.installdir = os.path.join(parts_dir, part_name, 'install')
31+ self.stagedir = os.path.join(os.getcwd(), 'stage')
32+ self.snapdir = os.path.join(os.getcwd(), 'snap')
33+ self.statefile = os.path.join(parts_dir, part_name, 'state')
34
35 try:
36 if load_config:
37@@ -124,26 +125,12 @@
38 return self.part_names[0]
39
40 def makedirs(self):
41- try:
42- os.makedirs(self.sourcedir)
43- except FileExistsError:
44- pass
45- try:
46- os.makedirs(self.builddir)
47- except FileExistsError:
48- pass
49- try:
50- os.makedirs(self.installdir)
51- except FileExistsError:
52- pass
53- try:
54- os.makedirs(self.stagedir)
55- except FileExistsError:
56- pass
57- try:
58- os.makedirs(self.snapdir)
59- except FileExistsError:
60- pass
61+ dirs = [
62+ self.sourcedir, self.builddir, self.installdir, self.stagedir,
63+ self.snapdir
64+ ]
65+ for d in dirs:
66+ os.makedirs(d, exist_ok=True)
67
68 def is_valid(self):
69 return self.valid
70
71=== modified file 'snapcraft/tests/test_plugin.py'
72--- snapcraft/tests/test_plugin.py 2015-07-23 18:30:21 +0000
73+++ snapcraft/tests/test_plugin.py 2015-08-05 14:26:20 +0000
74@@ -32,27 +32,28 @@
75 from snapcraft.tests import mock_plugin
76
77
78-class TestPlugin(tests.TestCase):
79-
80- def get_test_plugin(self, name='mock', part_name='mock-part',
81- properties=None, load_code=False, load_config=False):
82- if properties is None:
83- properties = {}
84- return plugin.PluginHandler(
85- name, part_name, properties, load_code=load_code,
86- load_config=load_config)
87+def get_test_plugin(name='mock', part_name='mock-part',
88+ properties=None, load_code=False, load_config=False):
89+ if properties is None:
90+ properties = {}
91+ return plugin.PluginHandler(
92+ name, part_name, properties, load_code=load_code,
93+ load_config=load_config)
94+
95+
96+class PluginTestCase(tests.TestCase):
97
98 def test_init_unknown_plugin_must_log_error(self):
99 fake_logger = fixtures.FakeLogger(level=logging.ERROR)
100 self.useFixture(fake_logger)
101
102- self.get_test_plugin('test_unexisting_name', load_config=True)
103+ get_test_plugin('test_unexisting_name', load_config=True)
104
105 self.assertEqual(
106 'Unknown plugin: test_unexisting_name\n', fake_logger.output)
107
108 def test_is_dirty(self):
109- p = self.get_test_plugin()
110+ p = get_test_plugin()
111 p.statefile = tempfile.NamedTemporaryFile().name
112 self.addCleanup(os.remove, p.statefile)
113 p.code = Mock()
114@@ -65,7 +66,7 @@
115 self.assertFalse(p.code.pull.called)
116
117 def test_collect_snap_files(self):
118- p = self.get_test_plugin()
119+ p = get_test_plugin()
120
121 tmpdirObject = tempfile.TemporaryDirectory()
122 self.addCleanup(tmpdirObject.cleanup)
123@@ -116,7 +117,7 @@
124 fake_logger = fixtures.FakeLogger(level=logging.INFO)
125 self.useFixture(fake_logger)
126
127- p = self.get_test_plugin()
128+ p = get_test_plugin()
129 p.notify_stage('test stage')
130
131 self.assertEqual('test stage mock-part\n', fake_logger.output)
132@@ -145,7 +146,7 @@
133 "mock", "mock-part", {}, load_config=False, load_code=True)
134
135 def test_collect_snap_files_with_absolute_includes_must_raise_error(self):
136- p = self.get_test_plugin()
137+ p = get_test_plugin()
138 with self.assertRaises(plugin.PluginError) as raised:
139 p.collect_snap_files(includes=['rel', '/abs/include'], excludes=[])
140
141@@ -153,7 +154,7 @@
142 "path '/abs/include' must be relative", str(raised.exception))
143
144 def test_collect_snap_files_with_absolute_excludes_must_raise_error(self):
145- p = self.get_test_plugin()
146+ p = get_test_plugin()
147 with self.assertRaises(plugin.PluginError) as raised:
148 p.collect_snap_files(includes=[], excludes=['rel', '/abs/exclude'])
149
150@@ -173,3 +174,34 @@
151 'Unknown plugin: test_unexisting_name\n'
152 'Could not load part test_unexisting_name\n',
153 fake_logger.output)
154+
155+
156+class PluginMakedirsTestCase(tests.TestCase):
157+
158+ scenarios = [
159+ ('existing_dirs', {'make_dirs': True}),
160+ ('unexisting_dirs', {'make_dirs': False})
161+ ]
162+
163+ def get_plugin_dirs(self, part_name):
164+ parts_dir = os.path.join(self.path, 'parts')
165+ return [
166+ os.path.join(parts_dir, part_name, 'src'),
167+ os.path.join(parts_dir, part_name, 'build'),
168+ os.path.join(parts_dir, part_name, 'install'),
169+ os.path.join(self.path, 'stage'),
170+ os.path.join(self.path, 'snap')
171+ ]
172+
173+ def test_makedirs_with_existing_dirs(self):
174+ part_name = 'test_part'
175+ dirs = self.get_plugin_dirs(part_name)
176+ if self.make_dirs:
177+ os.makedirs(os.path.join('parts', part_name))
178+ for d in dirs:
179+ os.mkdir(d)
180+
181+ p = get_test_plugin(part_name=part_name)
182+ p.makedirs()
183+ for d in dirs:
184+ self.assertTrue(os.path.exists(d), '{} does not exist'.format(d))

Subscribers

People subscribed via source and target branches

to all changes: