summaryrefslogtreecommitdiff
path: root/test/test_cerbero_packages_packagesstore.py
blob: 6cd450530c8028cf82b405f274553e04b66f773a (plain)
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
# 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, 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, 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, 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,  None)
        package2 = common.Package2(self.config, None, 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]:
            p = klass(self.config, None, None)
            self.store.add_package(p)
        for klass in [common.MetaPackage]:
            p = klass(self.config, None)
            self.store.add_package(p)
        deps = ['gstreamer-test-bindings', 'gstreamer-test1',
                'gstreamer-test2', 'gstreamer-test3']
        res = [x.name for x in self.store.get_package_deps(metapackage.name)]
        self.assertEquals(sorted(deps), sorted(res))

    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)