← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3-soyuztestpublisher-bytesio into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-soyuztestpublisher-bytesio into launchpad:master.

Commit message:
Port SoyuzTestPublisher.addMockFile to BytesIO

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/391089

This also requires various tests to explicitly pass bytes.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-soyuztestpublisher-bytesio into launchpad:master.
diff --git a/lib/lp/archivepublisher/tests/deathrow.txt b/lib/lp/archivepublisher/tests/deathrow.txt
index 87b919b..7bb3c7e 100644
--- a/lib/lp/archivepublisher/tests/deathrow.txt
+++ b/lib/lp/archivepublisher/tests/deathrow.txt
@@ -65,19 +65,19 @@ be removed.
     >>> deleted_source = test_publisher.getPubSource(
     ...     sourcename="deleted",
     ...     status=PackagePublishingStatus.DELETED,
-    ...     filecontent='X',
+    ...     filecontent=b'X',
     ...     scheduleddeletiondate=past_date)
 
     >>> superseded_source = test_publisher.getPubSource(
     ...     sourcename="superseded",
     ...     status=PackagePublishingStatus.SUPERSEDED,
-    ...     filecontent='X',
+    ...     filecontent=b'X',
     ...     scheduleddeletiondate=past_date)
 
     >>> obsolete_source = test_publisher.getPubSource(
     ...     sourcename="obsolete",
     ...     status=PackagePublishingStatus.OBSOLETE,
-    ...     filecontent='X',
+    ...     filecontent=b'X',
     ...     scheduleddeletiondate=past_date)
 
 Create a chain of dependent source publications:
@@ -89,24 +89,24 @@ Create a chain of dependent source publications:
     >>> removed_source = test_publisher.getPubSource(
     ...     sourcename="stuck",
     ...     status=PackagePublishingStatus.SUPERSEDED,
-    ...     filecontent='A',
+    ...     filecontent=b'A',
     ...     scheduleddeletiondate=past_date)
 
     >>> postponed_source = test_publisher.getPubSource(
     ...     sourcename="stuck", version="667",
     ...     status=PackagePublishingStatus.SUPERSEDED,
-    ...     filecontent='B',
+    ...     filecontent=b'B',
     ...     scheduleddeletiondate=future_date)
 
     >>> published_source = test_publisher.getPubSource(
     ...     sourcename="stuck", version="668",
-    ...     filecontent='C',
+    ...     filecontent=b'C',
     ...     status=PackagePublishingStatus.PUBLISHED)
 
 They all share a source file.
 
     >>> shared_file = test_publisher.addMockFile(
-    ...     'shared_1.0.tar.gz', filecontent='Y')
+    ...     'shared_1.0.tar.gz', filecontent=b'Y')
     >>> discard = removed_source.sourcepackagerelease.addFile(shared_file)
     >>> discard = postponed_source.sourcepackagerelease.addFile(shared_file)
     >>> discard = published_source.sourcepackagerelease.addFile(shared_file)
@@ -120,7 +120,7 @@ be removed.
     ...     binaryname="deleted-bin",
     ...     pub_source=deleted_base_source,
     ...     status=PackagePublishingStatus.DELETED,
-    ...     filecontent='Z',
+    ...     filecontent=b'Z',
     ...     scheduleddeletiondate = past_date)
 
     >>> superseded_base_source = test_publisher.getPubSource(
@@ -129,7 +129,7 @@ be removed.
     ...     binaryname="superseded-bin",
     ...     pub_source=superseded_base_source,
     ...     status=PackagePublishingStatus.SUPERSEDED,
-    ...     filecontent='Z',
+    ...     filecontent=b'Z',
     ...     scheduleddeletiondate = past_date)
 
     >>> obsolete_base_source = test_publisher.getPubSource(
@@ -138,7 +138,7 @@ be removed.
     ...     binaryname="obsolete-bin",
     ...     pub_source=obsolete_base_source,
     ...     status=PackagePublishingStatus.OBSOLETE,
-    ...     filecontent='Z',
+    ...     filecontent=b'Z',
     ...     scheduleddeletiondate = past_date)
 
 Dependent binary publications.
@@ -150,7 +150,7 @@ Dependent binary publications.
     ...     binaryname="stuck-bin",
     ...     pub_source=removed_base_source,
     ...     status=PackagePublishingStatus.SUPERSEDED,
-    ...     filecontent='Z',
+    ...     filecontent=b'Z',
     ...     scheduleddeletiondate = past_date)
 
     >>> [postponed_binary] =  removed_binary.copyTo(
diff --git a/lib/lp/archivepublisher/tests/test_publishdistro.py b/lib/lp/archivepublisher/tests/test_publishdistro.py
index 3d6d699..6507fa6 100644
--- a/lib/lp/archivepublisher/tests/test_publishdistro.py
+++ b/lib/lp/archivepublisher/tests/test_publishdistro.py
@@ -93,7 +93,7 @@ class TestPublishDistro(TestNativePublishingBase):
 
         This method also ensures the publish-distro.py script is runnable.
         """
-        pub_source = self.getPubSource(filecontent='foo')
+        pub_source = self.getPubSource(filecontent=b'foo')
         self.layer.txn.commit()
 
         rc, out, err = self.runPublishDistroScript()
@@ -111,7 +111,7 @@ class TestPublishDistro(TestNativePublishingBase):
         Make a DELETED source to see if the dirty pocket processing
         works for deletions.
         """
-        pub_source = self.getPubSource(filecontent='foo')
+        pub_source = self.getPubSource(filecontent=b'foo')
         self.layer.txn.commit()
         self.runPublishDistro()
         pub_source.sync()
@@ -141,9 +141,9 @@ class TestPublishDistro(TestNativePublishingBase):
         targeted to the specified suite, other records should be untouched
         and not present in disk.
         """
-        pub_source = self.getPubSource(filecontent='foo')
+        pub_source = self.getPubSource(filecontent=b'foo')
         pub_source2 = self.getPubSource(
-            sourcename='baz', filecontent='baz',
+            sourcename='baz', filecontent=b'baz',
             distroseries=self.ubuntutest['hoary-test'])
         self.layer.txn.commit()
 
@@ -168,7 +168,7 @@ class TestPublishDistro(TestNativePublishingBase):
         :return: A tuple of the path to the overridden distsroot and the
                  configured distsroot, in that order.
         """
-        self.getPubSource(filecontent="flangetrousers", archive=archive)
+        self.getPubSource(filecontent=b"flangetrousers", archive=archive)
         self.layer.txn.commit()
         pubconf = getPubConfig(archive)
         tmp_path = os.path.join(pubconf.archiveroot, "tmpdistroot")
@@ -234,18 +234,18 @@ class TestPublishDistro(TestNativePublishingBase):
 
         It should deal only with PPA publications.
         """
-        pub_source = self.getPubSource(filecontent='foo')
+        pub_source = self.getPubSource(filecontent=b'foo')
 
         cprov = getUtility(IPersonSet).getByName('cprov')
         pub_source2 = self.getPubSource(
-            sourcename='baz', filecontent='baz', archive=cprov.archive)
+            sourcename='baz', filecontent=b'baz', archive=cprov.archive)
 
         ubuntutest = getUtility(IDistributionSet)['ubuntutest']
         name16 = getUtility(IPersonSet).getByName('name16')
         getUtility(IArchiveSet).new(purpose=ArchivePurpose.PPA, owner=name16,
             distribution=ubuntutest)
         pub_source3 = self.getPubSource(
-            sourcename='bar', filecontent='bar', archive=name16.archive)
+            sourcename='bar', filecontent=b'bar', archive=name16.archive)
 
         # Override PPAs distributions
         naked_archive = removeSecurityProxy(cprov.archive)
@@ -302,7 +302,7 @@ class TestPublishDistro(TestNativePublishingBase):
 
         # Publish something to the private PPA:
         pub_source = self.getPubSource(
-            sourcename='baz', filecontent='baz', archive=private_ppa)
+            sourcename='baz', filecontent=b'baz', archive=private_ppa)
         self.layer.txn.commit()
 
         self.setUpRequireSigningKeys()
@@ -351,7 +351,7 @@ class TestPublishDistro(TestNativePublishingBase):
 
         # Publish something.
         pub_source = self.getPubSource(
-            sourcename='baz', filecontent='baz', archive=copy_archive)
+            sourcename='baz', filecontent=b'baz', archive=copy_archive)
 
         # Try a plain PPA run, to ensure the copy archive is not published.
         self.runPublishDistro(['--ppa'])
@@ -408,7 +408,7 @@ class TestPublishDistro(TestNativePublishingBase):
     def testCarefulRelease(self):
         """publish-distro can be asked to just rewrite Release files."""
         archive = self.factory.makeArchive(distribution=self.ubuntutest)
-        pub_source = self.getPubSource(filecontent='foo', archive=archive)
+        pub_source = self.getPubSource(filecontent=b'foo', archive=archive)
 
         self.setUpRequireSigningKeys()
         yield self.useFixture(InProcessKeyServerFixture()).start()
diff --git a/lib/lp/archivepublisher/tests/test_publisher.py b/lib/lp/archivepublisher/tests/test_publisher.py
index c60eccc..3d0d89d 100644
--- a/lib/lp/archivepublisher/tests/test_publisher.py
+++ b/lib/lp/archivepublisher/tests/test_publisher.py
@@ -34,6 +34,7 @@ from debian.deb822 import Release
 from fixtures import MonkeyPatch
 import pytz
 import scandir
+import six
 from testscenarios import (
     load_tests_apply_scenarios,
     WithScenarios,
@@ -153,11 +154,11 @@ class TestPublisherSeries(TestNativePublishingBase):
     def _createLinkedPublication(self, name, pocket):
         """Return a linked pair of source and binary publications."""
         pub_source = self.getPubSource(
-            sourcename=name, filecontent="Hello", pocket=pocket)
+            sourcename=name, filecontent=b"Hello", pocket=pocket)
 
         binaryname = '%s-bin' % name
         pub_bin = self.getPubBinaries(
-            binaryname=binaryname, filecontent="World",
+            binaryname=binaryname, filecontent=b"World",
             pub_source=pub_source, pocket=pocket)[0]
 
         return (pub_source, pub_bin)
@@ -762,7 +763,7 @@ class TestPublisher(TestPublisherBase):
             self.logger, self.config, self.disk_pool,
             self.ubuntutest.main_archive)
 
-        pub_source = self.getPubSource(filecontent='Hello world')
+        pub_source = self.getPubSource(filecontent=b'Hello world')
 
         publisher.A_publish(False)
         self.layer.txn.commit()
@@ -926,7 +927,7 @@ class TestPublisher(TestPublisherBase):
             pub_config.poolroot, pub_config.temproot, self.logger)
         publisher = Publisher(
             self.logger, pub_config, disk_pool, archive)
-        self.getPubSource(archive=archive, filecontent="I am partner")
+        self.getPubSource(archive=archive, filecontent=b"I am partner")
 
         publisher.A_publish(False)
 
@@ -968,7 +969,7 @@ class TestPublisher(TestPublisherBase):
             pub_config.poolroot, pub_config.temproot, self.logger)
         publisher = Publisher(self.logger, pub_config, disk_pool, archive)
         self.getPubSource(
-            archive=archive, filecontent="I am partner",
+            archive=archive, filecontent=b"I am partner",
             status=PackagePublishingStatus.PENDING)
 
         publisher.A_publish(force_publishing=False)
@@ -998,9 +999,9 @@ class TestPublisher(TestPublisherBase):
             self.ubuntutest.main_archive,
             allowed_suites=[('hoary-test', PackagePublishingPocket.RELEASE)])
 
-        pub_source = self.getPubSource(filecontent='foo')
+        pub_source = self.getPubSource(filecontent=b'foo')
         pub_source2 = self.getPubSource(
-            sourcename='baz', filecontent='baz',
+            sourcename='baz', filecontent=b'baz',
             distroseries=self.ubuntutest['hoary-test'])
 
         publisher.A_publish(force_publishing=False)
@@ -1029,11 +1030,11 @@ class TestPublisher(TestPublisherBase):
             SeriesStatus.CURRENT)
 
         pub_source = self.getPubSource(
-            filecontent='foo',
+            filecontent=b'foo',
             pocket=PackagePublishingPocket.UPDATES)
 
         pub_source2 = self.getPubSource(
-            sourcename='baz', filecontent='baz',
+            sourcename='baz', filecontent=b'baz',
             pocket=PackagePublishingPocket.BACKPORTS)
 
         publisher.A_publish(force_publishing=False)
@@ -1076,7 +1077,7 @@ class TestPublisher(TestPublisherBase):
             self.ubuntutest.main_archive)
 
         self.getPubSource(
-            filecontent='Hello world',
+            filecontent=b'Hello world',
             status=PackagePublishingStatus.PUBLISHED)
 
         # Make everything other than breezy-autotest OBSOLETE so that they
@@ -1111,7 +1112,7 @@ class TestPublisher(TestPublisherBase):
             owner=ubuntu_team, purpose=ArchivePurpose.PPA)
 
         pub_source = self.getPubSource(
-            sourcename="foo", filename="foo_1.dsc", filecontent='Hello world',
+            sourcename="foo", filename="foo_1.dsc", filecontent=b'Hello world',
             status=PackagePublishingStatus.PENDING, archive=test_archive)
 
         publisher.A_publish(False)
@@ -1141,7 +1142,7 @@ class TestPublisher(TestPublisherBase):
 
         pub_source = self.getPubSource(
             sourcename="foo", filename="foo_1.dsc",
-            filecontent='I am supposed to be a embargoed archive',
+            filecontent=b'I am supposed to be a embargoed archive',
             status=PackagePublishingStatus.PENDING, archive=test_archive)
 
         publisher.A_publish(False)
@@ -1287,11 +1288,11 @@ class TestPublisher(TestPublisherBase):
             owner=name16, distribution=ubuntu, purpose=ArchivePurpose.PPA)
 
         self.getPubSource(
-            sourcename="foo", filename="foo_1.dsc", filecontent='Hello world',
+            sourcename="foo", filename="foo_1.dsc", filecontent=b'Hello world',
             status=PackagePublishingStatus.PENDING, archive=spiv.archive)
 
         self.getPubSource(
-            sourcename="foo", filename="foo_1.dsc", filecontent='Hello world',
+            sourcename="foo", filename="foo_1.dsc", filecontent=b'Hello world',
             status=PackagePublishingStatus.PUBLISHED, archive=name16.archive)
 
         self.assertEqual(4, ubuntu.getAllPPAs().count())
@@ -1390,7 +1391,7 @@ class TestPublisher(TestPublisherBase):
         # Pending source and binary publications.
         # The binary description explores index formatting properties.
         pub_source = self.getPubSource(
-            sourcename="foo", filename="foo_1.dsc", filecontent='Hello world',
+            sourcename="foo", filename="foo_1.dsc", filecontent=b'Hello world',
             status=PackagePublishingStatus.PENDING, archive=cprov.archive)
         self.getPubBinaries(
             pub_source=pub_source,
@@ -1891,7 +1892,7 @@ class TestPublisher(TestPublisherBase):
             self.logger, self.config, self.disk_pool,
             self.ubuntutest.main_archive)
 
-        self.getPubSource(filecontent='Hello world')
+        self.getPubSource(filecontent=b'Hello world')
 
         publisher.A_publish(False)
         publisher.C_doFTPArchive(False)
@@ -1948,7 +1949,7 @@ class TestPublisher(TestPublisherBase):
         archive_publisher = getPublisher(
             cprov.archive, allowed_suites, self.logger)
 
-        self.getPubSource(filecontent='Hello world', archive=cprov.archive)
+        self.getPubSource(filecontent=b'Hello world', archive=cprov.archive)
 
         archive_publisher.A_publish(False)
         self.layer.txn.commit()
@@ -1995,7 +1996,7 @@ class TestPublisher(TestPublisherBase):
         allowed_suites = []
         archive_publisher = getPublisher(
             named_ppa, allowed_suites, self.logger)
-        self.getPubSource(filecontent='Hello world', archive=named_ppa)
+        self.getPubSource(filecontent=b'Hello world', archive=named_ppa)
 
         archive_publisher.A_publish(False)
         self.layer.txn.commit()
@@ -2024,7 +2025,7 @@ class TestPublisher(TestPublisherBase):
         allowed_suites = []
         publisher = getPublisher(archive, allowed_suites, self.logger)
 
-        self.getPubSource(filecontent='Hello world', archive=archive)
+        self.getPubSource(filecontent=b'Hello world', archive=archive)
 
         publisher.A_publish(False)
         publisher.C_writeIndexes(False)
@@ -2062,8 +2063,8 @@ class TestPublisher(TestPublisherBase):
         publisher = Publisher(
             self.logger, self.config, self.disk_pool,
             self.ubuntutest.main_archive)
-        self.getPubSource(filecontent='Hello world', pocket=RELEASE)
-        self.getPubSource(filecontent='Hello world', pocket=BACKPORTS)
+        self.getPubSource(filecontent=b'Hello world', pocket=RELEASE)
+        self.getPubSource(filecontent=b'Hello world', pocket=BACKPORTS)
 
         # Make everything other than breezy-autotest OBSOLETE so that they
         # aren't republished.
@@ -2101,7 +2102,7 @@ class TestPublisher(TestPublisherBase):
         publisher = Publisher(
             self.logger, self.config, self.disk_pool,
             self.ubuntutest.main_archive)
-        self.getPubSource(filecontent='Hello world')
+        self.getPubSource(filecontent=b'Hello world')
 
         # Make sure that apt-ftparchive generates i18n/Translation-en* files.
         ds = self.ubuntutest.getSeries('breezy-autotest')
@@ -2225,7 +2226,7 @@ class TestPublisher(TestPublisherBase):
             self.logger, self.config, self.disk_pool,
             self.ubuntutest.main_archive)
 
-        self.getPubSource(filecontent='Hello world')
+        self.getPubSource(filecontent=b'Hello world')
 
         publisher.A_publish(False)
         publisher.C_doFTPArchive(False)
@@ -2587,7 +2588,7 @@ class TestArchiveIndices(TestPublisherBase):
             self.logger, self.config, self.disk_pool,
             self.ubuntutest.main_archive, allowed_suites=[])
 
-        self.getPubSource(filecontent='Hello world')
+        self.getPubSource(filecontent=b'Hello world')
         publisher.A_publish(False)
         self.runStepC(publisher)
 
@@ -2683,7 +2684,7 @@ class TestUpdateByHash(TestPublisherBase):
         publisher = Publisher(
             self.logger, self.config, self.disk_pool,
             self.ubuntutest.main_archive)
-        self.getPubSource(filecontent='Source: foo\n')
+        self.getPubSource(filecontent=b'Source: foo\n')
         self.runSteps(publisher, step_a=True, step_c=True, step_d=True)
 
         suite_path = partial(
@@ -2703,7 +2704,7 @@ class TestUpdateByHash(TestPublisherBase):
         publisher = Publisher(
             self.logger, self.config, self.disk_pool,
             self.ubuntutest.main_archive)
-        self.getPubSource(filecontent='Source: foo\n')
+        self.getPubSource(filecontent=b'Source: foo\n')
         self.runSteps(publisher, step_a=True, step_c=True, step_d=True)
 
         suite_path = partial(
@@ -2721,7 +2722,7 @@ class TestUpdateByHash(TestPublisherBase):
         publisher = Publisher(
             self.logger, self.config, self.disk_pool,
             self.ubuntutest.main_archive)
-        self.getPubSource(filecontent='Source: foo\n')
+        self.getPubSource(filecontent=b'Source: foo\n')
         self.runSteps(publisher, step_a=True, step_c=True, step_d=True)
         flush_database_caches()
 
@@ -2755,7 +2756,7 @@ class TestUpdateByHash(TestPublisherBase):
         publisher = Publisher(
             self.logger, self.config, self.disk_pool,
             self.ubuntutest.main_archive)
-        self.getPubSource(filecontent='Source: foo\n')
+        self.getPubSource(filecontent=b'Source: foo\n')
         self.runSteps(publisher, step_a=True, step_c=True, step_d=True)
 
         suite_path = partial(
@@ -2771,7 +2772,7 @@ class TestUpdateByHash(TestPublisherBase):
             with open(suite_path('universe', 'source', name), 'rb') as f:
                 universe_contents.add(f.read())
 
-        self.getPubSource(sourcename='baz', filecontent='Source: baz\n')
+        self.getPubSource(sourcename='baz', filecontent=b'Source: baz\n')
         self.runSteps(publisher, step_a=True, step_c=True, step_d=True)
         flush_database_caches()
 
@@ -2933,7 +2934,7 @@ class TestUpdateByHash(TestPublisherBase):
                 main_contents.add(f.read())
 
         # Add a source package so that Sources is non-empty.
-        pub_source = self.getPubSource(filecontent='Source: foo\n')
+        pub_source = self.getPubSource(filecontent=b'Source: foo\n')
         self.runSteps(publisher, step_a=True, step_c=True, step_d=True)
         transaction.commit()
         with open(suite_path('main', 'source', 'Sources'), 'rb') as f:
@@ -2979,7 +2980,8 @@ class TestUpdateByHash(TestPublisherBase):
         main_contents = []
         for sourcename in ('foo', 'bar', 'baz'):
             self.getPubSource(
-                sourcename=sourcename, filecontent='Source: %s\n' % sourcename)
+                sourcename=sourcename,
+                filecontent=six.ensure_binary('Source: %s\n' % sourcename))
             self.runSteps(publisher, step_a=True, step_c=True, step_d=True)
             with open(suite_path('Release'), 'rb') as f:
                 top_contents.append(f.read())
diff --git a/lib/lp/soyuz/scripts/tests/test_copypackage.py b/lib/lp/soyuz/scripts/tests/test_copypackage.py
index eee530a..6a99db9 100644
--- a/lib/lp/soyuz/scripts/tests/test_copypackage.py
+++ b/lib/lp/soyuz/scripts/tests/test_copypackage.py
@@ -772,10 +772,10 @@ class CopyCheckerDifferentArchiveHarness(TestCaseWithFactory,
             archive=self.archive)
         orig_tarball = 'test-source_1.0.orig.tar.gz'
         prev_tar = self.test_publisher.addMockFile(
-            orig_tarball, filecontent='aaabbbccc')
+            orig_tarball, filecontent=b'aaabbbccc')
         prev_source.sourcepackagerelease.addFile(prev_tar)
         new_tar = self.test_publisher.addMockFile(
-            orig_tarball, filecontent='zzzyyyxxx')
+            orig_tarball, filecontent=b'zzzyyyxxx')
         spr.addFile(new_tar)
         # Commit to ensure librarian files are written.
         self.layer.txn.commit()
@@ -792,10 +792,10 @@ class CopyCheckerDifferentArchiveHarness(TestCaseWithFactory,
             archive=self.archive)
         orig_tarball = 'test-source_1.0.orig.tar.gz'
         prev_tar = self.test_publisher.addMockFile(
-            orig_tarball, filecontent='aaabbbccc')
+            orig_tarball, filecontent=b'aaabbbccc')
         prev_source.sourcepackagerelease.addFile(prev_tar)
         new_tar = self.test_publisher.addMockFile(
-            orig_tarball, filecontent='aaabbbccc')
+            orig_tarball, filecontent=b'aaabbbccc')
         spr.addFile(new_tar)
         # Commit to ensure librarian files are written.
         self.layer.txn.commit()
@@ -810,10 +810,10 @@ class CopyCheckerDifferentArchiveHarness(TestCaseWithFactory,
             archive=self.archive)
         orig_tarball = 'test-source_1.0.orig.tar.gz'
         prev_tar = self.test_publisher.addMockFile(
-            orig_tarball, filecontent='aaabbbccc')
+            orig_tarball, filecontent=b'aaabbbccc')
         prev_source.sourcepackagerelease.addFile(prev_tar)
         new_tar = self.test_publisher.addMockFile(
-            orig_tarball, filecontent='aaabbbccc')
+            orig_tarball, filecontent=b'aaabbbccc')
         spr.addFile(new_tar)
         # Set previous source tarball to be expired.
         with dbuser('librarian'):
diff --git a/lib/lp/soyuz/stories/ppa/xx-ppa-files.txt b/lib/lp/soyuz/stories/ppa/xx-ppa-files.txt
index 2b9cde6..2b2a68e 100644
--- a/lib/lp/soyuz/stories/ppa/xx-ppa-files.txt
+++ b/lib/lp/soyuz/stories/ppa/xx-ppa-files.txt
@@ -44,7 +44,7 @@ Publish a source.
 Include a source tarball.
 
     >>> tar_gz = test_publisher.addMockFile(
-    ...     'test-pkg_1.0.tar.gz', filecontent='TAR', restricted=True)
+    ...     'test-pkg_1.0.tar.gz', filecontent=b'TAR', restricted=True)
     >>> unused = test_source.sourcepackagerelease.addFile(tar_gz)
 
 Create a corresponding binary publication and its changesfile.
@@ -58,7 +58,7 @@ Create a corresponding binary publication and its changesfile.
 Create a buildlog and a binary upload_log.
 
     >>> buildlog = test_publisher.addMockFile(
-    ...     'log.txt', filecontent='bogus buildlog', restricted=True)
+    ...     'log.txt', filecontent=b'bogus buildlog', restricted=True)
     >>> build.storeUploadLog('bogus build upload_log')
 
 Create a subsequent source publication so a package diff can be provided.
@@ -74,7 +74,7 @@ Create a subsequent source publication so a package diff can be provided.
     >>> package_diff  = test_source.sourcepackagerelease.requestDiffTo(
     ...     no_priv, another_test_source.sourcepackagerelease)
     >>> package_diff.diff_content = test_publisher.addMockFile(
-    ...     'test-pkg_1.0_1.1.diff.gz', filecontent='bogus diff',
+    ...     'test-pkg_1.0_1.1.diff.gz', filecontent=b'bogus diff',
     ...     restricted=True)
     >>> package_diff.date_fulfilled = package_diff.date_requested
 
diff --git a/lib/lp/soyuz/tests/test_publishing.py b/lib/lp/soyuz/tests/test_publishing.py
index cd7d1ea..b96db01 100644
--- a/lib/lp/soyuz/tests/test_publishing.py
+++ b/lib/lp/soyuz/tests/test_publishing.py
@@ -6,10 +6,10 @@
 from __future__ import absolute_import, print_function, unicode_literals
 
 import datetime
+import io
 import operator
 import os
 import shutil
-from StringIO import StringIO
 import tempfile
 
 import pytz
@@ -167,7 +167,7 @@ class SoyuzTestPublisher:
         Returns a ILibraryFileAlias corresponding to the file uploaded.
         """
         library_file = getUtility(ILibraryFileAliasSet).create(
-            filename, len(filecontent), StringIO(filecontent),
+            filename, len(filecontent), io.BytesIO(filecontent),
             'application/text', restricted=restricted)
         return library_file