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 pytest-xdist # MIT
ddt # MIT ddt # MIT
mock # OSI Approved :: BSD License
python-dateutil # Dual License python-dateutil # Dual License
testtools # UNKNOWN testtools # UNKNOWN
@ -24,3 +23,4 @@ testresources # UNKNOWN
# needed for functional job # needed for functional job
stestr # Apache Software License stestr # Apache Software License
mock

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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