Use unittests.mock instead of mock lib

Change-Id: I07400c7fd829dea86774f3f695c8a976550c6baf
This commit is contained in:
Andrey Kurilin 2020-03-21 15:24:26 +02:00
parent de4fe90b35
commit b086b2cd50
77 changed files with 98 additions and 126 deletions

View File

@ -1,9 +0,0 @@
# Purpose of optional-requirements is simple - list requirements which cannot
# be placed in main requirements.txt .
#
# Reasons:
# - package doesn't support the same Python versions as Rally package
# supports (see classifiers from setup.cfg)
# - package doesn't have releases
# If these rules do not relate to your package, feel free to propose it as main
# requirement to Rally (requirements.txt file).

View File

@ -13,7 +13,6 @@ pytest-html>=1.10.0 # Mozilla Public License
pytest-xdist # MIT
ddt # MIT
mock # OSI Approved :: BSD License
python-dateutil # Dual License
testtools # UNKNOWN
@ -24,3 +23,4 @@ testresources # UNKNOWN
# needed for functional job
stestr # Apache Software License
mock

View File

@ -18,9 +18,9 @@ import os
import re
import threading
import time
from unittest import mock
import jsonschema
import mock
import testtools
from rally import api

View File

@ -14,12 +14,13 @@
# under the License.
import re
import unittest
import testtools
from tests.functional import utils
class VerifyTestCase(unittest.TestCase):
class VerifyTestCase(testtools.TestCase):
def test_list_plugins(self):
rally = utils.Rally(plugin_path="tests/functional/extra")

View File

@ -13,8 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from rally.cli.commands import db
from tests.unit import fakes

View File

@ -16,8 +16,7 @@
import collections
import io
import os
import mock
from unittest import mock
from rally.cli import cliutils
from rally.cli.commands import deployment

View File

@ -16,10 +16,9 @@
import collections
import datetime as dt
import json
from unittest import mock
import uuid
import mock
from rally.cli.commands import env
from rally.env import env_mgr
from rally import exceptions

View File

@ -14,9 +14,9 @@
# under the License.
import io
from unittest import mock
import ddt
import mock
from rally.cli import cliutils
from rally.cli.commands import plugin as plugin_cmd

View File

@ -18,9 +18,9 @@ import io
import json
import os.path
import sys
from unittest import mock
import ddt
import mock
import rally
from rally import api

View File

@ -15,8 +15,7 @@
import io
import tempfile
import mock
from unittest import mock
from rally.cli import cliutils
from rally.cli.commands import verify

View File

@ -14,9 +14,9 @@
# under the License.
import io
from unittest import mock
import ddt
import mock
import sqlalchemy.exc
from rally.cli import cliutils

View File

@ -13,10 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
import io
import os
import mock
from six import moves
from unittest import mock
from rally.cli import envutils
from rally import exceptions
@ -34,7 +33,7 @@ class EnvUtilsTestCase(test.TestCase):
pass
with mock.patch("sys.stdout",
new_callable=moves.StringIO) as mock_stdout:
new_callable=io.StringIO) as mock_stdout:
test_function()
self.assertEqual("Missing argument: --test_missing_arg\n",
mock_stdout.getvalue())

View File

@ -16,9 +16,7 @@
"""Tests for db.api layer."""
import datetime as dt
import mock
from six import moves
from unittest import mock
from rally.common import db
from rally import consts
@ -122,12 +120,12 @@ class TasksTestCase(test.DBTestCase):
def test_task_list(self):
INIT = consts.TaskStatus.INIT
task_init = sorted(self._create_task()["uuid"] for i in moves.range(3))
task_init = sorted(self._create_task()["uuid"] for i in range(3))
FINISHED = consts.TaskStatus.FINISHED
task_finished = sorted(self._create_task(
{"status": FINISHED,
"env_uuid": self.env["uuid"]}
)["uuid"] for i in moves.range(3))
)["uuid"] for i in range(3))
task_all = sorted(task_init + task_finished)

View File

@ -22,11 +22,11 @@ import iso8601
import json
import pickle
import pprint
from unittest import mock
import uuid
import alembic
import jsonschema
import mock
from oslo_db.sqlalchemy import test_migrations
from oslo_db.sqlalchemy import utils as db_utils
import sqlalchemy as sa

View File

@ -14,7 +14,8 @@
"""Tests for custom sqlalchemy types"""
import mock
from unittest import mock
import sqlalchemy as sa
from rally.common.db import sa_types

View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from rally.common.io import junit
from tests.unit import test

View File

@ -12,8 +12,7 @@
# under the License.
import os
import mock
from unittest import mock
from rally.common.io import subunit_v2
from tests.unit import test

View File

@ -16,7 +16,7 @@
"""Tests for db.deploy layer."""
import datetime as dt
import mock
from unittest import mock
from rally.common import objects
from rally import consts

View File

@ -17,9 +17,9 @@
import collections
import datetime as dt
from unittest import mock
import ddt
import mock
from rally.common import objects
from rally import consts

View File

@ -15,8 +15,7 @@
import copy
import datetime as dt
import mock
from unittest import mock
from rally.common import objects
from rally import consts

View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from rally.common import objects
from rally import exceptions

View File

@ -13,10 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import uuid
import mock
from rally.common.plugin import discover
from tests.unit import test

View File

@ -14,8 +14,7 @@
# under the License.
import collections
import mock
from unittest import mock
from rally.common import broker
from tests.unit import test

View File

@ -14,8 +14,7 @@
# under the License.
import os
import mock
from unittest import mock
from rally.common import fileutils
from tests.unit import test

View File

@ -14,8 +14,7 @@
# under the License.
import logging # noqa
import mock
from unittest import mock
from rally.common import logging as rally_logging
from tests.unit import test
@ -93,7 +92,7 @@ class RallyContaxtAdapterTestCase(test.TestCase):
foo()
# the number of the line which calls logging_method
lineno = 92
lineno = 91
self.assertEqual((__file__, lineno, "logging_method()"), self.caller)
@mock.patch("rally.common.logging.getLogger")
@ -110,7 +109,7 @@ class RallyContaxtAdapterTestCase(test.TestCase):
foo(1)
# the number of the line which calls foo
lineno = 110
lineno = 109
mock_get_logger.assert_called_once_with("%s:%s" % (__file__, lineno))
logger = mock_get_logger.return_value
self.assertEqual(1, logger.warning.call_count)
@ -129,7 +128,7 @@ class RallyContaxtAdapterTestCase(test.TestCase):
radapter.exception(Exception("!2!"))
# the number of the line which calls foo
lineno = 129
lineno = 128
mock_get_logger.assert_called_once_with("%s:%s" % (__file__, lineno))
logger = mock_get_logger.return_value
@ -146,7 +145,7 @@ class RallyContaxtAdapterTestCase(test.TestCase):
radapter.error("foo", "bar")
# the number of the line which calls foo
lineno = 146
lineno = 145
mock_get_logger.assert_called_once_with("%s:%s" % (__file__, lineno))
logger = mock_get_logger.return_value

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from rally.common import opts
from tests.unit import test

View File

@ -19,9 +19,9 @@ import string
import sys
import threading
import time
from unittest import mock
import ddt
import mock
import testtools
from rally.common import utils

View File

@ -11,7 +11,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from rally.common import version
from tests.unit import test

View File

@ -17,7 +17,7 @@ from docutils.parsers import rst
from docutils import utils
import sys
import mock
from unittest import mock
@mock.patch.object(sys, "stderr")

View File

@ -15,8 +15,7 @@
import copy
import datetime as dt
import os
import mock
from unittest import mock
from rally.env import env_mgr
from rally.env import platform

View File

@ -15,8 +15,7 @@
import itertools
import multiprocessing
import mock
from unittest import mock
from rally import api
from rally.common import utils as rally_utils

View File

@ -12,7 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
from rally import exceptions
from rally.plugins.common.contexts import dummy
from tests.unit import test

View File

@ -13,8 +13,7 @@
# under the License.
import copy
import mock
from unittest import mock
from rally import exceptions
from rally.plugins.common.exporters.elastic import client

View File

@ -13,10 +13,10 @@
# under the License.
import copy
import json
from unittest import mock
import ddt
import json
import mock
from rally import exceptions
from rally.plugins.common.exporters.elastic import exporter as elastic

View File

@ -13,8 +13,7 @@
# under the License.
import os
import mock
from unittest import mock
from rally.plugins.common.exporters import html
from tests.unit import test

View File

@ -14,8 +14,7 @@
import collections
import datetime as dt
import mock
from unittest import mock
from rally.common import version as rally_version
from rally.plugins.common.exporters import json_exporter

View File

@ -14,8 +14,7 @@
import datetime as dt
import os
import mock
from unittest import mock
from rally.plugins.common.exporters import junit
from tests.unit import test

View File

@ -13,8 +13,7 @@
# under the License.
import os
import mock
from unittest import mock
from rally.plugins.common.exporters import trends
from tests.unit import test

View File

@ -14,9 +14,9 @@
# under the License.
import subprocess
from unittest import mock
import ddt
import mock
from rally import consts
from rally.plugins.common.hook import sys_call

View File

@ -13,8 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import ddt
import mock
from rally.plugins.common.hook.triggers import event
from rally.task import hook

View File

@ -13,8 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import ddt
import mock
from rally.plugins.common.hook.triggers import periodic
from rally.task import hook

View File

@ -13,8 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import ddt
import mock
from rally.plugins.common.runners import constant
from rally.task import runner

View File

@ -13,8 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import ddt
import mock
from rally.plugins.common.runners import rps
from rally.task import runner

View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from rally.plugins.common.runners import serial
from tests.unit import fakes

View File

@ -10,9 +10,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import ddt
import mock
from rally.plugins.common.scenarios.dummy import dummy
from tests.unit import test

View File

@ -10,8 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from rally.plugins.common.scenarios.requests import http_requests
from tests.unit import test

View File

@ -10,8 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from rally.plugins.common.scenarios.requests import utils
from tests.unit import test

View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from rally import exceptions
from rally.plugins.common import types

View File

@ -12,11 +12,12 @@
# License for the specific language governing permissions and limitations
# under the License.
import ddt
import mock
import os
import shutil
import tempfile
from unittest import mock
import ddt
import rally
from rally.common.plugin import plugin

View File

@ -15,9 +15,9 @@
import collections
import datetime as dt
import os
from unittest import mock
import ddt
import mock
from rally.common import utils
from rally.plugins.common.verification import reporters

View File

@ -13,8 +13,7 @@
import os
import subprocess
import mock
from unittest import mock
from rally import exceptions
from rally.plugins.common.verification import testr

View File

@ -14,9 +14,9 @@
# under the License.
import collections
from unittest import mock
import ddt
import mock
from rally.common.plugin import plugin
from rally.task.processing import charts

View File

@ -15,9 +15,9 @@
import collections
import json
from unittest import mock
import ddt
import mock
from rally.task.processing import plot
from tests.unit import test

View File

@ -14,8 +14,7 @@
# under the License.
import collections
import mock
from unittest import mock
from rally.task import atomic
from tests.unit import test

View File

@ -13,8 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import ddt
import mock
from rally import exceptions
from rally.task import context

View File

@ -17,8 +17,7 @@
import collections
import threading
import mock
from unittest import mock
from rally.common import objects
from rally import consts

View File

@ -12,8 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import jsonschema
import mock
from rally.task import exporter
from tests.unit import test

View File

@ -15,8 +15,9 @@
"""Tests for HookExecutor and Hook classes."""
from unittest import mock
import ddt
import mock
from rally import consts
from rally.task import hook

View File

@ -15,9 +15,9 @@
import collections
import multiprocessing
from unittest import mock
import ddt
import mock
from rally.plugins.common.runners import serial
from rally.task import runner

View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from rally import exceptions
from rally.task import context

View File

@ -11,7 +11,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from rally import exceptions
from rally.task import service

View File

@ -13,8 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import ddt
import mock
from rally.common.plugin import plugin
from rally.task import sla

View File

@ -13,8 +13,7 @@
# under the License.
import collections
import mock
from unittest import mock
from rally import exceptions
from rally.task import task_cfg

View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from rally.common.plugin import plugin
from rally.task import scenario

View File

@ -15,11 +15,11 @@
import collections
import datetime as dt
from unittest import mock
import uuid
import ddt
from jsonschema import exceptions as schema_exceptions
import mock
from rally import exceptions
from rally.task import utils

View File

@ -16,9 +16,9 @@
import fixtures
from fixtures._fixtures.tempdir import TempDir
import os
from unittest import mock
import uuid
import mock
import testtools
from rally.common import cfg

View File

@ -17,9 +17,9 @@
import copy
import os
from unittest import mock
import ddt
import mock
from rally import api
from rally.common import cfg

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from rally import exceptions
from tests.unit import test

View File

@ -13,8 +13,7 @@
# under the License.
import os
import mock
from unittest import mock
from tests.ci import pytest_launcher
from tests.unit import test

View File

@ -12,8 +12,7 @@
import ast
import sys
import mock
from unittest import mock
from tests.unit import test
from tests.unit import test_mock

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from rally.utils import encodeutils
from tests.unit import test

View File

@ -16,9 +16,9 @@
import io
import os
import socket
from unittest import mock
import ddt
import mock
import paramiko
from rally import exceptions

View File

@ -12,10 +12,10 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import uuid
import ddt
import mock
from rally.utils import strutils
from tests.unit import test

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from rally.verification import context
from tests.unit import test

View File

@ -12,8 +12,7 @@
import os
import sys
import mock
from unittest import mock
from rally import exceptions
from rally.verification import manager

View File

@ -12,8 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import jsonschema
import mock
from rally.verification import reporter
from tests.unit import test

View File

@ -14,8 +14,7 @@
import configparser
import subprocess
import mock
from unittest import mock
from rally.verification import utils
from tests.unit import test