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

Proposed by Leo Arias
Status: Rejected
Rejected by: Sergio Schvezov
Proposed branch: lp:~elopio/snapcraft/symlinks
Merge into: lp:~snappy-dev/snapcraft/core
Diff against target: 164 lines (+67/-63)
2 files modified
snapcraft/plugins/tests/test_ubuntu.py (+0/-61)
snapcraft/tests/test_ubuntu_plugin.py (+67/-2)
To merge this branch: bzr merge lp:~elopio/snapcraft/symlinks
Reviewer Review Type Date Requested Status
Sergio Schvezov Disapprove
Review via email: mp+267218@code.launchpad.net

Commit message

Joined the ubuntu plugin unit tests.

Description of the change

I found another ubuntu plugin tests file. IMO, it's better to keep all the tests in the same directory, so I moved them to snapcraft/tests. If we add many tests for plugins, we can make a directory snapcraft/tests/plugins.

To post a comment you must log in.
lp:~elopio/snapcraft/symlinks updated
132. By Leo Arias

Fixed flakes.

133. By Leo Arias

Clear the test values.

Revision history for this message
Sergio Schvezov (sergiusens) wrote :

I'm going to reject this as it is no longer as relevant with filesets.

review: Disapprove

Unmerged revisions

133. By Leo Arias

Clear the test values.

132. By Leo Arias

Fixed flakes.

131. By Leo Arias

Use scenarios for symlinks.

130. By Leo Arias

Joined the ubuntu plugin unit tests.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed directory 'snapcraft/plugins/tests'
2=== removed file 'snapcraft/plugins/tests/__init__.py'
3=== removed file 'snapcraft/plugins/tests/test_ubuntu.py'
4--- snapcraft/plugins/tests/test_ubuntu.py 2015-08-06 01:00:44 +0000
5+++ snapcraft/plugins/tests/test_ubuntu.py 1970-01-01 00:00:00 +0000
6@@ -1,61 +0,0 @@
7-# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
8-#
9-# Copyright (C) 2015 Canonical Ltd
10-#
11-# This program is free software: you can redistribute it and/or modify
12-# it under the terms of the GNU General Public License version 3 as
13-# published by the Free Software Foundation.
14-#
15-# This program is distributed in the hope that it will be useful,
16-# but WITHOUT ANY WARRANTY; without even the implied warranty of
17-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18-# GNU General Public License for more details.
19-#
20-# You should have received a copy of the GNU General Public License
21-# along with this program. If not, see <http://www.gnu.org/licenses/>.
22-
23-import os
24-import tempfile
25-from unittest.mock import (
26- Mock,
27-)
28-
29-from snapcraft.plugins.ubuntu import UbuntuPlugin
30-
31-from snapcraft.tests import TestCase
32-
33-
34-class TestUbuntu(TestCase):
35-
36- def test_fix_symlinks(self):
37- tempdirObj = tempfile.TemporaryDirectory()
38- self.addCleanup(tempdirObj.cleanup)
39- tempdir = tempdirObj.name
40-
41- os.makedirs(tempdir + '/a')
42- open(tempdir + '/1', mode='w').close()
43-
44- os.symlink('a', tempdir + '/rel-to-a')
45- os.symlink('/a', tempdir + '/abs-to-a')
46- os.symlink('/b', tempdir + '/abs-to-b')
47- os.symlink('1', tempdir + '/rel-to-1')
48- os.symlink('/1', tempdir + '/abs-to-1')
49-
50- options = Mock()
51- options.packages = ['test']
52- ubuntu = UbuntuPlugin('ubuntu', options)
53- ubuntu.fix_symlinks(debdir=tempdir)
54-
55- self.assertEqual(os.readlink(tempdir + '/rel-to-a'), 'a')
56- self.assertEqual(os.readlink(tempdir + '/abs-to-a'), 'a')
57- self.assertEqual(os.readlink(tempdir + '/abs-to-b'), '/b')
58- self.assertEqual(os.readlink(tempdir + '/rel-to-1'), '1')
59- self.assertEqual(os.readlink(tempdir + '/abs-to-1'), '1')
60-
61- def test_recommends_ignored_properly(self):
62- class Options:
63- packages = ['my-excellent-package']
64- ubuntu = UbuntuPlugin('myplug', Options())
65-
66- self.assertTrue('my-excellent-package' in ubuntu.included_packages)
67- self.assertEqual(ubuntu.recommends, None)
68
69=== modified file 'snapcraft/tests/test_ubuntu_plugin.py'
70--- snapcraft/tests/test_ubuntu_plugin.py 2015-08-05 20:19:47 +0000
71+++ snapcraft/tests/test_ubuntu_plugin.py 2015-08-06 18:24:36 +0000
72@@ -15,6 +15,7 @@
73 # along with this program. If not, see <http://www.gnu.org/licenses/>.
74
75 import logging
76+import os
77
78 import fixtures
79
80@@ -22,14 +23,28 @@
81 from snapcraft.plugins import ubuntu
82
83
84+class Options:
85+
86+ def __init__(self, packages=None, recommends=None):
87+ self.packages = packages
88+ self.recommends = recommends
89+
90+
91 class UbuntuPluginTestCase(tests.TestCase):
92
93+ def test_recommends_ignored_properly(self):
94+ plugin = ubuntu.UbuntuPlugin(
95+ 'test-plugin', Options(packages=['test-package']))
96+
97+ self.assertTrue('test-package' in plugin.included_packages)
98+ self.assertEqual(plugin.recommends, None)
99+
100 def test_get_all_dep_packages_with_unrecognized_package(self):
101 fake_logger = fixtures.FakeLogger(level=logging.ERROR)
102 self.useFixture(fake_logger)
103
104- test_options = type('obj', (object,), {'packages': False, 'recommends': False})
105- plugin = ubuntu.UbuntuPlugin('test_plugin', test_options)
106+ plugin = ubuntu.UbuntuPlugin(
107+ 'test_plugin', Options(packages=['other-test-package']))
108
109 with self.assertRaises(SystemExit) as raised:
110 plugin.get_all_dep_packages(['test_package'])
111@@ -37,3 +52,53 @@
112 self.assertEqual(raised.exception.code, 1, 'Wrong exit code returned.')
113 self.assertEqual(
114 "Package 'test_package' not recognized\n", fake_logger.output)
115+
116+
117+class FixFileSymlinksTestCase(tests.TestCase):
118+
119+ scenarios = [
120+ ('relative_file_path', {
121+ 'source_name': 'test_source_file',
122+ 'abs_source': False,
123+ 'type_': 'file',
124+ 'expected_link': 'test_source_file'}),
125+ ('absolute_file_path', {
126+ 'source_name': 'test_source_file',
127+ 'abs_source': True,
128+ 'type_': 'file',
129+ 'expected_link': 'test_source_file'}),
130+ ('relative_dir_path', {
131+ 'source_name': 'test_source_dir',
132+ 'abs_source': False,
133+ 'type_': 'dir',
134+ 'expected_link': 'test_source_dir'}),
135+ ('absolute_dir_path', {
136+ 'source_name': 'test_source_dir',
137+ 'abs_source': True,
138+ 'type_': 'dir',
139+ 'expected_link': 'test_source_dir'}),
140+ ('absolute_unexisting_path', {
141+ 'source_name': 'unexisting_test_source',
142+ 'abs_source': True,
143+ 'type_': 'unexisting',
144+ 'expected_link': '/unexisting_test_source'})
145+ ]
146+
147+ def test_fix_symliks(self):
148+ if self.abs_source:
149+ source_path = '/' + self.source_name
150+ else:
151+ source_path = self.source_name
152+
153+ if self.type_ == 'file':
154+ open(self.source_name, 'w').close()
155+ elif self.type_ == 'dir':
156+ os.mkdir(self.source_name)
157+
158+ link_name = 'test_link_name'
159+ os.symlink(source_path, link_name)
160+ plugin = ubuntu.UbuntuPlugin(
161+ 'dummy-plugin', Options(packages=['dummy-package']))
162+ plugin.fix_symlinks(debdir=self.path)
163+
164+ self.assertEqual(os.readlink(link_name), self.expected_link)

Subscribers

People subscribed via source and target branches

to all changes: