/usr/share/pyshared/germinate/tests/test_germinator.py is in python-germinate 2.8.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | #! /usr/bin/env python
"""Unit tests for germinate.germinator."""
# Copyright (C) 2012 Canonical Ltd.
#
# Germinate 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, or (at your option) any
# later version.
#
# Germinate 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 Germinate; see the file COPYING. If not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301, USA.
from germinate.archive import TagFile
from germinate.germinator import (
BuildDependsReason,
DependsReason,
ExtraReason,
GerminatedSeed,
Germinator,
RecommendsReason,
RescueReason,
SeedReason,
)
from germinate.tests.helpers import TestCase
class TestSeedReason(TestCase):
def test_str(self):
"""SeedReason stringifies to a description of the seed."""
reason = SeedReason("branch", "base")
self.assertEqual("Branch base seed", str(reason))
class TestBuildDependsReason(TestCase):
def test_str(self):
"""BuildDependsReason stringifies to a description of the reason."""
reason = BuildDependsReason("foo")
self.assertEqual("foo (Build-Depend)", str(reason))
class TestRecommendsReason(TestCase):
def test_str(self):
"""RecommendsReason stringifies to a description of the reason."""
reason = RecommendsReason("foo")
self.assertEqual("foo (Recommends)", str(reason))
class TestDependsReason(TestCase):
def test_str(self):
"""DependsReason stringifies to the package name."""
reason = DependsReason("foo")
self.assertEqual("foo", str(reason))
class TestExtraReason(TestCase):
def test_str(self):
"""ExtraReason stringifies to a description of the reason."""
reason = ExtraReason("foo")
self.assertEqual("Generated by foo", str(reason))
class TestRescueReason(TestCase):
def test_str(self):
"""RescueReason stringifies to a description of the reason."""
reason = RescueReason("foo")
self.assertEqual("Rescued from foo", str(reason))
class TestGerminatedSeed(TestCase):
def test_basic(self):
"""GerminatedSeed has reasonable basic properties."""
branch = "collection.dist"
self.addSeed(branch, "one")
self.addSeedPackage(branch, "one", "one-package")
structure = self.openSeedStructure(branch)
seed = GerminatedSeed(None, "one", structure, structure["one"])
self.assertEqual("one", seed.name)
self.assertEqual(structure, seed.structure)
self.assertEqual("one", str(seed))
self.assertEqual(structure["one"], seed._raw_seed)
def test_equal_if_same_contents(self):
"""GerminatedSeeds with the same seeds and inheritance are equal."""
one = "one.dist"
two = "two.dist"
self.addSeed(one, "base")
self.addSeedPackage(one, "base", "base")
self.addSeed(one, "desktop", parents=["base"])
self.addSeedPackage(one, "desktop", "desktop")
self.addSeed(two, "base")
self.addSeedPackage(two, "base", "base")
self.addSeed(two, "desktop", parents=["base"])
self.addSeedPackage(two, "desktop", "desktop")
structure_one = self.openSeedStructure(one)
structure_two = self.openSeedStructure(two)
germinator = Germinator("i386")
desktop_one = GerminatedSeed(
germinator, "desktop", structure_one, structure_one["desktop"])
desktop_two = GerminatedSeed(
germinator, "desktop", structure_two, structure_two["desktop"])
self.assertEqual(desktop_one, desktop_two)
def test_not_equal_if_different_contents(self):
"""GerminatedSeeds with different seeds/inheritance are not equal."""
one = "one.dist"
two = "two.dist"
self.addSeed(one, "base")
self.addSeedPackage(one, "base", "base")
self.addSeed(one, "desktop", parents=["base"])
self.addSeedPackage(one, "desktop", "desktop")
self.addSeed(two, "base")
self.addSeedPackage(two, "base", "base")
self.addSeed(two, "desktop")
self.addSeedPackage(two, "desktop", "desktop")
structure_one = self.openSeedStructure(one)
structure_two = self.openSeedStructure(two)
germinator = Germinator("i386")
desktop_one = GerminatedSeed(
germinator, "desktop", structure_one, structure_one["desktop"])
desktop_two = GerminatedSeed(
germinator, "desktop", structure_two, structure_two["desktop"])
self.assertNotEqual(desktop_one, desktop_two)
class TestGerminator(TestCase):
def test_parse_archive(self):
"""Germinator.parse_archive successfully parses a simple archive."""
self.addSource("warty", "main", "hello", "1.0-1",
["hello", "hello-dependency"],
fields={"Maintainer": "Test Person <test@example.com>"})
self.addPackage("warty", "main", "i386", "hello", "1.0-1",
fields={
"Maintainer": "Test Person <test@example.com>",
"Depends": "hello-dependency",
})
self.addPackage("warty", "main", "i386", "hello-dependency", "1.0-1",
fields={"Source": "hello"})
self.addSeed("ubuntu.warty", "supported")
self.addSeedPackage("ubuntu.warty", "supported", "hello")
germinator = Germinator("i386")
archive = TagFile(
"warty", "main", "i386", "file://%s" % self.archive_dir)
germinator.parse_archive(archive)
self.assertIn("hello", germinator._sources)
self.assertEqual({
"Maintainer": u"Test Person <test@example.com>",
"Version": "1.0-1",
"Build-Depends": [],
"Build-Depends-Indep": [],
"Binaries": ["hello", "hello-dependency"],
}, germinator._sources["hello"])
self.assertIn("hello", germinator._packages)
self.assertEqual({
"Section": "",
"Version": "1.0-1",
"Maintainer": u"Test Person <test@example.com>",
"Essential": "",
"Pre-Depends": [],
"Depends": [[("hello-dependency", "", "")]],
"Recommends": [],
"Size": 0,
"Installed-Size": 0,
"Source": "hello",
"Provides": [],
"Kernel-Version": "",
}, germinator._packages["hello"])
self.assertEqual("deb", germinator._packagetype["hello"])
self.assertIn("hello-dependency", germinator._packages)
self.assertEqual({
"Section": "",
"Version": "1.0-1",
"Maintainer": u"",
"Essential": "",
"Pre-Depends": [],
"Depends": [],
"Recommends": [],
"Size": 0,
"Installed-Size": 0,
"Source": "hello",
"Provides": [],
"Kernel-Version": "",
}, germinator._packages["hello-dependency"])
self.assertEqual("deb", germinator._packagetype["hello-dependency"])
self.assertEqual({}, germinator._provides)
def test_different_providers_between_suites(self):
"""Provides from later versions override those from earlier ones."""
self.addSource("warty", "main", "hello", "1.0-1", ["hello"])
self.addPackage("warty", "main", "i386", "hello", "1.0-1",
fields={"Provides": "goodbye"})
self.addSource("warty-updates", "main", "hello", "1.0-1.1", ["hello"])
self.addPackage("warty-updates", "main", "i386", "hello", "1.0-1.1",
fields={"Provides": "hello-goodbye"})
germinator = Germinator("i386")
archive = TagFile(
["warty", "warty-updates"], "main", "i386",
"file://%s" % self.archive_dir)
germinator.parse_archive(archive)
self.assertNotIn("goodbye", germinator._provides)
self.assertIn("hello-goodbye", germinator._provides)
self.assertEqual(["hello"], germinator._provides["hello-goodbye"])
# TODO: Germinator needs many more unit tests.
|