Merge lp:~cjwatson/rabbitfixture/py3 into lp:rabbitfixture

Proposed by Colin Watson
Status: Merged
Merged at revision: 39
Proposed branch: lp:~cjwatson/rabbitfixture/py3
Merge into: lp:rabbitfixture
Diff against target: 183 lines (+38/-22)
3 files modified
rabbitfixture/server.py (+12/-8)
rabbitfixture/tests/test_server.py (+19/-12)
setup.py (+7/-2)
To merge this branch: bzr merge lp:~cjwatson/rabbitfixture/py3
Reviewer Review Type Date Requested Status
Free Ekanayaka (community) Approve
Review via email: mp+341297@code.launchpad.net

Commit message

Add Python 3 support.

Description of the change

This also involves porting from amqplib to the better-maintained amqp. I've tested this with a Launchpad branch which I've also ported from amqplib to amqp, and it seems to be behaving itself in the relevant subset of the test suite.

To post a comment you must log in.
lp:~cjwatson/rabbitfixture/py3 updated
41. By Colin Watson

Require amqp >= 2.0.0, since that has the big async refactoring.

Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

+1 from me as long as the test suite works, as it seems you have checked.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'rabbitfixture/server.py'
2--- rabbitfixture/server.py 2016-08-30 09:23:00 +0000
3+++ rabbitfixture/server.py 2018-03-12 11:54:53 +0000
4@@ -3,6 +3,8 @@
5
6 """Test server fixtures for RabbitMQ."""
7
8+from __future__ import absolute_import, print_function
9+
10 __metaclass__ = type
11
12 __all__ = [
13@@ -20,7 +22,7 @@
14 import subprocess
15 import time
16
17-from amqplib import client_0_8 as amqp
18+import amqp
19 from fixtures import (
20 EnvironmentVariableFixture,
21 Fixture,
22@@ -198,11 +200,11 @@
23 def _get_errors(self):
24 """Yield all errors as UTF-8 encoded text."""
25 for error in self._errors:
26- if type(error) is unicode:
27+ if isinstance(error, bytes):
28+ yield error
29+ else:
30 yield error.encode('utf8')
31- else:
32- yield error
33- yield '\n'
34+ yield b'\n'
35
36 @property
37 def ctlbin(self):
38@@ -223,7 +225,7 @@
39 ctl = subprocess.Popen(
40 (self.ctlbin, "-n", nodename) + command, env=env,
41 stdout=subprocess.PIPE, stderr=subprocess.PIPE,
42- preexec_fn=preexec_fn)
43+ preexec_fn=preexec_fn, universal_newlines=True)
44 try:
45 outstr, errstr = ctl.communicate(timeout=timeout)
46 except subprocess.TimeoutExpired:
47@@ -257,9 +259,11 @@
48 :raises socket.error: If the connection cannot be made.
49 """
50 host_port = "%s:%s" % (self.config.hostname, self.config.port)
51- return amqp.Connection(
52+ connection = amqp.Connection(
53 host=host_port, userid="guest",
54- password="guest", virtual_host="/", insist=False)
55+ password="guest", virtual_host="/")
56+ connection.connect()
57+ return connection
58
59
60 class RabbitServerRunner(Fixture):
61
62=== modified file 'rabbitfixture/tests/test_server.py'
63--- rabbitfixture/tests/test_server.py 2016-08-30 09:23:00 +0000
64+++ rabbitfixture/tests/test_server.py 2018-03-12 11:54:53 +0000
65@@ -3,6 +3,8 @@
66
67 """Tests for the Rabbit fixture."""
68
69+from __future__ import absolute_import, print_function
70+
71 __metaclass__ = type
72
73 import os.path
74@@ -10,7 +12,7 @@
75 import stat
76 from textwrap import dedent
77
78-from amqplib import client_0_8 as amqp
79+import amqp
80 from fixtures import (
81 EnvironmentVariableFixture,
82 MonkeyPatch,
83@@ -22,6 +24,7 @@
84 RabbitServerEnvironment,
85 RabbitServerResources,
86 )
87+import six
88 from testtools import TestCase
89 from testtools.testcase import gather_details
90
91@@ -43,9 +46,11 @@
92 connect_arguments = {
93 "host": 'localhost:%s' % fixture.config.port,
94 "userid": "guest", "password": "guest",
95- "virtual_host": "/", "insist": False,
96+ "virtual_host": "/",
97 }
98- amqp.Connection(**connect_arguments).close()
99+ connection = amqp.Connection(**connect_arguments)
100+ connection.connect()
101+ connection.close()
102 # And get a log file.
103 log = fixture.runner.getDetails()["server.log"]
104 # Which shouldn't blow up on iteration.
105@@ -58,7 +63,8 @@
106 raise
107
108 # The daemon should be closed now.
109- self.assertRaises(socket.error, amqp.Connection, **connect_arguments)
110+ connection = amqp.Connection(**connect_arguments)
111+ self.assertRaises(socket.error, connection.connect)
112
113 def test_stop_hang(self):
114 # If rabbitctl hangs on shutdown, the fixture eventually manages to
115@@ -75,7 +81,7 @@
116 connect_arguments = {
117 "host": 'localhost:%s' % fixture.config.port,
118 "userid": "guest", "password": "guest",
119- "virtual_host": "/", "insist": False,
120+ "virtual_host": "/",
121 }
122
123 self.useFixture(MonkeyPatch(
124@@ -92,7 +98,8 @@
125 raise
126
127 # The daemon should be closed now.
128- self.assertRaises(socket.error, amqp.Connection, **connect_arguments)
129+ connection = amqp.Connection(**connect_arguments)
130+ self.assertRaises(socket.error, connection.connect)
131
132 def test_config(self):
133 # The configuration can be passed in.
134@@ -118,11 +125,11 @@
135 self.assertEqual("localhost", resources.hostname)
136 self.assertIsInstance(resources.port, int)
137 self.assertIsInstance(resources.dist_port, int)
138- self.assertIsInstance(resources.homedir, (str, unicode))
139- self.assertIsInstance(resources.mnesiadir, (str, unicode))
140- self.assertIsInstance(resources.logfile, (str, unicode))
141- self.assertIsInstance(resources.nodename, (str, unicode))
142- self.assertIsInstance(resources.pluginsdir, (str, unicode))
143+ self.assertIsInstance(resources.homedir, six.string_types)
144+ self.assertIsInstance(resources.mnesiadir, six.string_types)
145+ self.assertIsInstance(resources.logfile, six.string_types)
146+ self.assertIsInstance(resources.nodename, six.string_types)
147+ self.assertIsInstance(resources.pluginsdir, six.string_types)
148 self.assertEqual(resources.pluginsfile, os.devnull)
149
150 def test_passed_to_init(self):
151@@ -133,7 +140,7 @@
152 resources = RabbitServerResources(**args)
153 for i in range(2):
154 with resources:
155- for key, value in args.iteritems():
156+ for key, value in args.items():
157 self.assertEqual(value, getattr(resources, key))
158
159 def test_defaults_reallocated_after_teardown(self):
160
161=== modified file 'setup.py'
162--- setup.py 2016-09-05 15:18:29 +0000
163+++ setup.py 2018-03-12 11:54:53 +0000
164@@ -7,7 +7,7 @@
165
166
167 install_requires = [
168- 'amqplib >= 0.6.1',
169+ 'amqp >= 2.0.0',
170 'fixtures >= 0.3.6',
171 'setuptools',
172 'testtools >= 0.9.12',
173@@ -23,4 +23,9 @@
174 include_package_data=True,
175 zip_safe=False,
176 description='Magic.',
177- install_requires=install_requires)
178+ install_requires=install_requires,
179+ extras_require={
180+ 'test': [
181+ 'six',
182+ ],
183+ })

Subscribers

People subscribed via source and target branches

to all changes: