summaryrefslogtreecommitdiff
path: root/test/unit
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/test_command_helpers.py2
-rw-r--r--test/unit/test_multithreading.py10
-rw-r--r--test/unit/test_service.py23
-rw-r--r--test/unit/test_shell.py24
-rw-r--r--test/unit/test_swiftclient.py27
-rw-r--r--test/unit/test_utils.py28
-rw-r--r--test/unit/utils.py26
7 files changed, 62 insertions, 78 deletions
diff --git a/test/unit/test_command_helpers.py b/test/unit/test_command_helpers.py
index 24684ae..1cb3bb1 100644
--- a/test/unit/test_command_helpers.py
+++ b/test/unit/test_command_helpers.py
@@ -14,7 +14,7 @@
# limitations under the License.
import mock
-from six import StringIO
+from io import StringIO
import unittest
from swiftclient import command_helpers as h
diff --git a/test/unit/test_multithreading.py b/test/unit/test_multithreading.py
index e9732cd..ee9e7cc 100644
--- a/test/unit/test_multithreading.py
+++ b/test/unit/test_multithreading.py
@@ -12,13 +12,13 @@
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+
+from queue import Queue, Empty
import sys
import unittest
import threading
-import six
from concurrent.futures import as_completed
-from six.moves.queue import Queue, Empty
from time import sleep
from swiftclient import multithreading as mt
@@ -216,11 +216,7 @@ class TestOutputManager(unittest.TestCase):
# The threads should have been cleaned up
self.assertEqual(starting_thread_count, threading.active_count())
- if six.PY3:
- over_the = "over the '\u062a\u062a'\n"
- else:
- over_the = "over the u'\\u062a\\u062a'\n"
- # We write to the CaptureStream so no decoding is performed
+ over_the = "over the '\u062a\u062a'\n"
self.assertEqual(''.join([
'one-argument\n',
'one fish, 88 fish\n',
diff --git a/test/unit/test_service.py b/test/unit/test_service.py
index 8c38bd3..9f3a2a2 100644
--- a/test/unit/test_service.py
+++ b/test/unit/test_service.py
@@ -13,20 +13,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import builtins
import contextlib
+import io
import mock
import os
-import six
import tempfile
import unittest
import time
import json
+from io import BytesIO
from concurrent.futures import Future
from hashlib import md5
from mock import Mock, PropertyMock
-from six.moves.queue import Queue, Empty as QueueEmptyError
-from six import BytesIO
+from queue import Queue, Empty as QueueEmptyError
from time import sleep
import swiftclient
@@ -46,12 +47,6 @@ for key in os.environ:
clean_os_environ[key] = ''
-if six.PY2:
- import __builtin__ as builtins
-else:
- import builtins
-
-
class TestSwiftPostObject(unittest.TestCase):
def setUp(self):
@@ -1268,7 +1263,7 @@ class TestService(unittest.TestCase):
for obj in objects:
with mock.patch('swiftclient.service.Connection') as mock_conn, \
mock.patch.object(builtins, 'open') as mock_open:
- mock_open.return_value = six.StringIO('asdf')
+ mock_open.return_value = io.StringIO('asdf')
mock_conn.return_value.head_object.side_effect = \
ClientException('Not Found', http_status=404)
mock_conn.return_value.put_object.return_value =\
@@ -2318,7 +2313,7 @@ class TestServiceDownload(_TestServiceBase):
def test_download_object_job(self):
mock_conn = self._get_mock_connection()
- objcontent = six.BytesIO(b'objcontent')
+ objcontent = io.BytesIO(b'objcontent')
mock_conn.get_object.side_effect = [
({'content-type': 'text/plain',
'etag': '2cbbfe139a744d6abbe695e17f3c1991'},
@@ -2360,7 +2355,7 @@ class TestServiceDownload(_TestServiceBase):
def test_download_object_job_with_mtime(self):
mock_conn = self._get_mock_connection()
- objcontent = six.BytesIO(b'objcontent')
+ objcontent = io.BytesIO(b'objcontent')
mock_conn.get_object.side_effect = [
({'content-type': 'text/plain',
'etag': '2cbbfe139a744d6abbe695e17f3c1991',
@@ -2406,7 +2401,7 @@ class TestServiceDownload(_TestServiceBase):
def test_download_object_job_bad_mtime(self):
mock_conn = self._get_mock_connection()
- objcontent = six.BytesIO(b'objcontent')
+ objcontent = io.BytesIO(b'objcontent')
mock_conn.get_object.side_effect = [
({'content-type': 'text/plain',
'etag': '2cbbfe139a744d6abbe695e17f3c1991',
@@ -2451,7 +2446,7 @@ class TestServiceDownload(_TestServiceBase):
def test_download_object_job_ignore_mtime(self):
mock_conn = self._get_mock_connection()
- objcontent = six.BytesIO(b'objcontent')
+ objcontent = io.BytesIO(b'objcontent')
mock_conn.get_object.side_effect = [
({'content-type': 'text/plain',
'etag': '2cbbfe139a744d6abbe695e17f3c1991',
diff --git a/test/unit/test_shell.py b/test/unit/test_shell.py
index 8d3b163..adf3776 100644
--- a/test/unit/test_shell.py
+++ b/test/unit/test_shell.py
@@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import io
import contextlib
from genericpath import getmtime
import getpass
@@ -26,8 +27,6 @@ import unittest
import textwrap
from time import localtime, mktime, strftime, strptime
-import six
-
import swiftclient
from swiftclient.service import SwiftError
import swiftclient.shell
@@ -46,10 +45,7 @@ try:
except ImportError:
InsecureRequestWarning = None
-if six.PY2:
- BUILTIN_OPEN = '__builtin__.open'
-else:
- BUILTIN_OPEN = 'builtins.open'
+BUILTIN_OPEN = 'builtins.open'
mocked_os_environ = {
'ST_AUTH': 'http://localhost:8080/auth/v1.0',
@@ -631,7 +627,7 @@ class TestShell(unittest.TestCase):
@mock.patch('swiftclient.service.makedirs')
@mock.patch('swiftclient.service.Connection')
def test_download(self, connection, makedirs):
- objcontent = six.BytesIO(b'objcontent')
+ objcontent = io.BytesIO(b'objcontent')
connection.return_value.get_object.side_effect = [
({'content-type': 'text/plain',
'etag': '2cbbfe139a744d6abbe695e17f3c1991'},
@@ -666,7 +662,7 @@ class TestShell(unittest.TestCase):
makedirs.reset_mock()
# Test downloading single object
- objcontent = six.BytesIO(b'objcontent')
+ objcontent = io.BytesIO(b'objcontent')
connection.return_value.get_object.side_effect = [
({'content-type': 'text/plain',
'etag': '2cbbfe139a744d6abbe695e17f3c1991'},
@@ -682,7 +678,7 @@ class TestShell(unittest.TestCase):
self.assertEqual([], makedirs.mock_calls)
# Test downloading without md5 checks
- objcontent = six.BytesIO(b'objcontent')
+ objcontent = io.BytesIO(b'objcontent')
connection.return_value.get_object.side_effect = [
({'content-type': 'text/plain',
'etag': '2cbbfe139a744d6abbe695e17f3c1991'},
@@ -700,7 +696,7 @@ class TestShell(unittest.TestCase):
self.assertEqual([], makedirs.mock_calls)
# Test downloading single object to stdout
- objcontent = six.BytesIO(b'objcontent')
+ objcontent = io.BytesIO(b'objcontent')
connection.return_value.get_object.side_effect = [
({'content-type': 'text/plain',
'etag': '2cbbfe139a744d6abbe695e17f3c1991'},
@@ -3246,7 +3242,7 @@ class TestAuth(MockHttpTest):
}
mock_resp = self.fake_http_connection(200, headers=headers)
with mock.patch('swiftclient.client.http_connection', new=mock_resp):
- stdout = six.StringIO()
+ stdout = io.StringIO()
with mock.patch('sys.stdout', new=stdout):
argv = [
'',
@@ -3265,7 +3261,7 @@ class TestAuth(MockHttpTest):
def test_auth_verbose(self):
with mock.patch('swiftclient.client.http_connection') as mock_conn:
- stdout = six.StringIO()
+ stdout = io.StringIO()
with mock.patch('sys.stdout', new=stdout):
argv = [
'',
@@ -3289,7 +3285,7 @@ class TestAuth(MockHttpTest):
os_options = {'tenant_name': 'demo'}
with mock.patch('swiftclient.client.get_auth_keystone',
new=fake_get_auth_keystone(os_options)):
- stdout = six.StringIO()
+ stdout = io.StringIO()
with mock.patch('sys.stdout', new=stdout):
argv = [
'',
@@ -3310,7 +3306,7 @@ class TestAuth(MockHttpTest):
def test_auth_verbose_v2(self):
with mock.patch('swiftclient.client.get_auth_keystone') \
as mock_keystone:
- stdout = six.StringIO()
+ stdout = io.StringIO()
with mock.patch('sys.stdout', new=stdout):
argv = [
'',
diff --git a/test/unit/test_swiftclient.py b/test/unit/test_swiftclient.py
index 6bdd6ad..55c18fa 100644
--- a/test/unit/test_swiftclient.py
+++ b/test/unit/test_swiftclient.py
@@ -17,15 +17,14 @@ import gzip
import json
import logging
import mock
-import six
+import io
import socket
import string
import unittest
import warnings
import tempfile
from hashlib import md5
-from six import binary_type
-from six.moves.urllib.parse import urlparse
+from urllib.parse import urlparse
from requests.exceptions import RequestException
from .utils import (MockHttpTest, fake_get_auth_keystone, StubResponse,
@@ -214,12 +213,12 @@ class TestHttpHelpers(MockHttpTest):
self.assertEqual(len(headers), len(r))
# ensure non meta headers are not encoded
- self.assertIs(type(r.get('abc')), binary_type)
+ self.assertIs(type(r.get('abc')), bytes)
del r['abc']
for k, v in r.items():
- self.assertIs(type(k), binary_type)
- self.assertIs(type(v), binary_type)
+ self.assertIs(type(k), bytes)
+ self.assertIs(type(v), bytes)
self.assertIn(v, (b'123', b'12.3', b'True'))
def test_set_user_agent_default(self):
@@ -1329,7 +1328,7 @@ class TestPutObject(MockHttpTest):
c.http_connection = self.fake_http_connection(200)
args = ('http://www.test.com', 'TOKEN', 'container', 'obj', 'body', 4)
value = c.put_object(*args)
- self.assertIsInstance(value, six.string_types)
+ self.assertIsInstance(value, str)
self.assertEqual(value, EMPTY_ETAG)
self.assertRequests([
('PUT', '/container/obj', 'body', {
@@ -1340,7 +1339,7 @@ class TestPutObject(MockHttpTest):
def test_unicode_ok(self):
conn = c.http_connection(u'http://www.test.com/')
- mock_file = six.StringIO(u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91')
+ mock_file = io.StringIO(u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91')
args = (u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91',
u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91',
u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91',
@@ -1354,7 +1353,7 @@ class TestPutObject(MockHttpTest):
conn[1].getresponse = resp.fake_response
conn[1]._request = resp._fake_request
value = c.put_object(*args, headers=headers, http_conn=conn)
- self.assertIsInstance(value, six.string_types)
+ self.assertIsInstance(value, str)
# Test for RFC-2616 encoded symbols
self.assertIn(("a-b", b".x:yz mn:fg:lp"),
resp.buffer)
@@ -1364,7 +1363,7 @@ class TestPutObject(MockHttpTest):
def test_chunk_warning(self):
conn = c.http_connection('http://www.test.com/')
- mock_file = six.StringIO('asdf')
+ mock_file = io.StringIO('asdf')
args = ('asdf', 'asdf', 'asdf', 'asdf', mock_file)
resp = MockHttpResponse()
conn[1].getresponse = resp.fake_response
@@ -1960,7 +1959,7 @@ class TestHTTPConnection(MockHttpTest):
self.assertFalse(resp.read())
self.assertTrue(resp.closed)
- def test_response_python3_headers(self):
+ def test_response_headers(self):
'''Test latin1-encoded headers.
'''
_, conn = c.http_connection(u'http://www.test.com/')
@@ -2547,7 +2546,7 @@ class TestConnection(MockHttpTest):
class LocalContents(object):
def __init__(self, tell_value=0):
- self.data = six.BytesIO(string.ascii_letters.encode() * 10)
+ self.data = io.BytesIO(string.ascii_letters.encode() * 10)
self.data.seek(tell_value)
self.reads = []
self.seeks = []
@@ -2845,7 +2844,7 @@ class TestLogging(MockHttpTest):
c.http_connection = self.fake_http_connection(200)
args = ('http://www.test.com', 'asdf', 'asdf', 'asdf', 'asdf')
value = c.put_object(*args)
- self.assertIsInstance(value, six.string_types)
+ self.assertIsInstance(value, str)
def test_head_error(self):
c.http_connection = self.fake_http_connection(500)
@@ -2859,7 +2858,7 @@ class TestLogging(MockHttpTest):
self.assertEqual(exc_context.exception.http_status, 404)
def test_content_encoding_gzip_body_is_logged_decoded(self):
- buf = six.BytesIO()
+ buf = io.BytesIO()
gz = gzip.GzipFile(fileobj=buf, mode='w')
data = {"test": u"\u2603"}
decoded_body = json.dumps(data).encode('utf-8')
diff --git a/test/unit/test_utils.py b/test/unit/test_utils.py
index cbee82b..02d19f3 100644
--- a/test/unit/test_utils.py
+++ b/test/unit/test_utils.py
@@ -14,10 +14,10 @@
# limitations under the License.
import gzip
+import io
import json
import unittest
import mock
-import six
import tempfile
from time import gmtime, localtime, mktime, strftime, strptime
from hashlib import md5, sha1
@@ -142,7 +142,7 @@ class TestTempURL(unittest.TestCase):
url = u.generate_temp_url(self.url, self.seconds,
self.key, self.method)
key = self.key
- if not isinstance(key, six.binary_type):
+ if not isinstance(key, bytes):
key = key.encode('utf-8')
self.assertEqual(url, self.expected_url)
self.assertEqual(hmac_mock.mock_calls, [
@@ -170,10 +170,10 @@ class TestTempURL(unittest.TestCase):
self.key, self.method,
ip_range=ip_range)
key = self.key
- if not isinstance(key, six.binary_type):
+ if not isinstance(key, bytes):
key = key.encode('utf-8')
- if isinstance(ip_range, six.binary_type):
+ if isinstance(ip_range, bytes):
ip_range_expected_url = (
expected_url + ip_range.decode('utf-8')
)
@@ -215,7 +215,7 @@ class TestTempURL(unittest.TestCase):
lt = localtime()
expires = strftime(u.EXPIRES_ISO8601_FORMAT[:-1], lt)
- if not isinstance(self.expected_url, six.string_types):
+ if not isinstance(self.expected_url, str):
expected_url = self.expected_url.replace(
b'1400003600', bytes(str(int(mktime(lt))), encoding='ascii'))
else:
@@ -228,7 +228,7 @@ class TestTempURL(unittest.TestCase):
expires = strftime(u.SHORT_EXPIRES_ISO8601_FORMAT, lt)
lt = strptime(expires, u.SHORT_EXPIRES_ISO8601_FORMAT)
- if not isinstance(self.expected_url, six.string_types):
+ if not isinstance(self.expected_url, str):
expected_url = self.expected_url.replace(
b'1400003600', bytes(str(int(mktime(lt))), encoding='ascii'))
else:
@@ -246,11 +246,11 @@ class TestTempURL(unittest.TestCase):
self.key, self.method,
iso8601=True)
key = self.key
- if not isinstance(key, six.binary_type):
+ if not isinstance(key, bytes):
key = key.encode('utf-8')
expires = strftime(u.EXPIRES_ISO8601_FORMAT, gmtime(1400003600))
- if not isinstance(self.url, six.string_types):
+ if not isinstance(self.url, str):
self.assertTrue(url.endswith(bytes(expires, 'utf-8')))
else:
self.assertTrue(url.endswith(expires))
@@ -280,7 +280,7 @@ class TestTempURL(unittest.TestCase):
url = u.generate_temp_url(path, self.seconds,
self.key, self.method, prefix=True)
key = self.key
- if not isinstance(key, six.binary_type):
+ if not isinstance(key, bytes):
key = key.encode('utf-8')
self.assertEqual(url, expected_url)
self.assertEqual(hmac_mock.mock_calls, [
@@ -299,7 +299,7 @@ class TestTempURL(unittest.TestCase):
@mock.patch('hmac.HMAC.hexdigest', return_value="temp_url_signature")
def test_generate_absolute_expiry_temp_url(self, hmac_mock):
- if isinstance(self.expected_url, six.binary_type):
+ if isinstance(self.expected_url, bytes):
expected_url = self.expected_url.replace(
b'1400003600', b'2146636800')
else:
@@ -486,7 +486,7 @@ class TestReadableToIterable(unittest.TestCase):
class TestLengthWrapper(unittest.TestCase):
def test_stringio(self):
- contents = six.StringIO(u'a' * 50 + u'b' * 50)
+ contents = io.StringIO(u'a' * 50 + u'b' * 50)
contents.seek(22)
data = u.LengthWrapper(contents, 42, True)
s = u'a' * 28 + u'b' * 14
@@ -506,7 +506,7 @@ class TestLengthWrapper(unittest.TestCase):
self.assertEqual(md5(s.encode()).hexdigest(), data.get_md5sum())
def test_bytesio(self):
- contents = six.BytesIO(b'a' * 50 + b'b' * 50)
+ contents = io.BytesIO(b'a' * 50 + b'b' * 50)
contents.seek(22)
data = u.LengthWrapper(contents, 42, True)
s = b'a' * 28 + b'b' * 14
@@ -613,7 +613,7 @@ class TestApiResponeParser(unittest.TestCase):
self.assertEqual({u't\xe9st': u'\xff'}, result)
def test_gzipped_utf8(self):
- buf = six.BytesIO()
+ buf = io.BytesIO()
gz = gzip.GzipFile(fileobj=buf, mode='w')
gz.write(u'{"test": "\u2603"}'.encode('utf8'))
gz.close()
@@ -631,7 +631,7 @@ class TestGetBody(unittest.TestCase):
self.assertEqual({'test': u'\u2603'}, result)
def test_gzipped_body(self):
- buf = six.BytesIO()
+ buf = io.BytesIO()
gz = gzip.GzipFile(fileobj=buf, mode='w')
gz.write(u'{"test": "\u2603"}'.encode('utf8'))
gz.close()
diff --git a/test/unit/utils.py b/test/unit/utils.py
index 3190e9d..0dc0b3c 100644
--- a/test/unit/utils.py
+++ b/test/unit/utils.py
@@ -12,17 +12,19 @@
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+
import functools
+import io
+import importlib
+import os
import sys
-from requests import RequestException
-from requests.structures import CaseInsensitiveDict
from time import sleep
import unittest
+
+from requests import RequestException
+from requests.structures import CaseInsensitiveDict
import mock
-import six
-import os
-from six.moves import reload_module
-from six.moves.urllib.parse import urlparse, ParseResult
+from urllib.parse import urlparse, ParseResult
from swiftclient import client as c
from swiftclient import shell as s
from swiftclient.utils import EMPTY_ETAG
@@ -406,7 +408,7 @@ class MockHttpTest(unittest.TestCase):
# un-hygienic mocking on the swiftclient.client module; which may lead
# to some unfortunate test order dependency bugs by way of the broken
# window theory if any other modules are similarly patched
- reload_module(c)
+ importlib.reload(c)
class CaptureStreamPrinter(object):
@@ -421,24 +423,20 @@ class CaptureStreamPrinter(object):
# No encoding, just convert the raw bytes into a str for testing
# The below call also validates that we have a byte string.
self._captured_stream.write(
- data if isinstance(data, six.binary_type) else data.encode('utf8'))
+ data if isinstance(data, bytes) else data.encode('utf8'))
class CaptureStream(object):
def __init__(self, stream):
self.stream = stream
- self._buffer = six.BytesIO()
+ self._buffer = io.BytesIO()
self._capture = CaptureStreamPrinter(self._buffer)
self.streams = [self._capture]
@property
def buffer(self):
- if six.PY3:
- return self._buffer
- else:
- raise AttributeError(
- 'Output stream has no attribute "buffer" in Python2')
+ return self._buffer
def flush(self):
pass