Merge ~cjwatson/launchpad:py3-nascentuploadfile into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 628635c24e3a997f3e67b9bea107159ee3891c43
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:py3-nascentuploadfile
Merge into: launchpad:master
Diff against target: 204 lines (+27/-21)
3 files modified
lib/lp/archiveuploader/nascentuploadfile.py (+6/-2)
lib/lp/archiveuploader/tests/test_buildinfofile.py (+2/-2)
lib/lp/archiveuploader/tests/test_nascentuploadfile.py (+19/-17)
Reviewer Review Type Date Requested Status
Cristian Gonzalez (community) Approve
Review via email: mp+398909@code.launchpad.net

Commit message

Fix NascentUploadFile and its tests on Python 3

Description of the change

This is mostly just being stricter about bytes vs. text types where needed.

To post a comment you must log in.
Revision history for this message
Cristian Gonzalez (cristiangsp) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/archiveuploader/nascentuploadfile.py b/lib/lp/archiveuploader/nascentuploadfile.py
2index 7183c9a..cf710e8 100644
3--- a/lib/lp/archiveuploader/nascentuploadfile.py
4+++ b/lib/lp/archiveuploader/nascentuploadfile.py
5@@ -721,7 +721,9 @@ class BaseBinaryUploadFile(PackageUploadFile):
6 yield UploadError(
7 "%s: 'dpkg-deb -I' invocation failed." % self.filename)
8 yield UploadError(
9- prefix_multi_line_string(e.output, " [dpkg-deb output:] "))
10+ prefix_multi_line_string(
11+ six.ensure_text(e.output, errors="replace"),
12+ " [dpkg-deb output:] "))
13
14 try:
15 subprocess.check_output(
16@@ -730,7 +732,9 @@ class BaseBinaryUploadFile(PackageUploadFile):
17 yield UploadError(
18 "%s: 'dpkg-deb -c' invocation failed." % self.filename)
19 yield UploadError(
20- prefix_multi_line_string(e.output, " [dpkg-deb output:] "))
21+ prefix_multi_line_string(
22+ six.ensure_text(e.output, errors="replace"),
23+ " [dpkg-deb output:] "))
24
25 def verifyDebTimestamp(self):
26 """Check specific DEB format timestamp checks."""
27diff --git a/lib/lp/archiveuploader/tests/test_buildinfofile.py b/lib/lp/archiveuploader/tests/test_buildinfofile.py
28index 10cae54..59a1451 100644
29--- a/lib/lp/archiveuploader/tests/test_buildinfofile.py
30+++ b/lib/lp/archiveuploader/tests/test_buildinfofile.py
31@@ -32,7 +32,7 @@ class TestBuildInfoFile(PackageUploadFileTestCase):
32 def makeBuildInfoFile(self, filename, buildinfo, component_and_section,
33 priority_name, package, version, changes):
34 path, md5, sha1, size = self.writeUploadFile(
35- filename, buildinfo.dump())
36+ filename, buildinfo.dump().encode("UTF-8"))
37 return BuildInfoFile(
38 path, {"MD5": md5}, size, component_and_section, priority_name,
39 package, version, changes, self.policy, self.logger)
40@@ -63,7 +63,7 @@ class TestBuildInfoFile(PackageUploadFileTestCase):
41 self.createChangesFile("foo_0.1-1_source.changes", changes))
42 lfa = buildinfofile.storeInDatabase()
43 self.layer.txn.commit()
44- self.assertEqual(buildinfo.dump(), lfa.read())
45+ self.assertEqual(buildinfo.dump().encode('UTF-8'), lfa.read())
46
47 def test_checkBuild(self):
48 das = self.factory.makeDistroArchSeries(
49diff --git a/lib/lp/archiveuploader/tests/test_nascentuploadfile.py b/lib/lp/archiveuploader/tests/test_nascentuploadfile.py
50index eac0c5b..b43d762 100644
51--- a/lib/lp/archiveuploader/tests/test_nascentuploadfile.py
52+++ b/lib/lp/archiveuploader/tests/test_nascentuploadfile.py
53@@ -20,6 +20,7 @@ from debian.deb822 import (
54 Deb822,
55 Dsc,
56 )
57+import six
58 from testtools.matchers import (
59 Contains,
60 Equals,
61@@ -79,7 +80,7 @@ class NascentUploadFileTestCase(TestCaseWithFactory):
62 :return: Tuple with path, md5 and size
63 """
64 path = os.path.join(self.makeTemporaryDirectory(), filename)
65- with open(path, 'w') as f:
66+ with open(path, 'wb') as f:
67 f.write(contents)
68 return (
69 path, hashlib.md5(contents).hexdigest(),
70@@ -91,7 +92,7 @@ class TestNascentUploadFile(NascentUploadFileTestCase):
71 layer = ZopelessDatabaseLayer
72
73 def test_checkSizeAndCheckSum_validates_size(self):
74- (path, md5, sha1, size) = self.writeUploadFile('foo', 'bar')
75+ (path, md5, sha1, size) = self.writeUploadFile('foo', b'bar')
76 nuf = NascentUploadFile(
77 path, dict(MD5=md5), size - 1, 'main/devel', None, None, None)
78 self.assertRaisesWithContent(
79@@ -100,7 +101,7 @@ class TestNascentUploadFile(NascentUploadFileTestCase):
80 nuf.checkSizeAndCheckSum)
81
82 def test_checkSizeAndCheckSum_validates_md5(self):
83- (path, md5, sha1, size) = self.writeUploadFile('foo', 'bar')
84+ (path, md5, sha1, size) = self.writeUploadFile('foo', b'bar')
85 nuf = NascentUploadFile(
86 path, dict(MD5='deadbeef'), size, 'main/devel', None, None, None)
87 self.assertRaisesWithContent(
88@@ -110,7 +111,7 @@ class TestNascentUploadFile(NascentUploadFileTestCase):
89 nuf.checkSizeAndCheckSum)
90
91 def test_checkSizeAndCheckSum_validates_sha1(self):
92- (path, md5, sha1, size) = self.writeUploadFile('foo', 'bar')
93+ (path, md5, sha1, size) = self.writeUploadFile('foo', b'bar')
94 nuf = NascentUploadFile(
95 path, dict(MD5=md5, SHA1='foobar'), size, 'main/devel', None,
96 None, None)
97@@ -138,7 +139,7 @@ class CustomUploadFileTests(NascentUploadFileTestCase):
98 def test_custom_type(self):
99 # The mime type gets set according to PackageUploadCustomFormat.
100 uploadfile = self.createCustomUploadFile(
101- "bla.txt", "data", "main/raw-installer", "extra")
102+ "bla.txt", b"data", "main/raw-installer", "extra")
103 self.assertEqual(
104 PackageUploadCustomFormat.DEBIAN_INSTALLER,
105 uploadfile.custom_type)
106@@ -146,7 +147,7 @@ class CustomUploadFileTests(NascentUploadFileTestCase):
107 def test_storeInDatabase(self):
108 # storeInDatabase creates a library file.
109 uploadfile = self.createCustomUploadFile(
110- "bla.txt", "data", "main/raw-installer", "extra")
111+ "bla.txt", b"data", "main/raw-installer", "extra")
112 self.assertEqual("application/octet-stream", uploadfile.content_type)
113 libraryfile = uploadfile.storeInDatabase()
114 self.assertEqual("bla.txt", libraryfile.filename)
115@@ -155,11 +156,11 @@ class CustomUploadFileTests(NascentUploadFileTestCase):
116 def test_debian_installer_verify(self):
117 # debian-installer uploads are required to have sensible filenames.
118 uploadfile = self.createCustomUploadFile(
119- "debian-installer-images_20120627_i386.tar.gz", "data",
120+ "debian-installer-images_20120627_i386.tar.gz", b"data",
121 "main/raw-installer", "extra")
122 self.assertEqual([], list(uploadfile.verify()))
123 uploadfile = self.createCustomUploadFile(
124- "bla.txt", "data", "main/raw-installer", "extra")
125+ "bla.txt", b"data", "main/raw-installer", "extra")
126 errors = list(uploadfile.verify())
127 self.assertEqual(1, len(errors))
128 self.assertIsInstance(errors[0], UploadError)
129@@ -167,25 +168,25 @@ class CustomUploadFileTests(NascentUploadFileTestCase):
130 def test_no_handler_no_verify(self):
131 # Uploads without special handlers have no filename checks.
132 uploadfile = self.createCustomUploadFile(
133- "bla.txt", "data", "main/raw-meta-data", "extra")
134+ "bla.txt", b"data", "main/raw-meta-data", "extra")
135 self.assertEqual([], list(uploadfile.verify()))
136
137 def test_debian_installer_auto_approved(self):
138 # debian-installer uploads are auto-approved.
139 uploadfile = self.createCustomUploadFile(
140- "bla.txt", "data", "main/raw-installer", "extra")
141+ "bla.txt", b"data", "main/raw-installer", "extra")
142 self.assertTrue(uploadfile.autoApprove())
143
144 def test_uefi_not_auto_approved(self):
145 # UEFI uploads are auto-approved.
146 uploadfile = self.createCustomUploadFile(
147- "bla.txt", "data", "main/raw-uefi", "extra")
148+ "bla.txt", b"data", "main/raw-uefi", "extra")
149 self.assertFalse(uploadfile.autoApprove())
150
151 def test_signing_not_auto_approved(self):
152 # UEFI uploads are auto-approved.
153 uploadfile = self.createCustomUploadFile(
154- "bla.txt", "data", "main/raw-signing", "extra")
155+ "bla.txt", b"data", "main/raw-signing", "extra")
156 self.assertFalse(uploadfile.autoApprove())
157
158
159@@ -249,7 +250,8 @@ class DSCFileTests(PackageUploadFileTestCase):
160
161 def createDSCFile(self, filename, dsc, component_and_section,
162 priority_name, package, version, changes):
163- (path, md5, sha1, size) = self.writeUploadFile(filename, dsc.dump())
164+ (path, md5, sha1, size) = self.writeUploadFile(
165+ filename, dsc.dump().encode("UTF-8"))
166 if changes:
167 self.assertEqual([], list(changes.processAddresses()))
168 return DSCFile(
169@@ -392,6 +394,7 @@ class DebBinaryUploadFileTests(PackageUploadFileTestCase):
170 members=None):
171 """Return the contents of a dummy .deb file."""
172 tempdir = self.makeTemporaryDirectory()
173+ control = {k: six.ensure_text(v) for k, v in control.items()}
174 if members is None:
175 members = [
176 "debian-binary",
177@@ -427,7 +430,7 @@ class DebBinaryUploadFileTests(PackageUploadFileTestCase):
178 retcode = subprocess.call(
179 ["ar", "rc", filename] + members, cwd=tempdir)
180 self.assertEqual(0, retcode)
181- with open(os.path.join(tempdir, filename)) as f:
182+ with open(os.path.join(tempdir, filename), "rb") as f:
183 return f.read()
184
185 def createDebBinaryUploadFile(self, filename, component_and_section,
186@@ -443,7 +446,7 @@ class DebBinaryUploadFileTests(PackageUploadFileTestCase):
187 filename, control, control_format, data_format,
188 members=members)
189 else:
190- data = "DUMMY DATA"
191+ data = b"DUMMY DATA"
192 (path, md5, sha1, size) = self.writeUploadFile(filename, data)
193 return DebBinaryUploadFile(
194 path, dict(MD5=md5), size, component_and_section, priority_name,
195@@ -534,8 +537,7 @@ class DebBinaryUploadFileTests(PackageUploadFileTestCase):
196 self.assertIsInstance(error, UploadError)
197 self.assertEqual(
198 "empty_0.1_all.deb: extracting control file raised "
199- "<type 'exceptions.KeyError'>: u'banana not found'."
200- " giving up.", str(error))
201+ "%s: %r. giving up." % (KeyError, "banana not found"), str(error))
202
203 def test_verifyDebTimestamp_SystemError(self):
204 # verifyDebTimestamp produces a reasonable error if we provoke a

Subscribers

People subscribed via source and target branches

to status/vote changes: