[PATCH 01 of 13] Initial patch for making the test suite run on Py3k. Created a simple (and ugly!) read/write wrapper, and updated a print statement
Alejandro Santos
alejolp at alejolp.com
Wed Aug 5 20:55:35 UTC 2009
# HG changeset patch
# User Alejandro Santos <alejolp at alejolp.com>
# Date 1249486789 10800
# Node ID ef9c62cd2ad6ef208e7110202b42fecee28f18c7
# Parent 05d485a117d7d1d35bc8a5538f1c6255a7e3c44e
Initial patch for making the test suite run on Py3k. Created a simple (and ugly!) read/write wrapper, and updated a print statement.
diff -r 05d485a117d7 -r ef9c62cd2ad6 tests/run-tests.py
--- a/tests/run-tests.py Wed Aug 05 12:39:49 2009 -0300
+++ b/tests/run-tests.py Wed Aug 05 12:39:49 2009 -0300
@@ -50,6 +50,32 @@
import tempfile
import time
+if sys.version_info[0] == 2:
+ def decode(data):
+ return data
+
+ def encode(data):
+ return data
+else:
+ # FIXME: Initial attempt, WIP.
+ # Read wrapper for Py3k
+ def decode(data):
+ """Returns an str"""
+ if type(data) is bytes:
+ return data.decode()
+ elif type(data) is str:
+ return data
+ raise Exception('Don\'t know how to wrap data')
+
+ # Write wrapper for Py3k
+ def encode(data):
+ """Returns bytes"""
+ if type(data) is str:
+ return data.encode()
+ elif type(data) is bytes:
+ return data
+ raise Exception('Don\'t know how to wrap data')
+
closefds = os.name == 'posix'
def Popen4(cmd, bufsize=-1):
p = subprocess.Popen(cmd, shell=True, bufsize=bufsize,
@@ -383,7 +409,7 @@
try:
output = ''
proc.tochild.close()
- output = proc.fromchild.read()
+ output = decode(proc.fromchild.read())
ret = proc.wait()
if os.WIFEXITED(ret):
ret = os.WEXITSTATUS(ret)
@@ -485,7 +511,7 @@
# If reference output file exists, check test output against it
if os.path.exists(ref):
f = open(ref, "r")
- refout = splitnewlines(f.read())
+ refout = splitnewlines(decode(f.read()))
f.close()
else:
refout = []
@@ -520,7 +546,7 @@
# Save errors to a file for diagnosis
f = open(err, "wb")
for line in out:
- f.write(line)
+ f.write(encode(line))
f.close()
# Kill off any leftover daemon processes
@@ -563,7 +589,7 @@
if _hgpath is not None:
return _hgpath
- cmd = '%s -c "import mercurial; print mercurial.__path__[0]"'
+ cmd = '%s -c "import mercurial; print(mercurial.__path__[0])"'
pipe = os.popen(cmd % PYTHON)
try:
_hgpath = pipe.read().strip()
More information about the Mercurial-devel
mailing list