Merge "Fix tests to be Python 3 compatible"

This commit is contained in:
Jenkins 2014-06-17 22:42:47 +00:00 committed by Gerrit Code Review
commit c4674d76b0
6 changed files with 17 additions and 11 deletions

View File

@ -17,6 +17,7 @@ import os
import fixtures
from oslo.config import cfg
import six
import testtools
@ -83,7 +84,7 @@ class TestBase(testtools.TestCase):
All overrides are automatically cleared at the end of the current
test by the tearDown() method.
"""
for k, v in kw.iteritems():
for k, v in six.iteritems(kw):
self.conf.set_override(k, v, group)
def _my_dir(self):

View File

@ -162,7 +162,7 @@ class FunctionalTestBase(testing.TestBase):
expected_keys = ['age', 'created', 'href']
response_keys = message.keys()
response_keys.sort()
response_keys = sorted(response_keys)
self.assertEqual(response_keys, expected_keys)
# Verify that age has valid values

View File

@ -23,7 +23,7 @@ from marconi.tests.queues.transport.wsgi import base
import mock
from testtools import matchers
from marconi.openstack.common import jsonutils
from marconi.openstack.common import timeutils
from marconi import tests as testing
@ -108,7 +108,7 @@ class ClaimsBaseTest(base.V1_1Base):
headers=self.headers)
self.assertEqual(self.srmock.status, falcon.HTTP_201)
claimed = json.loads(body[0])
claimed = jsonutils.loads(body[0])
claim_href = self.srmock.headers_dict['Location']
message_href, params = claimed[0]['href'].split('?')
@ -156,7 +156,7 @@ class ClaimsBaseTest(base.V1_1Base):
query_string='include_claimed=true'
'&echo=true',
headers=self.headers)
listed = json.loads(body[0])
listed = jsonutils.loads(body[0])
self.assertEqual(self.srmock.status, falcon.HTTP_200)
self.assertEqual(len(listed['messages']), len(claimed))
@ -166,7 +166,7 @@ class ClaimsBaseTest(base.V1_1Base):
mock_utcnow.return_value = now
body = self.simulate_get(claim_href, headers=self.headers)
claim = json.loads(body[0])
claim = jsonutils.loads(body[0])
self.assertEqual(self.srmock.status, falcon.HTTP_200)
self.assertEqual(self.srmock.headers_dict['Content-Location'],
@ -207,7 +207,7 @@ class ClaimsBaseTest(base.V1_1Base):
# Get the claimed messages (again)
body = self.simulate_get(claim_href, headers=self.headers)
query = timeutils.utcnow()
claim = json.loads(body[0])
claim = jsonutils.loads(body[0])
message_href, params = claim['messages'][0]['href'].split('?')
self.assertEqual(claim['ttl'], 60)

View File

@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import division
import uuid
import ddt
@ -52,7 +54,7 @@ class TestMessages(base.FunctionalTestBase):
doc = '[{{"body": "{0}", "ttl": 300}}, {{"body": "{1}", "ttl": 120}}]'
overhead = len(doc.format('', ''))
half_size = (self.limits.max_message_size - overhead) / 2
half_size = (self.limits.max_message_size - overhead) // 2
doc = doc.format(helpers.generate_random_string(half_size),
helpers.generate_random_string(half_size + offset))
@ -271,7 +273,7 @@ class TestMessages(base.FunctionalTestBase):
doc = '[{{"body": "{0}", "ttl": 300}}, {{"body": "{1}", "ttl": 120}}]'
overhead = len(doc.format('', ''))
half_size = (self.limits.max_message_size - overhead) / 2
half_size = (self.limits.max_message_size - overhead) // 2
doc = doc.format(helpers.generate_random_string(half_size),
helpers.generate_random_string(half_size + 1))

View File

@ -118,7 +118,7 @@ class TestDecorators(base.TestBase):
self.assertEqual(instance.user_gets, 1)
# Should be in the cache now.
user = msgpack.unpackb(cache.get(name))
user = msgpack.unpackb(cache.get(name), encoding='utf-8')
self.assertEqual(user, name)
# Should read from the cache this time (counter will not

View File

@ -21,6 +21,7 @@ import uuid
import mock
from pymongo import cursor
import pymongo.errors
import six
from testtools import matchers
from marconi.openstack.common.cache import cache as oslo_cache
@ -174,7 +175,9 @@ class MongodbQueueTests(base.QueueControllerTest):
def test_raises_connection_error(self):
with mock.patch.object(cursor.Cursor, 'next', autospec=True) as method:
with mock.patch.object(cursor.Cursor,
'next' if six.PY2 else '__next__',
autospec=True) as method:
error = pymongo.errors.ConnectionFailure()
method.side_effect = error