summaryrefslogtreecommitdiff
path: root/test/test_cerbero_packages_packagemaker.py
blob: d6596401ed67ca4e64fbc50224825ae94711cf8d (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
# 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 os
import shutil
import unittest
import tempfile

from cerbero.config import Platform
from cerbero.packages import PackageType
from cerbero.packages.packagemaker import OSXPackage, PackageMaker
from cerbero.utils import shell
from test.test_packages_common import create_store
from test.test_common import DummyConfig


class PackageMakerTest(unittest.TestCase):

    def setUp(self):
        self.tmp = tempfile.mkdtemp()
        self.config = DummyConfig()
        self.config.prefix = self.tmp
        self.config.target_platform = Platform.LINUX
        self.store = create_store(self.config)

    def tearDown(self):
        shutil.rmtree(self.tmp)

    def testCreateBundle(self):
        self._add_files()
        p = self.store.get_package('gstreamer-test1')
        self.files = p.files_list()
        packager = OSXPackage(self.config, p, self.store)
        files = OSXPackage.files_list(packager, PackageType.RUNTIME, False)
        tmpdest = packager._create_bundle(files, PackageType.RUNTIME)
        bundlefiles = shell.check_call('find . -type f ', tmpdest).split('\n')
        bundlefiles = sorted([f[2:] for f in bundlefiles])[1:]
        self.assertEquals(bundlefiles, self.files)
        shutil.rmtree(tmpdest)

    def _add_files(self):
        bindir = os.path.join(self.tmp, 'bin')
        libdir = os.path.join(self.tmp, 'lib')
        os.makedirs(bindir)
        os.makedirs(libdir)
        os.makedirs(os.path.join(self.tmp, 'libexec', 'gstreamer-0.10'))
        shell.call('touch '
            'README '
            'linux '
            'libexec/gstreamer-0.10/pluginsloader '
            'bin/gst-launch '
            'bin/linux '
            'lib/libgstreamer-0.10.so.1 '
            'lib/libgstreamer-x11.so.1 '
            'lib/notincluded1 '
            'notincluded2 ', self.tmp)


class DummyPackageMaker(PackageMaker):

    def _execute(self, cmd):
        self.cmd = cmd


class TestPackageMaker(unittest.TestCase):
    

    def testFillArgs(self):
        pm = PackageMaker()
        args = {'r': 'root', 'i': 'pkg_id', 'n': 'version', 't': 'title',
                'l': 'destination', 'o': 'output_file'}
        cmd = pm._cmd_with_args(args)
        self.assertEquals(cmd,
            "./PackageMaker  -i 'pkg_id' -l 'destination' -o 'output_file' "
            "-n 'version' -r 'root' -t 'title'")

    def testCreatePackage(self):
        pm = DummyPackageMaker()
        pm.create_package('root', 'pkg_id', 'version', 'title',
                          'output_file', 'destination')
        self.assertEquals(pm.cmd,
            "./PackageMaker  -g '10.5' -i 'pkg_id' -l 'destination' -o 'output_file' "
            "-n 'version' -r 'root' -t 'title'")