diff --git a/oslo_utils/encodeutils.py b/oslo_utils/encodeutils.py index 761aef76..597e662f 100644 --- a/oslo_utils/encodeutils.py +++ b/oslo_utils/encodeutils.py @@ -139,7 +139,7 @@ def exception_to_unicode(exc): # be easily casted to unicode, whereas they have no __unicode__() # method. try: - msg = unicode(exc) + msg = unicode(exc) # NOQA except UnicodeError: # unicode(exc) fail with UnicodeDecodeError on Python 2 if # exc.__unicode__() or exc.__str__() returns a bytes string not diff --git a/oslo_utils/tests/test_excutils.py b/oslo_utils/tests/test_excutils.py index 6f419725..8e2650ed 100644 --- a/oslo_utils/tests/test_excutils.py +++ b/oslo_utils/tests/test_excutils.py @@ -327,7 +327,7 @@ class ExceptionFilterTest(test_base.BaseTestCase): def _make_filter_func(self, ignore_classes=AssertionError): @excutils.exception_filter def ignore_exceptions(ex): - '''Ignore some exceptions F''' + '''Ignore some exceptions F.''' return isinstance(ex, ignore_classes) return ignore_exceptions @@ -339,7 +339,7 @@ class ExceptionFilterTest(test_base.BaseTestCase): @excutils.exception_filter def ignore_exceptions(self, ex): - '''Ignore some exceptions M''' + '''Ignore some exceptions M.''' return isinstance(ex, self.ignore) return ExceptionIgnorer(ignore_classes).ignore_exceptions @@ -351,7 +351,7 @@ class ExceptionFilterTest(test_base.BaseTestCase): @excutils.exception_filter @classmethod def ignore_exceptions(cls, ex): - '''Ignore some exceptions C''' + '''Ignore some exceptions C.''' return isinstance(ex, cls.ignore) return ExceptionIgnorer.ignore_exceptions @@ -361,7 +361,7 @@ class ExceptionFilterTest(test_base.BaseTestCase): @excutils.exception_filter @staticmethod def ignore_exceptions(ex): - '''Ignore some exceptions S''' + '''Ignore some exceptions S.''' return isinstance(ex, ignore_classes) return ExceptionIgnorer.ignore_exceptions @@ -461,7 +461,7 @@ class ExceptionFilterTest(test_base.BaseTestCase): def test_func_docstring(self): ignore_func = self._make_filter_func() - self.assertEqual('Ignore some exceptions F', ignore_func.__doc__) + self.assertEqual('Ignore some exceptions F.', ignore_func.__doc__) def test_filter_method_call(self): ignore_assertion_error = self._make_filter_method() @@ -496,7 +496,7 @@ class ExceptionFilterTest(test_base.BaseTestCase): def test_method_docstring(self): ignore_func = self._make_filter_method() - self.assertEqual('Ignore some exceptions M', ignore_func.__doc__) + self.assertEqual('Ignore some exceptions M.', ignore_func.__doc__) def test_filter_classmethod_call(self): ignore_assertion_error = self._make_filter_classmethod() @@ -531,7 +531,7 @@ class ExceptionFilterTest(test_base.BaseTestCase): def test_classmethod_docstring(self): ignore_func = self._make_filter_classmethod() - self.assertEqual('Ignore some exceptions C', ignore_func.__doc__) + self.assertEqual('Ignore some exceptions C.', ignore_func.__doc__) def test_filter_staticmethod_call(self): ignore_assertion_error = self._make_filter_staticmethod() @@ -566,4 +566,4 @@ class ExceptionFilterTest(test_base.BaseTestCase): def test_staticmethod_docstring(self): ignore_func = self._make_filter_staticmethod() - self.assertEqual('Ignore some exceptions S', ignore_func.__doc__) + self.assertEqual('Ignore some exceptions S.', ignore_func.__doc__) diff --git a/oslo_utils/tests/test_fnmatch.py b/oslo_utils/tests/test_fnmatch.py index 233138e6..2c94dea9 100644 --- a/oslo_utils/tests/test_fnmatch.py +++ b/oslo_utils/tests/test_fnmatch.py @@ -19,7 +19,7 @@ import sys import mock from oslotest import base -from six.moves import reload_module +import six fnmatch = None @@ -57,5 +57,5 @@ class TestFnmatch(base.BaseTestCase): self._test_fnmatch_posix_nt() with mock.patch.object(sys, 'version_info', new=(2, 7, 0)): - reload_module(oslo_fnmatch) + 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 823c502d..394bdc4b 100644 --- a/oslo_utils/tests/test_netutils.py +++ b/oslo_utils/tests/test_netutils.py @@ -17,7 +17,6 @@ import contextlib import socket import mock -from mock import patch import netifaces from oslotest import base as test_base import six @@ -261,7 +260,7 @@ class NetworkUtilsTest(test_base.BaseTestCase): @mock.patch('netifaces.ifaddresses') def test_get_my_ipv4_address_with_default_route( self, ifaddr, gateways): - with patch.dict(netifaces.__dict__, {'AF_INET': '0'}): + with mock.patch.dict(netifaces.__dict__, {'AF_INET': '0'}): ifaddr.return_value = {'0': [{'addr': '172.18.204.1'}]} addr = netutils._get_my_ipv4_address() self.assertEqual('172.18.204.1', addr) @@ -270,7 +269,7 @@ class NetworkUtilsTest(test_base.BaseTestCase): @mock.patch('netifaces.ifaddresses') def test_get_my_ipv4_address_without_default_route( self, ifaddr, gateways): - with patch.dict(netifaces.__dict__, {'AF_INET': '0'}): + with mock.patch.dict(netifaces.__dict__, {'AF_INET': '0'}): ifaddr.return_value = {} addr = netutils._get_my_ipv4_address() self.assertEqual('127.0.0.1', addr) diff --git a/oslo_utils/tests/test_timeutils.py b/oslo_utils/tests/test_timeutils.py index 08ed5cef..b1b1f8a7 100644 --- a/oslo_utils/tests/test_timeutils.py +++ b/oslo_utils/tests/test_timeutils.py @@ -39,8 +39,8 @@ class TimeUtilsTest(test_base.BaseTestCase): self.skynet_self_aware_time_str = '1997-08-29T06:14:00Z' self.skynet_self_aware_time_ms_str = '1997-08-29T06:14:00.000123Z' self.skynet_self_aware_time = datetime.datetime(1997, 8, 29, 6, 14, 0) - self.skynet_self_aware_ms_time = datetime.datetime( - 1997, 8, 29, 6, 14, 0, 123) + self.skynet_self_aware_ms_time = datetime.datetime(1997, 8, 29, 6, 14, + 0, 123) self.one_minute_before = datetime.datetime(1997, 8, 29, 6, 13, 0) self.one_minute_after = datetime.datetime(1997, 8, 29, 6, 15, 0) self.skynet_self_aware_time_perfect_str = '1997-08-29T06:14:00.000000' diff --git a/oslo_utils/tests/tests_encodeutils.py b/oslo_utils/tests/tests_encodeutils.py index ded44c2c..834c6d2a 100644 --- a/oslo_utils/tests/tests_encodeutils.py +++ b/oslo_utils/tests/tests_encodeutils.py @@ -16,11 +16,11 @@ # under the License. import mock +from oslo_i18n import fixture as oslo_i18n_fixture from oslotest import base as test_base import six import testtools -import oslo_i18n.fixture from oslo_utils import encodeutils @@ -116,7 +116,7 @@ class EncodeUtilsTest(test_base.BaseTestCase): # oslo.i18n Message objects should also be accepted for convenience. # It works because Message is a subclass of six.text_type. Use the # lazy translation to get a Message instance of oslo_i18n. - msg = oslo_i18n.fixture.Translation().lazy("test") + msg = oslo_i18n_fixture.Translation().lazy("test") self.assertEqual(encodeutils.to_utf8(msg), b'test') @@ -251,6 +251,6 @@ class ExceptionToUnicodeTest(test_base.BaseTestCase): 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") + exc = oslo_i18n_fixture.Translation().lazy("test") self.assertEqual(encodeutils.exception_to_unicode(exc), u"test") diff --git a/oslo_utils/timeutils.py b/oslo_utils/timeutils.py index ca809fc9..4509da6b 100644 --- a/oslo_utils/timeutils.py +++ b/oslo_utils/timeutils.py @@ -25,7 +25,7 @@ import time from debtcollector import removals import iso8601 from monotonic import monotonic as now # noqa -from pytz import timezone +import pytz import six from oslo_utils import reflection @@ -283,7 +283,7 @@ def unmarshall_time(tyme): microsecond=tyme['microsecond']) tzname = tyme.get('tzname') if tzname: - tzinfo = timezone(tzname) + tzinfo = pytz.timezone(tzname) dt = tzinfo.localize(dt) return dt diff --git a/oslo_utils/versionutils.py b/oslo_utils/versionutils.py index 09f867ac..3a6fd79f 100644 --- a/oslo_utils/versionutils.py +++ b/oslo_utils/versionutils.py @@ -21,10 +21,10 @@ Helpers for comparing version strings. import logging -from oslo_utils._i18n import _ import pkg_resources import six +from oslo_utils._i18n import _ LOG = logging.getLogger(__name__)