1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# cerbero - a multi-platform build system for Open Source software
# Copyright (C) 2012 Andoni Morales Alastruey <ylatuya@gmail.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
import unittest
import os
from cerbero.config import DEFAULT_PACKAGER
from cerbero.packages import PackageType
from cerbero.packages import linux, PackagerBase
from test.test_common import DummyConfig as Config
from test.test_packages_common import Package1, create_store
packed = []
class LoggerPackager(linux.LinuxPackager):
def pack(self, output_dir, devel, force, keep_temp, pack_deps, tmpdir):
packed.append(self.package.name)
class DummyPackager(linux.LinuxPackager):
def build(self, output_dir, tarname, tmpdir, packagedir, srcdir):
linux.LinuxPackager.build(self, output_dir, tarname, tmpdir, packagedir, srcdir)
return ['test']
def create_tree(self, tmpdir):
linux.LinuxPackager.create_tree(self, tmpdir)
return ('', '', '')
class DummyTarballPackager(PackagerBase):
def pack(self, output_dir, devel=True, force=False, split=True, package_prefix=''):
return ['test']
linux.DistTarball = DummyTarballPackager
class LinuxPackagesTest(unittest.TestCase):
def setUp(self):
self.config = Config()
self.store = create_store(self.config)
self.packager = linux.LinuxPackager(self.config, self.store.get_package('gstreamer-runtime'), self.store)
def testInit(self):
config = Config()
# Test default values
package = Package1(config, None, None)
packager = linux.LinuxPackager(config, package, None)
self.assertEqual(packager.package_prefix, '')
self.assertEqual(packager.full_package_name, 'gstreamer-test1-1.0')
self.assertEqual(packager.packager, DEFAULT_PACKAGER)
# Test packages_prefix and packager
config.packages_prefix = 'test'
config.packager = 'Pin <pan@p.un>'
packager = linux.LinuxPackager(config, package, None)
self.assertEqual(packager.package_prefix, 'test-')
self.assertEqual(packager.full_package_name, 'test-gstreamer-test1-1.0')
self.assertEqual(packager.packager, 'Pin <pan@p.un>')
# Test ignore package
package.ignore_package_prefix = True
packager = linux.LinuxPackager(config, package, None)
self.assertEqual(packager.package_prefix, '')
self.assertEqual(packager.full_package_name, 'gstreamer-test1-1.0')
def testRequires(self):
self.packager._empty_packages = []
expected = sorted(['gstreamer-test-bindings', 'gstreamer-test2', 'gstreamer-test3', 'gstreamer-test1'])
requires = self.packager.get_requires(PackageType.RUNTIME, '-dev')
self.assertEqual(expected, requires)
# test devel packages
requires = self.packager.get_requires(PackageType.DEVEL, '-dev')
self.assertEqual([], requires)
self.store.get_package('gstreamer-test1').has_devel_package = True
requires = self.packager.get_requires(PackageType.DEVEL, '-dev')
self.assertEqual(['gstreamer-test1-dev'], requires)
for p in expected:
self.store.get_package(p).has_devel_package = True
requires = self.packager.get_requires(PackageType.DEVEL, '-dev')
self.assertEqual([x + '-dev' for x in expected], requires)
# test empty packages
self.packager._empty_packages = [self.store.get_package('gstreamer-test2')]
requires = self.packager.get_requires(PackageType.RUNTIME, '-dev')
expected.remove('gstreamer-test2')
self.assertEqual(expected, requires)
def testMetaPackageRequires(self):
self.packager._empty_packages = []
expected = (['gstreamer-test1'], ['gstreamer-test3'], ['gstreamer-test-bindings'])
self.store.get_package('gstreamer-test1').has_runtime_package = True
self.store.get_package('gstreamer-test3').has_runtime_package = True
self.store.get_package('gstreamer-test-bindings').has_runtime_package = True
requires = self.packager.get_meta_requires(PackageType.RUNTIME, '')
self.assertEqual(expected, requires)
# test devel packages
requires = self.packager.get_meta_requires(PackageType.DEVEL, '-dev')
self.assertEqual(([], [], []), requires)
# test empty packages
self.store.get_package('gstreamer-test1').has_devel_package = True
requires = self.packager.get_meta_requires(PackageType.DEVEL, '-dev')
self.assertEqual((['gstreamer-test1-dev'], [], []), requires)
for p in [self.store.get_package(x[0]) for x in expected]:
p.has_devel_package = True
requires = self.packager.get_meta_requires(PackageType.DEVEL, '-dev')
expected = (['gstreamer-test1-dev'], ['gstreamer-test3-dev'], ['gstreamer-test-bindings-dev'])
self.assertEqual(expected, requires)
def testPackDeps(self):
expected = sorted(['gstreamer-test-bindings', 'gstreamer-test2', 'gstreamer-test3', 'gstreamer-test1'])
self.packager = LoggerPackager(self.config, self.store.get_package('gstreamer-runtime'), self.store)
self.packager.devel = False
self.packager.force = False
global packed
packed = []
self.packager.pack_deps('', '', True)
self.assertEqual(sorted(packed), expected)
packed = []
self.packager.devel = False
self.packager.pack_deps('', '', True)
self.assertEqual(sorted(packed), expected)
packed = []
def testPack(self):
self.packager = DummyPackager(self.config, self.store.get_package('gstreamer-runtime'), self.store)
paths = self.packager.pack('', False, True, True, False, None)
self.assertTrue(os.path.exists('gstreamer-runtime-stamp'))
os.remove('gstreamer-runtime-stamp')
self.assertEqual(paths, ['test'])
self.packager = DummyPackager(self.config, self.store.get_package('gstreamer-test1'), self.store)
paths = self.packager.pack('', False, True, True, False, None)
self.assertTrue(os.path.exists('gstreamer-test1-stamp'))
os.remove('gstreamer-test1-stamp')
self.assertEqual(paths, ['test'])
|