diff options
Diffstat (limited to 'test/LedgerHarness.py')
-rwxr-xr-x | test/LedgerHarness.py | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/test/LedgerHarness.py b/test/LedgerHarness.py index 63d6a0ec..2373ea32 100755 --- a/test/LedgerHarness.py +++ b/test/LedgerHarness.py @@ -1,4 +1,7 @@ #!/usr/bin/env python +# -*- coding: utf-8 -*- + +from __future__ import print_function, unicode_literals import sys import os @@ -6,8 +9,11 @@ import re from subprocess import Popen, PIPE -import copy_reg import types +if sys.version_info.major == 2: + import copy_reg as copyreg +else: + import copyreg def _pickle_method(method): func_name = method.im_func.__name__ @@ -25,7 +31,7 @@ def _unpickle_method(func_name, obj, cls): break return func.__get__(obj, cls) -copy_reg.pickle(types.MethodType, _pickle_method, _unpickle_method) +copyreg.pickle(types.MethodType, _pickle_method, _unpickle_method) class LedgerHarness: ledger = None @@ -38,10 +44,10 @@ class LedgerHarness: def __init__(self, argv): if not os.path.isfile(argv[1]): - print "Cannot find ledger at '%s'" % argv[1] + print("Cannot find ledger at '%s'" % argv[1]) sys.exit(1) if not os.path.isdir(argv[2]): - print "Cannot find source path at '%s'" % argv[2] + print("Cannot find source path at '%s'" % argv[2]) sys.exit(1) self.ledger = os.path.abspath(argv[1]) @@ -109,14 +115,18 @@ class LedgerHarness: def readlines(self, fd): lines = [] for line in fd.readlines(): - if not line.startswith("GuardMalloc"): + if sys.version_info.major == 2: + line = unicode(line, 'utf-8') + else: + line = line.decode('utf-8') + if not line.startswith('GuardMalloc'): lines.append(line) return lines def wait(self, process, msg='Ledger invocation failed:'): if process.wait() != 0: - print msg - print process.stderr.read() + print(msg) + print(process.stderr.read()) self.failure() return False return True @@ -134,21 +144,21 @@ class LedgerHarness: self.failed += 1 def exit(self): - print + print() if self.succeeded > 0: - print "OK (%d) " % self.succeeded, + print("OK (%d) " % self.succeeded,) if self.failed > 0: - print "FAILED (%d)" % self.failed, - print + print("FAILED (%d)" % self.failed,) + print() sys.exit(self.failed) if __name__ == '__main__': harness = LedgerHarness(sys.argv) proc = harness.run('$ledger -f doc/sample.dat reg') - print 'STDOUT:' - print proc.stdout.read() - print 'STDERR:' - print proc.stderr.read() + print('STDOUT:') + print(proc.stdout.read()) + print('STDERR:') + print(proc.stderr.read()) harness.success() harness.exit() |