You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kg...@apache.org on 2015/06/22 14:57:06 UTC
[03/34] qpid-proton git commit: PROTON-490: futurize the python code
under the test directory
PROTON-490: futurize the python code under the test directory
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/979471f5
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/979471f5
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/979471f5
Branch: refs/heads/master
Commit: 979471f5ee355b3eca43f8cf176ebc7e241ab603
Parents: aae1d20
Author: Ken Giusti <kg...@apache.org>
Authored: Fri Apr 17 09:39:51 2015 -0400
Committer: Ken Giusti <kg...@apache.org>
Committed: Mon Apr 20 12:46:47 2015 -0400
----------------------------------------------------------------------
tests/python/proton_tests/codec.py | 87 +++++++++++++++--------------
tests/python/proton_tests/common.py | 24 +++++++-
tests/python/proton_tests/engine.py | 8 ++-
tests/python/proton_tests/interop.py | 21 +++----
tests/python/proton_tests/message.py | 3 +-
tests/python/proton_tests/messenger.py | 9 ++-
tests/python/proton_tests/reactor.py | 3 +-
tests/python/proton_tests/sasl.py | 6 +-
tests/python/proton_tests/soak.py | 3 +-
tests/python/proton_tests/ssl.py | 11 ++--
tests/python/proton_tests/transport.py | 9 ++-
tests/python/proton_tests/url.py | 3 +-
tests/smoke/recv.py | 3 +-
tests/smoke/send.py | 5 +-
tests/tools/apps/python/msgr-recv.py | 1 +
tests/tools/apps/python/msgr-send.py | 1 +
16 files changed, 121 insertions(+), 76 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/979471f5/tests/python/proton_tests/codec.py
----------------------------------------------------------------------
diff --git a/tests/python/proton_tests/codec.py b/tests/python/proton_tests/codec.py
index 81bb4de..e8893cf 100644
--- a/tests/python/proton_tests/codec.py
+++ b/tests/python/proton_tests/codec.py
@@ -17,7 +17,8 @@
# under the License.
#
-import os, common, sys
+import os, sys
+from . import common
from proton import *
try:
from uuid import uuid4
@@ -36,58 +37,58 @@ class Test(common.Test):
class DataTest(Test):
def testTopLevelNext(self):
- assert self.data.next() is None
+ assert next(self.data) is None
self.data.put_null()
self.data.put_bool(False)
self.data.put_int(0)
- assert self.data.next() is None
+ assert next(self.data) is None
self.data.rewind()
- assert self.data.next() == Data.NULL
- assert self.data.next() == Data.BOOL
- assert self.data.next() == Data.INT
- assert self.data.next() is None
+ assert next(self.data) == Data.NULL
+ assert next(self.data) == Data.BOOL
+ assert next(self.data) == Data.INT
+ assert next(self.data) is None
def testNestedNext(self):
- assert self.data.next() is None
+ assert next(self.data) is None
self.data.put_null()
- assert self.data.next() is None
+ assert next(self.data) is None
self.data.put_list()
- assert self.data.next() is None
+ assert next(self.data) is None
self.data.put_bool(False)
- assert self.data.next() is None
+ assert next(self.data) is None
self.data.rewind()
- assert self.data.next() is Data.NULL
- assert self.data.next() is Data.LIST
+ assert next(self.data) is Data.NULL
+ assert next(self.data) is Data.LIST
self.data.enter()
- assert self.data.next() is None
+ assert next(self.data) is None
self.data.put_ubyte(0)
- assert self.data.next() is None
+ assert next(self.data) is None
self.data.put_uint(0)
- assert self.data.next() is None
+ assert next(self.data) is None
self.data.put_int(0)
- assert self.data.next() is None
+ assert next(self.data) is None
self.data.exit()
- assert self.data.next() is Data.BOOL
- assert self.data.next() is None
+ assert next(self.data) is Data.BOOL
+ assert next(self.data) is None
self.data.rewind()
- assert self.data.next() is Data.NULL
- assert self.data.next() is Data.LIST
+ assert next(self.data) is Data.NULL
+ assert next(self.data) is Data.LIST
assert self.data.enter()
- assert self.data.next() is Data.UBYTE
- assert self.data.next() is Data.UINT
- assert self.data.next() is Data.INT
- assert self.data.next() is None
+ assert next(self.data) is Data.UBYTE
+ assert next(self.data) is Data.UINT
+ assert next(self.data) is Data.INT
+ assert next(self.data) is None
assert self.data.exit()
- assert self.data.next() is Data.BOOL
- assert self.data.next() is None
+ assert next(self.data) is Data.BOOL
+ assert next(self.data) is None
def testEnterExit(self):
- assert self.data.next() is None
+ assert next(self.data) is None
assert not self.data.enter()
self.data.put_list()
assert self.data.enter()
- assert self.data.next() is None
+ assert next(self.data) is None
self.data.put_list()
assert self.data.enter()
self.data.put_list()
@@ -100,19 +101,19 @@ class DataTest(Test):
assert self.data.get_list() == 1
assert not self.data.exit()
assert self.data.get_list() == 1
- assert self.data.next() is None
+ assert next(self.data) is None
self.data.rewind()
- assert self.data.next() is Data.LIST
+ assert next(self.data) is Data.LIST
assert self.data.get_list() == 1
assert self.data.enter()
- assert self.data.next() is Data.LIST
+ assert next(self.data) is Data.LIST
assert self.data.get_list() == 1
assert self.data.enter()
- assert self.data.next() is Data.LIST
+ assert next(self.data) is Data.LIST
assert self.data.get_list() == 0
assert self.data.enter()
- assert self.data.next() is None
+ assert next(self.data) is None
assert self.data.exit()
assert self.data.get_list() == 0
assert self.data.exit()
@@ -126,7 +127,7 @@ class DataTest(Test):
"""More informative exception from putters, include bad value"""
try:
putter(v)
- except Exception, e:
+ except Exception:
etype, value, trace = sys.exc_info()
raise etype, "%s(%r): %s" % (putter.__name__, v, value), trace
return putter
@@ -168,7 +169,7 @@ class DataTest(Test):
self.put(putter, v)
self.data.exit()
self.data.rewind()
- assert self.data.next() == Data.ARRAY
+ assert next(self.data) == Data.ARRAY
count, described, type = self.data.get_array()
assert count == len(values), count
if dtype is None:
@@ -178,17 +179,17 @@ class DataTest(Test):
assert type == aTYPE, type
assert self.data.enter()
if described:
- assert self.data.next() == dTYPE
+ assert next(self.data) == dTYPE
getter = getattr(self.data, "get_%s" % dtype)
gotten = getter()
assert gotten == descriptor, gotten
if values:
getter = getattr(self.data, "get_%s" % atype)
for v in values:
- assert self.data.next() == aTYPE
+ assert next(self.data) == aTYPE
gotten = getter()
assert gotten == v, gotten
- assert self.data.next() is None
+ assert next(self.data) is None
assert self.data.exit()
def testStringArray(self):
@@ -230,7 +231,7 @@ class DataTest(Test):
self.data.rewind()
for v in values:
- vtype = self.data.next()
+ vtype = next(self.data)
assert vtype == ntype, vtype
gotten = getter()
assert eq(gotten, v), (gotten, v)
@@ -245,7 +246,7 @@ class DataTest(Test):
cgetter = getattr(copy, "get_%s" % dtype)
for v in values:
- vtype = copy.next()
+ vtype = next(copy)
assert vtype == ntype, vtype
gotten = cgetter()
assert eq(gotten, v), (gotten, v)
@@ -345,7 +346,7 @@ class DataTest(Test):
data = Data()
data.decode(enc)
data.rewind()
- assert data.next()
+ assert next(data)
copy = data.get_object()
assert copy == obj, (copy, obj)
@@ -355,7 +356,7 @@ class DataTest(Test):
symbol("list"): [1, 2, 3, 4]}
self.data.put_object(obj)
self.data.rewind()
- self.data.next()
+ next(self.data)
self.data.enter()
self.data.narrow()
assert self.data.lookup("pi")
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/979471f5/tests/python/proton_tests/common.py
----------------------------------------------------------------------
diff --git a/tests/python/proton_tests/common.py b/tests/python/proton_tests/common.py
index 1b8dbdb..585ea02 100644
--- a/tests/python/proton_tests/common.py
+++ b/tests/python/proton_tests/common.py
@@ -27,6 +27,27 @@ from proton import Connection, Transport, SASL, Endpoint, Delivery, SSL
from proton.reactor import Container
from proton.handlers import CHandshaker, CFlowController
+if sys.version_info[0] == 2 and sys.version_info[1] < 6:
+ # this is for compatibility, apparently the version of jython we
+ # use doesn't have the next() builtin.
+ # we should remove this when we upgrade to a python 2.6+ compatible version
+ # of jython
+ #_DEF = object() This causes the test loader to fail (why?)
+ class _dummy(): pass
+ _DEF = _dummy
+
+ def next(iter, default=_DEF):
+ try:
+ return iter.next()
+ except StopIteration:
+ if default is _DEF:
+ raise
+ else:
+ return default
+ # I may goto hell for this:
+ import __builtin__
+ __builtin__.__dict__['next'] = next
+
def free_tcp_ports(count=1):
""" return a list of 'count' TCP ports that are free to used (ie. unbound)
@@ -224,7 +245,8 @@ class MessengerApp(object):
cmd.insert(0, foundfile)
cmd.insert(0, sys.executable)
self._process = Popen(cmd, stdout=PIPE, stderr=STDOUT, bufsize=4096)
- except OSError, e:
+ except OSError:
+ e = sys.exc_info()[1]
print("ERROR: '%s'" % e)
assert False, "Unable to execute command '%s', is it in your PATH?" % cmd[0]
self._ready() # wait for it to initialize
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/979471f5/tests/python/proton_tests/engine.py
----------------------------------------------------------------------
diff --git a/tests/python/proton_tests/engine.py b/tests/python/proton_tests/engine.py
index 99125d9..7835792 100644
--- a/tests/python/proton_tests/engine.py
+++ b/tests/python/proton_tests/engine.py
@@ -1,3 +1,4 @@
+from __future__ import absolute_import
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -17,10 +18,11 @@
# under the License.
#
-import os, common, gc
+import os, gc
+from . import common
from time import time, sleep
from proton import *
-from common import pump
+from .common import pump
from proton.reactor import Reactor
# older versions of gc do not provide the garbage list
@@ -1836,7 +1838,7 @@ class PipelineTest(Test):
assert rcv.queued == 0, rcv.queued
import sys
-from common import Skipped
+from .common import Skipped
class ServerTest(Test):
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/979471f5/tests/python/proton_tests/interop.py
----------------------------------------------------------------------
diff --git a/tests/python/proton_tests/interop.py b/tests/python/proton_tests/interop.py
index baf998d..1ef92dd 100644
--- a/tests/python/proton_tests/interop.py
+++ b/tests/python/proton_tests/interop.py
@@ -18,7 +18,8 @@
#
from proton import *
-import os, common
+import os
+from . import common
def find_test_interop_dir():
@@ -70,7 +71,7 @@ class InteropTest(common.Test):
self.decode_data(body)
def assert_next(self, type, value):
- next_type = self.data.next()
+ next_type = next(self.data)
assert next_type == type, "Type mismatch: %s != %s"%(
Data.type_names[next_type], Data.type_names[type])
next_value = self.data.get_object()
@@ -79,7 +80,7 @@ class InteropTest(common.Test):
def test_message(self):
self.decode_message_file("message")
self.assert_next(Data.STRING, "hello")
- assert self.data.next() is None
+ assert next(self.data) is None
def test_primitives(self):
self.decode_data_file("primitives")
@@ -94,7 +95,7 @@ class InteropTest(common.Test):
self.assert_next(Data.LONG, -12345)
self.assert_next(Data.FLOAT, 0.125)
self.assert_next(Data.DOUBLE, 0.125)
- assert self.data.next() is None
+ assert next(self.data) is None
def test_strings(self):
self.decode_data_file("strings")
@@ -104,20 +105,20 @@ class InteropTest(common.Test):
self.assert_next(Data.BINARY, "")
self.assert_next(Data.STRING, "")
self.assert_next(Data.SYMBOL, "")
- assert self.data.next() is None
+ assert next(self.data) is None
def test_described(self):
self.decode_data_file("described")
self.assert_next(Data.DESCRIBED, Described("foo-descriptor", "foo-value"))
self.data.exit()
- assert self.data.next() == Data.DESCRIBED
+ assert next(self.data) == Data.DESCRIBED
self.data.enter()
self.assert_next(Data.INT, 12)
self.assert_next(Data.INT, 13)
self.data.exit()
- assert self.data.next() is None
+ assert next(self.data) is None
def test_described_array(self):
self.decode_data_file("described_array")
@@ -128,17 +129,17 @@ class InteropTest(common.Test):
self.assert_next(Data.ARRAY, Array(UNDESCRIBED, Data.INT, *range(0,100)))
self.assert_next(Data.ARRAY, Array(UNDESCRIBED, Data.STRING, *["a", "b", "c"]))
self.assert_next(Data.ARRAY, Array(UNDESCRIBED, Data.INT))
- assert self.data.next() is None
+ assert next(self.data) is None
def test_lists(self):
self.decode_data_file("lists")
self.assert_next(Data.LIST, [32, "foo", True])
self.assert_next(Data.LIST, [])
- assert self.data.next() is None
+ assert next(self.data) is None
def test_maps(self):
self.decode_data_file("maps")
self.assert_next(Data.MAP, {"one":1, "two":2, "three":3 })
self.assert_next(Data.MAP, {1:"one", 2:"two", 3:"three"})
self.assert_next(Data.MAP, {})
- assert self.data.next() is None
+ assert next(self.data) is None
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/979471f5/tests/python/proton_tests/message.py
----------------------------------------------------------------------
diff --git a/tests/python/proton_tests/message.py b/tests/python/proton_tests/message.py
index 6bf94fe..3366366 100644
--- a/tests/python/proton_tests/message.py
+++ b/tests/python/proton_tests/message.py
@@ -17,7 +17,8 @@
# under the License.
#
-import os, common
+import os
+from . import common
from proton import *
try:
from uuid import uuid4
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/979471f5/tests/python/proton_tests/messenger.py
----------------------------------------------------------------------
diff --git a/tests/python/proton_tests/messenger.py b/tests/python/proton_tests/messenger.py
index c7c7dd3..03a1b6b 100644
--- a/tests/python/proton_tests/messenger.py
+++ b/tests/python/proton_tests/messenger.py
@@ -1,3 +1,4 @@
+from __future__ import absolute_import
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -17,11 +18,12 @@
# under the License.
#
-import os, common, sys, traceback
+import os, sys, traceback
+from . import common
from proton import *
from threading import Thread, Event
from time import sleep, time
-from common import Skipped
+from .common import Skipped
class Test(common.Test):
@@ -180,7 +182,8 @@ class MessengerTest(Test):
try:
self.client.put(msg)
assert False, "Expecting MessengerException"
- except MessengerException, exc:
+ except MessengerException:
+ exc = sys.exc_info()[1]
err = str(exc)
assert "unable to send to address: totally-bogus-address" in err, err
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/979471f5/tests/python/proton_tests/reactor.py
----------------------------------------------------------------------
diff --git a/tests/python/proton_tests/reactor.py b/tests/python/proton_tests/reactor.py
index 4e660a5..6afee30 100644
--- a/tests/python/proton_tests/reactor.py
+++ b/tests/python/proton_tests/reactor.py
@@ -1,3 +1,4 @@
+from __future__ import absolute_import
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -17,7 +18,7 @@
# under the License.
#
-from common import Test
+from .common import Test
from proton.reactor import Reactor
class Barf(Exception):
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/979471f5/tests/python/proton_tests/sasl.py
----------------------------------------------------------------------
diff --git a/tests/python/proton_tests/sasl.py b/tests/python/proton_tests/sasl.py
index a14a0db..0d6761f 100644
--- a/tests/python/proton_tests/sasl.py
+++ b/tests/python/proton_tests/sasl.py
@@ -1,3 +1,4 @@
+from __future__ import absolute_import
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -17,9 +18,10 @@
# under the License.
#
-import os, common
+import os
+from . import common
from proton import *
-from common import pump
+from .common import pump
class Test(common.Test):
pass
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/979471f5/tests/python/proton_tests/soak.py
----------------------------------------------------------------------
diff --git a/tests/python/proton_tests/soak.py b/tests/python/proton_tests/soak.py
index 9e5ceab..0a6e693 100644
--- a/tests/python/proton_tests/soak.py
+++ b/tests/python/proton_tests/soak.py
@@ -1,3 +1,4 @@
+from __future__ import absolute_import
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -18,7 +19,7 @@
#
import os
import sys
-from common import Test, Skipped, free_tcp_ports, \
+from .common import Test, Skipped, free_tcp_ports, \
MessengerReceiverC, MessengerSenderC, \
MessengerReceiverValgrind, MessengerSenderValgrind, \
MessengerReceiverPython, MessengerSenderPython, \
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/979471f5/tests/python/proton_tests/ssl.py
----------------------------------------------------------------------
diff --git a/tests/python/proton_tests/ssl.py b/tests/python/proton_tests/ssl.py
index f5fae3f..fd5aaf1 100644
--- a/tests/python/proton_tests/ssl.py
+++ b/tests/python/proton_tests/ssl.py
@@ -1,3 +1,4 @@
+from __future__ import absolute_import
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -17,13 +18,14 @@
# under the License.
#
-import os, common
+import os
+from . import common
import random
import string
import subprocess
from proton import *
-from common import Skipped, pump
+from .common import Skipped, pump
def _testpath(file):
@@ -791,7 +793,7 @@ class SslTest(common.Test):
try:
ssl3 = SSL(transport, self.server_domain)
assert False, "Expected error did not occur!"
- except SSLException, e:
+ except SSLException:
pass
class MessengerSSLTests(common.Test):
@@ -834,7 +836,8 @@ class MessengerSSLTests(common.Test):
self.server.subscribe("amqps://~0.0.0.0:12345")
if exception is not None:
assert False, "expected failure did not occur"
- except MessengerException, e:
+ except MessengerException:
+ e = sys.exc_info()[1]
if exception:
assert exception in str(e), str(e)
else:
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/979471f5/tests/python/proton_tests/transport.py
----------------------------------------------------------------------
diff --git a/tests/python/proton_tests/transport.py b/tests/python/proton_tests/transport.py
index dcf7636..512d816 100644
--- a/tests/python/proton_tests/transport.py
+++ b/tests/python/proton_tests/transport.py
@@ -17,7 +17,8 @@
# under the License.
#
-import os, common
+import os
+from . import common
from proton import *
@@ -119,7 +120,8 @@ class TransportTest(Test):
assert n > 0, n
try:
self.transport.close_head()
- except TransportException, e:
+ except TransportException:
+ e = sys.exc_info()[1]
assert "aborted" in str(e), str(e)
n = self.transport.pending()
assert n < 0, n
@@ -129,7 +131,8 @@ class TransportTest(Test):
assert n > 0, n
try:
self.transport.close_tail()
- except TransportException, e:
+ except TransportException:
+ e = sys.exc_info()[1]
assert "aborted" in str(e), str(e)
n = self.transport.capacity()
assert n < 0, n
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/979471f5/tests/python/proton_tests/url.py
----------------------------------------------------------------------
diff --git a/tests/python/proton_tests/url.py b/tests/python/proton_tests/url.py
index 77a16ff..40a257c 100644
--- a/tests/python/proton_tests/url.py
+++ b/tests/python/proton_tests/url.py
@@ -1,3 +1,4 @@
+from __future__ import absolute_import
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -18,7 +19,7 @@
#
-import common
+from . import common
from proton import Url
class UrlTest(common.Test):
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/979471f5/tests/smoke/recv.py
----------------------------------------------------------------------
diff --git a/tests/smoke/recv.py b/tests/smoke/recv.py
index 3b2b0e5..e6aa2b6 100755
--- a/tests/smoke/recv.py
+++ b/tests/smoke/recv.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+from __future__ import print_function
import sys
from proton import *
@@ -16,7 +17,7 @@ messenger.start()
while True:
messenger.recv()
messenger.get(message)
- print "Got: %s" % message
+ print("Got: %s" % message)
messenger.accept()
messenger.stop()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/979471f5/tests/smoke/send.py
----------------------------------------------------------------------
diff --git a/tests/smoke/send.py b/tests/smoke/send.py
index 1aed9c8..7daee01 100755
--- a/tests/smoke/send.py
+++ b/tests/smoke/send.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+from __future__ import print_function
import sys
from proton import *
@@ -17,7 +18,7 @@ message.body = u"Hello World!"
messenger.start()
tracker = messenger.put(message)
-print "Put: %s" % message
+print("Put: %s" % message)
messenger.send()
-print "Status: %s" % messenger.status(tracker)
+print("Status: %s" % messenger.status(tracker))
messenger.stop()
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/979471f5/tests/tools/apps/python/msgr-recv.py
----------------------------------------------------------------------
diff --git a/tests/tools/apps/python/msgr-recv.py b/tests/tools/apps/python/msgr-recv.py
index 73c2a3a..079c871 100755
--- a/tests/tools/apps/python/msgr-recv.py
+++ b/tests/tools/apps/python/msgr-recv.py
@@ -18,6 +18,7 @@
# specific language governing permissions and limitations
# under the License.
#
+from __future__ import print_function
import sys, optparse, time
import logging
from proton import *
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/979471f5/tests/tools/apps/python/msgr-send.py
----------------------------------------------------------------------
diff --git a/tests/tools/apps/python/msgr-send.py b/tests/tools/apps/python/msgr-send.py
index 872122b..a2f67c5 100755
--- a/tests/tools/apps/python/msgr-send.py
+++ b/tests/tools/apps/python/msgr-send.py
@@ -18,6 +18,7 @@
# specific language governing permissions and limitations
# under the License.
#
+from __future__ import print_function
import sys, optparse, time
import logging
from proton import *
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org