Port to Python 3

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
This commit is contained in:
Julien Danjou 2014-07-18 15:32:56 +02:00
parent 991cf14726
commit 4cb33ecc94
10 changed files with 78 additions and 14 deletions

View File

@ -606,11 +606,11 @@ class Connection(object):
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
@ -619,6 +619,7 @@ class Connection(object):
# 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

View File

@ -89,3 +89,6 @@ class Target(object):
attrs.append((a, v))
values = ', '.join(['%s=%s' % i for i in attrs])
return '<Target ' + values + '>'
def __hash__(self):
return id(self)

20
requirements-py3.txt Normal file
View File

@ -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
test-requirements-py3.txt Normal file
View File

@ -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

View File

@ -14,12 +14,16 @@
import operator
import random
import thread
import threading
import time
import unittest
import mock
try:
import qpid
except ImportError:
raise unittest.SkipTest("qpid not available")
from six.moves import _thread
import testscenarios
from oslo import messaging
@ -368,7 +372,7 @@ class TestQpidTopicAndFanout(_QpidBaseTestCase):
msgcontent = msg
splitmsg = msgcontent.split('-')
key = thread.get_ident()
key = _thread.get_ident()
if key not in self._messages:
self._messages[key] = dict()

View File

@ -16,8 +16,12 @@
import contextlib
import threading
import unittest
try:
import eventlet
except ImportError:
raise unittest.SkipTest("Eventlet not available")
import mock
import testscenarios

View File

@ -382,7 +382,7 @@ group_2:
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)

View File

@ -287,7 +287,7 @@ class TestRPCServer(test_utils.BaseTestCase, ServerSetupMixin):
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)
@ -308,7 +308,7 @@ class TestRPCServer(test_utils.BaseTestCase, ServerSetupMixin):
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)

View File

@ -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
try:
from oslo.messaging import opts
except ImportError:
import six
if six.PY3:
raise unittest.SkipTest
from tests import utils as test_utils

View File

@ -1,5 +1,5 @@
[tox]
envlist = py26,py27,pep8
envlist = py33,py26,py27,pep8
[testenv]
setenv =
@ -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
@ -32,3 +36,4 @@ builtins = _
[hacking]
import_exceptions =
oslo.messaging.openstack.common.gettextutils
six.moves