~salgado/linaro-image-tools/bug-643601

« back to all changes in this revision

Viewing changes to hwpack/tests/test_packages.py

Add the dependencies of the package to the generated Packages file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
            get_packages_file([package1]) + get_packages_file([package2]),
42
42
            get_packages_file([package1, package2]))
43
43
 
44
 
 
45
 
class FetchedPackageTests(TestCase):
 
44
    def test_with_depends(self):
 
45
        package = DummyFetchedPackage("foo", "1.1", depends="bar | baz")
 
46
        self.assertEqual(textwrap.dedent("""\
 
47
            Package: foo
 
48
            Version: 1.1
 
49
            Filename: %(filename)s
 
50
            Size: %(size)d
 
51
            Architecture: all
 
52
            Depends: bar | baz
 
53
            MD5sum: %(md5)s
 
54
            \n""" % {
 
55
                'filename': package.filename,
 
56
                'size': package.size,
 
57
                'md5': package.md5,
 
58
            }), get_packages_file([package]))
 
59
 
 
60
 
 
61
class FetchedPackageTests(TestCaseWithFixtures):
46
62
 
47
63
    def test_attributes(self):
48
64
        package = FetchedPackage(
112
128
            "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "i386")
113
129
        self.assertNotEqual(package1, package2)
114
130
 
 
131
    def test_not_equal_different_depends(self):
 
132
        package1 = FetchedPackage(
 
133
            "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",
 
134
            depends="bar")
 
135
        package2 = FetchedPackage(
 
136
            "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",
 
137
            depends="baz")
 
138
        self.assertNotEqual(package1, package2)
 
139
 
 
140
    def test_not_equal_different_depends_one_None(self):
 
141
        package1 = FetchedPackage(
 
142
            "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",
 
143
            depends="bar")
 
144
        package2 = FetchedPackage(
 
145
            "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",
 
146
            depends=None)
 
147
        self.assertNotEqual(package1, package2)
 
148
 
 
149
    def test_equal_same_depends(self):
 
150
        package1 = FetchedPackage(
 
151
            "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",
 
152
            depends="bar")
 
153
        package2 = FetchedPackage(
 
154
            "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",
 
155
            depends="bar")
 
156
        self.assertEqual(package1, package2)
 
157
 
115
158
    def test_equal_hash_equal(self):
116
159
        package1 = FetchedPackage(
117
160
            "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel")
119
162
            "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel")
120
163
        self.assertEqual(hash(package1), hash(package2))
121
164
 
 
165
    def test_equal_hash_equal_with_depends(self):
 
166
        package1 = FetchedPackage(
 
167
            "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",
 
168
            depends="bar")
 
169
        package2 = FetchedPackage(
 
170
            "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",
 
171
            depends="bar")
 
172
        self.assertEqual(hash(package1), hash(package2))
 
173
 
 
174
    def test_from_apt(self):
 
175
        target_package = DummyFetchedPackage("foo", "1.0")
 
176
        source = self.useFixture(AptSourceFixture([target_package]))
 
177
        with IsolatedAptCache([source.sources_entry]) as cache:
 
178
            candidate = cache.cache['foo'].candidate
 
179
            created_package = FetchedPackage.from_apt(
 
180
                candidate, target_package.filename, target_package.content)
 
181
            self.assertEqual(target_package, created_package)
 
182
 
 
183
    def test_from_apt_with_depends(self):
 
184
        target_package = DummyFetchedPackage(
 
185
            "foo", "1.0", depends="bar | baz (>= 1.0), zap")
 
186
        source = self.useFixture(AptSourceFixture([target_package]))
 
187
        with IsolatedAptCache([source.sources_entry]) as cache:
 
188
            candidate = cache.cache['foo'].candidate
 
189
            created_package = FetchedPackage.from_apt(
 
190
                candidate, target_package.filename, target_package.content)
 
191
            self.assertEqual(target_package, created_package)
 
192
 
122
193
 
123
194
class AptCacheTests(TestCaseWithFixtures):
124
195