summaryrefslogtreecommitdiff
path: root/oslo_utils/tests
diff options
context:
space:
mode:
Diffstat (limited to 'oslo_utils/tests')
-rw-r--r--oslo_utils/tests/test_eventletutils.py14
-rw-r--r--oslo_utils/tests/test_fileutils.py5
-rw-r--r--oslo_utils/tests/test_fixture.py3
-rw-r--r--oslo_utils/tests/test_fnmatch.py11
-rw-r--r--oslo_utils/tests/test_netutils.py20
-rw-r--r--oslo_utils/tests/test_reflection.py25
-rw-r--r--oslo_utils/tests/test_strutils.py36
-rw-r--r--oslo_utils/tests/tests_encodeutils.py127
8 files changed, 59 insertions, 182 deletions
diff --git a/oslo_utils/tests/test_eventletutils.py b/oslo_utils/tests/test_eventletutils.py
index 62b72af..ebbdbb0 100644
--- a/oslo_utils/tests/test_eventletutils.py
+++ b/oslo_utils/tests/test_eventletutils.py
@@ -19,7 +19,6 @@ import warnings
import eventlet
from eventlet import greenthread
from oslotest import base as test_base
-import six
from oslo_utils import eventletutils
@@ -44,7 +43,7 @@ class EventletUtilsTest(test_base.BaseTestCase):
self.assertEqual(1, len(capture))
w = capture[0]
self.assertEqual(RuntimeWarning, w.category)
- self.assertIn('os', six.text_type(w.message))
+ self.assertIn('os', str(w.message))
@mock.patch("oslo_utils.eventletutils._patcher")
def test_warning_not_patched_none_provided(self, mock_patcher):
@@ -57,7 +56,7 @@ class EventletUtilsTest(test_base.BaseTestCase):
w = capture[0]
self.assertEqual(RuntimeWarning, w.category)
for m in eventletutils._ALL_PATCH:
- self.assertIn(m, six.text_type(w.message))
+ self.assertIn(m, str(w.message))
@mock.patch("oslo_utils.eventletutils._patcher")
def test_warning_not_patched_all(self, mock_patcher):
@@ -70,7 +69,7 @@ class EventletUtilsTest(test_base.BaseTestCase):
w = capture[0]
self.assertEqual(RuntimeWarning, w.category)
for m in eventletutils._ALL_PATCH:
- self.assertIn(m, six.text_type(w.message))
+ self.assertIn(m, str(w.message))
@mock.patch("oslo_utils.eventletutils._patcher")
def test_no_warning(self, mock_patcher):
@@ -118,7 +117,7 @@ class EventletUtilsTest(test_base.BaseTestCase):
w = capture[0]
self.assertEqual(RuntimeWarning, w.category)
for m in ['os', 'thread']:
- self.assertNotIn(m, six.text_type(w.message))
+ self.assertNotIn(m, str(w.message))
def test_invalid_patch_check(self):
self.assertRaises(ValueError,
@@ -133,10 +132,7 @@ class EventletUtilsTest(test_base.BaseTestCase):
self.assertIsInstance(e_event, eventletutils.EventletEvent)
t_event = eventletutils.Event()
- if six.PY3:
- t_event_cls = threading.Event
- else:
- t_event_cls = threading._Event
+ t_event_cls = threading.Event
self.assertIsInstance(t_event, t_event_cls)
public_methods = [m for m in dir(t_event) if not m.startswith("_") and
diff --git a/oslo_utils/tests/test_fileutils.py b/oslo_utils/tests/test_fileutils.py
index f70b2f4..e45d1e9 100644
--- a/oslo_utils/tests/test_fileutils.py
+++ b/oslo_utils/tests/test_fileutils.py
@@ -26,7 +26,6 @@ import uuid
import yaml
from oslotest import base as test_base
-import six
from oslo_utils import fileutils
@@ -131,7 +130,7 @@ class WriteToTempfileTestCase(test_base.BaseTestCase):
def check_file_content(self, path):
with open(path, 'r') as fd:
ans = fd.read()
- self.assertEqual(self.content, six.b(ans))
+ self.assertEqual(self.content, ans.encode("latin-1"))
def test_file_without_path_and_suffix(self):
res = fileutils.write_to_tempfile(self.content)
@@ -204,7 +203,7 @@ class TestComputeFileChecksum(test_base.BaseTestCase):
def check_file_content(self, content, path):
with open(path, 'r') as fd:
ans = fd.read()
- self.assertEqual(content, six.b(ans))
+ self.assertEqual(content, ans.encode("latin-1"))
def test_compute_checksum_default_algorithm(self):
path = fileutils.write_to_tempfile(self.content)
diff --git a/oslo_utils/tests/test_fixture.py b/oslo_utils/tests/test_fixture.py
index 5775136..b106f15 100644
--- a/oslo_utils/tests/test_fixture.py
+++ b/oslo_utils/tests/test_fixture.py
@@ -17,7 +17,6 @@
import datetime
from oslotest import base as test_base
-import six
from oslo_utils import fixture
from oslo_utils.fixture import uuidsentinel as uuids
@@ -81,4 +80,4 @@ class UUIDSentinelsTest(test_base.BaseTestCase):
def test_with_underline_prefix(self):
ex = self.assertRaises(AttributeError, getattr, uuids, '_foo')
- self.assertIn("Sentinels must not start with _", six.text_type(ex))
+ self.assertIn("Sentinels must not start with _", str(ex))
diff --git a/oslo_utils/tests/test_fnmatch.py b/oslo_utils/tests/test_fnmatch.py
index 78e11e6..ec9583d 100644
--- a/oslo_utils/tests/test_fnmatch.py
+++ b/oslo_utils/tests/test_fnmatch.py
@@ -13,11 +13,9 @@
import fnmatch as standard_fnmatch
import ntpath
import posixpath
-import sys
from unittest import mock
from oslotest import base
-import six
fnmatch = None
@@ -48,12 +46,3 @@ class TestFnmatch(base.BaseTestCase):
fnmatch = standard_fnmatch
self._test_fnmatch_posix_nt()
-
- with mock.patch.object(sys, 'version_info', new=(2, 7, 11)):
- from oslo_utils import fnmatch as oslo_fnmatch
- fnmatch = oslo_fnmatch
- self._test_fnmatch_posix_nt()
-
- with mock.patch.object(sys, 'version_info', new=(2, 7, 0)):
- six.moves.reload_module(oslo_fnmatch)
- self._test_fnmatch_posix_nt()
diff --git a/oslo_utils/tests/test_netutils.py b/oslo_utils/tests/test_netutils.py
index 260e1b1..28bb1d9 100644
--- a/oslo_utils/tests/test_netutils.py
+++ b/oslo_utils/tests/test_netutils.py
@@ -14,13 +14,13 @@
# under the License.
import contextlib
+import io
import socket
from unittest import mock
import netaddr
import netifaces
from oslotest import base as test_base
-import six
from oslo_utils import netutils
@@ -393,7 +393,7 @@ class MACbyIPv6TestCase(test_base.BaseTestCase):
@contextlib.contextmanager
def mock_file_content(content):
# Allows StringIO to act like a context manager-enabled file.
- yield six.StringIO(content)
+ yield io.StringIO(content)
class TestIsIPv6Enabled(test_base.BaseTestCase):
@@ -407,19 +407,19 @@ class TestIsIPv6Enabled(test_base.BaseTestCase):
self.addCleanup(reset_detection_flag)
@mock.patch('os.path.exists', return_value=True)
- @mock.patch('six.moves.builtins.open', return_value=mock_file_content('0'))
+ @mock.patch('builtins.open', return_value=mock_file_content('0'))
def test_enabled(self, mock_open, exists):
enabled = netutils.is_ipv6_enabled()
self.assertTrue(enabled)
@mock.patch('os.path.exists', return_value=True)
- @mock.patch('six.moves.builtins.open', return_value=mock_file_content('1'))
+ @mock.patch('builtins.open', return_value=mock_file_content('1'))
def test_disabled(self, mock_open, exists):
enabled = netutils.is_ipv6_enabled()
self.assertFalse(enabled)
@mock.patch('os.path.exists', return_value=False)
- @mock.patch('six.moves.builtins.open',
+ @mock.patch('builtins.open',
side_effect=AssertionError('should not read'))
def test_disabled_non_exists(self, mock_open, exists):
enabled = netutils.is_ipv6_enabled()
@@ -429,14 +429,14 @@ class TestIsIPv6Enabled(test_base.BaseTestCase):
def test_memoize_enabled(self, exists):
# Reset the flag to appear that we haven't looked for it yet.
netutils._IS_IPV6_ENABLED = None
- with mock.patch('six.moves.builtins.open',
+ with mock.patch('builtins.open',
return_value=mock_file_content('0')) as mock_open:
enabled = netutils.is_ipv6_enabled()
self.assertTrue(mock_open.called)
self.assertTrue(netutils._IS_IPV6_ENABLED)
self.assertTrue(enabled)
# The second call should not use open again
- with mock.patch('six.moves.builtins.open',
+ with mock.patch('builtins.open',
side_effect=AssertionError('should not be called')):
enabled = netutils.is_ipv6_enabled()
self.assertTrue(enabled)
@@ -445,18 +445,18 @@ class TestIsIPv6Enabled(test_base.BaseTestCase):
def test_memoize_disabled(self, exists):
# Reset the flag to appear that we haven't looked for it yet.
netutils._IS_IPV6_ENABLED = None
- with mock.patch('six.moves.builtins.open',
+ with mock.patch('builtins.open',
return_value=mock_file_content('1')):
enabled = netutils.is_ipv6_enabled()
self.assertFalse(enabled)
# The second call should not use open again
- with mock.patch('six.moves.builtins.open',
+ with mock.patch('builtins.open',
side_effect=AssertionError('should not be called')):
enabled = netutils.is_ipv6_enabled()
self.assertFalse(enabled)
@mock.patch('os.path.exists', return_value=False)
- @mock.patch('six.moves.builtins.open',
+ @mock.patch('builtins.open',
side_effect=AssertionError('should not read'))
def test_memoize_not_exists(self, mock_open, exists):
# Reset the flag to appear that we haven't looked for it yet.
diff --git a/oslo_utils/tests/test_reflection.py b/oslo_utils/tests/test_reflection.py
index 8ca49e9..f104a87 100644
--- a/oslo_utils/tests/test_reflection.py
+++ b/oslo_utils/tests/test_reflection.py
@@ -14,26 +14,21 @@
# License for the specific language governing permissions and limitations
# under the License.
+import functools
import sys
from oslotest import base as test_base
-import six
-import testtools
from oslo_utils import reflection
-if six.PY3:
- RUNTIME_ERROR_CLASSES = ['RuntimeError', 'Exception',
- 'BaseException', 'object']
-else:
- RUNTIME_ERROR_CLASSES = ['RuntimeError', 'StandardError', 'Exception',
- 'BaseException', 'object']
+RUNTIME_ERROR_CLASSES = ['RuntimeError', 'Exception',
+ 'BaseException', 'object']
def dummy_decorator(f):
- @six.wraps(f)
+ @functools.wraps(f)
def wrapper(*args, **kwargs):
return f(*args, **kwargs)
@@ -192,13 +187,8 @@ class GetCallableNameTest(test_base.BaseTestCase):
def test_static_method(self):
name = reflection.get_callable_name(Class.static_method)
- if six.PY3:
- self.assertEqual('.'.join((__name__, 'Class', 'static_method')),
- name)
- else:
- # NOTE(imelnikov): static method are just functions, class name
- # is not recorded anywhere in them.
- self.assertEqual('.'.join((__name__, 'static_method')), name)
+ self.assertEqual('.'.join((__name__, 'Class', 'static_method')),
+ name)
def test_class_method(self):
name = reflection.get_callable_name(Class.class_method)
@@ -218,9 +208,6 @@ class GetCallableNameTest(test_base.BaseTestCase):
'__call__')), name)
-# These extended/special case tests only work on python 3, due to python 2
-# being broken/incorrect with regard to these special cases...
-@testtools.skipIf(not six.PY3, 'python 3.x is not currently available')
class GetCallableNameTestExtended(test_base.BaseTestCase):
# Tests items in http://legacy.python.org/dev/peps/pep-3155/
diff --git a/oslo_utils/tests/test_strutils.py b/oslo_utils/tests/test_strutils.py
index f43cef2..0ee35b8 100644
--- a/oslo_utils/tests/test_strutils.py
+++ b/oslo_utils/tests/test_strutils.py
@@ -22,7 +22,6 @@ from unittest import mock
import ddt
from oslotest import base as test_base
-import six
import testscenarios
from oslo_utils import strutils
@@ -33,12 +32,6 @@ load_tests = testscenarios.load_tests_apply_scenarios
class StrUtilsTest(test_base.BaseTestCase):
- @mock.patch("six.text_type")
- def test_bool_bool_from_string_no_text(self, mock_text):
- self.assertTrue(strutils.bool_from_string(True))
- self.assertFalse(strutils.bool_from_string(False))
- self.assertEqual(0, mock_text.call_count)
-
def test_bool_bool_from_string(self):
self.assertTrue(strutils.bool_from_string(True))
self.assertFalse(strutils.bool_from_string(False))
@@ -85,7 +78,7 @@ class StrUtilsTest(test_base.BaseTestCase):
self._test_bool_from_string(lambda s: s)
def test_unicode_bool_from_string(self):
- self._test_bool_from_string(six.text_type)
+ self._test_bool_from_string(str)
self.assertFalse(strutils.bool_from_string(u'使用', strict=False))
exc = self.assertRaises(ValueError, strutils.bool_from_string,
@@ -93,7 +86,7 @@ class StrUtilsTest(test_base.BaseTestCase):
expected_msg = (u"Unrecognized value '使用', acceptable values are:"
u" '0', '1', 'f', 'false', 'n', 'no', 'off', 'on',"
u" 't', 'true', 'y', 'yes'")
- self.assertEqual(expected_msg, six.text_type(exc))
+ self.assertEqual(expected_msg, str(exc))
def test_other_bool_from_string(self):
self.assertFalse(strutils.bool_from_string(None))
@@ -170,16 +163,17 @@ class StrUtilsTest(test_base.BaseTestCase):
def test_slugify(self):
to_slug = strutils.to_slug
self.assertRaises(TypeError, to_slug, True)
- self.assertEqual(six.u("hello"), to_slug("hello"))
- self.assertEqual(six.u("two-words"), to_slug("Two Words"))
- self.assertEqual(six.u("ma-any-spa-ce-es"),
+ self.assertEqual("hello", to_slug("hello"))
+ self.assertEqual("two-words", to_slug("Two Words"))
+ self.assertEqual("ma-any-spa-ce-es",
to_slug("Ma-any\t spa--ce- es"))
- self.assertEqual(six.u("excamation"), to_slug("exc!amation!"))
- self.assertEqual(six.u("ampserand"), to_slug("&ampser$and"))
- self.assertEqual(six.u("ju5tnum8er"), to_slug("ju5tnum8er"))
- self.assertEqual(six.u("strip-"), to_slug(" strip - "))
- self.assertEqual(six.u("perche"), to_slug(six.b("perch\xc3\xa9")))
- self.assertEqual(six.u("strange"),
+ self.assertEqual("excamation", to_slug("exc!amation!"))
+ self.assertEqual("ampserand", to_slug("&ampser$and"))
+ self.assertEqual("ju5tnum8er", to_slug("ju5tnum8er"))
+ self.assertEqual("strip-", to_slug(" strip - "))
+ self.assertEqual("perche",
+ to_slug("perch\xc3\xa9".encode("latin-1")))
+ self.assertEqual("strange",
to_slug("\x80strange", errors="ignore"))
@@ -619,12 +613,12 @@ class MaskPasswordTestCase(test_base.BaseTestCase):
self.assertEqual(expected, strutils.mask_password(payload))
payload = """{'adminPass':'TL0EfN33'}"""
- payload = six.text_type(payload)
+ payload = str(payload)
expected = """{'adminPass':'***'}"""
self.assertEqual(expected, strutils.mask_password(payload))
payload = """{'token':'mytoken'}"""
- payload = six.text_type(payload)
+ payload = str(payload)
expected = """{'token':'***'}"""
self.assertEqual(expected, strutils.mask_password(payload))
@@ -950,7 +944,7 @@ class ValidateIntegerTestCase(test_base.BaseTestCase):
"min_value": 300, "max_value": 300},
{"value": 55, "name": "doing 55 in a 54",
"max_value": 54},
- {"value": six.unichr(129), "name": "UnicodeError",
+ {"value": chr(129), "name": "UnicodeError",
"max_value": 1000})
def test_invalid_inputs(self, value, name, **kwargs):
self.assertRaises(ValueError, strutils.validate_integer,
diff --git a/oslo_utils/tests/tests_encodeutils.py b/oslo_utils/tests/tests_encodeutils.py
index 546e8ea..b2f914f 100644
--- a/oslo_utils/tests/tests_encodeutils.py
+++ b/oslo_utils/tests/tests_encodeutils.py
@@ -19,8 +19,6 @@ from unittest import mock
from oslo_i18n import fixture as oslo_i18n_fixture
from oslotest import base as test_base
-import six
-import testtools
from oslo_utils import encodeutils
@@ -30,25 +28,23 @@ class EncodeUtilsTest(test_base.BaseTestCase):
def test_safe_decode(self):
safe_decode = encodeutils.safe_decode
self.assertRaises(TypeError, safe_decode, True)
- self.assertEqual(six.u('ni\xf1o'), safe_decode(six.b("ni\xc3\xb1o"),
- incoming="utf-8"))
- if six.PY2:
- # In Python 3, bytes.decode() doesn't support anymore
- # bytes => bytes encodings like base64
- self.assertEqual(six.u("test"), safe_decode("dGVzdA==",
- incoming='base64'))
-
- self.assertEqual(six.u("strange"), safe_decode(six.b('\x80strange'),
- errors='ignore'))
-
- self.assertEqual(six.u('\xc0'), safe_decode(six.b('\xc0'),
+ self.assertEqual('ni\xf1o',
+ safe_decode("ni\xc3\xb1o".encode("latin-1"),
+ incoming="utf-8"))
+
+ self.assertEqual("strange",
+ safe_decode('\x80strange'.encode("latin-1"),
+ errors='ignore'))
+
+ self.assertEqual('\xc0', safe_decode('\xc0'.encode("latin-1"),
incoming='iso-8859-1'))
# Forcing incoming to ascii so it falls back to utf-8
- self.assertEqual(six.u('ni\xf1o'), safe_decode(six.b('ni\xc3\xb1o'),
- incoming='ascii'))
+ self.assertEqual('ni\xf1o',
+ safe_decode('ni\xc3\xb1o'.encode("latin-1"),
+ incoming='ascii'))
- self.assertEqual(six.u('foo'), safe_decode(b'foo'))
+ self.assertEqual('foo', safe_decode(b'foo'))
def test_safe_encode_none_instead_of_text(self):
self.assertRaises(TypeError, encodeutils.safe_encode, None)
@@ -68,28 +64,18 @@ class EncodeUtilsTest(test_base.BaseTestCase):
def test_safe_encode_tuple_instead_of_text(self):
self.assertRaises(TypeError, encodeutils.safe_encode, ('foo', 'bar', ))
- def test_safe_encode_py2(self):
- if six.PY2:
- # In Python 3, str.encode() doesn't support anymore
- # text => text encodings like base64
- self.assertEqual(
- six.b("dGVzdA==\n"),
- encodeutils.safe_encode("test", encoding='base64'),
- )
- else:
- self.skipTest("Requires py2.x")
-
def test_safe_encode_force_incoming_utf8_to_ascii(self):
# Forcing incoming to ascii so it falls back to utf-8
self.assertEqual(
- six.b('ni\xc3\xb1o'),
- encodeutils.safe_encode(six.b('ni\xc3\xb1o'), incoming='ascii'),
+ 'ni\xc3\xb1o'.encode("latin-1"),
+ encodeutils.safe_encode('ni\xc3\xb1o'.encode("latin-1"),
+ incoming='ascii'),
)
def test_safe_encode_same_encoding_different_cases(self):
with mock.patch.object(encodeutils, 'safe_decode', mock.Mock()):
utf8 = encodeutils.safe_encode(
- six.u('foo\xf1bar'), encoding='utf-8')
+ 'foo\xf1bar', encoding='utf-8')
self.assertEqual(
encodeutils.safe_encode(utf8, 'UTF-8', 'utf-8'),
encodeutils.safe_encode(utf8, 'utf-8', 'UTF-8'),
@@ -101,11 +87,11 @@ class EncodeUtilsTest(test_base.BaseTestCase):
encodeutils.safe_decode.assert_has_calls([])
def test_safe_encode_different_encodings(self):
- text = six.u('foo\xc3\xb1bar')
+ text = 'foo\xc3\xb1bar'
result = encodeutils.safe_encode(
text=text, incoming='utf-8', encoding='iso-8859-1')
self.assertNotEqual(text, result)
- self.assertNotEqual(six.b("foo\xf1bar"), result)
+ self.assertNotEqual("foo\xf1bar".encode("latin-1"), result)
def test_to_utf8(self):
self.assertEqual(encodeutils.to_utf8(b'a\xe9\xff'), # bytes
@@ -115,7 +101,7 @@ class EncodeUtilsTest(test_base.BaseTestCase):
self.assertRaises(TypeError, encodeutils.to_utf8, 123) # invalid
# oslo.i18n Message objects should also be accepted for convenience.
- # It works because Message is a subclass of six.text_type. Use the
+ # It works because Message is a subclass of str. Use the
# lazy translation to get a Message instance of oslo_i18n.
msg = oslo_i18n_fixture.Translation().lazy("test")
self.assertEqual(encodeutils.to_utf8(msg),
@@ -177,79 +163,6 @@ class ExceptionToUnicodeTest(test_base.BaseTestCase):
self.assertEqual(encodeutils.exception_to_unicode(exc),
u'\u0420\u0443\u0441\u0441\u043a\u0438\u0439')
- @testtools.skipIf(six.PY3, 'test specific to Python 2')
- def test_unicode_exception(self):
- # Exception with a __unicode__() method, but no __str__()
- class UnicodeException(Exception):
- def __init__(self, value):
- Exception.__init__(self)
- self.value = value
-
- def __unicode__(self):
- return self.value
-
- # __unicode__() returns unicode
- exc = UnicodeException(u'unicode \xe9\u20ac')
- self.assertEqual(encodeutils.exception_to_unicode(exc),
- u'unicode \xe9\u20ac')
-
- # __unicode__() returns bytes (does this case really happen in the
- # wild?)
- exc = UnicodeException(b'utf-8 \xc3\xa9\xe2\x82\xac')
- self.assertEqual(encodeutils.exception_to_unicode(exc),
- u'utf-8 \xe9\u20ac')
-
- @testtools.skipIf(six.PY3, 'test specific to Python 2')
- def test_unicode_or_str_exception(self):
- # Exception with __str__() and __unicode__() methods
- class UnicodeOrStrException(Exception):
- def __init__(self, unicode_value, str_value):
- Exception.__init__(self)
- self.unicode_value = unicode_value
- self.str_value = str_value
-
- def __unicode__(self):
- return self.unicode_value
-
- def __str__(self):
- return self.str_value
-
- # __unicode__() returns unicode
- exc = UnicodeOrStrException(u'unicode \xe9\u20ac', b'str')
- self.assertEqual(encodeutils.exception_to_unicode(exc),
- u'unicode \xe9\u20ac')
-
- # __unicode__() returns bytes (does this case really happen in the
- # wild?)
- exc = UnicodeOrStrException(b'utf-8 \xc3\xa9\xe2\x82\xac', b'str')
- self.assertEqual(encodeutils.exception_to_unicode(exc),
- u'utf-8 \xe9\u20ac')
-
- @testtools.skipIf(six.PY3, 'test specific to Python 2')
- def test_unicode_only_exception(self):
- # Exception with a __unicode__() method and a __str__() which
- # raises an exception (similar to the Message class of oslo_i18n)
- class UnicodeOnlyException(Exception):
- def __init__(self, value):
- Exception.__init__(self)
- self.value = value
-
- def __unicode__(self):
- return self.value
-
- def __str__(self):
- raise UnicodeError("use unicode()")
-
- # __unicode__() returns unicode
- exc = UnicodeOnlyException(u'unicode \xe9\u20ac')
- self.assertEqual(encodeutils.exception_to_unicode(exc),
- u'unicode \xe9\u20ac')
-
- # __unicode__() returns bytes
- exc = UnicodeOnlyException(b'utf-8 \xc3\xa9\xe2\x82\xac')
- self.assertEqual(encodeutils.exception_to_unicode(exc),
- u'utf-8 \xe9\u20ac')
-
def test_oslo_i18n_message(self):
# use the lazy translation to get a Message instance of oslo_i18n
exc = oslo_i18n_fixture.Translation().lazy("test")