summaryrefslogtreecommitdiff
path: root/test/test_cerbero_packages_packagesstore.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_cerbero_packages_packagesstore.py')
-rw-r--r--test/test_cerbero_packages_packagesstore.py128
1 files changed, 128 insertions, 0 deletions
diff --git a/test/test_cerbero_packages_packagesstore.py b/test/test_cerbero_packages_packagesstore.py
new file mode 100644
index 00000000..accd99ee
--- /dev/null
+++ b/test/test_cerbero_packages_packagesstore.py
@@ -0,0 +1,128 @@
+# 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 tempfile
+
+from cerbero.config import Platform
+from cerbero.errors import PackageNotFoundError
+from cerbero.packages.package import Package, MetaPackage
+from cerbero.packages.packagesstore import PackagesStore
+from test import test_packages_common as common
+
+
+PACKAGE = '''
+class Package(package.Package):
+
+ name = 'test-package'
+
+ def test_imports(self):
+ Platform.WINDOWS
+ Distro.WINDOWS
+ DistroVersion.WINDOWS_7
+ Architecture.X86
+'''
+
+METAPACKAGE = '''
+class MetaPackage(package.MetaPackage):
+
+ name = 'test-package'
+'''
+
+
+class PackageTest(unittest.TestCase):
+
+ def setUp(self):
+ self.config = common.DummyConfig()
+ self.config.packages_dir = '/test'
+ self.config.target_platform = Platform.LINUX
+ self.store = PackagesStore(self.config, False)
+
+ def testAddPackage(self):
+ package = common.Package1(self.config, None)
+ self.assertEquals(len(self.store._packages), 0)
+ self.store.add_package(package)
+ self.assertEquals(len(self.store._packages), 1)
+ self.assertEquals(package, self.store._packages[package.name])
+
+ def testGetPackage(self):
+ package = common.Package1(self.config, None)
+ self.store.add_package(package)
+ self.assertEquals(package, self.store.get_package(package.name))
+
+ def testPackageNotFound(self):
+ self.failUnlessRaises(PackageNotFoundError, self.store.get_package,
+ 'unknown')
+
+ def testPackagesList(self):
+ package = common.Package1(self.config, None)
+ metapackage = common.MetaPackage(self.config, None)
+ self.store.add_package(package)
+ self.store.add_package(metapackage)
+ l = sorted([package, metapackage], key=lambda x: x.name)
+ self.assertEquals(l, self.store.get_packages_list())
+
+ def testPackageDeps(self):
+ package = common.Package1(self.config, None)
+ package2 = common.Package2(self.config, None)
+ self.store.add_package(package)
+ self.store.add_package(package2)
+ self.assertEquals(package.deps,
+ [x.name for x in self.store.get_package_deps(package.name)])
+
+ def testMetaPackageDeps(self):
+ metapackage = common.MetaPackage(self.config, None)
+ self.store.add_package(metapackage)
+ # the metapackage depends on package that are not yet in the store
+ self.failUnlessRaises(PackageNotFoundError,
+ self.store.get_package_deps, metapackage.name)
+ for klass in [common.Package1, common.Package2, common.Package3,
+ common.Package4, common.MetaPackage]:
+ p = klass(self.config, None)
+ self.store.add_package(p)
+ deps = ['gstreamer-test-bindings', 'gstreamer-test1',
+ 'gstreamer-test2', 'gstreamer-test3']
+ self.assertEquals(deps,
+ [x.name for x in self.store.get_package_deps(metapackage.name)])
+
+ def testLoadPackageFromFile(self):
+ package_file = tempfile.NamedTemporaryFile()
+ package_file.write(PACKAGE)
+ package_file.flush()
+ p = self.store._load_package_from_file(package_file.name)
+ self.assertIsInstance(p, Package)
+ self.assertEquals('test-package', p.name)
+
+ def testLoadMetaPackageFromFile(self):
+ package_file = tempfile.NamedTemporaryFile()
+ package_file.write(METAPACKAGE)
+ package_file.flush()
+ p = self.store._load_package_from_file(package_file.name)
+ self.assertIsInstance(p, MetaPackage)
+ self.assertEquals('test-package', p.name)
+
+ def testImports(self):
+ package_file = tempfile.NamedTemporaryFile()
+ package_file.write(PACKAGE)
+ package_file.flush()
+ p = self.store._load_package_from_file(package_file.name)
+ self.assertIsInstance(p, Package)
+ try:
+ p.test_imports()
+ except ImportError, e:
+ self.fail("Import error raised, %s", e)