Port more common unit tests to Python 3
* fakes/swift.py: replace httplib import with six.moves.http_client * replace sorted(dict.iterkeys()) with sorted(dict) * test_stream_codecs: use byte strings * test_stream_codecs: add test on non-ASCII byte string * Replace types.StringTypes with (bytes, six.text_type) * tox.ini: add test_notification, test_remote and test_stream_codecs to Python 3 Partially implements: blueprint trove-python3 Change-Id: I9498ff6a8f0a7bae2e9292eb74fc9c44a400754a
This commit is contained in:
parent
df9e3c571a
commit
fe52d5549e
4
tox.ini
4
tox.ini
|
@ -33,7 +33,11 @@ commands =
|
|||
python -bb -m testtools.run \
|
||||
trove/tests/unittests/common/test_context.py \
|
||||
trove/tests/unittests/common/test_exception.py \
|
||||
trove/tests/unittests/common/test_notification.py \
|
||||
trove/tests/unittests/common/test_remote.py \
|
||||
trove/tests/unittests/common/test_stream_codecs.py \
|
||||
trove/tests/unittests/common/test_template.py \
|
||||
trove/tests/unittests/common/test_utils.py \
|
||||
trove/tests/unittests/common/test_wsgi.py
|
||||
|
||||
[testenv:debug]
|
||||
|
|
|
@ -20,7 +20,6 @@ import inspect
|
|||
import os
|
||||
import shutil
|
||||
import time
|
||||
import types
|
||||
import uuid
|
||||
|
||||
from eventlet.timeout import Timeout
|
||||
|
@ -32,6 +31,7 @@ from oslo_utils import importutils
|
|||
from oslo_utils import strutils
|
||||
from oslo_utils import timeutils
|
||||
from passlib import utils as passlib_utils
|
||||
import six
|
||||
import six.moves.urllib.parse as urlparse
|
||||
|
||||
from trove.common import cfg
|
||||
|
@ -326,4 +326,4 @@ def is_collection(item):
|
|||
"""Return True is a given item is an iterable collection, but not a string.
|
||||
"""
|
||||
return (isinstance(item, collections.Iterable) and
|
||||
not isinstance(item, types.StringTypes))
|
||||
not isinstance(item, (bytes, six.text_type)))
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
from hashlib import md5
|
||||
from mock import MagicMock, patch
|
||||
import httplib
|
||||
import json
|
||||
import os
|
||||
import socket
|
||||
|
@ -24,6 +23,7 @@ import swiftclient.client as swift_client
|
|||
import uuid
|
||||
|
||||
from oslo_log import log as logging
|
||||
from six.moves import http_client
|
||||
from swiftclient import client as swift
|
||||
|
||||
from trove.common.i18n import _ # noqa
|
||||
|
@ -77,10 +77,10 @@ class FakeSwiftConnection(object):
|
|||
LOG.debug("fake head_container(%s)" % container)
|
||||
if container == 'missing_container':
|
||||
raise swift.ClientException('fake exception',
|
||||
http_status=httplib.NOT_FOUND)
|
||||
http_status=http_client.NOT_FOUND)
|
||||
elif container == 'unauthorized_container':
|
||||
raise swift.ClientException('fake exception',
|
||||
http_status=httplib.UNAUTHORIZED)
|
||||
http_status=http_client.UNAUTHORIZED)
|
||||
elif container == 'socket_error_on_head':
|
||||
raise socket.error(111, 'ECONNREFUSED')
|
||||
pass
|
||||
|
@ -102,7 +102,7 @@ class FakeSwiftConnection(object):
|
|||
{'container': container, 'name': name})
|
||||
checksum = md5()
|
||||
if self.manifest_prefix and self.manifest_name == name:
|
||||
for object_name in sorted(self.container_objects.iterkeys()):
|
||||
for object_name in sorted(self.container_objects):
|
||||
object_checksum = md5(self.container_objects[object_name])
|
||||
# The manifest file etag for a HEAD or GET is the checksum of
|
||||
# the concatenated checksums.
|
||||
|
|
|
@ -30,8 +30,9 @@ class TestStreamCodecs(trove_testtools.TestCase):
|
|||
|
||||
def test_serialize_deserialize_base64codec(self):
|
||||
random_data = bytearray(Random.new().read(12))
|
||||
data = ['abc',
|
||||
'numbers01234',
|
||||
data = [b'abc',
|
||||
b'numbers01234',
|
||||
b'non-ascii:\xe9\xff',
|
||||
random_data]
|
||||
|
||||
codec = stream_codecs.Base64Codec()
|
||||
|
|
Loading…
Reference in New Issue