summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndoni Morales Alastruey <ylatuya@gmail.com>2012-05-09 22:26:43 +0200
committerAndoni Morales Alastruey <ylatuya@gmail.com>2012-05-10 10:45:49 +0200
commitbf288bbc02e10d659f84fe5abc874cf841f61056 (patch)
tree9db6c1310f3f93db30101aa2572c69be24fea502 /test
parent76849d97274b9c9efa76a85491c5c8d8bdcc1b15 (diff)
packages: clean up linux packager and add unit tests
Diffstat (limited to 'test')
-rw-r--r--test/test_cerbero_packages_linux.py179
-rw-r--r--test/test_common.py5
2 files changed, 183 insertions, 1 deletions
diff --git a/test/test_cerbero_packages_linux.py b/test/test_cerbero_packages_linux.py
new file mode 100644
index 0000000..e1b99ca
--- /dev/null
+++ b/test/test_cerbero_packages_linux.py
@@ -0,0 +1,179 @@
+# 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, 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.assertEquals(packager.package_prefix, '')
+ self.assertEquals(packager.full_package_name, 'gstreamer-test1-1.0')
+ self.assertEquals(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.assertEquals(packager.package_prefix, 'test-')
+ self.assertEquals(packager.full_package_name,
+ 'test-gstreamer-test1-1.0')
+ self.assertEquals(packager.packager, 'Pin <pan@p.un>')
+
+ # Test ignore package
+ package.ignore_package_prefix = True
+ packager = linux.LinuxPackager(config, package, None)
+ self.assertEquals(packager.package_prefix, '')
+ self.assertEquals(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.assertEquals(expected, requires)
+
+ # test devel packages
+ requires = self.packager.get_requires(PackageType.DEVEL, '-dev')
+ self.assertEquals([], requires)
+ self.store.get_package('gstreamer-test1').has_devel_package = True
+ requires = self.packager.get_requires(PackageType.DEVEL, '-dev')
+ self.assertEquals(['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.assertEquals([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.assertEquals(expected, requires)
+
+ def testMetaPackageRequires(self):
+ self.packager._empty_packages = []
+ expected = (['gstreamer-test1'],
+ ['gstreamer-test3'],
+ ['gstreamer-test-bindings'])
+ requires = self.packager.get_meta_requires(PackageType.RUNTIME, '-dev')
+ self.assertEquals(expected, requires)
+
+ # test devel packages
+ requires = self.packager.get_meta_requires(PackageType.DEVEL, '-dev')
+ self.assertEquals(([], [], []), requires)
+
+ # test empty packages
+ self.store.get_package('gstreamer-test1').has_devel_package = True
+ requires = self.packager.get_meta_requires(PackageType.DEVEL, '-dev')
+ self.assertEquals((['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.assertEquals(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.assertEquals(sorted(packed), expected)
+ packed = []
+
+ self.packager.devel = False
+ self.packager.pack_deps('', '', True)
+ self.assertEquals(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, False, None)
+ self.assertTrue(os.path.exists('gstreamer-runtime-stamp'))
+ os.remove('gstreamer-runtime-stamp')
+ self.assertEquals(paths, ['test'])
+
+ self.packager = DummyPackager(self.config,
+ self.store.get_package('gstreamer-test1'), self.store)
+ paths = self.packager.pack('', False, True, False, None)
+ self.assertTrue(os.path.exists('gstreamer-test1-stamp'))
+ os.remove('gstreamer-test1-stamp')
+ self.assertEquals(paths, ['test'])
diff --git a/test/test_common.py b/test/test_common.py
index 2932be0..d03988d 100644
--- a/test/test_common.py
+++ b/test/test_common.py
@@ -16,12 +16,13 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
-from cerbero.config import Platform
+from cerbero.config import Platform, Distro, DEFAULT_PACKAGER
class DummyConfig(object):
prefix = '/test/'
target_platform = Platform.WINDOWS
+ target_distro = Distro.WINDOWS
platform = None
sources = ''
local_sources = ''
@@ -33,6 +34,8 @@ class DummyConfig(object):
target_version = None
target_distro_version = None
packages_prefix = ''
+ packager = DEFAULT_PACKAGER
+ install_dir = ''
class XMLMixin():