launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #26110
[Merge] ~cjwatson/launchpad:py3-doctests-bytesio into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:py3-doctests-bytesio into launchpad:master.
Commit message:
Port various doctests to io.BytesIO
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/396918
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-doctests-bytesio into launchpad:master.
diff --git a/lib/lp/bugs/doc/bug.txt b/lib/lp/bugs/doc/bug.txt
index 5010450..629e560 100644
--- a/lib/lp/bugs/doc/bug.txt
+++ b/lib/lp/bugs/doc/bug.txt
@@ -664,7 +664,7 @@ Marking as duplicate.
Adding an attachment.
- >>> from StringIO import StringIO
+ >>> import io
>>> from lp.bugs.interfaces.bugattachment import IBugAttachmentSet
>>> from lp.services.librarian.interfaces import (
... ILibraryFileAliasSet)
@@ -675,10 +675,10 @@ Adding an attachment.
(Upload a file to the Librarian.)
- >>> filecontent = 'Some useful information.'
+ >>> filecontent = b'Some useful information.'
>>> filealias = getUtility(ILibraryFileAliasSet).create(
... name='foo.txt', size=len(filecontent),
- ... file=StringIO(filecontent), contentType='text/plain')
+ ... file=io.BytesIO(filecontent), contentType='text/plain')
(Attach it to the bug.)
diff --git a/lib/lp/registry/doc/distribution-mirror.txt b/lib/lp/registry/doc/distribution-mirror.txt
index 4b0731c..aeb5b73 100644
--- a/lib/lp/registry/doc/distribution-mirror.txt
+++ b/lib/lp/registry/doc/distribution-mirror.txt
@@ -253,10 +253,10 @@ weren't probed in the last 23 (the value of PROBE_INTERVAL) hours.
>>> valid_mirror = mirrorset[1]
>>> valid_mirror.name
u'archive-mirror'
- >>> from StringIO import StringIO
- >>> log_file = StringIO()
- >>> log_file.write("Fake probe, nothing useful here.")
- >>> log_file.seek(0)
+ >>> import io
+ >>> log_file = io.BytesIO()
+ >>> _ = log_file.write(b"Fake probe, nothing useful here.")
+ >>> _ = log_file.seek(0)
>>> library_alias = getUtility(ILibraryFileAliasSet).create(
... name='foo', size=len(log_file.getvalue()),
... file=log_file, contentType='text/plain')
diff --git a/lib/lp/services/doc/tarfile_helpers.txt b/lib/lp/services/doc/tarfile_helpers.txt
index 769dec7..034c8d4 100644
--- a/lib/lp/services/doc/tarfile_helpers.txt
+++ b/lib/lp/services/doc/tarfile_helpers.txt
@@ -4,7 +4,7 @@ Launchpad helper to write tar files
LaunchpadWriteTarFile is a helper class to make .tar.gz generation
easy.
- >>> from StringIO import StringIO
+ >>> import io
>>> import tarfile
>>> from lp.services.tarfile_helpers import LaunchpadWriteTarFile
@@ -23,7 +23,8 @@ output we will get.
... file = tar.extractfile(member)
...
... if file is not None:
- ... print format % (member.name, file.read())
+ ... print format % (
+ ... member.name, six.ensure_text(file.read()))
... else:
... print format % (member.name, '')
... elif member.type == tarfile.SYMTYPE:
@@ -34,7 +35,7 @@ output we will get.
# Start off by creating a blank archive.
# We'll need a filehandle to store it in.
- >>> buffer = StringIO()
+ >>> buffer = io.BytesIO()
>>> archive = LaunchpadWriteTarFile(buffer)
We can add files individually. First argument is the file name, second
@@ -61,7 +62,7 @@ Once we are done adding files, the archive needs to be closed.
And now we can inspect the produced file.
- >>> buffer.seek(0)
+ >>> _ = buffer.seek(0)
>>> archive = tarfile.open('', 'r', buffer)
>>> examine_tarfile(archive)
foo | 1
@@ -100,7 +101,7 @@ files_to_tarfile...
...or a data string.
>>> data = LaunchpadWriteTarFile.files_to_string(files)
- >>> archive = tarfile.open('', 'r', StringIO(data))
+ >>> archive = tarfile.open('', 'r', io.BytesIO(data))
>>> examine_tarfile(archive)
drei | vier
eins | zwei
diff --git a/lib/lp/services/webapp/doc/webapp-publication.txt b/lib/lp/services/webapp/doc/webapp-publication.txt
index ffe6a69..3df0f24 100644
--- a/lib/lp/services/webapp/doc/webapp-publication.txt
+++ b/lib/lp/services/webapp/doc/webapp-publication.txt
@@ -107,7 +107,7 @@ A number of VirtualHostRequestPublicationFactories are registered with
Zope to handle requests for a particular vhost, port, and set of HTTP
methods.
- >>> from cStringIO import StringIO
+ >>> import io
>>> from lp.services.webapp.publication import (
... LaunchpadBrowserPublication)
>>> from lp.services.webapp.servers import (
@@ -181,7 +181,7 @@ host configured settings.
>>> type(requestfactory)
<class '...ApplicationServerSettingRequestFactory'>
- >>> request = requestfactory(StringIO(''), environment)
+ >>> request = requestfactory(io.BytesIO(), environment)
>>> type(request)
<class 'lp.services.webapp.servers.LaunchpadBrowserRequest'>
>>> request.getApplicationURL()
diff --git a/lib/lp/soyuz/doc/distroseriesqueue-translations.txt b/lib/lp/soyuz/doc/distroseriesqueue-translations.txt
index 765b09f..97b7cdf 100644
--- a/lib/lp/soyuz/doc/distroseriesqueue-translations.txt
+++ b/lib/lp/soyuz/doc/distroseriesqueue-translations.txt
@@ -385,9 +385,9 @@ The LibraryFileAlias returned by getLatestTranslationsUploads on the
source package points to a tarball with translations files for the
package.
+ >>> import io
>>> import tarfile
- >>> from StringIO import StringIO
- >>> tarball = StringIO(latest_translations_upload.read())
+ >>> tarball = io.BytesIO(latest_translations_upload.read())
>>> archive = tarfile.open('', 'r|gz', tarball)
>>> translation_files = sorted([
... entry.name for entry in archive.getmembers()
diff --git a/lib/lp/soyuz/stories/soyuz/xx-package-diff.txt b/lib/lp/soyuz/stories/soyuz/xx-package-diff.txt
index d345a64..6dd04bb 100644
--- a/lib/lp/soyuz/stories/soyuz/xx-package-diff.txt
+++ b/lib/lp/soyuz/stories/soyuz/xx-package-diff.txt
@@ -84,8 +84,8 @@ Perform some diffs in advance, the first diff in ubuntu and the diff
in PPA will be performed, the second diff in ubuntu will be performed
later.
+ >>> import io
>>> from zope.security.proxy import removeSecurityProxy
- >>> from StringIO import StringIO
>>> from lp.services.database.constants import UTC_NOW
>>> from lp.services.librarian.interfaces.client import ILibrarianClient
>>> from lp.soyuz.enums import PackageDiffStatus
@@ -95,7 +95,7 @@ later.
... naked_diff.date_fulfilled = UTC_NOW
... naked_diff.status = PackageDiffStatus.COMPLETED
... naked_diff.diff_content = getUtility(ILibrarianClient).addFile(
- ... filename, 3, StringIO('Foo'), 'application/gzipped-patch')
+ ... filename, 3, io.BytesIO(b'Foo'), 'application/gzipped-patch')
>>> perform_fake_diff(diff_one, 'biscuit_1.0-1_1.0-2.diff.gz')
diff --git a/lib/lp/soyuz/stories/soyuz/xx-queue-pages.txt b/lib/lp/soyuz/stories/soyuz/xx-queue-pages.txt
index 4e2ec21..3a93c4d 100644
--- a/lib/lp/soyuz/stories/soyuz/xx-queue-pages.txt
+++ b/lib/lp/soyuz/stories/soyuz/xx-queue-pages.txt
@@ -177,8 +177,8 @@ Queue item filelist
First set up some additional data to show in the listing: a package diff
and an extra, expired, source file.
+ >>> import io
>>> from zope.security.proxy import removeSecurityProxy
- >>> from StringIO import StringIO
>>> from lp.services.database.constants import UTC_NOW
>>> from lp.services.librarian.interfaces.client import ILibrarianClient
>>> from lp.soyuz.enums import PackageDiffStatus
@@ -193,7 +193,7 @@ and an extra, expired, source file.
>>> diff.date_fulfilled = UTC_NOW
>>> diff.status = PackageDiffStatus.COMPLETED
>>> diff.diff_content = getUtility(ILibrarianClient).addFile(
- ... 'alsa-utils.diff.gz', 11, StringIO('i am a diff'),
+ ... 'alsa-utils.diff.gz', 11, io.BytesIO(b'i am a diff'),
... 'application/gzipped-patch')
>>> sprf = new.addFile(factory.makeLibraryFileAlias(
... filename='alsa-utils_1.0.9a-4ubuntu1.diff.gz'))
diff --git a/lib/lp/translations/browser/tests/pofile-views.txt b/lib/lp/translations/browser/tests/pofile-views.txt
index 2221e92..5b84b54 100644
--- a/lib/lp/translations/browser/tests/pofile-views.txt
+++ b/lib/lp/translations/browser/tests/pofile-views.txt
@@ -5,8 +5,8 @@ On this section, we are going to test the view class for an IPOFile.
First, we need some imports.
+ >>> import io
>>> from zope.publisher.browser import FileUpload
- >>> from StringIO import StringIO
>>> from lp.services.database.sqlbase import flush_database_caches
>>> from lp.translations.model.translationmessage import (
... TranslationMessage, DummyTranslationMessage)
@@ -381,7 +381,7 @@ string again once we're on zope.publisher >= 4.0.0a1.
>>> class FileUploadArgument:
... filename=b'po/es.po'
- ... file=StringIO(b'foos')
+ ... file=io.BytesIO(b'foos')
... headers=''
Now, we do the upload.
diff --git a/lib/lp/translations/browser/tests/potemplate-views.txt b/lib/lp/translations/browser/tests/potemplate-views.txt
index 712ca5a..ca09db0 100644
--- a/lib/lp/translations/browser/tests/potemplate-views.txt
+++ b/lib/lp/translations/browser/tests/potemplate-views.txt
@@ -5,8 +5,8 @@ On this section, we are going to test the view class for an IPOTemplate.
First, we need some imports.
+ >>> import io
>>> from zope.publisher.browser import FileUpload
- >>> from StringIO import StringIO
>>> from lp.translations.interfaces.translationimportqueue import (
... ITranslationImportQueue)
>>> from lp.registry.interfaces.distribution import IDistributionSet
@@ -47,7 +47,7 @@ string again once we're on zope.publisher >= 4.0.0a1.
>>> class FileUploadArgument:
... filename=b'po/foo.pot'
- ... file=StringIO(b'foos')
+ ... file=io.BytesIO(b'foos')
... headers=''
Now, we do the upload.
@@ -81,7 +81,7 @@ string again once we're on zope.publisher >= 4.0.0a1.
>>> class FileUploadArgument:
... filename=b'po/es.po'
- ... file=StringIO(b'foos')
+ ... file=io.BytesIO(b'foos')
... headers=''
We do the upload...
diff --git a/lib/lp/translations/doc/poexport-language-pack.txt b/lib/lp/translations/doc/poexport-language-pack.txt
index 062abc8..a892b4d 100644
--- a/lib/lp/translations/doc/poexport-language-pack.txt
+++ b/lib/lp/translations/doc/poexport-language-pack.txt
@@ -109,7 +109,7 @@ changed since a certain date.
First we need to set up some data to test with, and for this we need
some DB classes.
- >>> from StringIO import StringIO
+ >>> import io
>>> from lp.registry.interfaces.distribution import IDistributionSet
>>> from lp.registry.interfaces.person import IPersonSet
>>> from lp.registry.model.sourcepackagename import SourcePackageName
@@ -132,12 +132,12 @@ Get a source package name to go with our distro series.
Put a dummy file in the Librarian required by the new template we are
creating.
- >>> contents = '# Test PO template.'
+ >>> contents = b'# Test PO template.'
>>> file_alias = getUtility(ILibrarianClient).addFile(
- ... name = 'test.po',
- ... size = len(contents),
- ... file = StringIO(contents),
- ... contentType = 'application/x-po')
+ ... name='test.po',
+ ... size=len(contents),
+ ... file=io.BytesIO(contents),
+ ... contentType='application/x-po')
Get some dates.