Skip to content

Commit

Permalink
Merge "Use unittests.mock instead of mock lib"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and openstack-gerrit committed Mar 21, 2020
2 parents c239b13 + b086b2c commit 208b2b6
Show file tree
Hide file tree
Showing 77 changed files with 98 additions and 126 deletions.
9 changes: 0 additions & 9 deletions optional-requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -24,3 +23,4 @@ testresources # UNKNOWN

# needed for functional job
stestr # Apache Software License
mock
2 changes: 1 addition & 1 deletion tests/functional/test_cli_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import re
import threading
import time
from unittest import mock

import jsonschema
import mock
import testtools

from rally import api
Expand Down
5 changes: 3 additions & 2 deletions tests/functional/test_cli_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/cli/commands/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/cli/commands/test_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/cli/commands/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/cli/commands/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/cli/commands/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import json
import os.path
import sys
from unittest import mock

import ddt
import mock

import rally
from rally import api
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/cli/commands/test_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/cli/test_cliutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions tests/unit/cli/test_envutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,7 +33,7 @@ def test_function(test_arg_name=None):
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())
Expand Down
8 changes: 3 additions & 5 deletions tests/unit/common/db/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -122,12 +120,12 @@ def test_task_list_empty(self):

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)

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/common/db/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
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
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/common/db/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/common/io/test_junit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/common/io/test_subunit_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/common/objects/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/common/objects/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/common/objects/test_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/common/objects/test_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/common/plugin/test_discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions tests/unit/common/test_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/common/test_fileutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions tests/unit/common/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -93,7 +92,7 @@ def foo():

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")
Expand All @@ -110,7 +109,7 @@ def foo(*args):
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)
Expand All @@ -129,7 +128,7 @@ def test_exception(self, mock_get_logger):
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
Expand All @@ -146,7 +145,7 @@ def test_error(self, mock_get_logger):
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
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/common/test_opts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/common/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import sys
import threading
import time
from unittest import mock

import ddt
import mock
import testtools

from rally.common import utils
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/common/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/doc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from docutils import utils
import sys

import mock
from unittest import mock


@mock.patch.object(sys, "stderr")
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/env/test_env_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion tests/unit/plugins/common/contexts/test_dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 208b2b6

Please sign in to comment.