Skip to content

Commit

Permalink
Port to Python 3
Browse files Browse the repository at this point in the history
This patch enables running all the unit tests (except the qpid ones that
are skipped) under Python 3.3 and Python 3.4.

Change-Id: I711663b4eedfb3cdeea7e6da7d28c6b92663e611
  • Loading branch information
jd committed Aug 18, 2014
1 parent 991cf14 commit 4cb33ec
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 14 deletions.
11 changes: 6 additions & 5 deletions oslo/messaging/_drivers/impl_rabbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,11 +606,11 @@ def reconnect(self, retry=None):
try:
self._connect(broker)
return
except IOError as e:
pass
except self.connection_errors as e:
pass
except Exception as e:
except IOError as ex:
e = ex
except self.connection_errors as ex:
e = ex
except Exception as ex:
# NOTE(comstud): Unfortunately it's possible for amqplib
# to return an error not covered by its transport
# connection_errors in the case of a timeout waiting for
Expand All @@ -619,6 +619,7 @@ def reconnect(self, retry=None):
# and try to reconnect in this case.
if 'timeout' not in six.text_type(e):
raise
e = ex

log_info = {}
log_info['err_str'] = e
Expand Down
3 changes: 3 additions & 0 deletions oslo/messaging/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,6 @@ def __repr__(self):
attrs.append((a, v))
values = ', '.join(['%s=%s' % i for i in attrs])
return '<Target ' + values + '>'

def __hash__(self):
return id(self)
20 changes: 20 additions & 0 deletions requirements-py3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
oslo.config>=1.2.1
stevedore>=0.14

# for timeutils
iso8601>=0.1.9

# for jsonutils
six>=1.7.0

# used by openstack/common/gettextutils.py
Babel>=1.3

# for the routing notifier
PyYAML>=3.1.0

# rabbit driver is the default
kombu>=2.4.8

# middleware
WebOb>=1.2.3
21 changes: 21 additions & 0 deletions test-requirements-py3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Hacking already pins down pep8, pyflakes and flake8
hacking>=0.9.1,<0.10

discover
fixtures>=0.3.14
mock>=1.0
mox3>=0.7.0
python-subunit>=0.0.18
testrepository>=0.0.18
testscenarios>=0.4
testtools>=0.9.34
oslotest

# when we can require tox>= 1.4, this can go into tox.ini:
# [testenv:cover]
# deps = {[testenv]deps} coverage
coverage>=3.6

# this is required for the docs build jobs
sphinx>=1.1.2,!=1.2.0,<1.3
oslosphinx
10 changes: 7 additions & 3 deletions tests/drivers/test_impl_qpid.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@

import operator
import random
import thread
import threading
import time
import unittest

import mock
import qpid
try:
import qpid
except ImportError:
raise unittest.SkipTest("qpid not available")
from six.moves import _thread
import testscenarios

from oslo import messaging
Expand Down Expand Up @@ -368,7 +372,7 @@ def consumer_callback(self, msg):
msgcontent = msg

splitmsg = msgcontent.split('-')
key = thread.get_ident()
key = _thread.get_ident()

if key not in self._messages:
self._messages[key] = dict()
Expand Down
6 changes: 5 additions & 1 deletion tests/executors/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@

import contextlib
import threading
import unittest

import eventlet
try:
import eventlet
except ImportError:
raise unittest.SkipTest("Eventlet not available")
import mock
import testscenarios

Expand Down
2 changes: 1 addition & 1 deletion tests/notify/test_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def test_load_notifiers_config(self):
return_value=self._fake_extension_manager(
mock.MagicMock())):
self.router._load_notifiers()
groups = self.router.routing_groups.keys()
groups = list(self.router.routing_groups.keys())
groups.sort()
self.assertEqual(['group_1', 'group_2'], groups)

Expand Down
4 changes: 2 additions & 2 deletions tests/rpc/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def ping(self, ctxt, arg):
client.call({}, 'ping', arg='foo')
except Exception as ex:
self.assertIsInstance(ex, ValueError)
self.assertEqual('dsfoo', ex[0])
self.assertEqual('dsfoo', str(ex))
else:
self.assertTrue(False)

Expand All @@ -308,7 +308,7 @@ def ping(self, ctxt, arg):
client.call({}, 'ping', arg='foo')
except Exception as ex:
self.assertIsInstance(ex, ValueError)
self.assertEqual('dsfoo', ex[0])
self.assertEqual('dsfoo', str(ex))
else:
self.assertTrue(False)

Expand Down
8 changes: 7 additions & 1 deletion tests/test_opts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import unittest

import pkg_resources

from oslo.messaging import opts
try:
from oslo.messaging import opts
except ImportError:
import six
if six.PY3:
raise unittest.SkipTest
from tests import utils as test_utils


Expand Down
7 changes: 6 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py26,py27,pep8
envlist = py33,py26,py27,pep8

[testenv]
setenv =
Expand All @@ -23,6 +23,10 @@ commands = {posargs}
[testenv:docs]
commands = python setup.py build_sphinx

[testenv:py33]
deps = -r{toxinidir}/requirements-py3.txt
-r{toxinidir}/test-requirements-py3.txt

[flake8]
show-source = True
ignore = H237,H402,H405,H904
Expand All @@ -32,3 +36,4 @@ builtins = _
[hacking]
import_exceptions =
oslo.messaging.openstack.common.gettextutils
six.moves

0 comments on commit 4cb33ec

Please sign in to comment.