Merge lp:~james-w/linaro-image-tools/add-other-relations-to-packages-file into lp:linaro-image-tools/11.11

Proposed by James Westby
Status: Merged
Merged at revision: 77
Proposed branch: lp:~james-w/linaro-image-tools/add-other-relations-to-packages-file
Merge into: lp:linaro-image-tools/11.11
Prerequisite: lp:~james-w/linaro-image-tools/add-relations-to-packages-file
Diff against target: 563 lines (+283/-113)
5 files modified
hwpack/packages.py (+75/-25)
hwpack/tarfile_matchers.py (+4/-6)
hwpack/testing.py (+5/-1)
hwpack/tests/test_packages.py (+197/-36)
hwpack/tests/test_tarfile_matchers.py (+2/-45)
To merge this branch: bzr merge lp:~james-w/linaro-image-tools/add-other-relations-to-packages-file
Reviewer Review Type Date Requested Status
Zygmunt Krynicki (community) Approve
Review via email: mp+35172@code.launchpad.net

Description of the change

Hi,

This is similar to the last branch, just extends it to Pre-Depends,
Conflicts and Recommends as well. I didn't bother with Suggests, as
I doubt anyone would ever want to install a hwpack and pull in the
suggested packages at the same time. It would be easy to add
though.

There's some small refactorings thrown in now that code is shared
between these different paths.

Thanks,

James

To post a comment you must log in.
139. By James Westby

Merge add-relations-to-packages-file into add-other-relations-to-packages-file.

140. By James Westby

Merged add-relations-to-packages-file into add-other-relations-to-packages-file.

Revision history for this message
Zygmunt Krynicki (zyga) wrote :

You seem to have changed FetchedPackage.__eq__ but did not change __hash__ (it still refers to the old set of fields).

In addition you should not define __eq__ but __cmp__ unless you are prepared to define __ne__. Moreover you should not define __hash__ as your instances are not immutable.

Currently you can create two identical FetchedPackage objects A and B and the following will hold:
assert A == B # because we have __eq__ that works
assert A != B # because __ne__ compares id() by default

The same issue affects TarfileWrongValueMismatch and TarfileMissingPathMismatch

From pydoc SPECIALMETHODS

 There are no implied relationships among the comparison operators.
   The truth of ``x==y`` does not imply that ``x!=y`` is false.
   Accordingly, when defining ``__eq__()``, one should also define
   ``__ne__()`` so that the operators will behave as expected. See
   the paragraph on ``__hash__()`` for some important notes on
   creating *hashable* objects which support custom comparison
   operations and are usable as dictionary keys.

   If a class does not define a ``__cmp__()`` or ``__eq__()`` method
   it should not define a ``__hash__()`` operation either; if it
   defines ``__cmp__()`` or ``__eq__()`` but not ``__hash__()``, its
   instances will not be usable in hashed collections. If a class
   defines mutable objects and implements a ``__cmp__()`` or
   ``__eq__()`` method, it should not implement ``__hash__()``, since
   hashable collection implementations require that a object's hash
   value is immutable (if the object's hash value changes, it will be
   in the wrong hash bucket).

review: Needs Fixing
Revision history for this message
James Westby (james-w) wrote :

On Tue, 14 Sep 2010 19:47:43 -0000, Zygmunt Krynicki <email address hidden> wrote:
> Review: Needs Fixing
> You seem to have changed FetchedPackage.__eq__ but did not change
> __hash__ (it still refers to the old set of fields).

Because content() was never in the __hash__ calculation.

> In addition you should not define __eq__ but __cmp__ unless you are
> prepared to define __ne__. Moreover you should not define __hash__ as
> your instances are not immutable.

__cmp__ doesn't really make sense as there is no natural ordering. Your
other points make sense though.

Thanks,

James

Revision history for this message
James Westby (james-w) wrote :

Changed, thanks.

James

141. By James Westby

Define __ne__ and remove __hash__ on FetchedPackage. Thanks Zygmunt.

142. By James Westby

Add __ne__ and remove __hash__ from the Mismatches. Thanks Zygmunt.

Revision history for this message
Zygmunt Krynicki (zyga) wrote :

Looks fine now, please merge!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'hwpack/packages.py'
--- hwpack/packages.py 2010-09-10 21:51:33 +0000
+++ hwpack/packages.py 2010-09-14 20:36:09 +0000
@@ -25,12 +25,52 @@
25 parts.append('Architecture: %s' % package.architecture)25 parts.append('Architecture: %s' % package.architecture)
26 if package.depends:26 if package.depends:
27 parts.append('Depends: %s' % package.depends)27 parts.append('Depends: %s' % package.depends)
28 if package.pre_depends:
29 parts.append('Pre-Depends: %s' % package.pre_depends)
30 if package.conflicts:
31 parts.append('Conflicts: %s' % package.conflicts)
32 if package.recommends:
33 parts.append('Recommends: %s' % package.recommends)
28 parts.append('MD5sum: %s' % package.md5)34 parts.append('MD5sum: %s' % package.md5)
29 content += "\n".join(parts)35 content += "\n".join(parts)
30 content += "\n\n"36 content += "\n\n"
31 return content37 return content
3238
3339
40def stringify_relationship(pkg, relationship):
41 """Given a Package, return a string of the specified relationship.
42
43 apt.package.Version stores the relationship information of the
44 package as objects. This function will convert those objects
45 in to the string form that we are used to from debian/control
46 or Packages files.
47
48 :param pkg: the package to take the relationship information from.
49 :type pkg: apt.package.Version
50 :param relationship: the relationship to stringify, as understood
51 by apt.package.Package.get_dependencies, e.g. "Depends",
52 "PreDepends".
53 :type relationship: str or None if the package has no relationships
54 of that type.
55 """
56 relationship_str = None
57 pkg_dependencies = pkg.get_dependencies(relationship)
58 if pkg_dependencies:
59 relationship_list = []
60 for or_dep in pkg_dependencies:
61 or_list = []
62 for or_alternative in or_dep.or_dependencies:
63 suffix = ""
64 if or_alternative.relation:
65 suffix = " (%s %s)" % (
66 or_alternative.relation,
67 or_alternative.version)
68 or_list.append("%s%s" % (or_alternative.name, suffix))
69 relationship_list.append(" | ".join(or_list))
70 relationship_str = ", ".join(relationship_list)
71 return relationship_str
72
73
34class DummyProgress(object):74class DummyProgress(object):
35 """An AcquireProgress that silences all output.75 """An AcquireProgress that silences all output.
3676
@@ -79,14 +119,27 @@
79 :ivar architecture: the architecture that the package is for, may be119 :ivar architecture: the architecture that the package is for, may be
80 'all'.120 'all'.
81 :type architecture: str121 :type architecture: str
82 :ivar depends: the depends string that the package has, i.e. the122 :ivar depends: the Depends string that the package has, i.e. the
83 dependencies as specified in debian/control. May be None if the123 dependencies as specified in debian/control. May be None if the
84 package has none.124 package has none.
85 :type depends: str or None125 :type depends: str or None
126 :ivar pre_depends: the Pre-Depends string that the package has, i.e. the
127 pre-dependencies as specified in debian/control. May be None if the
128 package has none.
129 :type pre_depends: str or None
130 :ivar conflicts: the Conflicts string that the package has, i.e. the
131 conflicts as specified in debian/control. May be None if the
132 package has none.
133 :type conflicts: str or None
134 :ivar recommends: the Recommends string that the package has, i.e. the
135 recommends as specified in debian/control. May be None if the
136 package has none.
137 :type recommends: str or None
86 """138 """
87139
88 def __init__(self, name, version, filename, content, size, md5,140 def __init__(self, name, version, filename, content, size, md5,
89 architecture, depends=None):141 architecture, depends=None, pre_depends=None,
142 conflicts=None, recommends=None):
90 """Create a FetchedPackage.143 """Create a FetchedPackage.
91144
92 See the instance variables for the arguments.145 See the instance variables for the arguments.
@@ -99,6 +152,9 @@
99 self.md5 = md5152 self.md5 = md5
100 self.architecture = architecture153 self.architecture = architecture
101 self.depends = depends154 self.depends = depends
155 self.pre_depends = pre_depends
156 self.conflicts = conflicts
157 self.recommends = recommends
102158
103 @classmethod159 @classmethod
104 def from_apt(cls, pkg, filename, content):160 def from_apt(cls, pkg, filename, content):
@@ -116,23 +172,15 @@
116 :param content: the content of the package.172 :param content: the content of the package.
117 :type content: file-like object173 :type content: file-like object
118 """174 """
119 depends = None175 depends = stringify_relationship(pkg, "Depends")
120 pkg_dependencies = pkg.get_dependencies("Depends")176 pre_depends = stringify_relationship(pkg, "PreDepends")
121 if pkg_dependencies:177 conflicts = stringify_relationship(pkg, "Conflicts")
122 depends_list = []178 recommends = stringify_relationship(pkg, "Recommends")
123 for or_dep in pkg_dependencies:
124 or_list = []
125 for or_alternative in or_dep.or_dependencies:
126 suffix = ""
127 if or_alternative.relation:
128 suffix = " (%s %s)" % (
129 or_alternative.relation, or_alternative.version)
130 or_list.append("%s%s" % (or_alternative.name, suffix))
131 depends_list.append(" | ".join(or_list))
132 depends = ", ".join(depends_list)
133 return cls(179 return cls(
134 pkg.package.name, pkg.version, filename, content, pkg.size,180 pkg.package.name, pkg.version, filename, content, pkg.size,
135 pkg.md5, pkg.architecture, depends=depends)181 pkg.md5, pkg.architecture, depends=depends,
182 pre_depends=pre_depends, conflicts=conflicts,
183 recommends=recommends)
136184
137 def __eq__(self, other):185 def __eq__(self, other):
138 return (self.name == other.name186 return (self.name == other.name
@@ -142,19 +190,21 @@
142 and self.size == other.size190 and self.size == other.size
143 and self.md5 == other.md5191 and self.md5 == other.md5
144 and self.architecture == other.architecture192 and self.architecture == other.architecture
145 and self.depends == other.depends)193 and self.depends == other.depends
194 and self.pre_depends == other.pre_depends
195 and self.conflicts == other.conflicts
196 and self.recommends == other.recommends)
146197
147 def __hash__(self):198 def __ne__(self, other):
148 return hash(199 return not self.__eq__(other)
149 (self.name, self.version, self.filename, self.size, self.md5,
150 self.depends))
151200
152 def __repr__(self):201 def __repr__(self):
153 return (202 return (
154 '<%s name=%s version=%s size=%s md5=%s architecture=%s '203 '<%s name=%s version=%s size=%s md5=%s architecture=%s '
155 'depends="%s">' % (self.__class__.__name__, self.name,204 'depends="%s" pre_depends="%s" conflicts="%s" recommends="%s">'
156 self.version, self.size, self.md5, self.architecture,205 % (self.__class__.__name__, self.name, self.version, self.size,
157 self.depends))206 self.md5, self.architecture, self.depends, self.pre_depends,
207 self.conflicts, self.recommends))
158208
159209
160class IsolatedAptCache(object):210class IsolatedAptCache(object):
161211
=== modified file 'hwpack/tarfile_matchers.py'
--- hwpack/tarfile_matchers.py 2010-08-31 16:33:16 +0000
+++ hwpack/tarfile_matchers.py 2010-09-14 20:36:09 +0000
@@ -20,8 +20,8 @@
20 def __eq__(self, other):20 def __eq__(self, other):
21 return self.tarball == other.tarball and self.path == other.path21 return self.tarball == other.tarball and self.path == other.path
2222
23 def __hash__(self):23 def __ne__(self, other):
24 return hash((self.tarball, self.path))24 return not self.__eq__(other)
2525
2626
27class TarfileWrongValueMismatch(Mismatch):27class TarfileWrongValueMismatch(Mismatch):
@@ -56,10 +56,8 @@
56 and self.expected == other.expected56 and self.expected == other.expected
57 and self.actual == other.actual)57 and self.actual == other.actual)
5858
59 def __hash__(self):59 def __ne__(self, other):
60 return hash(60 return not self.__eq__(other)
61 (self.attribute, self.tarball, self.path, self.expected,
62 self.actual))
6361
6462
65class TarfileHasFile(Matcher):63class TarfileHasFile(Matcher):
6664
=== modified file 'hwpack/testing.py'
--- hwpack/testing.py 2010-09-10 18:58:06 +0000
+++ hwpack/testing.py 2010-09-14 20:36:09 +0000
@@ -54,11 +54,15 @@
54 See FetchedPackage for the instance variables.54 See FetchedPackage for the instance variables.
55 """55 """
5656
57 def __init__(self, name, version, architecture="all", depends=None):57 def __init__(self, name, version, architecture="all", depends=None,
58 pre_depends=None, conflicts=None, recommends=None):
58 self.name = name59 self.name = name
59 self.version = version60 self.version = version
60 self.architecture = architecture61 self.architecture = architecture
61 self.depends = depends62 self.depends = depends
63 self.pre_depends = pre_depends
64 self.conflicts = conflicts
65 self.recommends = recommends
6266
63 @property67 @property
64 def filename(self):68 def filename(self):
6569
=== modified file 'hwpack/tests/test_packages.py'
--- hwpack/tests/test_packages.py 2010-09-10 20:53:42 +0000
+++ hwpack/tests/test_packages.py 2010-09-14 20:36:09 +0000
@@ -9,6 +9,7 @@
9 FetchedPackage,9 FetchedPackage,
10 get_packages_file,10 get_packages_file,
11 PackageFetcher,11 PackageFetcher,
12 stringify_relationship,
12 )13 )
13from hwpack.testing import (14from hwpack.testing import (
14 AptSourceFixture,15 AptSourceFixture,
@@ -41,21 +42,89 @@
41 get_packages_file([package1]) + get_packages_file([package2]),42 get_packages_file([package1]) + get_packages_file([package2]),
42 get_packages_file([package1, package2]))43 get_packages_file([package1, package2]))
4344
45 def get_stanza(self, package, relationships=""):
46 stanza = textwrap.dedent("""\
47 Package: foo
48 Version: 1.1
49 Filename: %(filename)s
50 Size: %(size)d
51 Architecture: all
52 """ % {
53 'filename': package.filename,
54 'size': package.size,
55 })
56 stanza += relationships
57 stanza += "MD5sum: %s\n\n" % package.md5
58 return stanza
59
44 def test_with_depends(self):60 def test_with_depends(self):
45 package = DummyFetchedPackage("foo", "1.1", depends="bar | baz")61 package = DummyFetchedPackage("foo", "1.1", depends="bar | baz")
46 self.assertEqual(textwrap.dedent("""\62 self.assertEqual(
47 Package: foo63 self.get_stanza(package, "Depends: bar | baz\n"),
48 Version: 1.164 get_packages_file([package]))
49 Filename: %(filename)s65
50 Size: %(size)d66 def test_with_pre_depends(self):
51 Architecture: all67 package = DummyFetchedPackage("foo", "1.1", pre_depends="bar | baz")
52 Depends: bar | baz68 self.assertEqual(
53 MD5sum: %(md5)s69 self.get_stanza(package, "Pre-Depends: bar | baz\n"),
54 \n""" % {70 get_packages_file([package]))
55 'filename': package.filename,71
56 'size': package.size,72 def test_with_conflicts(self):
57 'md5': package.md5,73 package = DummyFetchedPackage("foo", "1.1", conflicts="bar | baz")
58 }), get_packages_file([package]))74 self.assertEqual(
75 self.get_stanza(package, "Conflicts: bar | baz\n"),
76 get_packages_file([package]))
77
78 def test_with_recommends(self):
79 package = DummyFetchedPackage("foo", "1.1", recommends="bar | baz")
80 self.assertEqual(
81 self.get_stanza(package, "Recommends: bar | baz\n"),
82 get_packages_file([package]))
83
84
85class StringifyRelationshipTests(TestCaseWithFixtures):
86
87 def test_no_relationship(self):
88 target_package = DummyFetchedPackage("foo", "1.0")
89 source = self.useFixture(AptSourceFixture([target_package]))
90 with IsolatedAptCache([source.sources_entry]) as cache:
91 candidate = cache.cache['foo'].candidate
92 self.assertEqual(
93 None, stringify_relationship(candidate, "Depends"))
94
95 def test_single_package(self):
96 target_package = DummyFetchedPackage("foo", "1.0", depends="bar")
97 source = self.useFixture(AptSourceFixture([target_package]))
98 with IsolatedAptCache([source.sources_entry]) as cache:
99 candidate = cache.cache['foo'].candidate
100 self.assertEqual(
101 "bar", stringify_relationship(candidate, "Depends"))
102
103 def test_multiple_package(self):
104 target_package = DummyFetchedPackage("foo", "1.0", depends="bar, baz")
105 source = self.useFixture(AptSourceFixture([target_package]))
106 with IsolatedAptCache([source.sources_entry]) as cache:
107 candidate = cache.cache['foo'].candidate
108 self.assertEqual(
109 "bar, baz", stringify_relationship(candidate, "Depends"))
110
111 def test_alternative_packages(self):
112 target_package = DummyFetchedPackage(
113 "foo", "1.0", depends="bar | baz")
114 source = self.useFixture(AptSourceFixture([target_package]))
115 with IsolatedAptCache([source.sources_entry]) as cache:
116 candidate = cache.cache['foo'].candidate
117 self.assertEqual(
118 "bar | baz", stringify_relationship(candidate, "Depends"))
119
120 def test_package_with_version(self):
121 target_package = DummyFetchedPackage(
122 "foo", "1.0", depends="baz (<= 2.0)")
123 source = self.useFixture(AptSourceFixture([target_package]))
124 with IsolatedAptCache([source.sources_entry]) as cache:
125 candidate = cache.cache['foo'].candidate
126 self.assertEqual(
127 "baz (<= 2.0)", stringify_relationship(candidate, "Depends"))
59128
60129
61class FetchedPackageTests(TestCaseWithFixtures):130class FetchedPackageTests(TestCaseWithFixtures):
@@ -78,6 +147,7 @@
78 package2 = FetchedPackage(147 package2 = FetchedPackage(
79 "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel")148 "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel")
80 self.assertEqual(package1, package2)149 self.assertEqual(package1, package2)
150 self.assertFalse(package1 != package2)
81151
82 def test_not_equal_different_name(self):152 def test_not_equal_different_name(self):
83 package1 = FetchedPackage(153 package1 = FetchedPackage(
@@ -155,21 +225,86 @@
155 depends="bar")225 depends="bar")
156 self.assertEqual(package1, package2)226 self.assertEqual(package1, package2)
157227
158 def test_equal_hash_equal(self):228 def test_not_equal_different_pre_depends(self):
159 package1 = FetchedPackage(229 package1 = FetchedPackage(
160 "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel")230 "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",
161 package2 = FetchedPackage(231 pre_depends="bar")
162 "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel")232 package2 = FetchedPackage(
163 self.assertEqual(hash(package1), hash(package2))233 "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",
164234 pre_depends="baz")
165 def test_equal_hash_equal_with_depends(self):235 self.assertNotEqual(package1, package2)
166 package1 = FetchedPackage(236
167 "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",237 def test_not_equal_different_pre_depends_one_None(self):
168 depends="bar")238 package1 = FetchedPackage(
169 package2 = FetchedPackage(239 "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",
170 "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",240 pre_depends="bar")
171 depends="bar")241 package2 = FetchedPackage(
172 self.assertEqual(hash(package1), hash(package2))242 "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",
243 pre_depends=None)
244 self.assertNotEqual(package1, package2)
245
246 def test_equal_same_pre_depends(self):
247 package1 = FetchedPackage(
248 "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",
249 pre_depends="bar")
250 package2 = FetchedPackage(
251 "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",
252 pre_depends="bar")
253 self.assertEqual(package1, package2)
254
255 def test_not_equal_different_conflicts(self):
256 package1 = FetchedPackage(
257 "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",
258 conflicts="bar")
259 package2 = FetchedPackage(
260 "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",
261 conflicts="baz")
262 self.assertNotEqual(package1, package2)
263
264 def test_not_equal_different_conflicts_one_None(self):
265 package1 = FetchedPackage(
266 "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",
267 conflicts="bar")
268 package2 = FetchedPackage(
269 "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",
270 conflicts=None)
271 self.assertNotEqual(package1, package2)
272
273 def test_equal_same_conflicts(self):
274 package1 = FetchedPackage(
275 "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",
276 conflicts="bar")
277 package2 = FetchedPackage(
278 "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",
279 conflicts="bar")
280 self.assertEqual(package1, package2)
281
282 def test_not_equal_different_recommends(self):
283 package1 = FetchedPackage(
284 "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",
285 recommends="bar")
286 package2 = FetchedPackage(
287 "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",
288 recommends="baz")
289 self.assertNotEqual(package1, package2)
290
291 def test_not_equal_different_recommends_one_None(self):
292 package1 = FetchedPackage(
293 "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",
294 recommends="bar")
295 package2 = FetchedPackage(
296 "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",
297 recommends=None)
298 self.assertNotEqual(package1, package2)
299
300 def test_equal_same_recommends(self):
301 package1 = FetchedPackage(
302 "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",
303 recommends="bar")
304 package2 = FetchedPackage(
305 "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel",
306 recommends="bar")
307 self.assertEqual(package1, package2)
173308
174 def test_from_apt(self):309 def test_from_apt(self):
175 target_package = DummyFetchedPackage("foo", "1.0")310 target_package = DummyFetchedPackage("foo", "1.0")
@@ -180,15 +315,28 @@
180 candidate, target_package.filename, target_package.content)315 candidate, target_package.filename, target_package.content)
181 self.assertEqual(target_package, created_package)316 self.assertEqual(target_package, created_package)
182317
318 def assert_from_apt_translates_relationship(self, relationship):
319 kwargs = {}
320 kwargs[relationship] = "bar | baz (>= 1.0), zap"
321 target_package = DummyFetchedPackage("foo", "1.0", **kwargs)
322 source = self.useFixture(AptSourceFixture([target_package]))
323 with IsolatedAptCache([source.sources_entry]) as cache:
324 candidate = cache.cache['foo'].candidate
325 created_package = FetchedPackage.from_apt(
326 candidate, target_package.filename, target_package.content)
327 self.assertEqual(target_package, created_package)
328
183 def test_from_apt_with_depends(self):329 def test_from_apt_with_depends(self):
184 target_package = DummyFetchedPackage(330 self.assert_from_apt_translates_relationship('depends')
185 "foo", "1.0", depends="bar | baz (>= 1.0), zap")331
186 source = self.useFixture(AptSourceFixture([target_package]))332 def test_from_apt_with_pre_depends(self):
187 with IsolatedAptCache([source.sources_entry]) as cache:333 self.assert_from_apt_translates_relationship('pre_depends')
188 candidate = cache.cache['foo'].candidate334
189 created_package = FetchedPackage.from_apt(335 def test_from_apt_with_conflicts(self):
190 candidate, target_package.filename, target_package.content)336 self.assert_from_apt_translates_relationship('conflicts')
191 self.assertEqual(target_package, created_package)337
338 def test_from_apt_with_recommends(self):
339 self.assert_from_apt_translates_relationship('recommends')
192340
193341
194class AptCacheTests(TestCaseWithFixtures):342class AptCacheTests(TestCaseWithFixtures):
@@ -386,3 +534,16 @@
386 fetcher = self.get_fetcher([source], architecture="arch1")534 fetcher = self.get_fetcher([source], architecture="arch1")
387 self.assertEqual(535 self.assertEqual(
388 wanted_package, fetcher.fetch_packages(["foo"])[0])536 wanted_package, fetcher.fetch_packages(["foo"])[0])
537
538 def test_fetch_package_fetches_with_relationships(self):
539 depends = "foo"
540 pre_depends = "bar (>= 1.0)"
541 conflicts = "baz | zap"
542 recommends = "zing, zang"
543 wanted_package = DummyFetchedPackage(
544 "foo", "1.0", depends=depends, pre_depends=pre_depends,
545 conflicts=conflicts, recommends=recommends)
546 source = self.useFixture(AptSourceFixture([wanted_package]))
547 fetcher = self.get_fetcher([source])
548 self.assertEqual(
549 wanted_package, fetcher.fetch_packages(["foo"])[0])
389550
=== modified file 'hwpack/tests/test_tarfile_matchers.py'
--- hwpack/tests/test_tarfile_matchers.py 2010-08-31 16:35:41 +0000
+++ hwpack/tests/test_tarfile_matchers.py 2010-09-14 20:36:09 +0000
@@ -21,6 +21,7 @@
21 mismatch1 = TarfileMissingPathMismatch("foo", "bar")21 mismatch1 = TarfileMissingPathMismatch("foo", "bar")
22 mismatch2 = TarfileMissingPathMismatch("foo", "bar")22 mismatch2 = TarfileMissingPathMismatch("foo", "bar")
23 self.assertEqual(mismatch1, mismatch2)23 self.assertEqual(mismatch1, mismatch2)
24 self.assertFalse(mismatch1 != mismatch2)
2425
25 def test_no_eq_different_tarball(self):26 def test_no_eq_different_tarball(self):
26 mismatch1 = TarfileMissingPathMismatch("foo", "bar")27 mismatch1 = TarfileMissingPathMismatch("foo", "bar")
@@ -32,21 +33,6 @@
32 mismatch2 = TarfileMissingPathMismatch("foo", "baz")33 mismatch2 = TarfileMissingPathMismatch("foo", "baz")
33 self.assertNotEqual(mismatch1, mismatch2)34 self.assertNotEqual(mismatch1, mismatch2)
3435
35 def test_hash_equal(self):
36 mismatch1 = TarfileMissingPathMismatch("foo", "bar")
37 mismatch2 = TarfileMissingPathMismatch("foo", "bar")
38 self.assertEqual(hash(mismatch1), hash(mismatch2))
39
40 def test_different_tarball_different_hash(self):
41 mismatch1 = TarfileMissingPathMismatch("foo", "bar")
42 mismatch2 = TarfileMissingPathMismatch("baz", "bar")
43 self.assertNotEqual(hash(mismatch1), hash(mismatch2))
44
45 def test_different_path_different_hash(self):
46 mismatch1 = TarfileMissingPathMismatch("foo", "bar")
47 mismatch2 = TarfileMissingPathMismatch("foo", "baz")
48 self.assertNotEqual(hash(mismatch1), hash(mismatch2))
49
5036
51class TarfileWrongTypeMismatchTests(TestCase):37class TarfileWrongTypeMismatchTests(TestCase):
5238
@@ -60,6 +46,7 @@
60 mismatch1 = TarfileWrongValueMismatch("type", "foo", "bar", 1, 2)46 mismatch1 = TarfileWrongValueMismatch("type", "foo", "bar", 1, 2)
61 mismatch2 = TarfileWrongValueMismatch("type", "foo", "bar", 1, 2)47 mismatch2 = TarfileWrongValueMismatch("type", "foo", "bar", 1, 2)
62 self.assertEqual(mismatch1, mismatch2)48 self.assertEqual(mismatch1, mismatch2)
49 self.assertFalse(mismatch1 != mismatch2)
6350
64 def test_not_eq_different_attribute(self):51 def test_not_eq_different_attribute(self):
65 mismatch1 = TarfileWrongValueMismatch("type", "foo", "bar", 1, 2)52 mismatch1 = TarfileWrongValueMismatch("type", "foo", "bar", 1, 2)
@@ -86,36 +73,6 @@
86 mismatch2 = TarfileWrongValueMismatch("type", "foo", "bar", 1, 3)73 mismatch2 = TarfileWrongValueMismatch("type", "foo", "bar", 1, 3)
87 self.assertNotEqual(mismatch1, mismatch2)74 self.assertNotEqual(mismatch1, mismatch2)
8875
89 def test_hash_equal(self):
90 mismatch1 = TarfileWrongValueMismatch("type", "foo", "bar", 1, 2)
91 mismatch2 = TarfileWrongValueMismatch("type", "foo", "bar", 1, 2)
92 self.assertEqual(hash(mismatch1), hash(mismatch2))
93
94 def test_different_attribute_different_hash(self):
95 mismatch1 = TarfileWrongValueMismatch("type", "foo", "bar", 1, 2)
96 mismatch2 = TarfileWrongValueMismatch("size", "foo", "bar", 1, 2)
97 self.assertNotEqual(hash(mismatch1), hash(mismatch2))
98
99 def test_different_tarball_different_hash(self):
100 mismatch1 = TarfileWrongValueMismatch("type", "foo", "bar", 1, 2)
101 mismatch2 = TarfileWrongValueMismatch("type", "baz", "bar", 1, 2)
102 self.assertNotEqual(hash(mismatch1), hash(mismatch2))
103
104 def test_different_path_different_hash(self):
105 mismatch1 = TarfileWrongValueMismatch("type", "foo", "bar", 1, 2)
106 mismatch2 = TarfileWrongValueMismatch("type", "foo", "baz", 1, 2)
107 self.assertNotEqual(hash(mismatch1), hash(mismatch2))
108
109 def test_different_expected_different_hash(self):
110 mismatch1 = TarfileWrongValueMismatch("type", "foo", "bar", 1, 2)
111 mismatch2 = TarfileWrongValueMismatch("type", "foo", "bar", 3, 2)
112 self.assertNotEqual(hash(mismatch1), hash(mismatch2))
113
114 def test_different_actual_different_hash(self):
115 mismatch1 = TarfileWrongValueMismatch("type", "foo", "bar", 1, 2)
116 mismatch2 = TarfileWrongValueMismatch("type", "foo", "bar", 1, 3)
117 self.assertNotEqual(hash(mismatch1), hash(mismatch2))
118
11976
120class TarfileHasFileTests(TestCase):77class TarfileHasFileTests(TestCase):
12178

Subscribers

People subscribed via source and target branches