Remove six usage

six library helped a lot for Py2/Py3 compatibility. Thanks the authors
for the great library.

Since we do not support Python 2, there is no need in six anymore

Change-Id: If5213c088964aa137e6ff5ac2c376a02a980aa72
This commit is contained in:
Andrey Kurilin 2020-02-21 15:50:03 +02:00
parent 2c6a3baec1
commit 1821656002
57 changed files with 212 additions and 320 deletions

View File

@ -252,7 +252,7 @@ class _Task(APIGroup):
# builtin functions (e.g. range()). Unfortunately,
# __builtins__ doesn't return them (when it is not
# main module)
from six.moves import builtins
import builtins
env = jinja2.Environment(
loader=jinja2.FileSystemLoader(template_dir, encoding="utf8"))

View File

@ -25,7 +25,6 @@ import warnings
import jsonschema
import prettytable
import six
import sqlalchemy.exc
from rally import api
@ -211,10 +210,10 @@ def print_dict(obj, fields=None, formatters=None, mixed_case_fields=False,
if isinstance(data, (dict, list)):
data = json.dumps(data)
if wrap > 0:
data = textwrap.fill(six.text_type(data), wrap)
data = textwrap.fill(str(data), wrap)
# if value has a newline, add in multiple rows
# e.g. fault with stacktrace
if (data and isinstance(data, six.string_types)
if (data and isinstance(data, str)
and (r"\n" in data or "\r" in data)):
# "\r" would break the table, so remove it.
if "\r" in data:
@ -623,7 +622,7 @@ def run(argv, categories):
v = getattr(CONF.category, "action_kwarg_" + k)
if v is None:
continue
if isinstance(v, six.string_types):
if isinstance(v, str):
v = encodeutils.safe_decode(v)
fn_kwargs[k] = v

View File

@ -25,7 +25,6 @@ import sys
import webbrowser
import jsonschema
import six
from rally.cli import cliutils
from rally.cli import envutils
@ -179,7 +178,7 @@ class TaskCommands(object):
if raw_args:
try:
data = yaml.safe_load(raw_args)
if isinstance(data, (six.text_type, six.string_types)):
if isinstance(data, str):
raise yaml.ParserError("String '%s' doesn't look like a "
"dictionary." % raw_args)
task_args.update(data)
@ -709,7 +708,7 @@ class TaskCommands(object):
result, OLD_TASK_RESULT_SCHEMA)
except jsonschema.ValidationError as e:
raise FailedToLoadResults(source=task_id,
msg=six.text_type(e))
msg=str(e))
iter_count = 0
failed_iter_count = 0
@ -795,7 +794,7 @@ class TaskCommands(object):
jsonschema.validate(task_result,
api.task.TASK_SCHEMA)
except jsonschema.ValidationError as e:
msg = six.text_type(e)
msg = str(e)
raise exceptions.RallyException(
"ERROR: Invalid task result format\n\n\t%s" % msg)
task_result.setdefault("env_name", "n/a")

View File

@ -17,13 +17,12 @@
from __future__ import print_function
import configparser
import datetime as dt
import json
import os
import webbrowser
from six.moves import configparser
from rally.cli import cliutils
from rally.cli import envutils
from rally.common import fileutils

View File

@ -42,7 +42,6 @@ these objects be simple dictionaries.
import datetime as dt
import functools
import six
import tempfile
import time
@ -101,9 +100,8 @@ def engine_reset():
def serialize(data):
if data is None:
return None
if isinstance(data, (six.integer_types,
six.string_types,
six.text_type,
if isinstance(data, (int,
str,
dt.date,
dt.time,
float,

View File

@ -18,7 +18,6 @@ SQLAlchemy models for rally data.
import datetime as dt
import uuid
import six
import sqlalchemy as sa
import sqlalchemy.ext.declarative
import sqlalchemy.orm # noqa (used as sa.orm)
@ -34,7 +33,7 @@ def UUID():
return str(uuid.uuid4())
class RallyBase(six.Iterator):
class RallyBase(object):
"""Base class for models."""
__table_initialized__ = False
metadata = None

View File

@ -18,7 +18,6 @@ import traceback
from oslo_log import handlers
from oslo_log import log as oslogging
import six
from rally.common import cfg
@ -107,7 +106,7 @@ class RallyContextAdapter(oslogging.KeywordArgumentAdapter):
self.log(log.ERROR, msg, *args, **kwargs)
def exception(self, msg, exc_info=True, *args, **kwargs):
if not isinstance(msg, (six.text_type, six.string_types)):
if not isinstance(msg, str):
caller = self._find_the_caller()
logger = getLogger("%s:%s" % (caller[0], caller[1]))
logger.warning("[%s] %s" % (caller[2], self._exc_msg))

View File

@ -16,7 +16,6 @@
import collections
import copy
import datetime as dt
import six
import uuid
from rally.common import db
@ -451,7 +450,7 @@ class Task(object):
actions_list.extend(action["children"])
for e in result["error"]:
if not isinstance(e, (six.string_types, six.text_type)):
if not isinstance(e, str):
LOG.warning("error value has wrong type '%s', should be 'str'"
% type(e))
return False

View File

@ -19,8 +19,6 @@ import pkg_resources
import pkgutil
import sys
import six
import rally
from rally.common import logging
@ -121,7 +119,7 @@ def import_modules_by_entry_point(_packages=None):
if logging.is_debug():
LOG.exception(msg)
else:
LOG.warning(msg + (": %s" % six.text_type(e)))
LOG.warning(msg + (": %s" % str(e)))
return loaded_packages

View File

@ -33,9 +33,6 @@ def base():
- Plugin lookup - one can easily get all plugins from some base.
Plugin bases by default initialize _default_meta
.. warning:: This decorator should be added the line before
six.add_metaclass if it is used.
"""
def wrapper(cls):
if not issubclass(cls, Plugin):

View File

@ -57,13 +57,14 @@ Eventlet:
"""
import io
import os
import select
import shlex
import socket
import time
import paramiko
import six
from rally.common import logging
from rally import exceptions
@ -95,8 +96,8 @@ class SSH(object):
self._client = False
def _get_pkey(self, key):
if isinstance(key, six.string_types):
key = six.moves.StringIO(key)
if isinstance(key, str):
key = io.StringIO(key)
errors = []
key_pos = key.seek(0, 1)
for key_class in (paramiko.rsakey.RSAKey, paramiko.dsskey.DSSKey):
@ -149,8 +150,8 @@ class SSH(object):
client = self._get_client()
if isinstance(stdin, six.string_types):
stdin = six.moves.StringIO(stdin)
if isinstance(stdin, str):
stdin = io.StringIO(stdin)
return self._run(client, cmd, stdin=stdin, stdout=stdout,
stderr=stderr, raise_on_error=raise_on_error,
@ -160,7 +161,7 @@ class SSH(object):
raise_on_error=True, timeout=3600):
if isinstance(cmd, (list, tuple)):
cmd = " ".join(six.moves.shlex_quote(str(p)) for p in cmd)
cmd = " ".join(shlex.quote(str(p)) for p in cmd)
transport = client.get_transport()
session = transport.open_session()
@ -238,8 +239,8 @@ class SSH(object):
:returns: tuple (exit_status, stdout, stderr)
"""
stdout = six.moves.StringIO()
stderr = six.moves.StringIO()
stdout = io.StringIO()
stderr = io.StringIO()
exit_status, data = self.run(cmd, stderr=stderr, stdout=stdout,
stdin=stdin, timeout=timeout,

View File

@ -21,13 +21,10 @@ import itertools
import math
import os
import six
from rally.common import utils as cutils
@six.add_metaclass(abc.ABCMeta)
class StreamingAlgorithm(object):
class StreamingAlgorithm(object, metaclass=abc.ABCMeta):
"""Base class for streaming computations that scale."""
@abc.abstractmethod

View File

@ -16,8 +16,6 @@
import abc
import traceback
import six
from rally.common import logging
from rally.common.plugin import plugin
from rally import exceptions
@ -38,8 +36,7 @@ def configure(name, platform="default", namespace=None):
@plugin.base()
@six.add_metaclass(abc.ABCMeta)
class Validator(plugin.Plugin):
class Validator(plugin.Plugin, metaclass=abc.ABCMeta):
"""A base class for all validators."""
def __init__(self):

View File

@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from rally.common.plugin import discover
@ -41,7 +39,7 @@ class RallyException(Exception):
super(RallyException, self).__init__(self.msg_fmt % kwargs)
def format_message(self):
return six.text_type(self)
return str(self)
def find_exception(response):

View File

@ -15,7 +15,6 @@
import copy
import requests
import six
from rally.common import logging
from rally import exceptions
@ -95,7 +94,7 @@ class ElasticSearchClient(object):
# in `documents` (action and document itself).
(len(documents) / 2, self.CHUNK_LENGTH / 2))
for pos in six.moves.range(0, len(documents), self.CHUNK_LENGTH):
for pos in range(0, len(documents), self.CHUNK_LENGTH):
data = "\n".join(documents[pos:pos + self.CHUNK_LENGTH]) + "\n"
raw_resp = requests.post(

View File

@ -12,8 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
def _join_keys(first, second):
if not second:
@ -25,7 +23,7 @@ def _join_keys(first, second):
def _process(obj):
if isinstance(obj, (six.string_types, six.binary_type)):
if isinstance(obj, (str, bytes)):
yield "", obj
elif isinstance(obj, dict):
for first, tmp_value in obj.items():

View File

@ -15,11 +15,10 @@
import collections
import multiprocessing
import queue as Queue
import threading
import time
from six.moves import queue as Queue
from rally.common import utils
from rally.common import validation
from rally import consts

View File

@ -15,10 +15,10 @@
import collections
import multiprocessing
import queue as Queue
import threading
import time
from six.moves import queue as Queue
from rally.common import logging
from rally.common import utils

View File

@ -16,7 +16,6 @@ import inspect
import os
import jsonschema
import six
from rally.common import logging
from rally.common import validation
@ -193,7 +192,7 @@ class EnumValidator(validation.Validator):
if self.case_insensitive:
self.values = []
for value in values:
if isinstance(value, (six.text_type, six.string_types)):
if isinstance(value, str):
value = value.lower()
self.values.append(value)
else:
@ -203,7 +202,7 @@ class EnumValidator(validation.Validator):
value = config.get("args", {}).get(self.param_name)
if value:
if self.case_insensitive:
if isinstance(value, (six.text_type, six.string_types)):
if isinstance(value, str):
value = value.lower()
if value not in self.values:

View File

@ -16,8 +16,6 @@
import abc
import collections
import six
from rally.common import cfg
from rally.common import logging
from rally.common.plugin import plugin
@ -86,9 +84,9 @@ def add_default_context(name, config):
# TODO(andreykurilin): BaseContext is used by Task and Verification and should
# be moved to common place
@six.add_metaclass(abc.ABCMeta)
class BaseContext(plugin.Plugin, functional.FunctionalMixin,
utils.RandomNameGeneratorMixin, atomic.ActionTimerMixin):
utils.RandomNameGeneratorMixin, atomic.ActionTimerMixin,
metaclass=abc.ABCMeta):
"""This class is a factory for context classes.
Every context class should be a subclass of this class and implement

View File

@ -22,7 +22,6 @@ system by connection string.
import abc
import jsonschema
import six
from rally.common import logging
from rally.common.plugin import plugin
@ -56,8 +55,8 @@ REPORT_RESPONSE_SCHEMA = {
@plugin.base()
@six.add_metaclass(abc.ABCMeta)
class TaskExporter(plugin.Plugin, validation.ValidatablePluginMixin):
class TaskExporter(plugin.Plugin, validation.ValidatablePluginMixin,
metaclass=abc.ABCMeta):
"""Plugin base for exporting tasks results to different systems&formats.
This type of plugins is designed to provide the way to present results in

View File

@ -17,8 +17,6 @@ import abc
import collections
import threading
import six
from rally.common import logging
from rally.common.plugin import plugin
from rally.common import utils as rutils
@ -110,8 +108,8 @@ class HookExecutor(object):
@validation.add_default("jsonschema")
@plugin.base()
@six.add_metaclass(abc.ABCMeta)
class HookAction(plugin.Plugin, validation.ValidatablePluginMixin):
class HookAction(plugin.Plugin, validation.ValidatablePluginMixin,
metaclass=abc.ABCMeta):
"""Factory for hook classes."""
CONFIG_SCHEMA = {"type": "null"}
@ -207,8 +205,8 @@ class HookAction(plugin.Plugin, validation.ValidatablePluginMixin):
@validation.add_default("jsonschema")
@plugin.base()
@six.add_metaclass(abc.ABCMeta)
class HookTrigger(plugin.Plugin, validation.ValidatablePluginMixin):
class HookTrigger(plugin.Plugin, validation.ValidatablePluginMixin,
metaclass=abc.ABCMeta):
"""Factory for hook trigger classes."""
CONFIG_SCHEMA = {"type": "null"}

View File

@ -16,7 +16,6 @@ import abc
import bisect
import collections
import math
import six
from rally.common.plugin import plugin
from rally.common import streaming_algorithms as streaming
@ -25,8 +24,7 @@ from rally.task.processing import utils
@plugin.base()
@six.add_metaclass(abc.ABCMeta)
class Chart(plugin.Plugin):
class Chart(plugin.Plugin, metaclass=abc.ABCMeta):
"""Base class for charts.
This is a base for all plugins that prepare data for specific charts
@ -176,7 +174,7 @@ class LoadProfileChart(Chart):
self.step = self._duration / float(scale)
self._time_axis = [self.step * x
for x in six.moves.range(int(scale))
for x in range(int(scale))
if (self.step * x) < self._duration]
self._time_axis.append(self._duration)
self._running = [0] * len(self._time_axis)
@ -298,8 +296,7 @@ class AtomicHistogramChart(HistogramChart):
return self._fix_atomic_actions(atomic_actions)
@six.add_metaclass(abc.ABCMeta)
class Table(Chart):
class Table(Chart, metaclass=abc.ABCMeta):
"""Base class for tables.
Each Table subclass represents HTML table which can be easily rendered in
@ -883,12 +880,12 @@ class OutputEmbeddedExternalChart(OutputChart):
_OUTPUT_SCHEMA = {
"key_types": {
"title": six.string_types,
"description": six.string_types,
"chart_plugin": six.string_types,
"title": str,
"description": str,
"chart_plugin": str,
"data": (list, dict),
"label": six.string_types,
"axis_label": six.string_types},
"label": str,
"axis_label": str},
"required": ["title", "chart_plugin", "data"]}

View File

@ -19,8 +19,6 @@ import hashlib
import itertools
import json
import six
from rally.common import objects
from rally.common.plugin import plugin
from rally.common import version
@ -270,7 +268,7 @@ class Trends(object):
"""Convert object into string."""
if obj is None:
return "None"
elif isinstance(obj, six.string_types + (int, float)):
elif isinstance(obj, (str, int, float)):
return str(obj).strip()
elif isinstance(obj, (list, tuple)):
return ",".join(sorted([self._to_str(v) for v in obj]))
@ -388,7 +386,7 @@ class Trends(object):
("avg", charts.streaming.MeanComputation())):
for k, v in trend["durations"]:
for i in v:
if isinstance(i[1], (float,) + six.integer_types):
if isinstance(i[1], (float, int)):
comp.add(i[1])
trend["stat"][stat] = comp.result()

View File

@ -19,8 +19,6 @@ import copy
import multiprocessing
import time
import six
from rally.common import logging
from rally.common.plugin import plugin
from rally.common import utils as rutils
@ -105,8 +103,8 @@ def _log_worker_info(**info):
@validation.add_default("jsonschema")
@plugin.base()
@six.add_metaclass(abc.ABCMeta)
class ScenarioRunner(plugin.Plugin, validation.ValidatablePluginMixin):
class ScenarioRunner(plugin.Plugin, validation.ValidatablePluginMixin,
metaclass=abc.ABCMeta):
"""Base class for all scenario runners.
Scenario runner is an entity that implements a certain strategy of

View File

@ -14,8 +14,6 @@
import functools
import inspect
import six
from rally.common.plugin import discover
from rally.common.plugin import meta
from rally import exceptions
@ -156,8 +154,7 @@ class ServiceMeta(type):
(cls.__name__, ", ".join(not_implemented_apis)))
@six.add_metaclass(ServiceMeta)
class Service(meta.MetaMixin):
class Service(meta.MetaMixin, metaclass=ServiceMeta):
"""Base help class for Cloud Services(for example OpenStack services).
A simple example of implementation:

View File

@ -20,8 +20,7 @@ with contracted values such as maximum error rate or minimum response time.
"""
import abc
import six
import itertools
from rally.common.plugin import plugin
from rally.common import validation
@ -65,11 +64,10 @@ class SLAChecker(object):
return all([self_sla.merge(other_sla)
for self_sla, other_sla
in six.moves.zip(
self.sla_criteria, other.sla_criteria)])
in zip(self.sla_criteria, other.sla_criteria)])
def _validate_sla_types(self, other):
for self_sla, other_sla in six.moves.zip_longest(
for self_sla, other_sla in itertools.zip_longest(
self.sla_criteria, other.sla_criteria):
self_sla.validate_type(other_sla)
@ -113,8 +111,8 @@ class SLAChecker(object):
@validation.add_default("jsonschema")
@plugin.base()
@six.add_metaclass(abc.ABCMeta)
class SLA(plugin.Plugin, validation.ValidatablePluginMixin):
class SLA(plugin.Plugin, validation.ValidatablePluginMixin,
metaclass=abc.ABCMeta):
"""Factory for criteria classes."""
CONFIG_SCHEMA = {"type": "null"}

View File

@ -16,7 +16,6 @@ import collections
import copy
import jsonschema
import six
from rally.common import cfg
from rally.common import logging
@ -332,7 +331,7 @@ class TaskConfig(object):
@staticmethod
def _check_title(title, identifier=None):
identifier = " of %s" % identifier if identifier else ""
if not isinstance(title, (six.text_type, six.string_types)):
if not isinstance(title, str):
raise exceptions.InvalidTaskException(
"Title%s should be a string, but '%s' is found." %
(identifier, type(title).__name__))
@ -353,7 +352,7 @@ class TaskConfig(object):
% (identifier, type(tags).__name__))
for tag in tags:
if not isinstance(tag, (six.text_type, six.string_types)):
if not isinstance(tag, str):
raise exceptions.InvalidTaskException(
"Tag '%s'%s should be a string, but '%s' is found." %
(tag, identifier, type(tag).__name__))

View File

@ -18,8 +18,6 @@ import copy
import operator
import re
import six
from rally.common import logging
from rally.common.plugin import plugin
from rally import exceptions
@ -91,8 +89,7 @@ def preprocess(name, context, args):
@plugin.base()
@six.add_metaclass(abc.ABCMeta)
class ResourceType(plugin.Plugin):
class ResourceType(plugin.Plugin, metaclass=abc.ABCMeta):
"""A helper plugin for pre-processing input data of resources."""
def __init__(self, context, cache=None):

View File

@ -19,7 +19,6 @@ import time
import traceback
import jsonschema
import six
from rally.common import logging
from rally import consts
@ -42,13 +41,13 @@ def get_status(resource, status_attr="status"):
for s_attr in ["stack_status", "state", status_attr]:
status = getattr(resource, s_attr, None)
if isinstance(status, six.string_types):
if isinstance(status, str):
return status.upper()
# Dict case
if (isinstance(resource, dict)
and status_attr in resource.keys()
and isinstance(resource[status_attr], six.string_types)):
and isinstance(resource[status_attr], str)):
return resource[status_attr].upper()
return "NONE"

View File

@ -14,8 +14,6 @@
import sys
import six
def _get_default_encoding():
return sys.stdin.encoding or sys.getdefaultencoding()
@ -31,10 +29,10 @@ def safe_decode(text, incoming=None, errors="strict"):
:returns: text or a unicode `incoming` encoded representation of it.
:raises TypeError: If text is not an instance of str
"""
if not isinstance(text, (six.string_types, six.binary_type)):
if not isinstance(text, (str, bytes)):
raise TypeError("%s can't be decoded" % type(text))
if isinstance(text, six.text_type):
if isinstance(text, str):
return text
if not incoming:
@ -74,7 +72,7 @@ def safe_encode(text, incoming=None, encoding="utf-8", errors="strict"):
See also to_utf8() function which is simpler and don't depend on
the locale encoding.
"""
if not isinstance(text, (six.string_types, six.binary_type)):
if not isinstance(text, (str, bytes)):
raise TypeError("%s can't be encoded" % type(text))
if not incoming:
@ -86,7 +84,7 @@ def safe_encode(text, incoming=None, encoding="utf-8", errors="strict"):
if hasattr(encoding, "lower"):
encoding = encoding.lower()
if isinstance(text, six.text_type):
if isinstance(text, str):
return text.encode(encoding, errors)
elif text and encoding != incoming:
# Decode text before encoding it with `encoding`

View File

@ -14,8 +14,6 @@
import uuid
import six
def _format_uuid_string(string):
return (string.replace("urn:", "")
@ -63,8 +61,8 @@ def bool_from_string(subject, strict=False, default=False):
"""
if isinstance(subject, bool):
return subject
if not isinstance(subject, six.string_types):
subject = six.text_type(subject)
if not isinstance(subject, str):
subject = str(subject)
lowered = subject.strip().lower()

View File

@ -14,13 +14,13 @@
import abc
import inspect
import io
import os
import re
import shutil
import sys
import pkg_resources
import six
from rally.common.io import subunit_v2
from rally.common import logging
@ -68,8 +68,7 @@ def configure(name, platform="default", default_repo=None,
@plugin.base()
@six.add_metaclass(abc.ABCMeta)
class VerifierManager(plugin.Plugin):
class VerifierManager(plugin.Plugin, metaclass=abc.ABCMeta):
"""Verifier base class.
This class provides an interface for operating specific tool.
@ -159,7 +158,7 @@ class VerifierManager(plugin.Plugin):
# NOTE(andreykurilin): By default we do not use jsonschema here.
# So it cannot be extended by inheritors => requires duplication.
if "pattern" in args:
if not isinstance(args["pattern"], six.string_types):
if not isinstance(args["pattern"], str):
raise exceptions.ValidationError(
"'pattern' argument should be a string.")
if "concurrency" in args:
@ -392,7 +391,7 @@ class VerifierManager(plugin.Plugin):
def parse_results(self, results_data):
"""Parse subunit results data of a test run."""
# TODO(andreykurilin): Support more formats.
return subunit_v2.parse(six.StringIO(results_data))
return subunit_v2.parse(io.StringIO(results_data))
@abc.abstractmethod
def run(self, context):

View File

@ -22,7 +22,6 @@ system or formats.
import abc
import jsonschema
import six
from rally.common.plugin import plugin
from rally import consts
@ -53,8 +52,7 @@ REPORT_RESPONSE_SCHEMA = {
@plugin.base()
@six.add_metaclass(abc.ABCMeta)
class VerificationReporter(plugin.Plugin):
class VerificationReporter(plugin.Plugin, metaclass=abc.ABCMeta):
"""Base class for all reporters for verifications."""
def __init__(self, verifications, output_destination):

View File

@ -12,12 +12,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import configparser
import io
import os
import subprocess
import six
from six.moves import configparser
from rally.common import logging
from rally.utils import encodeutils
@ -80,7 +79,7 @@ def extend_configfile(extra_options, conf_path):
with open(conf_path, "w") as configfile:
conf_object.write(configfile)
raw_conf = six.StringIO()
raw_conf = io.StringIO()
conf_object.write(raw_conf)
return raw_conf.getvalue()

View File

@ -20,5 +20,4 @@ PyYAML # MIT
python-subunit
requests!=2.20.0 # Apache License, Version 2.0
SQLAlchemy!=1.1.5,!=1.1.6,!=1.1.7,!=1.1.8 # MIT
six # MIT
virtualenv!=16.3.0 # MIT

View File

@ -15,7 +15,6 @@
import subprocess
import six
import testtools
from rally.utils import encodeutils
@ -31,12 +30,7 @@ class CLITestCase(testtools.TestCase):
else:
self.fail("It should ve non-zero exit code.")
# NOTE(andreykurilin): we should have the same errors...
if six.PY2:
self.assertIn("too few arguments", output)
else:
self.assertIn("the following arguments are required: category",
output)
self.assertIn("the following arguments are required: category", output)
def test_version_cli(self):
output = encodeutils.safe_decode(

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import configparser
import copy
import errno
import inspect
@ -22,8 +23,6 @@ import shutil
import subprocess
import tempfile
from six.moves import configparser
from rally.utils import encodeutils

View File

@ -1,39 +0,0 @@
Rally Style Commandments
========================
- Step 1: Read the OpenStack Style Commandments
https://docs.openstack.org/hacking/latest/
- Step 2: Read on
Rally Specific Commandments
---------------------------
* [N30x] - Reserved for rules related to ``mock`` library
* [N301] - Ensure that ``assert_*`` methods from ``mock`` library is used correctly
* [N302] - Ensure that nonexistent "assert_called" is not used
* [N303] - Ensure that nonexistent "assert_called_once" is not used
* [N310-N314] - Reserved for rules related to logging
* [N310] - Ensure that ``rally.common.log`` is used as logging module
* [N311] - Validate that debug level logs are not translated
* [N312] - Validate correctness of debug on check.
* [N313] - Validate that LOG.warning is used instead of deprecated LOG.warn.
* [N32x] - Reserved for rules related to assert* methods
* [N320] - Ensure that ``assertTrue(isinstance(A, B))`` is not used
* [N321] - Ensure that ``assertEqual(type(A), B)`` is not used
* [N322] - Ensure that ``assertEqual(A, None)`` and ``assertEqual(None, A)`` are not used
* [N323] - Ensure that ``assertTrue/assertFalse(A in/not in B)`` are not used with collection contents
* [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
* [N325] - Ensure that ``assertNotEqual(A, None)`` and ``assertNotEqual(None, A)`` are not used
* [N326] - Ensure that ``assertEqual(A, True/False)`` and ``assertEqual(True/False, A)`` are not used
* [N340] - Ensure that we are importing always ``from rally import objects``
* [N341] - Ensure that we are importing oslo_xyz packages instead of deprecated oslo.xyz ones
* [N342] - Ensure that we load opts from correct paths only
* [N350] - Ensure that single quotes are not used
* [N351] - Ensure that data structs (i.e Lists and Dicts) are declared literally rather than using constructors
* [N352] - Ensure that string formatting only uses a mapping if multiple mapping keys are used.
* [N353] - Ensure that unicode() function is not uset because of absence in py3
* [N354] - Ensure that ``:raises: Exception`` is not used
* [N355] - Ensure that we use only "new-style" Python classes
* [N356] - Ensure using ``dt`` as alias for ``datetime``
* [N360-N370] - Reserved for rules related to CLI
* [N360] - Ensure that CLI modules do not use ``rally.common.db``
* [N361] - Ensure that CLI modules do not use ``rally.common.objects``

View File

@ -507,7 +507,7 @@ def check_using_unicode(logical_line, physical_line, filename):
if re.search(r"\bunicode\(", logical_line):
yield (0, "N353 'unicode' function is absent in python3. Please "
"use 'six.text_type' instead.")
"use 'str' instead.")
def check_raises(logical_line, physical_line, filename):
@ -547,16 +547,6 @@ def check_datetime_alias(logical_line, physical_line, filename):
yield 0, "N356 Please use ``dt`` as alias for ``datetime``."
@skip_ignored_lines
def check_no_six_iteritems(logical_line, physical_line, filename):
"""Check no six.iteritems
N357
"""
if re.search(r"\six.iteritems\(\)", logical_line):
yield 0, "N357 Use dict.items() instead of six.iteritems()"
@skip_ignored_lines
def check_db_imports_in_cli(logical_line, physical_line, filename):
"""Ensure that CLI modules do not use ``rally.common.db``
@ -632,6 +622,5 @@ def factory(register):
register(check_db_imports_in_cli)
register(check_objects_imports_in_cli)
register(check_old_type_class)
register(check_no_six_iteritems)
register(check_log_warn)
register(check_opts_import_path)

View File

@ -14,10 +14,10 @@
# under the License.
import collections
import io
import os
import mock
import six
from rally.cli import cliutils
from rally.cli.commands import deployment
@ -363,7 +363,7 @@ class DeploymentCommandsTestCase(test.TestCase):
@mock.patch("rally.cli.commands.deployment.logging.is_debug",
return_value=False)
@mock.patch("sys.stdout", new_callable=six.StringIO)
@mock.patch("sys.stdout", new_callable=io.StringIO)
def test_deployment_check(self, mock_stdout, mock_is_debug):
deployment_uuid = "some"
# OrderedDict is used to predict the order of platfrom in output
@ -435,7 +435,7 @@ class DeploymentCommandsTestCase(test.TestCase):
@mock.patch("rally.cli.commands.deployment.logging.is_debug",
return_value=True)
@mock.patch("sys.stdout", new_callable=six.StringIO)
@mock.patch("sys.stdout", new_callable=io.StringIO)
def test_deployment_check_is_debug_turned_on(self, mock_stdout,
mock_is_debug):
deployment_uuid = "some"

View File

@ -13,9 +13,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import io
import ddt
import mock
import six
from rally.cli import cliutils
from rally.cli.commands import plugin as plugin_cmd
@ -65,7 +66,7 @@ class PluginCommandsTestCase(test.TestCase):
self.Plugin3.unregister()
def test__print_plugins_list(self):
out = six.StringIO()
out = io.StringIO()
original_print_list = cliutils.print_list
def print_list(*args, **kwargs):

View File

@ -14,13 +14,13 @@
# under the License.
import datetime as dt
import io
import json
import os.path
import sys
import ddt
import mock
import six
import rally
from rally import api
@ -707,7 +707,7 @@ class TaskCommandsTestCase(test.TestCase):
"status": consts.TaskStatus.RUNNING,
"tags": ["d"],
"deployment_name": "some_name"}]
out = six.StringIO()
out = io.StringIO()
with mock.patch.object(sys, "stdout", new=out):
self.task.list(self.fake_api, status="running", uuids_only=True)
self.assertEqual("a\n", out.getvalue())
@ -754,7 +754,7 @@ class TaskCommandsTestCase(test.TestCase):
print_list_calls = []
def print_list(*args, **kwargs):
print_list_calls.append(six.StringIO())
print_list_calls.append(io.StringIO())
kwargs["out"] = print_list_calls[-1]
original_print_list(*args, **kwargs)

View File

@ -13,10 +13,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import io
import tempfile
import mock
import six
from rally.cli import cliutils
from rally.cli.commands import verify
@ -195,7 +195,7 @@ class VerifyCommandsTestCase(test.TestCase):
print_dict_calls = []
def print_dict(*args, **kwargs):
print_dict_calls.append(six.StringIO())
print_dict_calls.append(io.StringIO())
kwargs["out"] = print_dict_calls[-1]
original_print_dict(*args, **kwargs)
@ -518,7 +518,7 @@ class VerifyCommandsTestCase(test.TestCase):
print_dict_calls = []
def print_dict(*args, **kwargs):
print_dict_calls.append(six.StringIO())
print_dict_calls.append(io.StringIO())
kwargs["out"] = print_dict_calls[-1]
original_print_dict(*args, **kwargs)

View File

@ -13,9 +13,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import io
import ddt
import mock
import six
import sqlalchemy.exc
from rally.cli import cliutils
@ -47,7 +48,7 @@ class CliUtilsTestCase(test.TestCase):
super(CliUtilsTestCase, self).tearDown()
def test_print_dict(self):
out = six.StringIO()
out = io.StringIO()
dict = {"key": "value"}
cliutils.print_dict(dict, out=out)
self.assertEqual("+----------+-------+\n"
@ -58,7 +59,7 @@ class CliUtilsTestCase(test.TestCase):
out.getvalue())
def test_print_dict_wrap(self):
out = six.StringIO()
out = io.StringIO()
dict = {"key1": "not wrapped",
"key2": "this will be wrapped"}
cliutils.print_dict(dict, wrap=16, out=out)
@ -72,7 +73,7 @@ class CliUtilsTestCase(test.TestCase):
out.getvalue())
def test_print_dict_formatters_and_fields(self):
out = six.StringIO()
out = io.StringIO()
dict = {"key1": "value",
"key2": "Value",
"key3": "vvv"}
@ -90,7 +91,7 @@ class CliUtilsTestCase(test.TestCase):
out.getvalue())
def test_print_dict_header(self):
out = six.StringIO()
out = io.StringIO()
dict = {"key": "value"}
cliutils.print_dict(dict, table_label="Some Table", print_header=False,
out=out)
@ -122,7 +123,7 @@ class CliUtilsTestCase(test.TestCase):
def foobar():
pass
out = six.StringIO()
out = io.StringIO()
formatters = {"c": lambda x: "a + b = %s" % x.c}
cliutils.print_dict(SomeStruct(1, 2), formatters=formatters, out=out)
self.assertEqual("+----------+-----------+\n"
@ -135,7 +136,7 @@ class CliUtilsTestCase(test.TestCase):
out.getvalue())
def test_print_dict_with_spec_chars(self):
out = six.StringIO()
out = io.StringIO()
dict = {"key": "line1\r\nline2"}
cliutils.print_dict(dict, out=out)
self.assertEqual("+----------+-------+\n"
@ -441,13 +442,13 @@ class CliUtilsTestCase(test.TestCase):
"+---+---+")})
@ddt.unpack
def test_print_list(self, args, kwargs, expected):
out = six.moves.StringIO()
out = io.StringIO()
kwargs["out"] = out
cliutils.print_list(*args, **kwargs)
self.assertEqual(expected, out.getvalue().strip())
def test_print_list_raises(self):
out = six.moves.StringIO()
out = io.StringIO()
self.assertRaisesRegex(
ValueError,
"Field labels list.*has different number "

View File

@ -17,6 +17,7 @@
import copy
import datetime as dt
import importlib
import iso8601
import json
import pickle
@ -28,7 +29,6 @@ import jsonschema
import mock
from oslo_db.sqlalchemy import test_migrations
from oslo_db.sqlalchemy import utils as db_utils
import six
import sqlalchemy as sa
import rally
@ -40,6 +40,10 @@ from tests.unit.common.db import test_migrations_base
from tests.unit import test as rtest
def b(s):
return s.encode("latin-1")
@context.configure(name="users", platform="testing", order=2)
class UsersContext(context.Context):
def setup(self):
@ -123,7 +127,7 @@ class MigrationTestCase(rtest.DBTestCase,
def setUp(self):
# we change DB metadata in tests so we reload
# models to refresh the metadata to it's original state
six.moves.reload_module(rally.common.db.models)
importlib.reload(rally.common.db.models)
super(MigrationTestCase, self).setUp()
self.alembic_config = db.schema._alembic_config()
self.engine = db.get_engine()
@ -352,8 +356,8 @@ class MigrationWalkTestCase(rtest.DBTestCase,
[{"uuid": deployment, "name": deployment,
"config": conf,
"enum_deployments_status": deployment_status,
"credentials": six.b(json.dumps([])),
"users": six.b(json.dumps([]))
"credentials": b(json.dumps([])),
"users": b(json.dumps([]))
}])
_OLD_DEPLOYMENT_SCHEMA = {
@ -494,11 +498,11 @@ class MigrationWalkTestCase(rtest.DBTestCase,
deployment_table.insert(),
[{"uuid": self._08e1515a576c_deployment_uuid,
"name": self._08e1515a576c_deployment_uuid,
"config": six.b("{}"),
"config": b("{}"),
"enum_deployments_status":
consts.DeployStatus.DEPLOY_FINISHED,
"credentials": six.b(json.dumps([])),
"users": six.b(json.dumps([]))
"credentials": b(json.dumps([])),
"users": b(json.dumps([]))
}])
for i in range(0, len(self._08e1515a576c_logs)):
log = json.dumps(self._08e1515a576c_logs[i]["pre"])
@ -553,8 +557,8 @@ class MigrationWalkTestCase(rtest.DBTestCase,
"name": self._e654a0648db0_deployment_uuid,
"config": "{}",
"enum_deployments_status": consts.DeployStatus.DEPLOY_INIT,
"credentials": six.b(json.dumps([])),
"users": six.b(json.dumps([]))
"credentials": b(json.dumps([])),
"users": b(json.dumps([]))
}]
)
@ -803,8 +807,8 @@ class MigrationWalkTestCase(rtest.DBTestCase,
"name": "my_deployment",
"config": json.dumps(conf),
"enum_deployments_status": deployment_status,
"credentials": six.b(json.dumps([])),
"users": six.b(json.dumps([]))
"credentials": b(json.dumps([])),
"users": b(json.dumps([]))
}])
# create task
@ -904,8 +908,8 @@ class MigrationWalkTestCase(rtest.DBTestCase,
[{"uuid": deployment, "name": deployment,
"config": conf,
"enum_deployments_status": deployment_status,
"credentials": six.b(json.dumps([])),
"users": six.b(json.dumps([]))
"credentials": b(json.dumps([])),
"users": b(json.dumps([]))
}])
def _check_32fada9b2fde(self, engine, data):
@ -1004,10 +1008,10 @@ class MigrationWalkTestCase(rtest.DBTestCase,
deployment_table.insert(),
[{"uuid": self._484cd9413e66_deployment_uuid,
"name": self._484cd9413e66_deployment_uuid,
"config": six.b(json.dumps([])),
"config": b(json.dumps([])),
"enum_deployments_status": deployment_status,
"credentials": six.b(json.dumps([])),
"users": six.b(json.dumps([]))
"credentials": b(json.dumps([])),
"users": b(json.dumps([]))
}])
for i in range(len(self._484cd9413e66_verifications)):
@ -1143,10 +1147,10 @@ class MigrationWalkTestCase(rtest.DBTestCase,
deployment_table.insert(),
[{"uuid": self._37fdbb373e8d_deployment_uuid,
"name": self._37fdbb373e8d_deployment_uuid,
"config": six.b(json.dumps([])),
"config": b(json.dumps([])),
"enum_deployments_status": deployment_status,
"credentials": six.b(json.dumps([])),
"users": six.b(json.dumps([]))
"credentials": b(json.dumps([])),
"users": b(json.dumps([]))
}])
conn.execute(
@ -1277,10 +1281,10 @@ class MigrationWalkTestCase(rtest.DBTestCase,
deployment_table.insert(),
[{"uuid": self._f33f4610dcda_deployment_uuid,
"name": self._f33f4610dcda_deployment_uuid,
"config": six.b(json.dumps([])),
"config": b(json.dumps([])),
"enum_deployments_status": deployment_status,
"credentials": six.b(json.dumps([])),
"users": six.b(json.dumps([]))
"credentials": b(json.dumps([])),
"users": b(json.dumps([]))
}])
conn.execute(
@ -1362,11 +1366,11 @@ class MigrationWalkTestCase(rtest.DBTestCase,
deployment_table.insert(),
[{"uuid": self._4ef544102ba7_deployment_uuid,
"name": self._4ef544102ba7_deployment_uuid,
"config": six.b(json.dumps([])),
"config": b(json.dumps([])),
"enum_deployments_status":
consts.DeployStatus.DEPLOY_FINISHED,
"credentials": six.b(json.dumps([])),
"users": six.b(json.dumps([]))
"credentials": b(json.dumps([])),
"users": b(json.dumps([]))
}])
task_table = db_utils.get_table(engine, "tasks")
@ -1531,8 +1535,8 @@ class MigrationWalkTestCase(rtest.DBTestCase,
"name": str(uuid.uuid4()),
"config": "{}",
"enum_deployments_status": consts.DeployStatus.DEPLOY_INIT,
"credentials": six.b(json.dumps([])),
"users": six.b(json.dumps([]))
"credentials": b(json.dumps([])),
"users": b(json.dumps([]))
}]
)
@ -1543,7 +1547,7 @@ class MigrationWalkTestCase(rtest.DBTestCase,
"created_at": dt.datetime.utcnow(),
"updated_at": dt.datetime.utcnow(),
"status": consts.TaskStatus.FINISHED,
"validation_result": six.b(json.dumps({})),
"validation_result": b(json.dumps({})),
"deployment_uuid": deployment_uuid
}]
)
@ -1556,8 +1560,8 @@ class MigrationWalkTestCase(rtest.DBTestCase,
"created_at": dt.datetime.utcnow(),
"updated_at": dt.datetime.utcnow(),
"task_uuid": self._35fe16d4ab1c_task_uuid,
"context": six.b(json.dumps([])),
"sla": six.b(json.dumps([])),
"context": b(json.dumps([])),
"sla": b(json.dumps([])),
"run_in_parallel": False
}]
)
@ -1652,8 +1656,8 @@ class MigrationWalkTestCase(rtest.DBTestCase,
"name": str(uuid.uuid4()),
"config": "{}",
"enum_deployments_status": consts.DeployStatus.DEPLOY_INIT,
"credentials": six.b(json.dumps([])),
"users": six.b(json.dumps([]))
"credentials": b(json.dumps([])),
"users": b(json.dumps([]))
}]
)
@ -1664,7 +1668,7 @@ class MigrationWalkTestCase(rtest.DBTestCase,
"created_at": dt.datetime.utcnow(),
"updated_at": dt.datetime.utcnow(),
"status": consts.TaskStatus.FINISHED,
"validation_result": six.b(json.dumps({})),
"validation_result": b(json.dumps({})),
"deployment_uuid": self._7948b83229f6_deployment_uuid
}]
)
@ -1676,8 +1680,8 @@ class MigrationWalkTestCase(rtest.DBTestCase,
"created_at": dt.datetime.utcnow(),
"updated_at": dt.datetime.utcnow(),
"task_uuid": self._7948b83229f6_task_uuid,
"context": six.b(json.dumps([])),
"sla": six.b(json.dumps([])),
"context": b(json.dumps([])),
"sla": b(json.dumps([])),
"run_in_parallel": False
}]
)
@ -1724,7 +1728,7 @@ class MigrationWalkTestCase(rtest.DBTestCase,
"failed_iteration_count": 0,
"chunk_size": 0,
"compressed_chunk_size": 0,
"chunk_data": six.b(json.dumps([]))
"chunk_data": b(json.dumps([]))
}]
)
@ -1806,8 +1810,8 @@ class MigrationWalkTestCase(rtest.DBTestCase,
"name": str(uuid.uuid4()),
"config": "{}",
"enum_deployments_status": consts.DeployStatus.DEPLOY_INIT,
"credentials": six.b(json.dumps([])),
"users": six.b(json.dumps([]))
"credentials": b(json.dumps([])),
"users": b(json.dumps([]))
}]
)
@ -1818,7 +1822,7 @@ class MigrationWalkTestCase(rtest.DBTestCase,
"created_at": dt.datetime.utcnow(),
"updated_at": dt.datetime.utcnow(),
"status": consts.TaskStatus.FINISHED,
"validation_result": six.b(json.dumps({})),
"validation_result": b(json.dumps({})),
"deployment_uuid": self._046a38742e89_deployment_uuid
}]
)
@ -1830,8 +1834,8 @@ class MigrationWalkTestCase(rtest.DBTestCase,
"created_at": dt.datetime.utcnow(),
"updated_at": dt.datetime.utcnow(),
"task_uuid": self._046a38742e89_task_uuid,
"context": six.b(json.dumps([])),
"sla": six.b(json.dumps([])),
"context": b(json.dumps([])),
"sla": b(json.dumps([])),
"run_in_parallel": False
}]
)
@ -2061,8 +2065,8 @@ class MigrationWalkTestCase(rtest.DBTestCase,
"name": str(uuid.uuid4()),
"config": "{}",
"enum_deployments_status": consts.DeployStatus.DEPLOY_INIT,
"credentials": six.b(json.dumps([])),
"users": six.b(json.dumps([]))
"credentials": b(json.dumps([])),
"users": b(json.dumps([]))
}]
)
@ -2073,7 +2077,7 @@ class MigrationWalkTestCase(rtest.DBTestCase,
"created_at": dt.datetime.utcnow(),
"updated_at": dt.datetime.utcnow(),
"status": consts.TaskStatus.FINISHED,
"validation_result": six.b(json.dumps({})),
"validation_result": b(json.dumps({})),
"deployment_uuid": self._4394bdc32cfd_deployment_uuid
}]
)
@ -2085,8 +2089,8 @@ class MigrationWalkTestCase(rtest.DBTestCase,
"created_at": dt.datetime.utcnow(),
"updated_at": dt.datetime.utcnow(),
"task_uuid": task_uuid,
"context": six.b(json.dumps([])),
"sla": six.b(json.dumps([])),
"context": b(json.dumps([])),
"sla": b(json.dumps([])),
"run_in_parallel": False
}]
)
@ -2236,8 +2240,8 @@ class MigrationWalkTestCase(rtest.DBTestCase,
"name": str(uuid.uuid4()),
"config": "{}",
"enum_deployments_status": consts.DeployStatus.DEPLOY_INIT,
"credentials": six.b(json.dumps([])),
"users": six.b(json.dumps([]))
"credentials": b(json.dumps([])),
"users": b(json.dumps([]))
}]
)
@ -2248,7 +2252,7 @@ class MigrationWalkTestCase(rtest.DBTestCase,
"created_at": dt.datetime.utcnow(),
"updated_at": dt.datetime.utcnow(),
"status": consts.TaskStatus.FINISHED,
"validation_result": six.b(json.dumps({})),
"validation_result": b(json.dumps({})),
"deployment_uuid": self._046a38742e89_deployment_uuid
}]
)
@ -2260,8 +2264,8 @@ class MigrationWalkTestCase(rtest.DBTestCase,
"created_at": dt.datetime.utcnow(),
"updated_at": dt.datetime.utcnow(),
"task_uuid": self._dc46687661df_task_uuid,
"context": six.b(json.dumps([])),
"sla": six.b(json.dumps([])),
"context": b(json.dumps([])),
"sla": b(json.dumps([])),
"run_in_parallel": False
}]
)
@ -2275,12 +2279,12 @@ class MigrationWalkTestCase(rtest.DBTestCase,
"created_at": w["created_at"],
"updated_at": dt.datetime.utcnow(),
"position": 0,
"runner": six.b(json.dumps([])),
"runner": b(json.dumps([])),
"runner_type": "",
"context": json.dumps(w["context"]),
"context_execution": "foo",
"statistics": "",
"hooks": six.b(json.dumps([])),
"hooks": b(json.dumps([])),
"sla": "",
"sla_results": "",
"args": "",
@ -2421,9 +2425,9 @@ class MigrationWalkTestCase(rtest.DBTestCase,
"name": str(uuid.uuid4()),
"config": (
json.dumps(d_cfg) if d_cfg
else six.b(json.dumps(d_cfg))),
else b(json.dumps(d_cfg))),
"enum_deployments_status": consts.DeployStatus.DEPLOY_INIT,
"credentials": six.b(json.dumps([]))
"credentials": b(json.dumps([]))
} for d_uuid, d_cfg in self._dc0fe6de6786_deployments]
)
@ -2494,9 +2498,9 @@ class MigrationWalkTestCase(rtest.DBTestCase,
"name": str(uuid.uuid4()),
"config": (
json.dumps(d_cfg) if d_cfg
else six.b(json.dumps(d_cfg))),
else b(json.dumps(d_cfg))),
"enum_deployments_status": consts.DeployStatus.DEPLOY_INIT,
"credentials": six.b(json.dumps([]))
"credentials": b(json.dumps([]))
} for d_uuid, d_cfg in self._bc908ac9a1fc_deployments]
)
@ -2507,7 +2511,7 @@ class MigrationWalkTestCase(rtest.DBTestCase,
"created_at": dt.datetime.utcnow(),
"updated_at": dt.datetime.utcnow(),
"status": consts.TaskStatus.FINISHED,
"validation_result": six.b(json.dumps({})),
"validation_result": b(json.dumps({})),
"deployment_uuid": self._bc908ac9a1fc_deployments[0][0]
}]
)

View File

@ -13,13 +13,13 @@
# License for the specific language governing permissions and limitations
# under the License.
import io
import os
import socket
import ddt
import mock
import paramiko
import six
from rally.common import sshutils
from rally import exceptions
@ -68,7 +68,7 @@ class SSHTestCase(test.TestCase):
self.assertRaises(exceptions.SSHError, self.ssh._get_pkey, "key")
def test__get_pkey_dss(self):
private_dss_key = six.StringIO()
private_dss_key = io.StringIO()
private_dss_key_obj = paramiko.DSSKey.generate(1024)
private_dss_key_obj.write_private_key(private_dss_key)
private_dss_key.seek(0)
@ -81,7 +81,7 @@ class SSHTestCase(test.TestCase):
paramiko.DSSKey)
def test__get_pkey_rsa(self):
private_rsa_key = six.StringIO()
private_rsa_key = io.StringIO()
private_rsa_key_obj = paramiko.RSAKey.generate(1024)
private_rsa_key_obj.write_private_key(private_rsa_key)
private_rsa_key.seek(0)
@ -119,7 +119,7 @@ class SSHTestCase(test.TestCase):
m_client.close.assert_called_once_with()
self.assertFalse(self.ssh._client)
@mock.patch("rally.common.sshutils.six.moves.StringIO")
@mock.patch("rally.common.sshutils.io.StringIO")
def test_execute(self, mock_string_io):
mock_string_io.side_effect = stdio = [mock.Mock(), mock.Mock()]
stdio[0].read.return_value = "stdout fake data"

View File

@ -17,7 +17,6 @@ import math
import os
import ddt
import six
from rally.common import streaming_algorithms as algo
from tests.unit import test
@ -45,14 +44,14 @@ class MeanComputationTestCase(test.TestCase):
def test_merge(self):
single_mean = algo.MeanComputation()
for val in six.moves.range(100):
for val in range(100):
single_mean.add(val)
means = [algo.MeanComputation()
for _ in six.moves.range(10)]
for _ in range(10)]
for idx, mean in enumerate(means):
for val in six.moves.range(idx * 10, (idx + 1) * 10):
for val in range(idx * 10, (idx + 1) * 10):
mean.add(val)
merged_mean = means[0]
@ -94,14 +93,14 @@ class StdDevComputationTestCase(test.TestCase):
def test_merge(self):
single_std = algo.StdDevComputation()
for val in six.moves.range(100):
for val in range(100):
single_std.add(val)
stds = [algo.StdDevComputation()
for _ in six.moves.range(10)]
for _ in range(10)]
for idx, std in enumerate(stds):
for val in six.moves.range(idx * 10, (idx + 1) * 10):
for val in range(idx * 10, (idx + 1) * 10):
std.add(val)
merged_std = stds[0]
@ -135,14 +134,14 @@ class MinComputationTestCase(test.TestCase):
def test_merge(self):
single_min_algo = algo.MinComputation()
for val in six.moves.range(100):
for val in range(100):
single_min_algo.add(val)
algos = [algo.MinComputation()
for _ in six.moves.range(10)]
for _ in range(10)]
for idx, min_algo in enumerate(algos):
for val in six.moves.range(idx * 10, (idx + 1) * 10):
for val in range(idx * 10, (idx + 1) * 10):
min_algo.add(val)
merged_min_algo = algos[0]
@ -174,14 +173,14 @@ class MaxComputationTestCase(test.TestCase):
def test_merge(self):
single_max_algo = algo.MaxComputation()
for val in six.moves.range(100):
for val in range(100):
single_max_algo.add(val)
algos = [algo.MaxComputation()
for _ in six.moves.range(10)]
for _ in range(10)]
for idx, max_algo in enumerate(algos):
for val in six.moves.range(idx * 10, (idx + 1) * 10):
for val in range(idx * 10, (idx + 1) * 10):
max_algo.add(val)
merged_max_algo = algos[0]
@ -204,14 +203,14 @@ class IncrementComputationTestCase(test.TestCase):
def test_merge(self):
single_inc = algo.IncrementComputation()
for val in six.moves.range(100):
for val in range(100):
single_inc.add(val)
incs = [algo.IncrementComputation()
for _ in six.moves.range(10)]
for _ in range(10)]
for idx, inc in enumerate(incs):
for val in six.moves.range(idx * 10, (idx + 1) * 10):
for val in range(idx * 10, (idx + 1) * 10):
inc.add(val)
merged_inc = incs[0]

View File

@ -14,6 +14,7 @@
from __future__ import print_function
import collections
import queue as Queue
import string
import sys
import threading
@ -21,7 +22,6 @@ import time
import ddt
import mock
from six.moves import queue as Queue
import testtools
from rally.common import utils

View File

@ -51,7 +51,7 @@ class PathOrUrlTestCase(test.TestCase):
class FileTypeTestCase(test.TestCase):
@mock.patch("six.moves.builtins.open",
@mock.patch("builtins.open",
side_effect=mock.mock_open(read_data="file_context"),
create=True)
def test_preprocess_by_path(self, mock_open):
@ -59,7 +59,7 @@ class FileTypeTestCase(test.TestCase):
file_context = types.FileType({}, {}).pre_process(resource_spec, {})
self.assertEqual("file_context", file_context)
@mock.patch("six.moves.builtins.open", side_effect=IOError, create=True)
@mock.patch("builtins.open", side_effect=IOError, create=True)
def test_preprocess_by_path_no_match(self, mock_open):
resource_spec = "nonexistant.yaml"
self.assertRaises(IOError,
@ -70,7 +70,7 @@ class FileTypeTestCase(test.TestCase):
class FileTypeDictTestCase(test.TestCase):
@mock.patch("six.moves.builtins.open",
@mock.patch("builtins.open",
side_effect=mock.mock_open(read_data="file_context"),
create=True)
def test_preprocess_by_path(self, mock_open):
@ -79,7 +79,7 @@ class FileTypeDictTestCase(test.TestCase):
{})
self.assertEqual({"file.yaml": "file_context"}, file_context)
@mock.patch("six.moves.builtins.open", side_effect=IOError, create=True)
@mock.patch("builtins.open", side_effect=IOError, create=True)
def test_preprocess_by_path_no_match(self, mock_open):
resource_spec = ["nonexistant.yaml"]
self.assertRaises(IOError,

View File

@ -19,7 +19,6 @@ import datetime as dt
import ddt
from jsonschema import exceptions as schema_exceptions
import mock
import six
from rally import exceptions
from rally.task import utils
@ -532,7 +531,7 @@ class WrapperForAtomicActionsTestCase(test.TestCase):
self.assertEqual(1, atomic_wrapper.get("action_1"))
self.assertIsNone(atomic_wrapper.get("action_3"))
self.assertEqual(2, len(atomic_wrapper))
self.assertEqual(atomic_actions[0], six.next(iter(atomic_wrapper)))
self.assertEqual(atomic_actions[0], next(iter(atomic_wrapper)))
def test__convert_new_atomic_actions(self):
atomic_actions = collections.OrderedDict(

View File

@ -10,10 +10,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import io
import tokenize
import ddt
import six
from tests.hacking import checks
from tests.unit import test
@ -310,14 +310,14 @@ class HackingTestCase(test.TestCase):
for sample in bad:
sample = "print(%s)" % sample
tokens = tokenize.generate_tokens(
six.moves.StringIO(sample).readline)
io.StringIO(sample).readline)
self.assertEqual(
1,
len(list(checks.check_dict_formatting_in_string(sample,
tokens))))
sample = "print(\"%(a)05.2lF\" % d + \" added: %(a)s\" % d)"
tokens = tokenize.generate_tokens(six.moves.StringIO(sample).readline)
tokens = tokenize.generate_tokens(io.StringIO(sample).readline)
self.assertEqual(
2,
len(list(checks.check_dict_formatting_in_string(sample, tokens))))
@ -329,7 +329,7 @@ class HackingTestCase(test.TestCase):
for sample in good:
sample = "print(%s)" % sample
tokens = tokenize.generate_tokens(
six.moves.StringIO(sample).readline)
io.StringIO(sample).readline)
self.assertEqual(
[],
list(checks.check_dict_formatting_in_string(sample, tokens)))

View File

@ -15,8 +15,6 @@ import itertools
import os
import re
import six.moves
from tests.unit import test
@ -255,7 +253,7 @@ class FuncMockArgsDecoratorsChecker(ast.NodeVisitor):
error_msgs = []
mismatched = False
for arg, dec_vars in six.moves.zip_longest(mock_args, mock_decs):
for arg, dec_vars in itertools.zip_longest(mock_args, mock_decs):
if not self.check_name(arg, dec_vars):
if arg and dec_vars:
sorted_by_len = sorted(

View File

@ -13,28 +13,31 @@
# under the License.
import mock
import six
from rally.utils import encodeutils
from tests.unit import test
def b(s):
return s.encode("latin-1")
class EncodeUtilsTestCase(test.TestCase):
def test_safe_decode(self):
safe_decode = encodeutils.safe_decode
self.assertRaises(TypeError, safe_decode, True)
self.assertEqual("ni\xf1o",
safe_decode(six.b("ni\xc3\xb1o"), incoming="utf-8"))
safe_decode(b("ni\xc3\xb1o"), incoming="utf-8"))
self.assertEqual("strange",
safe_decode(six.b("\x80strange"), errors="ignore"))
safe_decode(b("\x80strange"), errors="ignore"))
self.assertEqual("\xc0",
safe_decode(six.b("\xc0"), incoming="iso-8859-1"))
safe_decode(b("\xc0"), incoming="iso-8859-1"))
# Forcing incoming to ascii so it falls back to utf-8
self.assertEqual("ni\xf1o",
safe_decode(six.b("ni\xc3\xb1o"), incoming="ascii"))
safe_decode(b("ni\xc3\xb1o"), incoming="ascii"))
self.assertEqual("foo", safe_decode(b"foo"))
@ -59,8 +62,8 @@ class EncodeUtilsTestCase(test.TestCase):
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"),
b("ni\xc3\xb1o"),
encodeutils.safe_encode(b("ni\xc3\xb1o"), incoming="ascii"),
)
def test_safe_encode_same_encoding_different_cases(self):
@ -83,4 +86,4 @@ class EncodeUtilsTestCase(test.TestCase):
text=text, incoming="utf-8", encoding="iso-8859-1")
self.assertNotEqual(text, result)
self.assertNotEqual(six.b("foo\xf1bar"), result)
self.assertNotEqual(b("foo\xf1bar"), result)

View File

@ -48,11 +48,11 @@ class StrUtilsTestCase(test.TestCase):
def test_name_is_uuid_like(self):
self.assertFalse(strutils.is_uuid_like("asdasdasd"))
@mock.patch("six.text_type")
def test_bool_bool_from_string_no_text(self, mock_text_type):
@mock.patch("builtins.str")
def test_bool_bool_from_string_no_text(self, mock_str):
self.assertTrue(strutils.bool_from_string(True))
self.assertFalse(strutils.bool_from_string(False))
self.assertEqual(0, mock_text_type.call_count)
self.assertEqual(0, mock_str.call_count)
def test_bool_bool_from_string(self):
self.assertTrue(strutils.bool_from_string(True))

View File

@ -289,7 +289,7 @@ class VerifierManagerTestCase(test.TestCase):
FakeVerifier(mock.Mock()).uninstall_extension,
"name")
@mock.patch("rally.verification.manager.six.StringIO")
@mock.patch("rally.verification.manager.io.StringIO")
@mock.patch("rally.verification.manager.subunit_v2")
def test_parse_results(self, mock_subunit_v2, mock_string_io):
data = "123123"

View File

@ -12,10 +12,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import configparser
import subprocess
import mock
from six.moves import configparser
from rally.verification import utils
from tests.unit import test
@ -58,10 +58,10 @@ class UtilsTestCase(test.TestCase):
self.assertEqual(3, mock_log.error.call_count)
mock_log.error.assert_any_call(msg)
@mock.patch("rally.verification.utils.six.StringIO")
@mock.patch("rally.verification.utils.io.StringIO")
@mock.patch("rally.verification.utils.add_extra_options")
@mock.patch("rally.verification.utils.configparser.ConfigParser")
@mock.patch("six.moves.builtins.open", side_effect=mock.mock_open())
@mock.patch("builtins.open", side_effect=mock.mock_open())
def test_extend_configfile(self, mock_open, mock_config_parser,
mock_add_extra_options, mock_string_io):
extra_options = mock.Mock()