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
=== removed directory 'snapcraft/plugins/tests'
=== removed file 'snapcraft/plugins/tests/__init__.py'
=== removed file 'snapcraft/plugins/tests/test_ubuntu.py'
--- snapcraft/plugins/tests/test_ubuntu.py 2015-08-06 01:00:44 +0000
+++ snapcraft/plugins/tests/test_ubuntu.py 1970-01-01 00:00:00 +0000
@@ -1,61 +0,0 @@
1# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
2#
3# Copyright (C) 2015 Canonical Ltd
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 3 as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17import os
18import tempfile
19from unittest.mock import (
20 Mock,
21)
22
23from snapcraft.plugins.ubuntu import UbuntuPlugin
24
25from snapcraft.tests import TestCase
26
27
28class TestUbuntu(TestCase):
29
30 def test_fix_symlinks(self):
31 tempdirObj = tempfile.TemporaryDirectory()
32 self.addCleanup(tempdirObj.cleanup)
33 tempdir = tempdirObj.name
34
35 os.makedirs(tempdir + '/a')
36 open(tempdir + '/1', mode='w').close()
37
38 os.symlink('a', tempdir + '/rel-to-a')
39 os.symlink('/a', tempdir + '/abs-to-a')
40 os.symlink('/b', tempdir + '/abs-to-b')
41 os.symlink('1', tempdir + '/rel-to-1')
42 os.symlink('/1', tempdir + '/abs-to-1')
43
44 options = Mock()
45 options.packages = ['test']
46 ubuntu = UbuntuPlugin('ubuntu', options)
47 ubuntu.fix_symlinks(debdir=tempdir)
48
49 self.assertEqual(os.readlink(tempdir + '/rel-to-a'), 'a')
50 self.assertEqual(os.readlink(tempdir + '/abs-to-a'), 'a')
51 self.assertEqual(os.readlink(tempdir + '/abs-to-b'), '/b')
52 self.assertEqual(os.readlink(tempdir + '/rel-to-1'), '1')
53 self.assertEqual(os.readlink(tempdir + '/abs-to-1'), '1')
54
55 def test_recommends_ignored_properly(self):
56 class Options:
57 packages = ['my-excellent-package']
58 ubuntu = UbuntuPlugin('myplug', Options())
59
60 self.assertTrue('my-excellent-package' in ubuntu.included_packages)
61 self.assertEqual(ubuntu.recommends, None)
620
=== modified file 'snapcraft/tests/test_ubuntu_plugin.py'
--- snapcraft/tests/test_ubuntu_plugin.py 2015-08-05 20:19:47 +0000
+++ snapcraft/tests/test_ubuntu_plugin.py 2015-08-06 18:24:36 +0000
@@ -15,6 +15,7 @@
15# along with this program. If not, see <http://www.gnu.org/licenses/>.15# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
17import logging17import logging
18import os
1819
19import fixtures20import fixtures
2021
@@ -22,14 +23,28 @@
22from snapcraft.plugins import ubuntu23from snapcraft.plugins import ubuntu
2324
2425
26class Options:
27
28 def __init__(self, packages=None, recommends=None):
29 self.packages = packages
30 self.recommends = recommends
31
32
25class UbuntuPluginTestCase(tests.TestCase):33class UbuntuPluginTestCase(tests.TestCase):
2634
35 def test_recommends_ignored_properly(self):
36 plugin = ubuntu.UbuntuPlugin(
37 'test-plugin', Options(packages=['test-package']))
38
39 self.assertTrue('test-package' in plugin.included_packages)
40 self.assertEqual(plugin.recommends, None)
41
27 def test_get_all_dep_packages_with_unrecognized_package(self):42 def test_get_all_dep_packages_with_unrecognized_package(self):
28 fake_logger = fixtures.FakeLogger(level=logging.ERROR)43 fake_logger = fixtures.FakeLogger(level=logging.ERROR)
29 self.useFixture(fake_logger)44 self.useFixture(fake_logger)
3045
31 test_options = type('obj', (object,), {'packages': False, 'recommends': False})46 plugin = ubuntu.UbuntuPlugin(
32 plugin = ubuntu.UbuntuPlugin('test_plugin', test_options)47 'test_plugin', Options(packages=['other-test-package']))
3348
34 with self.assertRaises(SystemExit) as raised:49 with self.assertRaises(SystemExit) as raised:
35 plugin.get_all_dep_packages(['test_package'])50 plugin.get_all_dep_packages(['test_package'])
@@ -37,3 +52,53 @@
37 self.assertEqual(raised.exception.code, 1, 'Wrong exit code returned.')52 self.assertEqual(raised.exception.code, 1, 'Wrong exit code returned.')
38 self.assertEqual(53 self.assertEqual(
39 "Package 'test_package' not recognized\n", fake_logger.output)54 "Package 'test_package' not recognized\n", fake_logger.output)
55
56
57class FixFileSymlinksTestCase(tests.TestCase):
58
59 scenarios = [
60 ('relative_file_path', {
61 'source_name': 'test_source_file',
62 'abs_source': False,
63 'type_': 'file',
64 'expected_link': 'test_source_file'}),
65 ('absolute_file_path', {
66 'source_name': 'test_source_file',
67 'abs_source': True,
68 'type_': 'file',
69 'expected_link': 'test_source_file'}),
70 ('relative_dir_path', {
71 'source_name': 'test_source_dir',
72 'abs_source': False,
73 'type_': 'dir',
74 'expected_link': 'test_source_dir'}),
75 ('absolute_dir_path', {
76 'source_name': 'test_source_dir',
77 'abs_source': True,
78 'type_': 'dir',
79 'expected_link': 'test_source_dir'}),
80 ('absolute_unexisting_path', {
81 'source_name': 'unexisting_test_source',
82 'abs_source': True,
83 'type_': 'unexisting',
84 'expected_link': '/unexisting_test_source'})
85 ]
86
87 def test_fix_symliks(self):
88 if self.abs_source:
89 source_path = '/' + self.source_name
90 else:
91 source_path = self.source_name
92
93 if self.type_ == 'file':
94 open(self.source_name, 'w').close()
95 elif self.type_ == 'dir':
96 os.mkdir(self.source_name)
97
98 link_name = 'test_link_name'
99 os.symlink(source_path, link_name)
100 plugin = ubuntu.UbuntuPlugin(
101 'dummy-plugin', Options(packages=['dummy-package']))
102 plugin.fix_symlinks(debdir=self.path)
103
104 self.assertEqual(os.readlink(link_name), self.expected_link)

Subscribers

People subscribed via source and target branches

to all changes: