From afb9c0140fd6949ede64cc1a304e9349772fca04 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sun, 19 Aug 2018 21:12:33 -0400 Subject: Port pactest to python3 Use BytesIO instead of StringIO, and ensure that we unicode-encode data where needed. --- test/pacman/pactest.py | 5 +++-- test/pacman/pmdb.py | 4 ++-- test/pacman/pmpkg.py | 6 +++--- test/pacman/util.py | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/pacman/pactest.py b/test/pacman/pactest.py index 1f5b8483..85cce6a1 100755 --- a/test/pacman/pactest.py +++ b/test/pacman/pactest.py @@ -1,4 +1,4 @@ -#! /usr/bin/python2 +#! /usr/bin/python3 # # pactest : run automated testing on the pacman binary # @@ -45,7 +45,8 @@ class MultiWriter(): # duplicate stdout/stderr to a temporary file class OutputSaver(): def __init__(self): - self.save_file = tempfile.NamedTemporaryFile(prefix='pactest-output-') + self.save_file = tempfile.NamedTemporaryFile( + prefix='pactest-output-', mode='w') def __enter__(self): sys.stdout = MultiWriter(sys.stdout, self.save_file) diff --git a/test/pacman/pmdb.py b/test/pacman/pmdb.py index f7671987..95aa8756 100644 --- a/test/pacman/pmdb.py +++ b/test/pacman/pmdb.py @@ -15,9 +15,9 @@ # along with this program. If not, see . +from io import BytesIO import os import shutil -from StringIO import StringIO import tarfile import pmpkg @@ -251,7 +251,7 @@ class pmdb(object): filename = os.path.join(pkg.fullname(), name) info = tarfile.TarInfo(filename) info.size = len(data) - tar.addfile(info, StringIO(data)) + tar.addfile(info, BytesIO(data.encode('utf8'))) tar.close() # TODO: this is a bit unnecessary considering only one test uses it serverpath = os.path.join(self.root, util.SYNCREPO, self.treename) diff --git a/test/pacman/pmpkg.py b/test/pacman/pmpkg.py index 5a32ccd6..4667ebc1 100644 --- a/test/pacman/pmpkg.py +++ b/test/pacman/pmpkg.py @@ -14,8 +14,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from io import BytesIO import os -from StringIO import StringIO import tarfile import util @@ -146,7 +146,7 @@ class pmpkg(object): for name, data in archive_files: info = tarfile.TarInfo(name) info.size = len(data) - tar.addfile(info, StringIO(data)) + tar.addfile(info, BytesIO(data.encode('utf8'))) # Generate package file system for name in self.files: @@ -167,7 +167,7 @@ class pmpkg(object): # TODO wow what a hack, adding a newline to match mkfile? filedata = name + "\n" info.size = len(filedata) - tar.addfile(info, StringIO(filedata)) + tar.addfile(info, BytesIO(filedata.encode('utf8'))) tar.close() diff --git a/test/pacman/util.py b/test/pacman/util.py index 5fbe4c35..544bdd8d 100644 --- a/test/pacman/util.py +++ b/test/pacman/util.py @@ -152,7 +152,7 @@ def getmd5sum(filename): def mkmd5sum(data): checksum = hashlib.md5() - checksum.update("%s\n" % data) + checksum.update(("%s\n" % data).encode('utf8')) return checksum.hexdigest() -- cgit v1.2.3-70-g09d2