test_packagelist.py 6.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#! /usr/bin/python
#
# Copyright (C) 2014, Ansgar Burchardt <ansgar@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

from base_test import DakTestCase
import unittest
Chris Lamb's avatar
Chris Lamb committed
21
from daklib.packagelist import PackageList
22

23

24 25 26 27
class FakeArchitecture(object):
    def __init__(self, name):
        self.arch_string = name

28

29 30
class FakeSuite(object):
    def __init__(self, *architectures):
31
        self.architectures = [FakeArchitecture(a) for a in architectures]
32

33

34 35 36 37 38 39 40 41 42 43 44 45
source_all = {
    'Package-List': '\n libdune-common-doc deb doc optional arch=all\n',
    'Binary': 'libdune-common-doc\n',
    }

source_any = {
    'Package-List': '\n libdune-common-dev deb libdevel optional arch=any\n',
    'Binary': 'libdune-common-dev\n',
    }

source_all_any = {
    'Package-List': '\n libdune-common-dev deb libdevel optional arch=any\nlibdune-common-doc deb doc optional arch=all\n',
46
    'Binary': 'libdune-common-dev, libdune-common-doc\n',
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
    }

source_amd64 = {
    'Package-List': '\n libdune-common-dev deb libdevel optional arch=amd64\n',
    'Binary': 'libdune-common-dev\n',
    }

source_linuxany = {
    'Package-List': '\n libdune-common-dev deb libdevel optional arch=linux-any\n',
    'Binary': 'libdune-common-dev\n',
    }

source_noarch = {
    'Package-List': '\n libdune-common-dev deb libdevel optional\n',
    'Binary': 'libdune-common-dev\n',
}

source_fallback = {
    'Binary': 'libdune-common-dev\n',
}

68

69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
class TestPackageList(DakTestCase):
    def testArchAll(self):
        pl = PackageList(source_all)

        self.assertTrue(pl.has_arch_indep_packages())
        self.assertFalse(pl.has_arch_dep_packages())

        suite_amd64 = FakeSuite('amd64')
        p_amd64 = pl.packages_for_suite(suite_amd64)
        self.assertEqual(len(p_amd64), 0)

        suite_all = FakeSuite('all')
        p_all = pl.packages_for_suite(suite_all)
        self.assertEqual(len(p_all), 1)

        suite_all_amd64 = FakeSuite('amd64', 'all')
        p_all_amd64 = pl.packages_for_suite(suite_all_amd64)
        self.assertEqual(len(p_all_amd64), 1)

88 89 90 91 92 93 94 95
        p = p_all[0]
        self.assertEqual(p.name, 'libdune-common-doc')
        self.assertEqual(p.type, 'deb')
        self.assertEqual(p.section, 'doc')
        self.assertEqual(p.component, 'main')
        self.assertEqual(p.priority, 'optional')
        self.assertEqual(p.architectures, ['all'])

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 161 162 163 164 165 166 167
    def testArchAny(self):
        pl = PackageList(source_any)

        self.assertFalse(pl.has_arch_indep_packages())
        self.assertTrue(pl.has_arch_dep_packages())

        suite_amd64 = FakeSuite('amd64')
        p_amd64 = pl.packages_for_suite(suite_amd64)
        self.assertEqual(len(p_amd64), 1)

        suite_all = FakeSuite('all')
        p_all = pl.packages_for_suite(suite_all)
        self.assertEqual(len(p_all), 0)

        suite_all_amd64 = FakeSuite('amd64', 'all')
        p_all_amd64 = pl.packages_for_suite(suite_all_amd64)
        self.assertEqual(len(p_all_amd64), 1)

    def testArchAnyAll(self):
        pl = PackageList(source_all_any)

        self.assertTrue(pl.has_arch_indep_packages())
        self.assertTrue(pl.has_arch_dep_packages())

        suite_amd64 = FakeSuite('amd64')
        p_amd64 = pl.packages_for_suite(suite_amd64)
        self.assertEqual(len(p_amd64), 1)

        suite_amd64_i386 = FakeSuite('amd64', 'i386')
        p_amd64_i386 = pl.packages_for_suite(suite_amd64_i386)
        self.assertEqual(len(p_amd64_i386), 1)

        suite_all = FakeSuite('all')
        p_all = pl.packages_for_suite(suite_all)
        self.assertEqual(len(p_all), 1)

        suite_all_amd64 = FakeSuite('amd64', 'all')
        p_all_amd64 = pl.packages_for_suite(suite_all_amd64)
        self.assertEqual(len(p_all_amd64), 2)

    def testArchAmd64(self):
        pl = PackageList(source_amd64)

        self.assertFalse(pl.has_arch_indep_packages())
        self.assertTrue(pl.has_arch_dep_packages())

        suite_amd64 = FakeSuite('amd64')
        p_amd64 = pl.packages_for_suite(suite_amd64)
        self.assertEqual(len(p_amd64), 1)

        suite_i386 = FakeSuite('i386')
        p_i386 = pl.packages_for_suite(suite_i386)
        self.assertEqual(len(p_i386), 0)

    def testArchLinuxAny(self):
        pl = PackageList(source_linuxany)

        self.assertFalse(pl.has_arch_indep_packages())
        self.assertTrue(pl.has_arch_dep_packages())

        suite_amd64 = FakeSuite('amd64')
        p_amd64 = pl.packages_for_suite(suite_amd64)
        self.assertEqual(len(p_amd64), 1)

        suite_i386 = FakeSuite('i386')
        p_i386 = pl.packages_for_suite(suite_i386)
        self.assertEqual(len(p_i386), 1)

        suite_kfreebsdi386 = FakeSuite('kfreebsd-i386')
        p_kfreebsdi386 = pl.packages_for_suite(suite_kfreebsdi386)
        self.assertEqual(len(p_kfreebsdi386), 0)

168 169 170 171
        suite_source = FakeSuite('source')
        p_source = pl.packages_for_suite(suite_source)
        self.assertEqual(len(p_source), 0)

172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
    def testNoArch(self):
        pl = PackageList(source_noarch)

        self.assertIsNone(pl.has_arch_indep_packages())
        self.assertIsNone(pl.has_arch_dep_packages())

        suite_amd64 = FakeSuite('amd64')
        p_amd64 = pl.packages_for_suite(suite_amd64)
        self.assertEqual(len(p_amd64), 1)

    def testFallback(self):
        pl = PackageList(source_fallback)

        self.assertIsNone(pl.has_arch_indep_packages())
        self.assertIsNone(pl.has_arch_dep_packages())

        suite_amd64 = FakeSuite('amd64')
        p_amd64 = pl.packages_for_suite(suite_amd64)
        self.assertEqual(len(p_amd64), 1)

192

193 194
if __name__ == '__main__':
    unittest.main()