Merge "Use six.string_types instead of basestring"
This commit is contained in:
commit
6db0bde36a
@ -19,6 +19,7 @@ import traceback
|
||||
|
||||
from novaclient import exceptions as nova_exc
|
||||
from novaclient.v1_1 import servers
|
||||
import six
|
||||
|
||||
from rally import exceptions
|
||||
from rally import log as logging
|
||||
@ -34,7 +35,7 @@ def resource_is(status):
|
||||
def get_status(resource):
|
||||
# workaround for heat resources - using stack_status instead of status
|
||||
if ((hasattr(resource, "stack_status") and
|
||||
isinstance(resource.stack_status, basestring))):
|
||||
isinstance(resource.stack_status, six.string_types))):
|
||||
return resource.stack_status.upper()
|
||||
return resource.status.upper()
|
||||
|
||||
|
@ -21,6 +21,7 @@ import os
|
||||
import sys
|
||||
|
||||
from oslo.config import cfg
|
||||
import six
|
||||
|
||||
from rally.common.i18n import _
|
||||
from rally.common import version
|
||||
@ -268,7 +269,7 @@ def run(argv, categories):
|
||||
v = getattr(CONF.category, 'action_kwarg_' + k)
|
||||
if v is None:
|
||||
continue
|
||||
if isinstance(v, basestring):
|
||||
if isinstance(v, six.string_types):
|
||||
v = v.decode('utf-8')
|
||||
fn_kwargs[k] = v
|
||||
|
||||
|
@ -63,6 +63,7 @@ import StringIO
|
||||
import time
|
||||
|
||||
import paramiko
|
||||
import six
|
||||
|
||||
from rally.common.i18n import _
|
||||
from rally import log as logging
|
||||
@ -103,7 +104,7 @@ class SSH(object):
|
||||
self._client = False
|
||||
|
||||
def _get_pkey(self, key):
|
||||
if isinstance(key, basestring):
|
||||
if isinstance(key, six.string_types):
|
||||
key = StringIO.StringIO(key)
|
||||
errors = []
|
||||
for key_class in (paramiko.rsakey.RSAKey, paramiko.dsskey.DSSKey):
|
||||
@ -151,7 +152,7 @@ class SSH(object):
|
||||
|
||||
client = self._get_client()
|
||||
|
||||
if isinstance(stdin, basestring):
|
||||
if isinstance(stdin, six.string_types):
|
||||
stdin = StringIO.StringIO(stdin)
|
||||
|
||||
return self._run(client, cmd, stdin=stdin, stdout=stdout,
|
||||
|
@ -77,7 +77,7 @@ class MultihostEngine(engine.EngineFactory):
|
||||
keyval = enumerate(obj)
|
||||
|
||||
for key, value in keyval:
|
||||
if isinstance(value, basestring):
|
||||
if isinstance(value, six.string_types):
|
||||
obj[key] = value.format(controller_ip=self.controller_ip)
|
||||
elif type(value) in (dict, list):
|
||||
self._update_controller_ip(value)
|
||||
|
@ -23,3 +23,4 @@ Rally Specific Commandments
|
||||
* [N324] - Ensure that ``assertEqual(A in/not in B, True/False)`` and ``assertEqual(True/False, A in/not in B)`` are not used with collection contents
|
||||
* [N33x] - Reserved for rules related to Python 3 compatibility
|
||||
* [N330] - Ensure that ``dict.iteritems()`` is not used
|
||||
* [N331] - Ensure that ``basestring`` is not used
|
||||
|
@ -46,6 +46,7 @@ re_assert_equal_in_end_with_true_or_false = re.compile(
|
||||
re_assert_equal_in_start_with_true_or_false = re.compile(
|
||||
r"assertEqual\((True|False), (\w|[][.'\"])+( not)? in (\w|[][.'\", ])+\)")
|
||||
re_iteritems_method = re.compile(r"\.iteritems\(\)")
|
||||
re_basestring_method = re.compile(r"(^|[\s,(\[=])basestring([\s,)\]]|$)")
|
||||
|
||||
|
||||
def _parse_assert_mock_str(line):
|
||||
@ -232,13 +233,25 @@ def check_iteritems_method(logical_line):
|
||||
|
||||
N330
|
||||
"""
|
||||
|
||||
res = re_iteritems_method.search(logical_line)
|
||||
if res:
|
||||
yield (0, "N330: Use six.iteritems(dict) or dict.items() rather than "
|
||||
"dict.iteritems() to iterate a collection.")
|
||||
|
||||
|
||||
def check_basestring_method(logical_line):
|
||||
"""Check if basestring is properly called for compatibility with Python 3
|
||||
|
||||
There is no global variable "basestring" in Python 3.The correct form
|
||||
is six.string_types, instead of basestring.
|
||||
|
||||
N331
|
||||
"""
|
||||
res = re_basestring_method.search(logical_line)
|
||||
if res:
|
||||
yield (0, "N331: Use six.string_types rather than basestring.")
|
||||
|
||||
|
||||
def factory(register):
|
||||
register(check_assert_methods_from_mock)
|
||||
register(check_import_of_logging)
|
||||
@ -250,3 +263,4 @@ def factory(register):
|
||||
register(assert_true_or_false_with_in)
|
||||
register(assert_equal_in)
|
||||
register(check_iteritems_method)
|
||||
register(check_basestring_method)
|
||||
|
@ -14,6 +14,7 @@
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
import six
|
||||
|
||||
from rally.benchmark.scenarios.keystone import utils
|
||||
from tests.unit import fakes
|
||||
@ -26,7 +27,7 @@ class KeystoneUtilsTestCase(test.TestCase):
|
||||
|
||||
def test_RESOURCE_NAME_PREFIX(self):
|
||||
self.assertIsInstance(utils.KeystoneScenario.RESOURCE_NAME_PREFIX,
|
||||
basestring)
|
||||
six.string_types)
|
||||
# Prefix must be long enough to guarantee that resource
|
||||
# to be recognized as created by rally
|
||||
self.assertTrue(
|
||||
|
@ -16,6 +16,7 @@
|
||||
import traceback
|
||||
|
||||
import mock
|
||||
import six
|
||||
|
||||
from rally.benchmark.context import base as base_ctx
|
||||
from rally.benchmark.scenarios import base
|
||||
@ -278,7 +279,8 @@ class ScenarioTestCase(test.TestCase):
|
||||
"Scenario `%s` has wrong context" % scenario)
|
||||
|
||||
def test_RESOURCE_NAME_PREFIX(self):
|
||||
self.assertIsInstance(base.Scenario.RESOURCE_NAME_PREFIX, basestring)
|
||||
self.assertIsInstance(base.Scenario.RESOURCE_NAME_PREFIX,
|
||||
six.string_types)
|
||||
|
||||
def test_RESOURCE_NAME_LENGTH(self):
|
||||
self.assertIsInstance(base.Scenario.RESOURCE_NAME_LENGTH, int)
|
||||
|
@ -344,7 +344,7 @@ class FakeServerManager(FakeManager):
|
||||
pass
|
||||
|
||||
def delete(self, resource):
|
||||
if not isinstance(resource, basestring):
|
||||
if not isinstance(resource, six.string_types):
|
||||
resource = resource.id
|
||||
|
||||
cached = self.get(resource)
|
||||
@ -383,7 +383,7 @@ class FakeImageManager(FakeManager):
|
||||
return self._create(name=name)
|
||||
|
||||
def delete(self, resource):
|
||||
if not isinstance(resource, basestring):
|
||||
if not isinstance(resource, six.string_types):
|
||||
resource = resource.id
|
||||
|
||||
cached = self.get(resource)
|
||||
@ -440,7 +440,7 @@ class FakeKeypairManager(FakeManager):
|
||||
return self._cache(kp)
|
||||
|
||||
def delete(self, resource):
|
||||
if not isinstance(resource, basestring):
|
||||
if not isinstance(resource, six.string_types):
|
||||
resource = resource.id
|
||||
|
||||
cached = self.get(resource)
|
||||
@ -458,7 +458,7 @@ class FakeStackManager(FakeManager):
|
||||
return self._cache(stack)
|
||||
|
||||
def delete(self, resource):
|
||||
if not isinstance(resource, basestring):
|
||||
if not isinstance(resource, six.string_types):
|
||||
resource = resource.id
|
||||
|
||||
cached = self.get(resource)
|
||||
@ -476,7 +476,7 @@ class FakeDomainManager(FakeManager):
|
||||
return self._cache(domain)
|
||||
|
||||
def delete(self, resource):
|
||||
if not isinstance(resource, basestring):
|
||||
if not isinstance(resource, six.string_types):
|
||||
resource = resource.id
|
||||
|
||||
cached = self.get(resource)
|
||||
@ -533,7 +533,7 @@ class FakeSecurityGroupManager(FakeManager):
|
||||
raise nova_exceptions.NotFound('Security Group not found')
|
||||
|
||||
def delete(self, resource):
|
||||
if not isinstance(resource, basestring):
|
||||
if not isinstance(resource, six.string_types):
|
||||
resource = resource.id
|
||||
|
||||
cached = self.get(resource)
|
||||
@ -765,7 +765,7 @@ class FakeDbInstanceManager(FakeManager):
|
||||
return self.__db_instances.values()
|
||||
|
||||
def delete(self, resource):
|
||||
if not isinstance(resource, basestring):
|
||||
if not isinstance(resource, six.string_types):
|
||||
resource = resource.id
|
||||
|
||||
cached = self.get(resource)
|
||||
|
@ -128,6 +128,13 @@ class HackingTestCase(test.TestCase):
|
||||
self.assertEqual(len(list(checks.check_iteritems_method(
|
||||
"dict.items()"))), 0)
|
||||
|
||||
def test_check_basestring_method(self):
|
||||
self.assertEqual(len(list(checks.check_basestring_method(
|
||||
"basestring"))), 1)
|
||||
|
||||
self.assertEqual(len(list(checks.check_basestring_method(
|
||||
"six.string_types"))), 0)
|
||||
|
||||
def test_assert_equal_none(self):
|
||||
self.assertEqual(len(list(checks.assert_equal_none(
|
||||
"self.assertEqual(A, None)"))), 1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user