Remove library "six"
Now Python2 is not supported, this compatibility library for both versions is not needed anymore. Change-Id: Ic6da328a6219c8a00d38602f6b539a2ff5be1b2e
This commit is contained in:
parent
1d9d6d7bf5
commit
478502b3df
@ -43,7 +43,7 @@ to a boolean value.
|
||||
::
|
||||
|
||||
def convert_to_boolean(data):
|
||||
if isinstance(data, six.string_types):
|
||||
if isinstance(data, str):
|
||||
val = data.lower()
|
||||
if val == "true" or val == "1":
|
||||
return True
|
||||
|
@ -80,7 +80,6 @@ requestsexceptions==1.2.0
|
||||
rfc3986==0.3.1
|
||||
Routes==2.3.1
|
||||
setproctitle==1.1.10
|
||||
six==1.10.0
|
||||
snowballstemmer==1.2.1
|
||||
Sphinx==1.6.2
|
||||
sphinxcontrib-websupport==1.0.1
|
||||
|
@ -13,16 +13,11 @@
|
||||
import gettext
|
||||
|
||||
import pbr.version
|
||||
import six
|
||||
|
||||
from neutron_lib.db import api # noqa
|
||||
|
||||
|
||||
if six.PY2:
|
||||
# pylint: disable=unexpected-keyword-arg
|
||||
gettext.install('neutron_lib', unicode=1)
|
||||
else:
|
||||
gettext.install('neutron_lib')
|
||||
gettext.install('neutron_lib')
|
||||
|
||||
|
||||
# NOTE(boden): neutron_lib.db.api is imported to ensure the ORM event listeners
|
||||
|
@ -12,11 +12,8 @@
|
||||
|
||||
import abc
|
||||
|
||||
import six
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class AgentExtension(object):
|
||||
class AgentExtension(object, metaclass=abc.ABCMeta):
|
||||
"""Define stable abstract interface for agent extensions.
|
||||
|
||||
An agent extension extends the agent core functionality.
|
||||
|
@ -12,13 +12,10 @@
|
||||
|
||||
import abc
|
||||
|
||||
import six
|
||||
|
||||
from neutron_lib.agent import extension
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class L2AgentExtension(extension.AgentExtension):
|
||||
class L2AgentExtension(extension.AgentExtension, metaclass=abc.ABCMeta):
|
||||
"""Define stable abstract interface for l2 agent extensions.
|
||||
|
||||
An agent extension extends the agent core functionality.
|
||||
|
@ -12,13 +12,10 @@
|
||||
|
||||
import abc
|
||||
|
||||
import six
|
||||
|
||||
from neutron_lib.agent import extension
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class L3AgentExtension(extension.AgentExtension):
|
||||
class L3AgentExtension(extension.AgentExtension, metaclass=abc.ABCMeta):
|
||||
"""Define stable abstract interface for l3 agent extensions.
|
||||
|
||||
An agent extension extends the agent core functionality.
|
||||
|
@ -13,7 +13,6 @@
|
||||
import netaddr
|
||||
from oslo_config import cfg
|
||||
from oslo_utils import strutils
|
||||
import six
|
||||
|
||||
from neutron_lib._i18n import _
|
||||
from neutron_lib.api import validators
|
||||
@ -172,7 +171,7 @@ def convert_to_list(data):
|
||||
"""
|
||||
if data is None:
|
||||
return []
|
||||
elif hasattr(data, '__iter__') and not isinstance(data, six.string_types):
|
||||
elif hasattr(data, '__iter__') and not isinstance(data, str):
|
||||
return list(data)
|
||||
else:
|
||||
return [data]
|
||||
@ -191,7 +190,7 @@ def convert_ip_to_canonical_format(value):
|
||||
try:
|
||||
ip = netaddr.IPAddress(value)
|
||||
if ip.version == constants.IP_VERSION_6:
|
||||
return six.text_type(ip.format(dialect=netaddr.ipv6_compact))
|
||||
return str(ip.format(dialect=netaddr.ipv6_compact))
|
||||
except (netaddr.core.AddrFormatError, ValueError):
|
||||
pass
|
||||
return value
|
||||
@ -292,7 +291,7 @@ def convert_prefix_forced_case(data, prefix):
|
||||
replaced by <prefix>
|
||||
"""
|
||||
plen = len(prefix)
|
||||
if (isinstance(data, six.string_types) and len(data) >= plen and
|
||||
if (isinstance(data, str) and len(data) >= plen and
|
||||
data[0:plen].lower() == prefix.lower()):
|
||||
return prefix + data[plen:]
|
||||
return data
|
||||
|
@ -15,8 +15,6 @@
|
||||
|
||||
import abc
|
||||
|
||||
import six
|
||||
|
||||
from neutron_lib._i18n import _
|
||||
from neutron_lib import constants
|
||||
|
||||
@ -34,8 +32,7 @@ def is_extension_supported(plugin, alias):
|
||||
return alias in getattr(plugin, "supported_extension_aliases", [])
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class ExtensionDescriptor(object):
|
||||
class ExtensionDescriptor(object, metaclass=abc.ABCMeta):
|
||||
"""Base class that defines the contract for extensions."""
|
||||
|
||||
@abc.abstractmethod
|
||||
|
@ -22,7 +22,6 @@ from oslo_log import log as logging
|
||||
from oslo_utils import netutils
|
||||
from oslo_utils import strutils
|
||||
from oslo_utils import uuidutils
|
||||
import six
|
||||
from webob import exc
|
||||
|
||||
from neutron_lib._i18n import _
|
||||
@ -228,7 +227,7 @@ def validate_string(data, max_len=None):
|
||||
the given max_len. Otherwise a human readable message indicating why
|
||||
the data is invalid.
|
||||
"""
|
||||
if not isinstance(data, six.string_types):
|
||||
if not isinstance(data, str):
|
||||
msg = _("'%s' is not a valid string") % data
|
||||
LOG.debug(msg)
|
||||
return msg
|
||||
@ -1117,7 +1116,7 @@ def validate_subnet_service_types(service_types, valid_values=None):
|
||||
prefixes += constants.DEVICE_OWNER_COMPUTE_PREFIX
|
||||
|
||||
for service_type in service_types:
|
||||
if not isinstance(service_type, six.text_type):
|
||||
if not isinstance(service_type, str):
|
||||
raise n_exc.InvalidInputSubnetServiceType(
|
||||
service_type=service_type)
|
||||
elif not service_type.startswith(tuple(prefixes)):
|
||||
@ -1148,9 +1147,9 @@ def validate_ethertype(ethertype, valid_values=None):
|
||||
# Value of ethertype cannot be coerced into a string, like None
|
||||
pass
|
||||
try:
|
||||
if isinstance(ethertype, six.string_types):
|
||||
if isinstance(ethertype, str):
|
||||
ethertype = int(ethertype, 16)
|
||||
if (isinstance(ethertype, six.integer_types) and
|
||||
if (isinstance(ethertype, int) and
|
||||
constants.ETHERTYPE_MIN <= ethertype and
|
||||
ethertype <= constants.ETHERTYPE_MAX):
|
||||
return None
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
import contextlib
|
||||
import copy
|
||||
import functools
|
||||
import weakref
|
||||
|
||||
from oslo_concurrency import lockutils
|
||||
@ -24,7 +25,6 @@ from oslo_utils import excutils
|
||||
from osprofiler import opts as profiler_opts
|
||||
import osprofiler.sqlalchemy
|
||||
from pecan import util as p_util
|
||||
import six
|
||||
import sqlalchemy
|
||||
from sqlalchemy import event # noqa
|
||||
from sqlalchemy import exc as sql_exc
|
||||
@ -129,7 +129,7 @@ def _tag_retriables_as_unretriable(f):
|
||||
This decorator can be used outside of a retry decorator to prevent
|
||||
decorators higher up from retrying again.
|
||||
"""
|
||||
@six.wraps(f)
|
||||
@functools.wraps(f)
|
||||
def wrapped(*args, **kwargs):
|
||||
try:
|
||||
return f(*args, **kwargs)
|
||||
@ -169,7 +169,7 @@ def retry_db_errors(f):
|
||||
|
||||
@_tag_retriables_as_unretriable
|
||||
@_retry_db_errors
|
||||
@six.wraps(f)
|
||||
@functools.wraps(f)
|
||||
def wrapped(*args, **kwargs):
|
||||
try:
|
||||
# copy mutable args and kwargs to make retries safe. this doesn't
|
||||
@ -221,7 +221,7 @@ def retry_if_session_inactive(context_var_name='context'):
|
||||
raise RuntimeError(msg)
|
||||
f_with_retry = retry_db_errors(f)
|
||||
|
||||
@six.wraps(f)
|
||||
@functools.wraps(f)
|
||||
def wrapped(*args, **kwargs):
|
||||
# only use retry wrapper if we aren't nested in an active
|
||||
# transaction
|
||||
|
@ -10,7 +10,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import six
|
||||
import functools
|
||||
|
||||
from oslo_db import exception as db_exc
|
||||
from oslo_utils import excutils
|
||||
@ -97,7 +97,7 @@ def reraise_as_retryrequest(function):
|
||||
Exception's as a RetryRequest.
|
||||
:raises RetryRequest: If the wrapped function raises retriable exception.
|
||||
"""
|
||||
@six.wraps(function)
|
||||
@functools.wraps(function)
|
||||
def _wrapped(*args, **kwargs):
|
||||
try:
|
||||
return function(*args, **kwargs)
|
||||
|
@ -18,7 +18,6 @@ Neutron base exception handling.
|
||||
"""
|
||||
|
||||
from oslo_utils import excutils
|
||||
import six
|
||||
|
||||
from neutron_lib._i18n import _
|
||||
|
||||
@ -43,10 +42,6 @@ class NeutronException(Exception):
|
||||
# at least get the core message out if something happened
|
||||
super(NeutronException, self).__init__(self.message)
|
||||
|
||||
if six.PY2:
|
||||
def __unicode__(self):
|
||||
return unicode(self.msg) # noqa
|
||||
|
||||
def __str__(self):
|
||||
return self.msg
|
||||
|
||||
|
@ -384,8 +384,7 @@ class OpenFixture(fixtures.Fixture):
|
||||
return self.mock_open(name, *args, **kwargs)
|
||||
return self._orig_open(name, *args, **kwargs)
|
||||
|
||||
self._patch = mock.patch('six.moves.builtins.open',
|
||||
new=replacement_open)
|
||||
self._patch = mock.patch('builtins.open', new=replacement_open)
|
||||
self._patch.start()
|
||||
self.addCleanup(self._patch.stop)
|
||||
|
||||
|
@ -123,50 +123,6 @@ def check_no_contextlib_nested(logical_line, filename):
|
||||
yield(0, msg)
|
||||
|
||||
|
||||
def check_python3_xrange(logical_line):
|
||||
"""N525 - Do not use xrange.
|
||||
|
||||
:param logical_line: The logical line to check.
|
||||
:returns: None if the logical line passes the check, otherwise a tuple
|
||||
is yielded that contains the offending index in logical line and a
|
||||
message describe the check validation failure.
|
||||
"""
|
||||
if re.search(r"\bxrange\s*\(", logical_line):
|
||||
yield(0, "N525: Do not use xrange. Use range, or six.moves.range for "
|
||||
"large loops.")
|
||||
|
||||
|
||||
def check_no_basestring(logical_line):
|
||||
"""N526 - basestring is not Python3-compatible.
|
||||
|
||||
:param logical_line: The logical line to check.
|
||||
:returns: None if the logical line passes the check, otherwise a tuple
|
||||
is yielded that contains the offending index in logical line and a
|
||||
message describe the check validation failure.
|
||||
"""
|
||||
if re.search(r"\bbasestring\b", logical_line):
|
||||
msg = ("N526: basestring is not Python3-compatible, use "
|
||||
"six.string_types instead.")
|
||||
yield(0, msg)
|
||||
|
||||
|
||||
def check_python3_no_iteritems(logical_line):
|
||||
"""N527 - Use dict.items() instead of dict.iteritems().
|
||||
|
||||
:param logical_line: The logical line to check.
|
||||
:returns: None if the logical line passes the check, otherwise a tuple
|
||||
is yielded that contains the offending index in logical line and a
|
||||
message describe the check validation failure.
|
||||
"""
|
||||
if re.search(r".*\.iteritems\(\)", logical_line):
|
||||
msg = ("N527: Use dict.items() instead of dict.iteritems() to be "
|
||||
"compatible with both Python 2 and Python 3. In Python 2, "
|
||||
"dict.items() may be inefficient for very large dictionaries. "
|
||||
"If you can prove that you need the optimization of an "
|
||||
"iterator for Python 2, then you can use six.iteritems(dict).")
|
||||
yield(0, msg)
|
||||
|
||||
|
||||
def no_mutable_default_args(logical_line):
|
||||
"""N529 - Method's default argument shouldn't be mutable.
|
||||
|
||||
@ -235,9 +191,6 @@ def factory(register):
|
||||
"""
|
||||
register(use_jsonutils)
|
||||
register(check_no_contextlib_nested)
|
||||
register(check_python3_xrange)
|
||||
register(check_no_basestring)
|
||||
register(check_python3_no_iteritems)
|
||||
register(no_mutable_default_args)
|
||||
register(check_neutron_namespace_imports)
|
||||
register(translation_checks.no_translate_logs)
|
||||
|
@ -17,7 +17,6 @@ import uuid
|
||||
import netaddr
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_versionedobjects import fields as obj_fields
|
||||
import six
|
||||
|
||||
from neutron_lib._i18n import _
|
||||
from neutron_lib import constants as lib_constants
|
||||
@ -45,7 +44,7 @@ class RangeConstrainedInteger(obj_fields.Integer):
|
||||
super(RangeConstrainedInteger, self).__init__(**kwargs)
|
||||
|
||||
def coerce(self, obj, attr, value):
|
||||
if not isinstance(value, six.integer_types):
|
||||
if not isinstance(value, int):
|
||||
msg = _("Field value %s is not an integer") % value
|
||||
raise ValueError(msg)
|
||||
if not self._start <= value <= self._end:
|
||||
@ -101,7 +100,7 @@ class SetOfUUIDsField(obj_fields.AutoTypedField):
|
||||
|
||||
class DomainName(obj_fields.String):
|
||||
def coerce(self, obj, attr, value):
|
||||
if not isinstance(value, six.string_types):
|
||||
if not isinstance(value, str):
|
||||
msg = _("Field value %s is not a string") % value
|
||||
raise ValueError(msg)
|
||||
if len(value) > lib_db_const.FQDN_FIELD_SIZE:
|
||||
@ -120,14 +119,14 @@ class IntegerEnum(obj_fields.Integer):
|
||||
msg = _("No possible values specified")
|
||||
raise ValueError(msg)
|
||||
for value in valid_values:
|
||||
if not isinstance(value, six.integer_types):
|
||||
if not isinstance(value, int):
|
||||
msg = _("Possible value %s is not an integer") % value
|
||||
raise ValueError(msg)
|
||||
self._valid_values = valid_values
|
||||
super(IntegerEnum, self).__init__(**kwargs)
|
||||
|
||||
def coerce(self, obj, attr, value):
|
||||
if not isinstance(value, six.integer_types):
|
||||
if not isinstance(value, int):
|
||||
msg = _("Field value %s is not an integer") % value
|
||||
raise ValueError(msg)
|
||||
if value not in self._valid_values:
|
||||
@ -235,7 +234,7 @@ class DictOfMiscValues(obj_fields.FieldType):
|
||||
def coerce(obj, attr, value):
|
||||
if isinstance(value, dict):
|
||||
return value
|
||||
if isinstance(value, six.string_types):
|
||||
if isinstance(value, str):
|
||||
try:
|
||||
return jsonutils.loads(value)
|
||||
except Exception:
|
||||
|
@ -13,8 +13,6 @@
|
||||
import abc
|
||||
import copy
|
||||
|
||||
import six
|
||||
|
||||
from neutron_lib import exceptions
|
||||
|
||||
|
||||
@ -28,8 +26,7 @@ def convert_filters(**kwargs):
|
||||
return result
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class FilterObj(object):
|
||||
class FilterObj(object, metaclass=abc.ABCMeta):
|
||||
|
||||
@abc.abstractmethod
|
||||
def filter(self, column):
|
||||
|
@ -16,6 +16,7 @@
|
||||
import functools
|
||||
import re
|
||||
import time
|
||||
from urllib import parse
|
||||
import uuid
|
||||
|
||||
import requests
|
||||
@ -25,7 +26,6 @@ from keystoneauth1 import loading as keystone
|
||||
from oslo_log import log as logging
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import versionutils
|
||||
from six.moves.urllib.parse import urlencode
|
||||
|
||||
from neutron_lib._i18n import _
|
||||
from neutron_lib.exceptions import placement as n_exc
|
||||
@ -375,7 +375,7 @@ class PlacementAPIClient(object):
|
||||
filters['in_tree'] = in_tree
|
||||
if uuid:
|
||||
filters['uuid'] = uuid
|
||||
url = '%s?%s' % (url, urlencode(filters))
|
||||
url = '%s?%s' % (url, parse.urlencode(filters))
|
||||
return self._get(url).json()
|
||||
|
||||
@_check_placement_api_available
|
||||
|
@ -16,7 +16,6 @@ import uuid
|
||||
|
||||
import os_traits
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
|
||||
from neutron_lib._i18n import _
|
||||
from neutron_lib import constants as const
|
||||
@ -73,8 +72,6 @@ def six_uuid5(namespace, name):
|
||||
# cPython 3.6:
|
||||
# https://github.com/python/cpython/blob
|
||||
# /e9e2fd75ccbc6e9a5221cf3525e39e9d042d843f/Lib/uuid.py#L628
|
||||
if six.PY2:
|
||||
name = name.encode('utf-8')
|
||||
return uuid.uuid5(namespace=namespace, name=name)
|
||||
|
||||
|
||||
|
@ -14,8 +14,6 @@
|
||||
|
||||
import abc
|
||||
|
||||
import six
|
||||
|
||||
|
||||
# The following keys are used in the segment dictionaries passed via
|
||||
# the driver API.
|
||||
@ -33,8 +31,7 @@ BOUND_DRIVER = 'bound_driver'
|
||||
BOUND_SEGMENT = 'bound_segment'
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class MechanismDriver(object):
|
||||
class MechanismDriver(object, metaclass=abc.ABCMeta):
|
||||
"""Define stable abstract interface for ML2 mechanism drivers.
|
||||
|
||||
A mechanism driver is called on the creation, update, and deletion
|
||||
@ -459,8 +456,7 @@ class MechanismDriver(object):
|
||||
return []
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class _TypeDriverBase(object):
|
||||
class _TypeDriverBase(object, metaclass=abc.ABCMeta):
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_type(self):
|
||||
@ -520,8 +516,7 @@ class _TypeDriverBase(object):
|
||||
pass
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class TypeDriver(_TypeDriverBase):
|
||||
class TypeDriver(_TypeDriverBase, metaclass=abc.ABCMeta):
|
||||
"""Define abstract interface for ML2 type drivers.
|
||||
|
||||
ML2 type drivers each support a specific network_type for provider
|
||||
@ -592,8 +587,7 @@ class TypeDriver(_TypeDriverBase):
|
||||
pass
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class ML2TypeDriver(_TypeDriverBase):
|
||||
class ML2TypeDriver(_TypeDriverBase, metaclass=abc.ABCMeta):
|
||||
"""Define abstract interface for ML2 type drivers.
|
||||
|
||||
ML2 type drivers each support a specific network_type for provider
|
||||
@ -684,8 +678,7 @@ class ML2TypeDriver(_TypeDriverBase):
|
||||
pass
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class NetworkContext(object):
|
||||
class NetworkContext(object, metaclass=abc.ABCMeta):
|
||||
"""Context passed to MechanismDrivers for changes to network resources.
|
||||
|
||||
A NetworkContext instance wraps a network resource. It provides
|
||||
@ -722,8 +715,7 @@ class NetworkContext(object):
|
||||
pass
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class SubnetContext(object):
|
||||
class SubnetContext(object, metaclass=abc.ABCMeta):
|
||||
"""Context passed to MechanismDrivers for changes to subnet resources.
|
||||
|
||||
A SubnetContext instance wraps a subnet resource. It provides
|
||||
@ -755,8 +747,7 @@ class SubnetContext(object):
|
||||
pass
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class PortContext(object):
|
||||
class PortContext(object, metaclass=abc.ABCMeta):
|
||||
"""Context passed to MechanismDrivers for changes to port resources.
|
||||
|
||||
A PortContext instance wraps a port resource. It provides helper
|
||||
@ -1073,8 +1064,7 @@ class PortContext(object):
|
||||
pass
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class ExtensionDriver(object):
|
||||
class ExtensionDriver(object, metaclass=abc.ABCMeta):
|
||||
"""Define stable abstract interface for ML2 extension drivers.
|
||||
|
||||
An extension driver extends the core resources implemented by the
|
||||
|
@ -12,8 +12,6 @@
|
||||
|
||||
import abc
|
||||
|
||||
import six
|
||||
|
||||
|
||||
class WorkerBase(object):
|
||||
|
||||
@ -48,8 +46,7 @@ class WorkerBase(object):
|
||||
self._workers.extend(workers)
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class ServicePluginBase(WorkerBase):
|
||||
class ServicePluginBase(WorkerBase, metaclass=abc.ABCMeta):
|
||||
"""Define base interface for any Advanced Service plugin."""
|
||||
supported_extension_aliases = []
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
import mock
|
||||
import netaddr
|
||||
import six
|
||||
import testtools
|
||||
|
||||
from neutron_lib.api import converters
|
||||
@ -231,7 +230,7 @@ class TestConvertStringToCaseInsensitive(base.BaseTestCase):
|
||||
|
||||
def test_convert_string_to_lower(self):
|
||||
result = converters.convert_string_to_case_insensitive(u"THIS Is tEsT")
|
||||
self.assertIsInstance(result, six.string_types)
|
||||
self.assertIsInstance(result, str)
|
||||
|
||||
def test_assert_error_on_non_string(self):
|
||||
for invalid in [[], 123]:
|
||||
|
@ -18,7 +18,6 @@ from oslo_db.sqlalchemy import enginefacade
|
||||
from oslo_db.sqlalchemy import test_fixtures
|
||||
from oslo_utils import timeutils
|
||||
from oslo_utils import uuidutils
|
||||
import six
|
||||
import sqlalchemy as sa
|
||||
|
||||
from neutron_lib import context
|
||||
@ -28,9 +27,9 @@ from neutron_lib.tests import tools
|
||||
from neutron_lib.utils import net
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class SqlAlchemyTypesBaseTestCase(test_fixtures.OpportunisticDBTestMixin,
|
||||
test_base.BaseTestCase):
|
||||
test_base.BaseTestCase,
|
||||
metaclass=abc.ABCMeta):
|
||||
def setUp(self):
|
||||
super(SqlAlchemyTypesBaseTestCase, self).setUp()
|
||||
self.engine = enginefacade.writer.get_engine()
|
||||
|
@ -87,24 +87,6 @@ class HackingTestCase(base.BaseTestCase):
|
||||
self.assertLinePasses(f, '# with contextlib.nested():', '')
|
||||
self.assertLinePasses(f, 'print("with contextlib.nested():")', '')
|
||||
|
||||
def test_check_python3_xrange(self):
|
||||
f = checks.check_python3_xrange
|
||||
self.assertLineFails(f, 'a = xrange(1000)')
|
||||
self.assertLineFails(f, 'b =xrange ( 42 )')
|
||||
self.assertLineFails(f, 'c = xrange(1, 10, 2)')
|
||||
self.assertLinePasses(f, 'd = range(1000)')
|
||||
self.assertLinePasses(f, 'e = six.moves.range(1337)')
|
||||
|
||||
def test_no_basestring(self):
|
||||
f = checks.check_no_basestring
|
||||
self.assertLineFails(f, 'isinstance(x, basestring)')
|
||||
self.assertLinePasses(f, 'isinstance(x, BaseString)')
|
||||
|
||||
def test_check_python3_iteritems(self):
|
||||
f = checks.check_python3_no_iteritems
|
||||
self.assertLineFails(f, "d.iteritems()")
|
||||
self.assertLinePasses(f, "six.iteritems(d)")
|
||||
|
||||
def test_no_mutable_default_args(self):
|
||||
self.assertEqual(1, len(list(checks.no_mutable_default_args(
|
||||
" def fake_suds_context(calls={}):"))))
|
||||
|
@ -12,8 +12,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import six
|
||||
|
||||
import mock
|
||||
|
||||
from neutron_lib.callbacks import events
|
||||
@ -67,44 +65,44 @@ class TestBaseWorker(base.BaseTestCase):
|
||||
def test_proctitle_default(self):
|
||||
with mock.patch('setproctitle.setproctitle') as spt:
|
||||
_ProcWorker().start()
|
||||
six.assertRegex(self, spt.call_args[0][0],
|
||||
'^neutron-server: _ProcWorker \\(.*python.*\\)$')
|
||||
self.assertRegex(spt.call_args[0][0],
|
||||
'^neutron-server: _ProcWorker \\(.*python.*\\)$')
|
||||
|
||||
def test_proctitle_custom_desc(self):
|
||||
with mock.patch('setproctitle.setproctitle') as spt:
|
||||
_ProcWorker().start(desc="fancy title")
|
||||
six.assertRegex(self, spt.call_args[0][0],
|
||||
'^neutron-server: fancy title \\(.*python.*\\)$')
|
||||
self.assertRegex(spt.call_args[0][0],
|
||||
'^neutron-server: fancy title \\(.*python.*\\)$')
|
||||
|
||||
def test_proctitle_custom_name(self):
|
||||
with mock.patch('setproctitle.setproctitle') as spt:
|
||||
_ProcWorker().start(name="tardis")
|
||||
six.assertRegex(self, spt.call_args[0][0],
|
||||
'^tardis: _ProcWorker \\(.*python.*\\)$')
|
||||
self.assertRegex(spt.call_args[0][0],
|
||||
'^tardis: _ProcWorker \\(.*python.*\\)$')
|
||||
|
||||
def test_proctitle_empty(self):
|
||||
with mock.patch('setproctitle.setproctitle') as spt:
|
||||
_ProcWorker().start(desc="")
|
||||
six.assertRegex(self, spt.call_args[0][0],
|
||||
'^neutron-server: _ProcWorker \\(.*python.*\\)$')
|
||||
self.assertRegex(spt.call_args[0][0],
|
||||
'^neutron-server: _ProcWorker \\(.*python.*\\)$')
|
||||
|
||||
def test_proctitle_nonstring(self):
|
||||
with mock.patch('setproctitle.setproctitle') as spt:
|
||||
_ProcWorker().start(desc=2)
|
||||
six.assertRegex(self, spt.call_args[0][0],
|
||||
'^neutron-server: 2 \\(.*python.*\\)$')
|
||||
self.assertRegex(spt.call_args[0][0],
|
||||
'^neutron-server: 2 \\(.*python.*\\)$')
|
||||
|
||||
def test_proctitle_both_empty(self):
|
||||
with mock.patch('setproctitle.setproctitle') as spt:
|
||||
_ProcWorker().start(name="", desc="")
|
||||
six.assertRegex(self, spt.call_args[0][0],
|
||||
'^: _ProcWorker \\(.*python.*\\)$')
|
||||
self.assertRegex(spt.call_args[0][0],
|
||||
'^: _ProcWorker \\(.*python.*\\)$')
|
||||
|
||||
def test_proctitle_name_none(self):
|
||||
with mock.patch('setproctitle.setproctitle') as spt:
|
||||
_ProcWorker().start(name=None)
|
||||
six.assertRegex(self, spt.call_args[0][0],
|
||||
'^None: _ProcWorker \\(.*python.*\\)$')
|
||||
self.assertRegex(spt.call_args[0][0],
|
||||
'^None: _ProcWorker \\(.*python.*\\)$')
|
||||
|
||||
# Forked, but proctitle disabled
|
||||
|
||||
@ -123,8 +121,8 @@ class TestBaseWorker(base.BaseTestCase):
|
||||
def test_setproctitle_on(self):
|
||||
with mock.patch('setproctitle.setproctitle') as spt:
|
||||
_ProcWorker(set_proctitle='on').start(name="foo", desc="bar")
|
||||
six.assertRegex(self, spt.call_args[0][0],
|
||||
'^foo: bar \\(.*python.*\\)$')
|
||||
self.assertRegex(spt.call_args[0][0],
|
||||
'^foo: bar \\(.*python.*\\)$')
|
||||
|
||||
def test_setproctitle_off(self):
|
||||
with mock.patch('setproctitle.setproctitle') as spt:
|
||||
|
@ -14,7 +14,6 @@
|
||||
import collections
|
||||
import re
|
||||
|
||||
import six
|
||||
import testtools
|
||||
|
||||
from neutron_lib.tests import _base as base
|
||||
@ -160,33 +159,18 @@ class TestGetRandomString(base.BaseTestCase):
|
||||
self.assertIsNotNone(regex.match(random_string))
|
||||
|
||||
|
||||
def requires_py2(testcase):
|
||||
return testtools.skipUnless(six.PY2, "requires python 2.x")(testcase)
|
||||
|
||||
|
||||
def requires_py3(testcase):
|
||||
return testtools.skipUnless(six.PY3, "requires python 3.x")(testcase)
|
||||
|
||||
|
||||
class TestSafeDecodeUtf8(base.BaseTestCase):
|
||||
|
||||
@requires_py2
|
||||
def test_py2_does_nothing(self):
|
||||
s = 'test-py2'
|
||||
self.assertIs(s, helpers.safe_decode_utf8(s))
|
||||
|
||||
@requires_py3
|
||||
def test_py3_decoded_valid_bytes(self):
|
||||
s = bytes('test-py2', 'utf-8')
|
||||
decoded_str = helpers.safe_decode_utf8(s)
|
||||
self.assertIsInstance(decoded_str, six.text_type)
|
||||
self.assertIsInstance(decoded_str, str)
|
||||
self.assertEqual(s, decoded_str.encode('utf-8'))
|
||||
|
||||
@requires_py3
|
||||
def test_py3_decoded_invalid_bytes(self):
|
||||
s = bytes('test-py2', 'utf_16')
|
||||
decoded_str = helpers.safe_decode_utf8(s)
|
||||
self.assertIsInstance(decoded_str, six.text_type)
|
||||
self.assertIsInstance(decoded_str, str)
|
||||
|
||||
|
||||
class TestSafeSortKey(base.BaseTestCase):
|
||||
|
@ -16,8 +16,6 @@ import decimal
|
||||
import random
|
||||
import weakref
|
||||
|
||||
import six
|
||||
|
||||
from neutron_lib._i18n import _
|
||||
|
||||
|
||||
@ -174,7 +172,7 @@ def safe_decode_utf8(s):
|
||||
:param s: The str to decode.
|
||||
:returns: The decoded str.
|
||||
"""
|
||||
if six.PY3 and isinstance(s, bytes):
|
||||
if isinstance(s, bytes):
|
||||
return s.decode('utf-8', 'surrogateescape')
|
||||
return s
|
||||
|
||||
|
@ -15,7 +15,6 @@ import random
|
||||
import socket
|
||||
|
||||
import netaddr
|
||||
import six
|
||||
|
||||
from neutron_lib import constants
|
||||
|
||||
@ -96,7 +95,7 @@ class _AuthenticBase(object):
|
||||
self._initial_value = addr
|
||||
|
||||
def __str__(self):
|
||||
if isinstance(self._initial_value, six.string_types):
|
||||
if isinstance(self._initial_value, str):
|
||||
return self._initial_value
|
||||
return super(_AuthenticBase, self).__str__()
|
||||
|
||||
|
@ -14,11 +14,8 @@
|
||||
|
||||
import abc
|
||||
|
||||
import six
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class BaseChecks(object):
|
||||
class BaseChecks(object, metaclass=abc.ABCMeta):
|
||||
|
||||
"""Base class providing upgrade checks.
|
||||
|
||||
|
@ -8,7 +8,6 @@ SQLAlchemy>=1.2.0 # MIT
|
||||
pecan!=1.0.2,!=1.0.3,!=1.0.4,!=1.2,>=1.0.0 # BSD
|
||||
keystoneauth1>=3.4.0 # Apache-2.0
|
||||
netaddr>=0.7.18 # BSD
|
||||
six>=1.10.0 # MIT
|
||||
stevedore>=1.20.0 # Apache-2.0
|
||||
os-ken >= 0.3.0 # Apache-2.0
|
||||
oslo.concurrency>=3.26.0 # Apache-2.0
|
||||
|
@ -331,8 +331,7 @@ def ordered(obj):
|
||||
|
||||
|
||||
def json_primitive(val):
|
||||
if isinstance(val, (six.string_types, six.text_type,
|
||||
six.integer_types, bool)):
|
||||
if isinstance(val, (str, int, bool)):
|
||||
return str(val)
|
||||
elif str(val).startswith('<') or type(val) in [dict, list, set, tuple]:
|
||||
return str(type(val))
|
||||
@ -697,8 +696,7 @@ class PyLineTokens(object):
|
||||
CLOSED_B = ')'
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class AbstractFilter(object):
|
||||
class AbstractFilter(object, metaclass=abc.ABCMeta):
|
||||
|
||||
@abc.abstractmethod
|
||||
def mark(self, py_line):
|
||||
@ -709,8 +707,7 @@ class AbstractFilter(object):
|
||||
pass
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class AbstractPerFileFilter(AbstractFilter):
|
||||
class AbstractPerFileFilter(AbstractFilter, metaclass=abc.ABCMeta):
|
||||
|
||||
def __init__(self):
|
||||
self._marked = []
|
||||
@ -855,8 +852,7 @@ class RemoveCommentLines(AbstractFilter):
|
||||
py_file.del_line(py_line)
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class AbstractMultiLineCollector(AbstractFilter):
|
||||
class AbstractMultiLineCollector(AbstractFilter, metaclass=abc.ABCMeta):
|
||||
|
||||
def __init__(self):
|
||||
self._comment_stripper = StripTrailingComments()
|
||||
@ -1330,8 +1326,7 @@ class APIReport(object):
|
||||
}
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class AbstractCommand(object):
|
||||
class AbstractCommand(object, metaclass=abc.ABCMeta):
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_parser(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user