Merge ~cjwatson/launchpad:py3-doctest-bytes-text into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 9689c5d7d154eacea505ae0881e1285f0a90f5d1
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:py3-doctest-bytes-text
Merge into: launchpad:master
Diff against target: 341 lines (+49/-42)
15 files modified
lib/lp/app/stories/basics/notfound-head.txt (+3/-3)
lib/lp/blueprints/doc/specgraph.txt (+2/-2)
lib/lp/registry/stories/distribution/xx-distribution-overview.txt (+4/-4)
lib/lp/registry/stories/product/xx-product-files.txt (+1/-1)
lib/lp/services/doc/sprites.txt (+2/-2)
lib/lp/services/librarianserver/tests/test_doc.py (+6/-2)
lib/lp/services/messages/doc/message.txt (+2/-2)
lib/lp/services/webapp/doc/webapp-publication.txt (+3/-3)
lib/lp/services/webservice/stories/xx-wadl.txt (+4/-4)
lib/lp/soyuz/doc/soyuz-upload.txt (+10/-7)
lib/lp/translations/doc/poexport-language-pack.txt (+2/-2)
lib/lp/translations/doc/potemplate.txt (+5/-5)
lib/lp/translations/doc/translations-export-to-branch.txt (+1/-1)
lib/lp/translations/stories/standalone/xx-potemplate-export.txt (+2/-2)
lib/lp/translations/stories/translationgroups/xx-translationgroups.txt (+2/-2)
Reviewer Review Type Date Requested Status
Cristian Gonzalez (community) Approve
Review via email: mp+398877@code.launchpad.net

Commit message

Fix various simple bytes/text issues in doctests

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/app/stories/basics/notfound-head.txt b/lib/lp/app/stories/basics/notfound-head.txt
2index 8639eea..719a063 100644
3--- a/lib/lp/app/stories/basics/notfound-head.txt
4+++ b/lib/lp/app/stories/basics/notfound-head.txt
5@@ -9,7 +9,7 @@ errors (such as 404s).
6 HTTP/1.1 200 Ok
7 >>> print(response.getHeader('Content-Length'))
8 0
9- >>> print(response.getBody())
10+ >>> print(six.ensure_text(response.getBody()))
11 <BLANKLINE>
12
13 >>> response = http(r"""
14@@ -19,7 +19,7 @@ errors (such as 404s).
15 HTTP/1.1 404 Not Found
16 >>> print(response.getHeader('Content-Length'))
17 0
18- >>> print(response.getBody())
19+ >>> print(six.ensure_text(response.getBody()))
20 <BLANKLINE>
21
22 Register a test page that generates HTTP 500 errors.
23@@ -45,7 +45,7 @@ no body.
24 HTTP/1.1 500 Internal Server Error
25 >>> print(response.getHeader('Content-Length'))
26 0
27- >>> print(response.getBody())
28+ >>> print(six.ensure_text(response.getBody()))
29 <BLANKLINE>
30
31
32diff --git a/lib/lp/blueprints/doc/specgraph.txt b/lib/lp/blueprints/doc/specgraph.txt
33index 632cda1..ad3114e 100644
34--- a/lib/lp/blueprints/doc/specgraph.txt
35+++ b/lib/lp/blueprints/doc/specgraph.txt
36@@ -270,8 +270,8 @@ the renderGraphvizGraph() method from the view's parent class. The
37 method will make an image map when 'cmapx' is passed as an argument; It
38 also makes PNG images when it is passed 'png' as an argument.
39
40- >>> graph_view.renderGraphvizGraph('cmapx')
41- '<map id="deptree" name="deptree">...'
42+ >>> print(graph_view.renderGraphvizGraph('cmapx').decode('UTF-8'))
43+ <map id="deptree" name="deptree">...
44
45 The SpecificationTreeImageTag view is indirectly called when the spec's
46 +index template calls render().
47diff --git a/lib/lp/registry/stories/distribution/xx-distribution-overview.txt b/lib/lp/registry/stories/distribution/xx-distribution-overview.txt
48index 8deff14..2734a8c 100644
49--- a/lib/lp/registry/stories/distribution/xx-distribution-overview.txt
50+++ b/lib/lp/registry/stories/distribution/xx-distribution-overview.txt
51@@ -53,11 +53,11 @@ rules.
52 Each series and milestone are links that take you to that
53 series and milestone page.
54
55- >>> anon_browser.getLink(url='/debian/sarge').text
56- '3.1 \xe2\x80\x9cSarge\xe2\x80\x9d series'
57+ >>> print(anon_browser.getLink(url='/debian/sarge').text)
58+ 3.1 “Sarge” series
59
60- >>> anon_browser.getLink(url='/debian/woody').text
61- '3.0 \xe2\x80\x9cWoody\xe2\x80\x9d series'
62+ >>> print(anon_browser.getLink(url='/debian/woody').text)
63+ 3.0 “Woody” series
64
65 >>> anon_browser.getLink(url='/debian/+milestone/3.1').text
66 '3.1'
67diff --git a/lib/lp/registry/stories/product/xx-product-files.txt b/lib/lp/registry/stories/product/xx-product-files.txt
68index c288ace..11386bb 100644
69--- a/lib/lp/registry/stories/product/xx-product-files.txt
70+++ b/lib/lp/registry/stories/product/xx-product-files.txt
71@@ -425,7 +425,7 @@ XXX Mon May 7 10:02:49 2007 -- bac
72 ... if key.lower() == "location":
73 ... redirect_url = value
74 ... break
75- >>> print(urlopen(redirect_url).read())
76+ >>> print(six.ensure_text(urlopen(redirect_url).read()))
77 Foo2 installer package...
78
79 Delete the file foo2.txt.
80diff --git a/lib/lp/services/doc/sprites.txt b/lib/lp/services/doc/sprites.txt
81index 8c8d692..cfb367d 100644
82--- a/lib/lp/services/doc/sprites.txt
83+++ b/lib/lp/services/doc/sprites.txt
84@@ -96,7 +96,7 @@ image file. This allows the css file to be regenerated when the template
85 changes without requiring the combined image file to be recreated.
86
87 >>> sprite_util.savePositioning(new_positioning_file.name)
88- >>> print(new_positioning_file.read())
89+ >>> print(six.ensure_text(new_positioning_file.read()))
90 /*...
91 {
92 "../images/add.png": [
93@@ -138,7 +138,7 @@ referenced /@@/add.png, which was only added once to the combined file.
94 is not group1.png, since its sprite-ref is "group2".
95
96 >>> sprite_util.saveConvertedCSS(new_css_file.name, 'group1.png')
97- >>> print(new_css_file.read())
98+ >>> print(six.ensure_text(new_css_file.read()))
99 /*...
100 .add {
101 background-image: url(group1.png);
102diff --git a/lib/lp/services/librarianserver/tests/test_doc.py b/lib/lp/services/librarianserver/tests/test_doc.py
103index 613acf3..77a3844 100644
104--- a/lib/lp/services/librarianserver/tests/test_doc.py
105+++ b/lib/lp/services/librarianserver/tests/test_doc.py
106@@ -11,6 +11,8 @@ __metaclass__ = type
107
108 import os
109
110+import six
111+
112 from lp.services.librarianserver.libraryprotocol import FileUploadProtocol
113 from lp.services.librarianserver.storage import WrongDatabaseError
114 from lp.services.testing import build_test_suite
115@@ -118,7 +120,8 @@ def upload_request(request):
116 server.dataReceived(request.replace(b'\n', b'\r\n'))
117
118 # Report on what happened
119- print("reply: %r" % server.transport.bytesWritten.rstrip(b'\r\n'))
120+ print("reply: %r" %
121+ six.ensure_str(server.transport.bytesWritten.rstrip(b'\r\n')))
122
123 if server.transport.connectionLost:
124 print('connection closed')
125@@ -126,7 +129,8 @@ def upload_request(request):
126 mockFile = server.fileLibrary.file
127 if mockFile is not None and mockFile.stored:
128 print("file '%s' stored as %s, contents: %r" % (
129- mockFile.name, mockFile.mimetype, mockFile.bytes))
130+ mockFile.name, mockFile.mimetype,
131+ six.ensure_str(mockFile.bytes)))
132
133 # Cleanup: remove the observer.
134 log.removeObserver(log_observer)
135diff --git a/lib/lp/services/messages/doc/message.txt b/lib/lp/services/messages/doc/message.txt
136index d77836a..146684b 100644
137--- a/lib/lp/services/messages/doc/message.txt
138+++ b/lib/lp/services/messages/doc/message.txt
139@@ -269,7 +269,7 @@ as the request. I don't think this is important outside of tests.
140
141 >>> import transaction
142 >>> transaction.commit()
143- >>> blob.read()
144+ >>> six.ensure_str(blob.read())
145 '\x00\x01\x02\x03'
146
147 >>> print(blob2.read().decode('utf16'))
148@@ -534,7 +534,7 @@ which often works.
149 >>> msg_path = os.path.join(os.path.dirname(__file__), mail_path)
150 >>> with open(msg_path, 'rb') as f:
151 ... raw_msg = f.read()
152- >>> print(raw_msg)
153+ >>> print(raw_msg.decode('ISO-8859-1'))
154 MIME-Version: 1.0
155 ...
156 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed...
157diff --git a/lib/lp/services/webapp/doc/webapp-publication.txt b/lib/lp/services/webapp/doc/webapp-publication.txt
158index 8af06ab..35702c7 100644
159--- a/lib/lp/services/webapp/doc/webapp-publication.txt
160+++ b/lib/lp/services/webapp/doc/webapp-publication.txt
161@@ -1047,8 +1047,8 @@ afterCall() publication hook.)
162 >>> request._publication_start = 1.345
163 >>> request._publication_thread_start = None
164 >>> publication.afterCall(request, None)
165- >>> request.response.consumeBody()
166- ''
167+ >>> print(six.ensure_text(request.response.consumeBody()))
168+ <BLANKLINE>
169
170 In other cases, like a GET, the body would be unchanged.
171
172@@ -1064,7 +1064,7 @@ In other cases, like a GET, the body would be unchanged.
173 >>> request._publication_start = 1.345
174 >>> request._publication_thread_start = None
175 >>> publication.afterCall(request, None)
176- >>> print(request.response.consumeBody())
177+ >>> print(six.ensure_text(request.response.consumeBody()))
178 Some boring content.
179
180
181diff --git a/lib/lp/services/webservice/stories/xx-wadl.txt b/lib/lp/services/webservice/stories/xx-wadl.txt
182index bc9711f..396d57c 100644
183--- a/lib/lp/services/webservice/stories/xx-wadl.txt
184+++ b/lib/lp/services/webservice/stories/xx-wadl.txt
185@@ -33,8 +33,8 @@ Let's write some fake WADL to disk.
186 When we request the WADL for version "devel", the fake WADL is loaded
187 from disk.
188
189- >>> print(webservice.get(
190- ... '/', 'application/vd.sun.wadl+xml', api_version='devel').body)
191+ >>> print(six.ensure_text(webservice.get(
192+ ... '/', 'application/vd.sun.wadl+xml', api_version='devel').body))
193 Some fake WADL.
194
195 The fake WADL is now present in the cache.
196@@ -46,8 +46,8 @@ Change the cached value, and we change the document served.
197
198 >>> WebServiceApplication.cached_wadl['devel'] = "More fake WADL."
199
200- >>> print(webservice.get(
201- ... '/', 'application/vd.sun.wadl+xml', api_version='devel').body)
202+ >>> print(six.ensure_text(webservice.get(
203+ ... '/', 'application/vd.sun.wadl+xml', api_version='devel').body))
204 More fake WADL.
205
206 If there's no value in the cache and no cached file on disk, the WADL
207diff --git a/lib/lp/soyuz/doc/soyuz-upload.txt b/lib/lp/soyuz/doc/soyuz-upload.txt
208index 7962cb2..1a284c1 100644
209--- a/lib/lp/soyuz/doc/soyuz-upload.txt
210+++ b/lib/lp/soyuz/doc/soyuz-upload.txt
211@@ -169,7 +169,8 @@ So, load the GPG key:
212 >>> from lp.testing.gpgkeys import gpgkeysdir
213 >>> gpg_handler = getUtility(IGPGHandler)
214 >>> key_path = os.path.join(gpgkeysdir, 'ftpmaster@canonical.com.pub')
215- >>> key_data = open(key_path).read()
216+ >>> with open(key_path, 'rb') as key_file:
217+ ... key_data = key_file.read()
218 >>> key = gpg_handler.importPublicKey(key_data)
219 >>> assert key is not None
220 >>> print(key.fingerprint)
221@@ -580,16 +581,18 @@ Check the publishing history again
222
223 Check if the package was moved properly to the component 'multiverse':
224
225- >>> main_sources = gzip.open(
226- ... "/var/tmp/archive/ubuntutest/dists/breezy-autotest"
227- ... "/main/source/Sources.gz").read()
228+ >>> with gzip.open(
229+ ... "/var/tmp/archive/ubuntutest/dists/breezy-autotest"
230+ ... "/main/source/Sources.gz") as f:
231+ ... main_sources = six.ensure_text(f.read())
232 >>> print(main_sources + '\nEND')
233 <BLANKLINE>
234 END
235
236- >>> multiverse_sources = gzip.open(
237- ... "/var/tmp/archive/ubuntutest/dists/breezy-autotest"
238- ... "/multiverse/source/Sources.gz").read()
239+ >>> with gzip.open(
240+ ... "/var/tmp/archive/ubuntutest/dists/breezy-autotest"
241+ ... "/multiverse/source/Sources.gz") as f:
242+ ... multiverse_sources = six.ensure_text(f.read())
243 >>> print(multiverse_sources + '\nEND')
244 Package: drdsl
245 ...
246diff --git a/lib/lp/translations/doc/poexport-language-pack.txt b/lib/lp/translations/doc/poexport-language-pack.txt
247index da5d142..28334d8 100644
248--- a/lib/lp/translations/doc/poexport-language-pack.txt
249+++ b/lib/lp/translations/doc/poexport-language-pack.txt
250@@ -95,8 +95,8 @@ And one of the included .po files look like what we expected.
251
252 >>> fh = tarfile.extractfile(
253 ... 'rosetta-hoary/es/LC_MESSAGES/evolution-2.2.po')
254- >>> fh.readline()
255- '# traducci\xc3\xb3n de es.po al Spanish\n'
256+ >>> print(six.ensure_text(fh.readline()))
257+ # traducción de es.po al Spanish
258
259
260 Base language pack export using Librarian with date limits
261diff --git a/lib/lp/translations/doc/potemplate.txt b/lib/lp/translations/doc/potemplate.txt
262index cdf9515..3a4fc80 100644
263--- a/lib/lp/translations/doc/potemplate.txt
264+++ b/lib/lp/translations/doc/potemplate.txt
265@@ -598,15 +598,15 @@ The *-es.po file is indeed the Spanish translation...
266
267 >>> file_content = tarfile.extractfile(
268 ... 'evolution-2.2/evolution-2.2-es.po')
269- >>> file_content.readline()
270- '# traducci\xc3\xb3n de es.po al Spanish\n'
271+ >>> print(six.ensure_text(file_content.readline()))
272+ # traducción de es.po al Spanish
273
274 And GNU tar can cope with it.
275
276 >>> from lp.services.helpers import simple_popen2
277 >>> contents = simple_popen2(['tar', 'ztf', '-'], tarfile_bytes)
278 >>> for line in sorted(contents.splitlines()):
279- ... print(line)
280+ ... print(six.ensure_text(line))
281 evolution-2.2/
282 evolution-2.2/evolution-2.2-es.po
283 evolution-2.2/evolution-2.2-ja.po
284@@ -618,5 +618,5 @@ And GNU tar can cope with it.
285 >>> pofile = simple_popen2(
286 ... ['tar', 'zxfO', '-', 'evolution-2.2/evolution-2.2-es.po'],
287 ... tarfile_bytes)
288- >>> pofile.split(b'\n')[0]
289- '# traducci\xc3\xb3n de es.po al Spanish'
290+ >>> print(six.ensure_text(pofile).split('\n')[0])
291+ # traducción de es.po al Spanish
292diff --git a/lib/lp/translations/doc/translations-export-to-branch.txt b/lib/lp/translations/doc/translations-export-to-branch.txt
293index 5e07c5b..c8b74b0 100644
294--- a/lib/lp/translations/doc/translations-export-to-branch.txt
295+++ b/lib/lp/translations/doc/translations-export-to-branch.txt
296@@ -37,7 +37,7 @@ files into the branches. We mock it up here.
297 ...
298 ... def writeFile(self, path, contents):
299 ... self.logger.info("Writing file '%s':" % path)
300- ... self.logger.info(contents)
301+ ... self.logger.info(six.ensure_text(contents))
302 ... self.written_files += 1
303 ...
304 ... def lockForCommit(self):
305diff --git a/lib/lp/translations/stories/standalone/xx-potemplate-export.txt b/lib/lp/translations/stories/standalone/xx-potemplate-export.txt
306index 475a4c3..b933e0d 100644
307--- a/lib/lp/translations/stories/standalone/xx-potemplate-export.txt
308+++ b/lib/lp/translations/stories/standalone/xx-potemplate-export.txt
309@@ -19,8 +19,8 @@ Logged in as a regular user, the +export page is accessible.
310 ... 'http://translations.launchpad.test/ubuntu/hoary'
311 ... '/+source/evolution/+pots/evolution-2.2')
312 >>> browser.getLink('download').click()
313- >>> browser.title
314- 'Download translations : Template \xe2\x80\x9cevolution-2.2...
315+ >>> print(browser.title)
316+ Download translations : Template “evolution-2.2” ...
317
318 If we POST without the appropriate format included, we tell the user off:
319
320diff --git a/lib/lp/translations/stories/translationgroups/xx-translationgroups.txt b/lib/lp/translations/stories/translationgroups/xx-translationgroups.txt
321index 278e6db..4d8effc 100644
322--- a/lib/lp/translations/stories/translationgroups/xx-translationgroups.txt
323+++ b/lib/lp/translations/stories/translationgroups/xx-translationgroups.txt
324@@ -1120,7 +1120,7 @@ Uploading files with an unkown file format notifies the user that it
325 cannot be handled.
326
327 >>> from io import BytesIO
328- >>> af_file = b'''
329+ >>> af_file = '''
330 ... # Afrikaans translation for Silky
331 ... # Copyright (C) 2004 Free Software Foundation, Inc.
332 ... # This file is distributed under the same license as the silky package.
333@@ -1144,7 +1144,7 @@ cannot be handled.
334 ... #: hello.ycp:20
335 ... #, ycp-format
336 ... msgid "This program is running as process number %1."
337- ... msgstr "Hierdie program loop as prosesnommer %1."'''
338+ ... msgstr "Hierdie program loop as prosesnommer %1."'''.encode('UTF-8')
339
340 >>> upload = admin_browser.getControl(name='file')
341 >>> upload.add_file(BytesIO(af_file), 'application/msword', 'af.doc')

Subscribers

People subscribed via source and target branches

to status/vote changes: