PROTON-1659: Fix test to run with python 3
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/fb352ceb Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/fb352ceb Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/fb352ceb Branch: refs/heads/go1 Commit: fb352ceb4d6d668ba7132d182772c66ed9f12e4c Parents: 7781204 Author: Andrew Stitcher <astitc...@apache.org> Authored: Thu Oct 26 22:42:01 2017 -0400 Committer: Andrew Stitcher <astitc...@apache.org> Committed: Thu Oct 26 22:42:01 2017 -0400 ---------------------------------------------------------------------- examples/c/example_test.py | 2 +- proton-c/src/tests/fdlimit.py | 5 +++-- tools/py/proctest.py | 11 ++++++----- 3 files changed, 10 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/fb352ceb/examples/c/example_test.py ---------------------------------------------------------------------- diff --git a/examples/c/example_test.py b/examples/c/example_test.py index 31d941f..5c97e46 100644 --- a/examples/c/example_test.py +++ b/examples/c/example_test.py @@ -28,7 +28,7 @@ def python_cmd(name): MESSAGES=10 -def receive_expect_messages(n=MESSAGES): return ''.join(['{"sequence"=%s}\n'%i for i in xrange(1, n+1)]) +def receive_expect_messages(n=MESSAGES): return ''.join(['{"sequence"=%s}\n'%i for i in range(1, n+1)]) def receive_expect_total(n=MESSAGES): return "%s messages received\n"%n def receive_expect(n=MESSAGES): return receive_expect_messages(n)+receive_expect_total(n) http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/fb352ceb/proton-c/src/tests/fdlimit.py ---------------------------------------------------------------------- diff --git a/proton-c/src/tests/fdlimit.py b/proton-c/src/tests/fdlimit.py index c41d14a..53751cb 100644 --- a/proton-c/src/tests/fdlimit.py +++ b/proton-c/src/tests/fdlimit.py @@ -16,6 +16,7 @@ # specific language governing permissions and limitations # under the License # +from __future__ import print_function from proctest import * @@ -42,7 +43,7 @@ class LimitedBroker(object): try: Proc(["prlimit"]).wait_exit() except: - print "Skipping test: prlimit not available" + print("Skipping test: prlimit not available") sys.exit(0) class FdLimitTest(ProcTestCase): @@ -58,7 +59,7 @@ class FdLimitTest(ProcTestCase): with LimitedBroker(self, fdlimit) as b: receivers = [] # Start enough receivers to use all FDs, make sure the broker logs an error - for i in xrange(fdlimit+1): + for i in range(fdlimit+1): receivers.append(self.proc(["receive", "", b.port, str(i)])) # Note: libuv silently swallows EMFILE/ENFILE errors so there is no error reporting. http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/fb352ceb/tools/py/proctest.py ---------------------------------------------------------------------- diff --git a/tools/py/proctest.py b/tools/py/proctest.py index 947e7a5..8e3c473 100644 --- a/tools/py/proctest.py +++ b/tools/py/proctest.py @@ -79,14 +79,13 @@ class Proc(Popen): @property def out(self): self._out.seek(0) - # Normalize line endings, os.tmpfile() opens in binary mode. - return self._out.read().replace('\r\n','\n').replace('\r','\n') + return self._out.read() def __init__(self, args, valgrind=True, helgrind=False, **kwargs): """Start an example process""" self.args = list(args) self.kwargs = kwargs - self._out = tempfile.TemporaryFile() + self._out = tempfile.TemporaryFile(mode='w+') valgrind_exe = valgrind and os.getenv("VALGRIND") if valgrind_exe: # run valgrind for speed, not for detailed information @@ -100,11 +99,11 @@ class Proc(Popen): sys.stderr.write("\n== running == "+" ".join(self.args)+"\n") try: Popen.__init__(self, self.args, stdout=self._out, stderr=STDOUT, **kwargs) - except OSError, e: + except OSError as e: if e.errno == errno.ENOENT: raise NotFoundError(self, str(e)) raise ProcError(self, str(e)) - except Exception, e: + except Exception as e: raise ProcError(self, str(e)) def kill(self): @@ -213,6 +212,8 @@ class ProcTestCase(unittest.TestCase): def assertMultiLineEqual(self, a, b): self.assertEqual(a, b) +from functools import reduce + def find_file(filename, path): """ Find filename in path. Path is a list of directory names or OS path strings --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org