← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-doctest-bytes-text into launchpad:master.

Commit message:
Fix various simple bytes/text issues in doctests

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/398877
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-doctest-bytes-text into launchpad:master.
diff --git a/lib/lp/app/stories/basics/notfound-head.txt b/lib/lp/app/stories/basics/notfound-head.txt
index 8639eea..719a063 100644
--- a/lib/lp/app/stories/basics/notfound-head.txt
+++ b/lib/lp/app/stories/basics/notfound-head.txt
@@ -9,7 +9,7 @@ errors (such as 404s).
   HTTP/1.1 200 Ok
   >>> print(response.getHeader('Content-Length'))
   0
-  >>> print(response.getBody())
+  >>> print(six.ensure_text(response.getBody()))
   <BLANKLINE>
 
   >>> response = http(r"""
@@ -19,7 +19,7 @@ errors (such as 404s).
   HTTP/1.1 404 Not Found
   >>> print(response.getHeader('Content-Length'))
   0
-  >>> print(response.getBody())
+  >>> print(six.ensure_text(response.getBody()))
   <BLANKLINE>
 
 Register a test page that generates HTTP 500 errors.
@@ -45,7 +45,7 @@ no body.
   HTTP/1.1 500 Internal Server Error
   >>> print(response.getHeader('Content-Length'))
   0
-  >>> print(response.getBody())
+  >>> print(six.ensure_text(response.getBody()))
   <BLANKLINE>
 
 
diff --git a/lib/lp/blueprints/doc/specgraph.txt b/lib/lp/blueprints/doc/specgraph.txt
index 632cda1..ad3114e 100644
--- a/lib/lp/blueprints/doc/specgraph.txt
+++ b/lib/lp/blueprints/doc/specgraph.txt
@@ -270,8 +270,8 @@ the renderGraphvizGraph() method from the view's parent class. The
 method will make an image map when 'cmapx' is passed as an argument; It
 also makes PNG images when it is passed 'png' as an argument.
 
-    >>> graph_view.renderGraphvizGraph('cmapx')
-    '<map id="deptree" name="deptree">...'
+    >>> print(graph_view.renderGraphvizGraph('cmapx').decode('UTF-8'))
+    <map id="deptree" name="deptree">...
 
 The SpecificationTreeImageTag view is indirectly called when the spec's
 +index template calls render().
diff --git a/lib/lp/registry/stories/distribution/xx-distribution-overview.txt b/lib/lp/registry/stories/distribution/xx-distribution-overview.txt
index 8deff14..2734a8c 100644
--- a/lib/lp/registry/stories/distribution/xx-distribution-overview.txt
+++ b/lib/lp/registry/stories/distribution/xx-distribution-overview.txt
@@ -53,11 +53,11 @@ rules.
 Each series and milestone are links that take you to that
 series and milestone page.
 
-    >>> anon_browser.getLink(url='/debian/sarge').text
-    '3.1 \xe2\x80\x9cSarge\xe2\x80\x9d series'
+    >>> print(anon_browser.getLink(url='/debian/sarge').text)
+    3.1 “Sarge” series
 
-    >>> anon_browser.getLink(url='/debian/woody').text
-    '3.0 \xe2\x80\x9cWoody\xe2\x80\x9d series'
+    >>> print(anon_browser.getLink(url='/debian/woody').text)
+    3.0 “Woody” series
 
     >>> anon_browser.getLink(url='/debian/+milestone/3.1').text
     '3.1'
diff --git a/lib/lp/registry/stories/product/xx-product-files.txt b/lib/lp/registry/stories/product/xx-product-files.txt
index c288ace..11386bb 100644
--- a/lib/lp/registry/stories/product/xx-product-files.txt
+++ b/lib/lp/registry/stories/product/xx-product-files.txt
@@ -425,7 +425,7 @@ XXX Mon May  7 10:02:49 2007 -- bac
     ...     if key.lower() == "location":
     ...         redirect_url = value
     ...         break
-    >>> print(urlopen(redirect_url).read())
+    >>> print(six.ensure_text(urlopen(redirect_url).read()))
     Foo2 installer package...
 
 Delete the file foo2.txt.
diff --git a/lib/lp/services/doc/sprites.txt b/lib/lp/services/doc/sprites.txt
index 8c8d692..cfb367d 100644
--- a/lib/lp/services/doc/sprites.txt
+++ b/lib/lp/services/doc/sprites.txt
@@ -96,7 +96,7 @@ image file. This allows the css file to be regenerated when the template
 changes without requiring the combined image file to be recreated.
 
     >>> sprite_util.savePositioning(new_positioning_file.name)
-    >>> print(new_positioning_file.read())
+    >>> print(six.ensure_text(new_positioning_file.read()))
     /*...
     {
         "../images/add.png": [
@@ -138,7 +138,7 @@ referenced /@@/add.png, which was only added once to the combined file.
 is not group1.png, since its sprite-ref is "group2".
 
     >>> sprite_util.saveConvertedCSS(new_css_file.name, 'group1.png')
-    >>> print(new_css_file.read())
+    >>> print(six.ensure_text(new_css_file.read()))
     /*...
     .add {
         background-image: url(group1.png);
diff --git a/lib/lp/services/librarianserver/tests/test_doc.py b/lib/lp/services/librarianserver/tests/test_doc.py
index 613acf3..77a3844 100644
--- a/lib/lp/services/librarianserver/tests/test_doc.py
+++ b/lib/lp/services/librarianserver/tests/test_doc.py
@@ -11,6 +11,8 @@ __metaclass__ = type
 
 import os
 
+import six
+
 from lp.services.librarianserver.libraryprotocol import FileUploadProtocol
 from lp.services.librarianserver.storage import WrongDatabaseError
 from lp.services.testing import build_test_suite
@@ -118,7 +120,8 @@ def upload_request(request):
     server.dataReceived(request.replace(b'\n', b'\r\n'))
 
     # Report on what happened
-    print("reply: %r" % server.transport.bytesWritten.rstrip(b'\r\n'))
+    print("reply: %r" %
+          six.ensure_str(server.transport.bytesWritten.rstrip(b'\r\n')))
 
     if server.transport.connectionLost:
         print('connection closed')
@@ -126,7 +129,8 @@ def upload_request(request):
     mockFile = server.fileLibrary.file
     if mockFile is not None and mockFile.stored:
         print("file '%s' stored as %s, contents: %r" % (
-                mockFile.name, mockFile.mimetype, mockFile.bytes))
+                mockFile.name, mockFile.mimetype,
+                six.ensure_str(mockFile.bytes)))
 
     # Cleanup: remove the observer.
     log.removeObserver(log_observer)
diff --git a/lib/lp/services/messages/doc/message.txt b/lib/lp/services/messages/doc/message.txt
index d77836a..146684b 100644
--- a/lib/lp/services/messages/doc/message.txt
+++ b/lib/lp/services/messages/doc/message.txt
@@ -269,7 +269,7 @@ as the request. I don't think this is important outside of tests.
 
     >>> import transaction
     >>> transaction.commit()
-    >>> blob.read()
+    >>> six.ensure_str(blob.read())
     '\x00\x01\x02\x03'
 
     >>> print(blob2.read().decode('utf16'))
@@ -534,7 +534,7 @@ which often works.
     >>> msg_path = os.path.join(os.path.dirname(__file__), mail_path)
     >>> with open(msg_path, 'rb') as f:
     ...     raw_msg = f.read()
-    >>> print(raw_msg)
+    >>> print(raw_msg.decode('ISO-8859-1'))
     MIME-Version: 1.0
     ...
     Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed...
diff --git a/lib/lp/services/webapp/doc/webapp-publication.txt b/lib/lp/services/webapp/doc/webapp-publication.txt
index 8af06ab..35702c7 100644
--- a/lib/lp/services/webapp/doc/webapp-publication.txt
+++ b/lib/lp/services/webapp/doc/webapp-publication.txt
@@ -1047,8 +1047,8 @@ afterCall() publication hook.)
     >>> request._publication_start = 1.345
     >>> request._publication_thread_start = None
     >>> publication.afterCall(request, None)
-    >>> request.response.consumeBody()
-    ''
+    >>> print(six.ensure_text(request.response.consumeBody()))
+    <BLANKLINE>
 
 In other cases, like a GET, the body would be unchanged.
 
@@ -1064,7 +1064,7 @@ In other cases, like a GET, the body would be unchanged.
     >>> request._publication_start = 1.345
     >>> request._publication_thread_start = None
     >>> publication.afterCall(request, None)
-    >>> print(request.response.consumeBody())
+    >>> print(six.ensure_text(request.response.consumeBody()))
     Some boring content.
 
 
diff --git a/lib/lp/services/webservice/stories/xx-wadl.txt b/lib/lp/services/webservice/stories/xx-wadl.txt
index bc9711f..396d57c 100644
--- a/lib/lp/services/webservice/stories/xx-wadl.txt
+++ b/lib/lp/services/webservice/stories/xx-wadl.txt
@@ -33,8 +33,8 @@ Let's write some fake WADL to disk.
 When we request the WADL for version "devel", the fake WADL is loaded
 from disk.
 
-    >>> print(webservice.get(
-    ...     '/', 'application/vd.sun.wadl+xml', api_version='devel').body)
+    >>> print(six.ensure_text(webservice.get(
+    ...     '/', 'application/vd.sun.wadl+xml', api_version='devel').body))
     Some fake WADL.
 
 The fake WADL is now present in the cache.
@@ -46,8 +46,8 @@ Change the cached value, and we change the document served.
 
     >>> WebServiceApplication.cached_wadl['devel'] = "More fake WADL."
 
-    >>> print(webservice.get(
-    ...     '/', 'application/vd.sun.wadl+xml', api_version='devel').body)
+    >>> print(six.ensure_text(webservice.get(
+    ...     '/', 'application/vd.sun.wadl+xml', api_version='devel').body))
     More fake WADL.
 
 If there's no value in the cache and no cached file on disk, the WADL
diff --git a/lib/lp/soyuz/doc/soyuz-upload.txt b/lib/lp/soyuz/doc/soyuz-upload.txt
index 7962cb2..1a284c1 100644
--- a/lib/lp/soyuz/doc/soyuz-upload.txt
+++ b/lib/lp/soyuz/doc/soyuz-upload.txt
@@ -169,7 +169,8 @@ So, load the GPG key:
     >>> from lp.testing.gpgkeys import gpgkeysdir
     >>> gpg_handler = getUtility(IGPGHandler)
     >>> key_path = os.path.join(gpgkeysdir, 'ftpmaster@xxxxxxxxxxxxxxxxx')
-    >>> key_data = open(key_path).read()
+    >>> with open(key_path, 'rb') as key_file:
+    ...     key_data = key_file.read()
     >>> key = gpg_handler.importPublicKey(key_data)
     >>> assert key is not None
     >>> print(key.fingerprint)
@@ -580,16 +581,18 @@ Check the publishing history again
 
 Check if the package was moved properly to the component 'multiverse':
 
-    >>> main_sources = gzip.open(
-    ...     "/var/tmp/archive/ubuntutest/dists/breezy-autotest"
-    ...     "/main/source/Sources.gz").read()
+    >>> with gzip.open(
+    ...         "/var/tmp/archive/ubuntutest/dists/breezy-autotest"
+    ...         "/main/source/Sources.gz") as f:
+    ...     main_sources = six.ensure_text(f.read())
     >>> print(main_sources + '\nEND')
     <BLANKLINE>
     END
 
-    >>> multiverse_sources = gzip.open(
-    ...     "/var/tmp/archive/ubuntutest/dists/breezy-autotest"
-    ...     "/multiverse/source/Sources.gz").read()
+    >>> with gzip.open(
+    ...         "/var/tmp/archive/ubuntutest/dists/breezy-autotest"
+    ...         "/multiverse/source/Sources.gz") as f:
+    ...     multiverse_sources = six.ensure_text(f.read())
     >>> print(multiverse_sources + '\nEND')
     Package: drdsl
     ...
diff --git a/lib/lp/translations/doc/poexport-language-pack.txt b/lib/lp/translations/doc/poexport-language-pack.txt
index da5d142..28334d8 100644
--- a/lib/lp/translations/doc/poexport-language-pack.txt
+++ b/lib/lp/translations/doc/poexport-language-pack.txt
@@ -95,8 +95,8 @@ And one of the included .po files look like what we expected.
 
     >>> fh = tarfile.extractfile(
     ...     'rosetta-hoary/es/LC_MESSAGES/evolution-2.2.po')
-    >>> fh.readline()
-    '# traducci\xc3\xb3n de es.po al Spanish\n'
+    >>> print(six.ensure_text(fh.readline()))
+    # traducción de es.po al Spanish
 
 
 Base language pack export using Librarian with date limits
diff --git a/lib/lp/translations/doc/potemplate.txt b/lib/lp/translations/doc/potemplate.txt
index cdf9515..3a4fc80 100644
--- a/lib/lp/translations/doc/potemplate.txt
+++ b/lib/lp/translations/doc/potemplate.txt
@@ -598,15 +598,15 @@ The *-es.po file is indeed the Spanish translation...
 
     >>> file_content = tarfile.extractfile(
     ...     'evolution-2.2/evolution-2.2-es.po')
-    >>> file_content.readline()
-    '# traducci\xc3\xb3n de es.po al Spanish\n'
+    >>> print(six.ensure_text(file_content.readline()))
+    # traducción de es.po al Spanish
 
 And GNU tar can cope with it.
 
     >>> from lp.services.helpers import simple_popen2
     >>> contents = simple_popen2(['tar', 'ztf', '-'], tarfile_bytes)
     >>> for line in sorted(contents.splitlines()):
-    ...        print(line)
+    ...        print(six.ensure_text(line))
     evolution-2.2/
     evolution-2.2/evolution-2.2-es.po
     evolution-2.2/evolution-2.2-ja.po
@@ -618,5 +618,5 @@ And GNU tar can cope with it.
     >>> pofile = simple_popen2(
     ...        ['tar', 'zxfO', '-', 'evolution-2.2/evolution-2.2-es.po'],
     ...        tarfile_bytes)
-    >>> pofile.split(b'\n')[0]
-    '# traducci\xc3\xb3n de es.po al Spanish'
+    >>> print(six.ensure_text(pofile).split('\n')[0])
+    # traducción de es.po al Spanish
diff --git a/lib/lp/translations/doc/translations-export-to-branch.txt b/lib/lp/translations/doc/translations-export-to-branch.txt
index 5e07c5b..c8b74b0 100644
--- a/lib/lp/translations/doc/translations-export-to-branch.txt
+++ b/lib/lp/translations/doc/translations-export-to-branch.txt
@@ -37,7 +37,7 @@ files into the branches.  We mock it up here.
     ...
     ...     def writeFile(self, path, contents):
     ...         self.logger.info("Writing file '%s':" % path)
-    ...         self.logger.info(contents)
+    ...         self.logger.info(six.ensure_text(contents))
     ...         self.written_files += 1
     ...
     ...     def lockForCommit(self):
diff --git a/lib/lp/translations/stories/standalone/xx-potemplate-export.txt b/lib/lp/translations/stories/standalone/xx-potemplate-export.txt
index 475a4c3..b933e0d 100644
--- a/lib/lp/translations/stories/standalone/xx-potemplate-export.txt
+++ b/lib/lp/translations/stories/standalone/xx-potemplate-export.txt
@@ -19,8 +19,8 @@ Logged in as a regular user, the +export page is accessible.
   ...     'http://translations.launchpad.test/ubuntu/hoary'
   ...     '/+source/evolution/+pots/evolution-2.2')
   >>> browser.getLink('download').click()
-  >>> browser.title
-  'Download translations : Template \xe2\x80\x9cevolution-2.2...
+  >>> print(browser.title)
+  Download translations : Template “evolution-2.2” ...
 
 If we POST without the appropriate format included, we tell the user off:
 
diff --git a/lib/lp/translations/stories/translationgroups/xx-translationgroups.txt b/lib/lp/translations/stories/translationgroups/xx-translationgroups.txt
index 278e6db..4d8effc 100644
--- a/lib/lp/translations/stories/translationgroups/xx-translationgroups.txt
+++ b/lib/lp/translations/stories/translationgroups/xx-translationgroups.txt
@@ -1120,7 +1120,7 @@ Uploading files with an unkown file format notifies the user that it
 cannot be handled.
 
     >>> from io import BytesIO
-    >>> af_file = b'''
+    >>> af_file = '''
     ... # Afrikaans translation for Silky
     ... # Copyright (C) 2004 Free Software Foundation, Inc.
     ... # This file is distributed under the same license as the silky package.
@@ -1144,7 +1144,7 @@ cannot be handled.
     ... #: hello.ycp:20
     ... #, ycp-format
     ... msgid "This program is running as process number %1."
-    ... msgstr "Hierdie program loop as prosesnommer %1."'''
+    ... msgstr "Hierdie program loop as prosesnommer %1."'''.encode('UTF-8')
 
     >>> upload = admin_browser.getControl(name='file')
     >>> upload.add_file(BytesIO(af_file), 'application/msword', 'af.doc')