Merge lp:~james-w/linaro-image-tools/architecture-support into lp:linaro-image-tools/11.11
- architecture-support
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Michael Hudson-Doyle |
Approved revision: | 105 |
Merged at revision: | 66 |
Proposed branch: | lp:~james-w/linaro-image-tools/architecture-support |
Merge into: | lp:linaro-image-tools/11.11 |
Prerequisite: | lp:~james-w/linaro-image-tools/add-packages-to-hwpack |
Diff against target: |
413 lines (+115/-56) 5 files modified
hwpack/hardwarepack.py (+4/-2) hwpack/packages.py (+19/-5) hwpack/testing.py (+2/-8) hwpack/tests/test_hardwarepack.py (+30/-19) hwpack/tests/test_packages.py (+60/-22) |
To merge this branch: | bzr merge lp:~james-w/linaro-image-tools/architecture-support |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michael Hudson-Doyle (community) | Approve | ||
Review via email:
|
This proposal supersedes a proposal from 2010-09-02.
Commit message
Description of the change
Hi,
Here's a rather simple branch to add architecture support through the code
we have now.
I just updated the spec to state that ARCHITECTURE is a required field in
the metadata, so that's now a required argument to the constructor of the
corresponding class, and it is output in the __str__ method.
Also the Package classes get architecture as an ivar, such that we can
track which architecture they are for, which leads to the change in the
get_packages_file function, which can now stop hardcoding "all".
The dummy test package object defaults to "all" as that way the tests
will work on multiple architectures without updating.
However, that leaves a gap, so I added a couple of new tests to ensure
that we fetch packages from the right architecture.
In order to support cross-build of hardware packs I stole a trick from
the chdist tool, which allows us to tell apt to pretend it is on a
different architecture. I added a test to peek inside the implementation
and check we were writing the config correctly, but the two added tests
check that it has the desired effect.
There's still a gap, as noted in the spec, about how we specify the
architectures to build for, as I'm not sure whether it should be in
the configuration file or on the command line, or some combination
of the two. This will mainly depend on how we want to hook it in to
lexbuilder I think. At least now all the infrastructure is in place
to build for any arch that we like.
Thanks,
James
- 105. By James Westby
-
Merge add-packages-
to-hwpack in to architecture- support.
Preview Diff
1 | === modified file 'hwpack/hardwarepack.py' | |||
2 | --- hwpack/hardwarepack.py 2010-09-02 23:07:45 +0000 | |||
3 | +++ hwpack/hardwarepack.py 2010-09-02 23:07:46 +0000 | |||
4 | @@ -26,8 +26,8 @@ | |||
5 | 26 | :type support: str or None | 26 | :type support: str or None |
6 | 27 | """ | 27 | """ |
7 | 28 | 28 | ||
10 | 29 | def __init__(self, name, version, origin=None, maintainer=None, | 29 | def __init__(self, name, version, architecture, origin=None, |
11 | 30 | support=None): | 30 | maintainer=None, support=None): |
12 | 31 | """Create the Metadata for a hardware pack. | 31 | """Create the Metadata for a hardware pack. |
13 | 32 | 32 | ||
14 | 33 | See the instance variables for a description of the arguments. | 33 | See the instance variables for a description of the arguments. |
15 | @@ -37,11 +37,13 @@ | |||
16 | 37 | self.origin = origin | 37 | self.origin = origin |
17 | 38 | self.maintainer = maintainer | 38 | self.maintainer = maintainer |
18 | 39 | self.support = support | 39 | self.support = support |
19 | 40 | self.architecture = architecture | ||
20 | 40 | 41 | ||
21 | 41 | def __str__(self): | 42 | def __str__(self): |
22 | 42 | """Get the contents of the metadata file.""" | 43 | """Get the contents of the metadata file.""" |
23 | 43 | metadata = "NAME=%s\n" % self.name | 44 | metadata = "NAME=%s\n" % self.name |
24 | 44 | metadata += "VERSION=%s\n" % self.version | 45 | metadata += "VERSION=%s\n" % self.version |
25 | 46 | metadata += "ARCHITECTURE=%s\n" % self.architecture | ||
26 | 45 | if self.origin is not None: | 47 | if self.origin is not None: |
27 | 46 | metadata += "ORIGIN=%s\n" % self.origin | 48 | metadata += "ORIGIN=%s\n" % self.origin |
28 | 47 | if self.maintainer is not None: | 49 | if self.maintainer is not None: |
29 | 48 | 50 | ||
30 | === modified file 'hwpack/packages.py' | |||
31 | --- hwpack/packages.py 2010-09-02 23:07:45 +0000 | |||
32 | +++ hwpack/packages.py 2010-09-02 23:07:46 +0000 | |||
33 | @@ -23,7 +23,7 @@ | |||
34 | 23 | parts.append('Filename: %s' % package.filename) | 23 | parts.append('Filename: %s' % package.filename) |
35 | 24 | parts.append('Size: %d' % package.size) | 24 | parts.append('Size: %d' % package.size) |
36 | 25 | # TODO: architecture support | 25 | # TODO: architecture support |
38 | 26 | parts.append('Architecture: all') | 26 | parts.append('Architecture: %s' % package.architecture) |
39 | 27 | parts.append('MD5sum: %s' % package.md5) | 27 | parts.append('MD5sum: %s' % package.md5) |
40 | 28 | content += "\n".join(parts) | 28 | content += "\n".join(parts) |
41 | 29 | content += "\n\n" | 29 | content += "\n\n" |
42 | @@ -75,9 +75,13 @@ | |||
43 | 75 | :ivar md5: the hex representation of the md5sum of the contents of | 75 | :ivar md5: the hex representation of the md5sum of the contents of |
44 | 76 | the package. | 76 | the package. |
45 | 77 | :type md5: str | 77 | :type md5: str |
46 | 78 | :ivar architecture: the architecture that the package is for, may be | ||
47 | 79 | 'all'. | ||
48 | 80 | :type architecture: str | ||
49 | 78 | """ | 81 | """ |
50 | 79 | 82 | ||
52 | 80 | def __init__(self, name, version, filename, content, size, md5): | 83 | def __init__(self, name, version, filename, content, size, md5, |
53 | 84 | architecture): | ||
54 | 81 | """Create a FetchedPackage. | 85 | """Create a FetchedPackage. |
55 | 82 | 86 | ||
56 | 83 | See the instance variables for the arguments. | 87 | See the instance variables for the arguments. |
57 | @@ -88,6 +92,7 @@ | |||
58 | 88 | self.content = content | 92 | self.content = content |
59 | 89 | self.size = size | 93 | self.size = size |
60 | 90 | self.md5 = md5 | 94 | self.md5 = md5 |
61 | 95 | self.architecture = architecture | ||
62 | 91 | 96 | ||
63 | 92 | def __eq__(self, other): | 97 | def __eq__(self, other): |
64 | 93 | return (self.name == other.name | 98 | return (self.name == other.name |
65 | @@ -95,7 +100,8 @@ | |||
66 | 95 | and self.filename == other.filename | 100 | and self.filename == other.filename |
67 | 96 | and self.content.read() == other.content.read() | 101 | and self.content.read() == other.content.read() |
68 | 97 | and self.size == other.size | 102 | and self.size == other.size |
70 | 98 | and self.md5 == other.md5) | 103 | and self.md5 == other.md5 |
71 | 104 | and self.architecture == other.architecture) | ||
72 | 99 | 105 | ||
73 | 100 | def __hash__(self): | 106 | def __hash__(self): |
74 | 101 | return hash( | 107 | return hash( |
75 | @@ -105,7 +111,7 @@ | |||
76 | 105 | class PackageFetcher(object): | 111 | class PackageFetcher(object): |
77 | 106 | """A class to fetch packages from a defined list of sources.""" | 112 | """A class to fetch packages from a defined list of sources.""" |
78 | 107 | 113 | ||
80 | 108 | def __init__(self, sources): | 114 | def __init__(self, sources, architecture=None): |
81 | 109 | """Create a PackageFetcher. | 115 | """Create a PackageFetcher. |
82 | 110 | 116 | ||
83 | 111 | Once created a PackageFetcher should have its `prepare` method | 117 | Once created a PackageFetcher should have its `prepare` method |
84 | @@ -114,8 +120,11 @@ | |||
85 | 114 | :param sources: a list of sources such that they can be prefixed | 120 | :param sources: a list of sources such that they can be prefixed |
86 | 115 | with "deb " and fed to apt. | 121 | with "deb " and fed to apt. |
87 | 116 | :type sources: an iterable of str | 122 | :type sources: an iterable of str |
88 | 123 | :param architecture: the architecture to fetch packages for. | ||
89 | 124 | :type architecture: str | ||
90 | 117 | """ | 125 | """ |
91 | 118 | self.sources = sources | 126 | self.sources = sources |
92 | 127 | self.architecture = architecture | ||
93 | 119 | self.tempdir = None | 128 | self.tempdir = None |
94 | 120 | 129 | ||
95 | 121 | def prepare(self): | 130 | def prepare(self): |
96 | @@ -143,6 +152,10 @@ | |||
97 | 143 | with open(sources_list, 'w') as f: | 152 | with open(sources_list, 'w') as f: |
98 | 144 | for source in self.sources: | 153 | for source in self.sources: |
99 | 145 | f.write("deb %s\n" % source) | 154 | f.write("deb %s\n" % source) |
100 | 155 | if self.architecture is not None: | ||
101 | 156 | apt_conf = os.path.join(self.tempdir, "etc", "apt", "apt.conf") | ||
102 | 157 | with open(apt_conf, 'w') as f: | ||
103 | 158 | f.write('Apt {\nArchitecture "%s";\n}\n' % self.architecture) | ||
104 | 146 | self.cache = Cache(rootdir=self.tempdir, memonly=True) | 159 | self.cache = Cache(rootdir=self.tempdir, memonly=True) |
105 | 147 | self.cache.update() | 160 | self.cache.update() |
106 | 148 | self.cache.open() | 161 | self.cache.open() |
107 | @@ -183,6 +196,7 @@ | |||
108 | 183 | (acqfile.destfile, acqfile.error_text)) | 196 | (acqfile.destfile, acqfile.error_text)) |
109 | 184 | result_package = FetchedPackage( | 197 | result_package = FetchedPackage( |
110 | 185 | candidate.package.name, candidate.version, base, | 198 | candidate.package.name, candidate.version, base, |
112 | 186 | open(destfile), candidate.size, candidate.md5) | 199 | open(destfile), candidate.size, candidate.md5, |
113 | 200 | candidate.architecture) | ||
114 | 187 | results.append(result_package) | 201 | results.append(result_package) |
115 | 188 | return results | 202 | return results |
116 | 189 | 203 | ||
117 | === modified file 'hwpack/testing.py' | |||
118 | --- hwpack/testing.py 2010-09-02 23:07:45 +0000 | |||
119 | +++ hwpack/testing.py 2010-09-02 23:07:46 +0000 | |||
120 | @@ -52,16 +52,10 @@ | |||
121 | 52 | See FetchedPackage for the instance variables. | 52 | See FetchedPackage for the instance variables. |
122 | 53 | """ | 53 | """ |
123 | 54 | 54 | ||
132 | 55 | def __init__(self, name, version): | 55 | def __init__(self, name, version, architecture="all"): |
125 | 56 | """Create a DummyFetchedPackage. | ||
126 | 57 | |||
127 | 58 | :param name: the name of the package. | ||
128 | 59 | :type name: str | ||
129 | 60 | :param version: the version of the package. | ||
130 | 61 | :type version: str | ||
131 | 62 | """ | ||
133 | 63 | self.name = name | 56 | self.name = name |
134 | 64 | self.version = version | 57 | self.version = version |
135 | 58 | self.architecture = architecture | ||
136 | 65 | 59 | ||
137 | 66 | @property | 60 | @property |
138 | 67 | def filename(self): | 61 | def filename(self): |
139 | 68 | 62 | ||
140 | === modified file 'hwpack/tests/test_hardwarepack.py' | |||
141 | --- hwpack/tests/test_hardwarepack.py 2010-09-02 23:07:45 +0000 | |||
142 | +++ hwpack/tests/test_hardwarepack.py 2010-09-02 23:07:46 +0000 | |||
143 | @@ -12,56 +12,67 @@ | |||
144 | 12 | class MetadataTests(TestCase): | 12 | class MetadataTests(TestCase): |
145 | 13 | 13 | ||
146 | 14 | def test_name(self): | 14 | def test_name(self): |
148 | 15 | metadata = Metadata("ahwpack", "3") | 15 | metadata = Metadata("ahwpack", "3", "armel") |
149 | 16 | self.assertEqual("ahwpack", metadata.name) | 16 | self.assertEqual("ahwpack", metadata.name) |
150 | 17 | 17 | ||
151 | 18 | def test_version(self): | 18 | def test_version(self): |
153 | 19 | metadata = Metadata("ahwpack", "3") | 19 | metadata = Metadata("ahwpack", "3", "armel") |
154 | 20 | self.assertEqual("3", metadata.version) | 20 | self.assertEqual("3", metadata.version) |
155 | 21 | 21 | ||
156 | 22 | def test_architecture(self): | ||
157 | 23 | metadata = Metadata("ahwpack", "3", "armel") | ||
158 | 24 | self.assertEqual("armel", metadata.architecture) | ||
159 | 25 | |||
160 | 22 | def test_default_origin_is_None(self): | 26 | def test_default_origin_is_None(self): |
162 | 23 | metadata = Metadata("ahwpack", "4") | 27 | metadata = Metadata("ahwpack", "4", "armel") |
163 | 24 | self.assertEqual(None, metadata.origin) | 28 | self.assertEqual(None, metadata.origin) |
164 | 25 | 29 | ||
165 | 26 | def test_origin(self): | 30 | def test_origin(self): |
167 | 27 | metadata = Metadata("ahwpack", "4", origin="linaro") | 31 | metadata = Metadata("ahwpack", "4", "armel", origin="linaro") |
168 | 28 | self.assertEqual("linaro", metadata.origin) | 32 | self.assertEqual("linaro", metadata.origin) |
169 | 29 | 33 | ||
170 | 30 | def test_default_maintainer_is_None(self): | 34 | def test_default_maintainer_is_None(self): |
172 | 31 | metadata = Metadata("ahwpack", "4") | 35 | metadata = Metadata("ahwpack", "4", "armel") |
173 | 32 | self.assertEqual(None, metadata.maintainer) | 36 | self.assertEqual(None, metadata.maintainer) |
174 | 33 | 37 | ||
175 | 34 | def test_maintainer(self): | 38 | def test_maintainer(self): |
177 | 35 | metadata = Metadata("ahwpack", "4", maintainer="Some maintainer") | 39 | metadata = Metadata( |
178 | 40 | "ahwpack", "4", "armel", maintainer="Some maintainer") | ||
179 | 36 | self.assertEqual("Some maintainer", metadata.maintainer) | 41 | self.assertEqual("Some maintainer", metadata.maintainer) |
180 | 37 | 42 | ||
181 | 38 | def test_default_support_is_None(self): | 43 | def test_default_support_is_None(self): |
183 | 39 | metadata = Metadata("ahwpack", "4") | 44 | metadata = Metadata("ahwpack", "4", "armel") |
184 | 40 | self.assertEqual(None, metadata.support) | 45 | self.assertEqual(None, metadata.support) |
185 | 41 | 46 | ||
186 | 42 | def test_support(self): | 47 | def test_support(self): |
188 | 43 | metadata = Metadata("ahwpack", "4", support="supported") | 48 | metadata = Metadata("ahwpack", "4", "armel", support="supported") |
189 | 44 | self.assertEqual("supported", metadata.support) | 49 | self.assertEqual("supported", metadata.support) |
190 | 45 | 50 | ||
191 | 46 | def test_str(self): | 51 | def test_str(self): |
194 | 47 | metadata = Metadata("ahwpack", "4") | 52 | metadata = Metadata("ahwpack", "4", "armel") |
195 | 48 | self.assertEqual("NAME=ahwpack\nVERSION=4\n", str(metadata)) | 53 | self.assertEqual( |
196 | 54 | "NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n", str(metadata)) | ||
197 | 49 | 55 | ||
198 | 50 | def test_str_with_origin(self): | 56 | def test_str_with_origin(self): |
200 | 51 | metadata = Metadata("ahwpack", "4", origin="linaro") | 57 | metadata = Metadata("ahwpack", "4", "armel", origin="linaro") |
201 | 52 | self.assertEqual( | 58 | self.assertEqual( |
203 | 53 | "NAME=ahwpack\nVERSION=4\nORIGIN=linaro\n", str(metadata)) | 59 | "NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\nORIGIN=linaro\n", |
204 | 60 | str(metadata)) | ||
205 | 54 | 61 | ||
206 | 55 | def test_str_with_maintainer(self): | 62 | def test_str_with_maintainer(self): |
208 | 56 | metadata = Metadata("ahwpack", "4", maintainer="Some Maintainer") | 63 | metadata = Metadata( |
209 | 64 | "ahwpack", "4", "armel", maintainer="Some Maintainer") | ||
210 | 57 | self.assertEqual( | 65 | self.assertEqual( |
212 | 58 | "NAME=ahwpack\nVERSION=4\nMAINTAINER=Some Maintainer\n", | 66 | "NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n" |
213 | 67 | "MAINTAINER=Some Maintainer\n", | ||
214 | 59 | str(metadata)) | 68 | str(metadata)) |
215 | 60 | 69 | ||
216 | 61 | def test_str_with_support(self): | 70 | def test_str_with_support(self): |
218 | 62 | metadata = Metadata("ahwpack", "4", support="unsupported") | 71 | metadata = Metadata("ahwpack", "4", "armel", support="unsupported") |
219 | 63 | self.assertEqual( | 72 | self.assertEqual( |
221 | 64 | "NAME=ahwpack\nVERSION=4\nSUPPORT=unsupported\n", str(metadata)) | 73 | "NAME=ahwpack\nVERSION=4\nARCHITECTURE=armel\n" |
222 | 74 | "SUPPORT=unsupported\n", | ||
223 | 75 | str(metadata)) | ||
224 | 65 | 76 | ||
225 | 66 | 77 | ||
226 | 67 | class HardwarePackHasFile(TarfileHasFile): | 78 | class HardwarePackHasFile(TarfileHasFile): |
227 | @@ -111,7 +122,7 @@ | |||
228 | 111 | 122 | ||
229 | 112 | def setUp(self): | 123 | def setUp(self): |
230 | 113 | super(HardwarePackTests, self).setUp() | 124 | super(HardwarePackTests, self).setUp() |
232 | 114 | self.metadata = Metadata("ahwpack", 4) | 125 | self.metadata = Metadata("ahwpack", 4, "armel") |
233 | 115 | 126 | ||
234 | 116 | def test_format_is_1_0(self): | 127 | def test_format_is_1_0(self): |
235 | 117 | hwpack = HardwarePack(self.metadata) | 128 | hwpack = HardwarePack(self.metadata) |
236 | @@ -122,7 +133,7 @@ | |||
237 | 122 | self.assertEqual("hwpack_ahwpack_4.tar.gz", hwpack.filename()) | 133 | self.assertEqual("hwpack_ahwpack_4.tar.gz", hwpack.filename()) |
238 | 123 | 134 | ||
239 | 124 | def test_filename_with_support(self): | 135 | def test_filename_with_support(self): |
241 | 125 | metadata = Metadata("ahwpack", "4", support="supported") | 136 | metadata = Metadata("ahwpack", "4", "armel", support="supported") |
242 | 126 | hwpack = HardwarePack(metadata) | 137 | hwpack = HardwarePack(metadata) |
243 | 127 | self.assertEqual( | 138 | self.assertEqual( |
244 | 128 | "hwpack_ahwpack_4_supported.tar.gz", hwpack.filename()) | 139 | "hwpack_ahwpack_4_supported.tar.gz", hwpack.filename()) |
245 | @@ -144,7 +155,7 @@ | |||
246 | 144 | 155 | ||
247 | 145 | def test_creates_metadata_file(self): | 156 | def test_creates_metadata_file(self): |
248 | 146 | metadata = Metadata( | 157 | metadata = Metadata( |
250 | 147 | "ahwpack", "4", origin="linaro", | 158 | "ahwpack", "4", "armel", origin="linaro", |
251 | 148 | maintainer="Some Maintainer", support="unsupported") | 159 | maintainer="Some Maintainer", support="unsupported") |
252 | 149 | hwpack = HardwarePack(metadata) | 160 | hwpack = HardwarePack(metadata) |
253 | 150 | tf = self.get_tarfile(hwpack) | 161 | tf = self.get_tarfile(hwpack) |
254 | 151 | 162 | ||
255 | === modified file 'hwpack/tests/test_packages.py' | |||
256 | --- hwpack/tests/test_packages.py 2010-09-02 23:07:45 +0000 | |||
257 | +++ hwpack/tests/test_packages.py 2010-09-02 23:07:46 +0000 | |||
258 | @@ -19,13 +19,13 @@ | |||
259 | 19 | class GetPackagesFileTests(TestCase): | 19 | class GetPackagesFileTests(TestCase): |
260 | 20 | 20 | ||
261 | 21 | def test_single_stanza(self): | 21 | def test_single_stanza(self): |
263 | 22 | package = DummyFetchedPackage("foo", "1.1") | 22 | package = DummyFetchedPackage("foo", "1.1", architecture="armel") |
264 | 23 | self.assertEqual(textwrap.dedent("""\ | 23 | self.assertEqual(textwrap.dedent("""\ |
265 | 24 | Package: foo | 24 | Package: foo |
266 | 25 | Version: 1.1 | 25 | Version: 1.1 |
267 | 26 | Filename: %(filename)s | 26 | Filename: %(filename)s |
268 | 27 | Size: %(size)d | 27 | Size: %(size)d |
270 | 28 | Architecture: all | 28 | Architecture: armel |
271 | 29 | MD5sum: %(md5)s | 29 | MD5sum: %(md5)s |
272 | 30 | \n""" % { | 30 | \n""" % { |
273 | 31 | 'filename': package.filename, | 31 | 'filename': package.filename, |
274 | @@ -45,68 +45,77 @@ | |||
275 | 45 | 45 | ||
276 | 46 | def test_attributes(self): | 46 | def test_attributes(self): |
277 | 47 | package = FetchedPackage( | 47 | package = FetchedPackage( |
279 | 48 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa") | 48 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", |
280 | 49 | "armel") | ||
281 | 49 | self.assertEqual("foo", package.name) | 50 | self.assertEqual("foo", package.name) |
282 | 50 | self.assertEqual("1.1", package.version) | 51 | self.assertEqual("1.1", package.version) |
283 | 51 | self.assertEqual("foo_1.1.deb", package.filename) | 52 | self.assertEqual("foo_1.1.deb", package.filename) |
284 | 52 | self.assertEqual("xxxx", package.content.read()) | 53 | self.assertEqual("xxxx", package.content.read()) |
285 | 53 | self.assertEqual(4, package.size) | 54 | self.assertEqual(4, package.size) |
286 | 54 | self.assertEqual("aaaa", package.md5) | 55 | self.assertEqual("aaaa", package.md5) |
287 | 56 | self.assertEqual("armel", package.architecture) | ||
288 | 55 | 57 | ||
289 | 56 | def test_equal(self): | 58 | def test_equal(self): |
290 | 57 | package1 = FetchedPackage( | 59 | package1 = FetchedPackage( |
292 | 58 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa") | 60 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel") |
293 | 59 | package2 = FetchedPackage( | 61 | package2 = FetchedPackage( |
295 | 60 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa") | 62 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel") |
296 | 61 | self.assertEqual(package1, package2) | 63 | self.assertEqual(package1, package2) |
297 | 62 | 64 | ||
298 | 63 | def test_not_equal_different_name(self): | 65 | def test_not_equal_different_name(self): |
299 | 64 | package1 = FetchedPackage( | 66 | package1 = FetchedPackage( |
301 | 65 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa") | 67 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel") |
302 | 66 | package2 = FetchedPackage( | 68 | package2 = FetchedPackage( |
304 | 67 | "bar", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa") | 69 | "bar", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel") |
305 | 68 | self.assertNotEqual(package1, package2) | 70 | self.assertNotEqual(package1, package2) |
306 | 69 | 71 | ||
307 | 70 | def test_not_equal_different_version(self): | 72 | def test_not_equal_different_version(self): |
308 | 71 | package1 = FetchedPackage( | 73 | package1 = FetchedPackage( |
310 | 72 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa") | 74 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel") |
311 | 73 | package2 = FetchedPackage( | 75 | package2 = FetchedPackage( |
313 | 74 | "foo", "1.2", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa") | 76 | "foo", "1.2", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel") |
314 | 75 | self.assertNotEqual(package1, package2) | 77 | self.assertNotEqual(package1, package2) |
315 | 76 | 78 | ||
316 | 77 | def test_not_equal_different_filename(self): | 79 | def test_not_equal_different_filename(self): |
317 | 78 | package1 = FetchedPackage( | 80 | package1 = FetchedPackage( |
319 | 79 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa") | 81 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel") |
320 | 80 | package2 = FetchedPackage( | 82 | package2 = FetchedPackage( |
322 | 81 | "foo", "1.1", "afoo_1.1.deb", StringIO("xxxx"), 4, "aaaa") | 83 | "foo", "1.1", "afoo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel") |
323 | 82 | self.assertNotEqual(package1, package2) | 84 | self.assertNotEqual(package1, package2) |
324 | 83 | 85 | ||
325 | 84 | def test_not_equal_different_content(self): | 86 | def test_not_equal_different_content(self): |
326 | 85 | package1 = FetchedPackage( | 87 | package1 = FetchedPackage( |
328 | 86 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa") | 88 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel") |
329 | 87 | package2 = FetchedPackage( | 89 | package2 = FetchedPackage( |
331 | 88 | "foo", "1.1", "foo_1.1.deb", StringIO("yyyy"), 4, "aaaa") | 90 | "foo", "1.1", "foo_1.1.deb", StringIO("yyyy"), 4, "aaaa", "armel") |
332 | 89 | self.assertNotEqual(package1, package2) | 91 | self.assertNotEqual(package1, package2) |
333 | 90 | 92 | ||
334 | 91 | def test_not_equal_different_size(self): | 93 | def test_not_equal_different_size(self): |
335 | 92 | package1 = FetchedPackage( | 94 | package1 = FetchedPackage( |
337 | 93 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa") | 95 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel") |
338 | 94 | package2 = FetchedPackage( | 96 | package2 = FetchedPackage( |
340 | 95 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 5, "aaaa") | 97 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 5, "aaaa", "armel") |
341 | 96 | self.assertNotEqual(package1, package2) | 98 | self.assertNotEqual(package1, package2) |
342 | 97 | 99 | ||
343 | 98 | def test_not_equal_different_md5(self): | 100 | def test_not_equal_different_md5(self): |
344 | 99 | package1 = FetchedPackage( | 101 | package1 = FetchedPackage( |
348 | 100 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa") | 102 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel") |
349 | 101 | package2 = FetchedPackage( | 103 | package2 = FetchedPackage( |
350 | 102 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "bbbb") | 104 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "bbbb", "armel") |
351 | 105 | self.assertNotEqual(package1, package2) | ||
352 | 106 | |||
353 | 107 | def test_not_equal_different_architecture(self): | ||
354 | 108 | package1 = FetchedPackage( | ||
355 | 109 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel") | ||
356 | 110 | package2 = FetchedPackage( | ||
357 | 111 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "i386") | ||
358 | 103 | self.assertNotEqual(package1, package2) | 112 | self.assertNotEqual(package1, package2) |
359 | 104 | 113 | ||
360 | 105 | def test_equal_hash_equal(self): | 114 | def test_equal_hash_equal(self): |
361 | 106 | package1 = FetchedPackage( | 115 | package1 = FetchedPackage( |
363 | 107 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa") | 116 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel") |
364 | 108 | package2 = FetchedPackage( | 117 | package2 = FetchedPackage( |
366 | 109 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa") | 118 | "foo", "1.1", "foo_1.1.deb", StringIO("xxxx"), 4, "aaaa", "armel") |
367 | 110 | self.assertEqual(hash(package1), hash(package2)) | 119 | self.assertEqual(hash(package1), hash(package2)) |
368 | 111 | 120 | ||
369 | 112 | 121 | ||
370 | @@ -177,8 +186,18 @@ | |||
371 | 177 | open(os.path.join( | 186 | open(os.path.join( |
372 | 178 | fetcher.tempdir, "etc", "apt", "sources.list")).read()) | 187 | fetcher.tempdir, "etc", "apt", "sources.list")).read()) |
373 | 179 | 188 | ||
376 | 180 | def get_fetcher(self, sources): | 189 | def test_prepare_with_arch_creates_etc_apt_apt_conf(self): |
377 | 181 | fetcher = PackageFetcher([s.sources_entry for s in sources]) | 190 | fetcher = PackageFetcher([], architecture="arch") |
378 | 191 | self.addCleanup(fetcher.cleanup) | ||
379 | 192 | fetcher.prepare() | ||
380 | 193 | self.assertEqual( | ||
381 | 194 | 'Apt {\nArchitecture "arch";\n}\n', | ||
382 | 195 | open(os.path.join( | ||
383 | 196 | fetcher.tempdir, "etc", "apt", "apt.conf")).read()) | ||
384 | 197 | |||
385 | 198 | def get_fetcher(self, sources, architecture=None): | ||
386 | 199 | fetcher = PackageFetcher( | ||
387 | 200 | [s.sources_entry for s in sources], architecture=architecture) | ||
388 | 182 | self.addCleanup(fetcher.cleanup) | 201 | self.addCleanup(fetcher.cleanup) |
389 | 183 | fetcher.prepare() | 202 | fetcher.prepare() |
390 | 184 | return fetcher | 203 | return fetcher |
391 | @@ -257,3 +276,22 @@ | |||
392 | 257 | fetcher = self.get_fetcher([old_source, new_source]) | 276 | fetcher = self.get_fetcher([old_source, new_source]) |
393 | 258 | fetched = fetcher.fetch_packages(["bar"]) | 277 | fetched = fetcher.fetch_packages(["bar"]) |
394 | 259 | self.assertEqual(new_source_packages[0], fetched[0]) | 278 | self.assertEqual(new_source_packages[0], fetched[0]) |
395 | 279 | |||
396 | 280 | def test_fetch_package_records_correct_architecture(self): | ||
397 | 281 | available_package = DummyFetchedPackage( | ||
398 | 282 | "foo", "1.0", architecture="nonexistant") | ||
399 | 283 | source = self.useFixture(AptSourceFixture([available_package])) | ||
400 | 284 | fetcher = self.get_fetcher([source], architecture="nonexistant") | ||
401 | 285 | self.assertEqual( | ||
402 | 286 | "nonexistant", fetcher.fetch_packages(["foo"])[0].architecture) | ||
403 | 287 | |||
404 | 288 | def test_fetch_package_fetches_from_correct_architecture(self): | ||
405 | 289 | wanted_package = DummyFetchedPackage( | ||
406 | 290 | "foo", "1.0", architecture="arch1") | ||
407 | 291 | unwanted_package = DummyFetchedPackage( | ||
408 | 292 | "foo", "1.1", architecture="arch2") | ||
409 | 293 | source = self.useFixture( | ||
410 | 294 | AptSourceFixture([wanted_package, unwanted_package])) | ||
411 | 295 | fetcher = self.get_fetcher([source], architecture="arch1") | ||
412 | 296 | self.assertEqual( | ||
413 | 297 | wanted_package, fetcher.fetch_packages(["foo"])[0]) |
Looks fine to me!