From patchwork Fri Sep 20 14:23:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [13, of, 13, V2, py3, support] run-tests: minimum changes required to make run-tests work in python3 From: Augie Fackler X-Patchwork-Id: 2559 Message-Id: To: mercurial-devel@selenic.com Date: Fri, 20 Sep 2013 10:23:51 -0400 # HG changeset patch # User Augie Fackler # Date 1379621130 14400 # Thu Sep 19 16:05:30 2013 -0400 # Node ID f3a4a22f8d18a916f9faa48b6724a0ac1deab0f3 # Parent f1b096a613612935b9b556b25b33c32a29f75f67 run-tests: minimum changes required to make run-tests work in python3 This is just doing the dumbest thing possible and assumes test input/output is all utf-8[0]. This works for now, at least for the simple tests I'm interested in trying to run, so I'm calling it progress until I have to come back and figure out something smarter. With these changes in place, all tests continue to pass on python2, and you can run tests on python3 by running 2to3 over run-tests.py and killdaemons.py. At that point, demandimport breaks on python3, causing all tests to fail, but at least it's some progress. 0: subprocess works in bytes, but all the run-tests manipulation of test data currently happens on unicode string objects in Python 3, as many of the functions are missing on bytes for now. diff --git a/tests/run-tests.py b/tests/run-tests.py --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -60,11 +60,24 @@ processlock = threading.Lock() -# subprocess._cleanup can race with any Popen.wait or Popen.poll on py24 -# http://bugs.python.org/issue1731717 for details. We shouldn't be producing -# zombies but it's pretty harmless even if we do. -if sys.version_info[1] < 5: - subprocess._cleanup = lambda: None +if sys.version_info[0] >= 3: + def makebytes(d): + if isinstance(d, str): + return d.encode('utf-8') + return d + def makestr(d): + if isinstance(d, bytes): + return d.decode('utf-8') + return d +else: + # subprocess._cleanup can race with any Popen.wait or Popen.poll on py24 + # http://bugs.python.org/issue1731717 for details. We shouldn't be producing + # zombies but it's pretty harmless even if we do. + if sys.version_info[1] < 5: + subprocess._cleanup = lambda: None + def makebytes(d): + return d + makestr = makebytes closefds = os.name == 'posix' def Popen4(cmd, wd, timeout, env=None): @@ -764,7 +777,7 @@ fd, name = tempfile.mkstemp(suffix='hg-tst') try: for l in script: - os.write(fd, l) + os.write(fd, makebytes(l)) os.close(fd) cmd = '%s "%s"' % (options.shell, name) @@ -860,6 +873,7 @@ if abort: raise KeyboardInterrupt() + output = makestr(output) for s, r in replacements: output = re.sub(s, r, output) return ret, output.splitlines(True) @@ -994,7 +1008,7 @@ # Save errors to a file for diagnosis f = open(err, "wb") for line in out: - f.write(line) + f.write(makebytes(line)) f.close() if skipped: