Port pactest to python3

Use BytesIO instead of StringIO, and ensure that we unicode-encode data
where needed.
This commit is contained in:
Dave Reisner 2018-08-19 21:12:33 -04:00 committed by Andrew Gregory
parent ffde85aadf
commit afb9c0140f
5 changed files with 10 additions and 9 deletions

View file

@ -179,7 +179,7 @@ AC_SUBST(LFS_CFLAGS)
AC_PROG_AWK AC_PROG_AWK
AC_PROG_CC_C99 AC_PROG_CC_C99
AC_PROG_INSTALL AC_PROG_INSTALL
AC_CHECK_PROGS([PYTHON], [python2.7 python2 python], [false]) AC_CHECK_PROGS([PYTHON], [python3 python], [false])
AC_PATH_PROGS([BASH_SHELL], [bash bash4], [false]) AC_PATH_PROGS([BASH_SHELL], [bash bash4], [false])
# check for perl 5.10.1 (needed by makepkg-template) # check for perl 5.10.1 (needed by makepkg-template)

View file

@ -1,4 +1,4 @@
#! /usr/bin/python2 #! /usr/bin/python3
# #
# pactest : run automated testing on the pacman binary # pactest : run automated testing on the pacman binary
# #
@ -45,7 +45,8 @@ class MultiWriter():
# duplicate stdout/stderr to a temporary file # duplicate stdout/stderr to a temporary file
class OutputSaver(): class OutputSaver():
def __init__(self): def __init__(self):
self.save_file = tempfile.NamedTemporaryFile(prefix='pactest-output-') self.save_file = tempfile.NamedTemporaryFile(
prefix='pactest-output-', mode='w')
def __enter__(self): def __enter__(self):
sys.stdout = MultiWriter(sys.stdout, self.save_file) sys.stdout = MultiWriter(sys.stdout, self.save_file)

View file

@ -15,9 +15,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from io import BytesIO
import os import os
import shutil import shutil
from StringIO import StringIO
import tarfile import tarfile
import pmpkg import pmpkg
@ -251,7 +251,7 @@ class pmdb(object):
filename = os.path.join(pkg.fullname(), name) filename = os.path.join(pkg.fullname(), name)
info = tarfile.TarInfo(filename) info = tarfile.TarInfo(filename)
info.size = len(data) info.size = len(data)
tar.addfile(info, StringIO(data)) tar.addfile(info, BytesIO(data.encode('utf8')))
tar.close() tar.close()
# TODO: this is a bit unnecessary considering only one test uses it # TODO: this is a bit unnecessary considering only one test uses it
serverpath = os.path.join(self.root, util.SYNCREPO, self.treename) serverpath = os.path.join(self.root, util.SYNCREPO, self.treename)

View file

@ -14,8 +14,8 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from io import BytesIO
import os import os
from StringIO import StringIO
import tarfile import tarfile
import util import util
@ -146,7 +146,7 @@ class pmpkg(object):
for name, data in archive_files: for name, data in archive_files:
info = tarfile.TarInfo(name) info = tarfile.TarInfo(name)
info.size = len(data) info.size = len(data)
tar.addfile(info, StringIO(data)) tar.addfile(info, BytesIO(data.encode('utf8')))
# Generate package file system # Generate package file system
for name in self.files: for name in self.files:
@ -167,7 +167,7 @@ class pmpkg(object):
# TODO wow what a hack, adding a newline to match mkfile? # TODO wow what a hack, adding a newline to match mkfile?
filedata = name + "\n" filedata = name + "\n"
info.size = len(filedata) info.size = len(filedata)
tar.addfile(info, StringIO(filedata)) tar.addfile(info, BytesIO(filedata.encode('utf8')))
tar.close() tar.close()

View file

@ -152,7 +152,7 @@ def getmd5sum(filename):
def mkmd5sum(data): def mkmd5sum(data):
checksum = hashlib.md5() checksum = hashlib.md5()
checksum.update("%s\n" % data) checksum.update(("%s\n" % data).encode('utf8'))
return checksum.hexdigest() return checksum.hexdigest()