← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad-buildd:py3-fix-oci into launchpad-buildd:master

 

Colin Watson has proposed merging ~cjwatson/launchpad-buildd:py3-fix-oci into launchpad-buildd:master.

Commit message:
Fix OCI tests on Python 3

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad-buildd/+git/launchpad-buildd/+merge/383365
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad-buildd:py3-fix-oci into launchpad-buildd:master.
diff --git a/lpbuildd/tests/oci_tarball.py b/lpbuildd/tests/oci_tarball.py
index 6675256..70c055b 100644
--- a/lpbuildd/tests/oci_tarball.py
+++ b/lpbuildd/tests/oci_tarball.py
@@ -1,6 +1,6 @@
+import io
 import json
 import os
-import StringIO
 import tempfile
 import tarfile
 
@@ -9,10 +9,10 @@ class OCITarball:
     """Create a tarball for use in tests with OCI."""
 
     def _makeFile(self, contents, name):
-        json_contents = json.dumps(contents)
+        json_contents = json.dumps(contents).encode("UTF-8")
         tarinfo = tarfile.TarInfo(name)
         tarinfo.size = len(json_contents)
-        return tarinfo, StringIO.StringIO(json_contents)
+        return tarinfo, io.BytesIO(json_contents)
 
     @property
     def config(self):
@@ -35,7 +35,7 @@ class OCITarball:
         contents = "{}-contents".format(layer_name)
         tarinfo = tarfile.TarInfo(contents)
         tarinfo.size = len(contents)
-        layer_contents = StringIO.StringIO(contents)
+        layer_contents = io.BytesIO(contents.encode("UTF-8"))
         layer_tar_path = os.path.join(
             directory, '{}.tar.gz'.format(layer_name))
         layer_tar = tarfile.open(layer_tar_path, 'w:gz')
diff --git a/lpbuildd/tests/test_oci.py b/lpbuildd/tests/test_oci.py
index 35efd5b..f2dd421 100644
--- a/lpbuildd/tests/test_oci.py
+++ b/lpbuildd/tests/test_oci.py
@@ -6,10 +6,6 @@ __metaclass__ = type
 import io
 import json
 import os
-try:
-    from unittest import mock
-except ImportError:
-    import mock
 
 from fixtures import (
     EnvironmentVariable,
@@ -159,7 +155,7 @@ class TestOCIBuildManagerIteration(TestCase):
 
         cache_path = self.builder.cachePath(
             self.builder.waitingfiles['digests.json'])
-        with open(cache_path, "rb") as f:
+        with open(cache_path) as f:
             digests_contents = f.read()
         digests_expected = [{
             "sha256:diff1": {
@@ -242,7 +238,7 @@ class TestOCIBuildManagerIteration(TestCase):
 
         cache_path = self.builder.cachePath(
             self.builder.waitingfiles['digests.json'])
-        with open(cache_path, "rb") as f:
+        with open(cache_path) as f:
             digests_contents = f.read()
         digests_expected = [{
             "sha256:diff1": {