PROTON-490: fix examples, reactor

Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/9e7f16cc
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/9e7f16cc
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/9e7f16cc

Branch: refs/heads/kgiusti-python3
Commit: 9e7f16ccb5b2240c218af5ace2c4a61f07af1b9c
Parents: 646ee41
Author: Ken Giusti <kgiu...@apache.org>
Authored: Wed Apr 29 11:39:11 2015 -0400
Committer: Ken Giusti <kgiu...@apache.org>
Committed: Wed Apr 29 12:49:55 2015 -0400

----------------------------------------------------------------------
 examples/python/test_examples.py           | 57 +++++++++++++++++--------
 proton-c/bindings/python/proton/reactor.py |  2 +-
 2 files changed, 41 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/9e7f16cc/examples/python/test_examples.py
----------------------------------------------------------------------
diff --git a/examples/python/test_examples.py b/examples/python/test_examples.py
index 9c89344..6a411d3 100644
--- a/examples/python/test_examples.py
+++ b/examples/python/test_examples.py
@@ -17,13 +17,23 @@
 # under the License.
 #
 
+import sys
 import subprocess
 import time
 import unittest
 
+if sys.version_info[0] == 2:
+    _unicode_prefix = 'u'
+    _long_suffix = 'L'
+else:
+    _unicode_prefix = ''
+    _long_suffix = ''
+
+
 class ExamplesTest(unittest.TestCase):
     def test_helloworld(self, example="helloworld.py"):
-        p = subprocess.Popen([example], stderr=subprocess.STDOUT, 
stdout=subprocess.PIPE)
+        p = subprocess.Popen([example], stderr=subprocess.STDOUT, 
stdout=subprocess.PIPE,
+                             universal_newlines=True)
         p.wait()
         output = [l.strip() for l in p.stdout]
         self.assertEqual(output, ['Hello World!'])
@@ -41,19 +51,23 @@ class ExamplesTest(unittest.TestCase):
         self.test_helloworld('helloworld_direct_tornado.py')
 
     def test_simple_send_recv(self, recv='simple_recv.py', 
send='simple_send.py'):
-        r = subprocess.Popen([recv], stderr=subprocess.STDOUT, 
stdout=subprocess.PIPE)
-        s = subprocess.Popen([send], stderr=subprocess.STDOUT, 
stdout=subprocess.PIPE)
+        r = subprocess.Popen([recv], stderr=subprocess.STDOUT, 
stdout=subprocess.PIPE,
+                             universal_newlines=True)
+        s = subprocess.Popen([send], stderr=subprocess.STDOUT, 
stdout=subprocess.PIPE,
+                             universal_newlines=True)
         s.wait()
         r.wait()
         actual = [l.strip() for l in r.stdout]
-        expected = ["{'sequence': %iL}" % (i+1) for i in range(100)]
+        expected = ["{'sequence': %i%s}" % ((i+1), _long_suffix) for i in 
range(100)]
         self.assertEqual(actual, expected)
 
     def test_client_server(self, client=['client.py'], server=['server.py'], 
sleep=0):
-        s = subprocess.Popen(server, stderr=subprocess.STDOUT, 
stdout=subprocess.PIPE)
+        s = subprocess.Popen(server, stderr=subprocess.STDOUT, 
stdout=subprocess.PIPE,
+                             universal_newlines=True)
         if sleep:
             time.sleep(sleep)
-        c = subprocess.Popen(client, stderr=subprocess.STDOUT, 
stdout=subprocess.PIPE)
+        c = subprocess.Popen(client, stderr=subprocess.STDOUT, 
stdout=subprocess.PIPE,
+                             universal_newlines=True)
         c.wait()
         s.terminate()
         actual = [l.strip() for l in c.stdout]
@@ -84,14 +98,18 @@ class ExamplesTest(unittest.TestCase):
         # setup databases
         subprocess.check_call(['db_ctrl.py', 'init', './src_db'])
         subprocess.check_call(['db_ctrl.py', 'init', './dst_db'])
-        fill = subprocess.Popen(['db_ctrl.py', 'insert', './src_db'], 
stdin=subprocess.PIPE, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
+        fill = subprocess.Popen(['db_ctrl.py', 'insert', './src_db'],
+                                stdin=subprocess.PIPE, 
stderr=subprocess.STDOUT, stdout=subprocess.PIPE,
+                                universal_newlines=True)
         for i in range(100):
             fill.stdin.write("Message-%i\n" % (i+1))
         fill.stdin.close()
         fill.wait()
         # run send and recv
-        r = subprocess.Popen(['db_recv.py', '-m', '100'], 
stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
-        s = subprocess.Popen(['db_send.py', '-m', '100'], 
stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
+        r = subprocess.Popen(['db_recv.py', '-m', '100'], 
stderr=subprocess.STDOUT, stdout=subprocess.PIPE,
+                             universal_newlines=True)
+        s = subprocess.Popen(['db_send.py', '-m', '100'], 
stderr=subprocess.STDOUT, stdout=subprocess.PIPE,
+                             universal_newlines=True)
         s.wait()
         r.wait()
         # verify output of receive
@@ -99,9 +117,10 @@ class ExamplesTest(unittest.TestCase):
         expected = ["inserted message %i" % (i+1) for i in range(100)]
         self.assertEqual(actual, expected)
         # verify state of databases
-        v = subprocess.Popen(['db_ctrl.py', 'list', './dst_db'], 
stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
+        v = subprocess.Popen(['db_ctrl.py', 'list', './dst_db'], 
stderr=subprocess.STDOUT, stdout=subprocess.PIPE,
+                             universal_newlines=True)
         v.wait()
-        expected = ["(%i, u'Message-%i')" % ((i+1), (i+1)) for i in range(100)]
+        expected = ["(%i, %s'Message-%i')" % ((i+1), _unicode_prefix, (i+1)) 
for i in range(100)]
         actual = [l.strip() for l in v.stdout]
         self.assertEqual(actual, expected)
 
@@ -110,21 +129,25 @@ class ExamplesTest(unittest.TestCase):
 
     def test_simple_send_direct_recv(self):
         self.maxDiff = None
-        r = subprocess.Popen(['direct_recv.py', '-a', 'localhost:8888'], 
stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
+        r = subprocess.Popen(['direct_recv.py', '-a', 'localhost:8888'], 
stderr=subprocess.STDOUT, stdout=subprocess.PIPE,
+                             universal_newlines=True)
         time.sleep(0.5)
-        s = subprocess.Popen(['simple_send.py', '-a', 'localhost:8888'], 
stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
+        s = subprocess.Popen(['simple_send.py', '-a', 'localhost:8888'], 
stderr=subprocess.STDOUT, stdout=subprocess.PIPE,
+                             universal_newlines=True)
         s.wait()
         r.wait()
         actual = [l.strip() for l in r.stdout]
-        expected = ["{'sequence': %iL}" % (i+1) for i in range(100)]
+        expected = ["{'sequence': %i%s}" % ((i+1), _long_suffix) for i in 
range(100)]
         self.assertEqual(actual, expected)
 
     def test_direct_send_simple_recv(self):
-        s = subprocess.Popen(['direct_send.py', '-a', 'localhost:8888'], 
stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
+        s = subprocess.Popen(['direct_send.py', '-a', 'localhost:8888'], 
stderr=subprocess.STDOUT, stdout=subprocess.PIPE,
+                             universal_newlines=True)
         time.sleep(0.5)
-        r = subprocess.Popen(['simple_recv.py', '-a', 'localhost:8888'], 
stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
+        r = subprocess.Popen(['simple_recv.py', '-a', 'localhost:8888'], 
stderr=subprocess.STDOUT, stdout=subprocess.PIPE,
+                             universal_newlines=True)
         r.wait()
         s.wait()
         actual = [l.strip() for l in r.stdout]
-        expected = ["{'sequence': %iL}" % (i+1) for i in range(100)]
+        expected = ["{'sequence': %i%s}" % ((i+1), _long_suffix) for i in 
range(100)]
         self.assertEqual(actual, expected)

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/9e7f16cc/proton-c/bindings/python/proton/reactor.py
----------------------------------------------------------------------
diff --git a/proton-c/bindings/python/proton/reactor.py 
b/proton-c/bindings/python/proton/reactor.py
index 2260375..b475333 100644
--- a/proton-c/bindings/python/proton/reactor.py
+++ b/proton-c/bindings/python/proton/reactor.py
@@ -224,7 +224,7 @@ class EventInjector(object):
         then this will be removed from the set of interest.
         """
         self._closed = True
-        os.write(self.pipe[1], "!")
+        os.write(self.pipe[1], _compat.str2bin("!"))
 
     def fileno(self):
         return self.pipe[0]


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org
For additional commands, e-mail: commits-h...@qpid.apache.org

Reply via email to