From 18a47cb24a91026c509ead677e80a44c27ef6f73 Mon Sep 17 00:00:00 2001 From: Sean McGinnis Date: Fri, 27 Mar 2020 15:47:29 -0500 Subject: [PATCH] Use unittest.mock instead of third party mock We can now use the standard library mock library instead of the third party one previously needed for py27 compatibility. Change-Id: Ia8e87cd6a25621a97c876de5422d0c9d0c8dd751 Signed-off-by: Sean McGinnis --- cloudkitty/tests/__init__.py | 2 +- cloudkitty/tests/api/v2/dataframes/test_dataframes.py | 3 +-- cloudkitty/tests/api/v2/summary/test_summary.py | 3 +-- cloudkitty/tests/api/v2/test_utils.py | 3 ++- cloudkitty/tests/collectors/test_gnocchi.py | 2 +- cloudkitty/tests/collectors/test_monasca.py | 3 +-- cloudkitty/tests/collectors/test_prometheus.py | 3 +-- cloudkitty/tests/common/test_prometheus_client.py | 2 +- cloudkitty/tests/fetchers/test_prometheus.py | 2 +- cloudkitty/tests/gabbi/fixtures.py | 2 +- cloudkitty/tests/storage/v1/test_hybrid_storage.py | 2 +- cloudkitty/tests/storage/v1/test_storage.py | 2 +- .../tests/storage/v2/elasticsearch/test_client.py | 2 +- cloudkitty/tests/storage/v2/test_influxdb.py | 2 +- cloudkitty/tests/storage/v2/test_storage_unit.py | 2 +- cloudkitty/tests/test_hacking.py | 2 +- cloudkitty/tests/test_hashmap.py | 2 +- cloudkitty/tests/test_keystone_fetcher.py | 2 +- cloudkitty/tests/test_orchestrator.py | 2 +- cloudkitty/tests/test_pyscripts.py | 2 +- cloudkitty/tests/test_rating.py | 2 +- cloudkitty/tests/test_storage_state.py | 10 +++------- cloudkitty/tests/utils_tests/test_tz.py | 2 +- cloudkitty/tests/utils_tests/test_utils.py | 2 +- lower-constraints.txt | 1 - test-requirements.txt | 1 - 26 files changed, 27 insertions(+), 36 deletions(-) diff --git a/cloudkitty/tests/__init__.py b/cloudkitty/tests/__init__.py index ed84dae9..320ab332 100644 --- a/cloudkitty/tests/__init__.py +++ b/cloudkitty/tests/__init__.py @@ -14,9 +14,9 @@ # under the License. # import decimal +from unittest import mock from keystoneauth1 import session as ks_sess -import mock from oslo_config import fixture as config_fixture from oslotest import base import testscenarios diff --git a/cloudkitty/tests/api/v2/dataframes/test_dataframes.py b/cloudkitty/tests/api/v2/dataframes/test_dataframes.py index 68b05363..0d44d1c1 100644 --- a/cloudkitty/tests/api/v2/dataframes/test_dataframes.py +++ b/cloudkitty/tests/api/v2/dataframes/test_dataframes.py @@ -13,8 +13,7 @@ # under the License. # import unittest - -import mock +from unittest import mock from cloudkitty.api.v2.dataframes import dataframes from cloudkitty.utils import tz as tzutils diff --git a/cloudkitty/tests/api/v2/summary/test_summary.py b/cloudkitty/tests/api/v2/summary/test_summary.py index af5cfa13..5549722a 100644 --- a/cloudkitty/tests/api/v2/summary/test_summary.py +++ b/cloudkitty/tests/api/v2/summary/test_summary.py @@ -13,8 +13,7 @@ # under the License. # import unittest - -import mock +from unittest import mock from cloudkitty.api.v2.summary import summary from cloudkitty.utils import tz as tzutils diff --git a/cloudkitty/tests/api/v2/test_utils.py b/cloudkitty/tests/api/v2/test_utils.py index d3e8173b..484bce38 100644 --- a/cloudkitty/tests/api/v2/test_utils.py +++ b/cloudkitty/tests/api/v2/test_utils.py @@ -12,8 +12,9 @@ # License for the specific language governing permissions and limitations # under the License. # +from unittest import mock + import flask -import mock import voluptuous from werkzeug.datastructures import MultiDict from werkzeug.exceptions import BadRequest diff --git a/cloudkitty/tests/collectors/test_gnocchi.py b/cloudkitty/tests/collectors/test_gnocchi.py index 29b7a16c..e8375e60 100644 --- a/cloudkitty/tests/collectors/test_gnocchi.py +++ b/cloudkitty/tests/collectors/test_gnocchi.py @@ -14,9 +14,9 @@ # under the License. # import datetime +from unittest import mock from dateutil import tz -import mock from cloudkitty.collector import gnocchi from cloudkitty import tests diff --git a/cloudkitty/tests/collectors/test_monasca.py b/cloudkitty/tests/collectors/test_monasca.py index dbb202c6..a77fd8f1 100644 --- a/cloudkitty/tests/collectors/test_monasca.py +++ b/cloudkitty/tests/collectors/test_monasca.py @@ -13,8 +13,7 @@ # under the License. # import datetime - -import mock +from unittest import mock from cloudkitty.collector import monasca as mon_collector from cloudkitty import tests diff --git a/cloudkitty/tests/collectors/test_prometheus.py b/cloudkitty/tests/collectors/test_prometheus.py index 380d0287..7fd7320f 100644 --- a/cloudkitty/tests/collectors/test_prometheus.py +++ b/cloudkitty/tests/collectors/test_prometheus.py @@ -14,8 +14,7 @@ # under the License. # from decimal import Decimal - -import mock +from unittest import mock from cloudkitty import collector from cloudkitty.collector import exceptions diff --git a/cloudkitty/tests/common/test_prometheus_client.py b/cloudkitty/tests/common/test_prometheus_client.py index 1ed2a3d4..4fbd7512 100644 --- a/cloudkitty/tests/common/test_prometheus_client.py +++ b/cloudkitty/tests/common/test_prometheus_client.py @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. # -import mock +from unittest import mock from cloudkitty.collector import prometheus from cloudkitty import tests diff --git a/cloudkitty/tests/fetchers/test_prometheus.py b/cloudkitty/tests/fetchers/test_prometheus.py index 6c1863d6..e3d7f2d1 100644 --- a/cloudkitty/tests/fetchers/test_prometheus.py +++ b/cloudkitty/tests/fetchers/test_prometheus.py @@ -14,7 +14,7 @@ # under the License. # # -import mock +from unittest import mock from cloudkitty.common.prometheus_client import PrometheusClient from cloudkitty.common.prometheus_client import PrometheusResponseError diff --git a/cloudkitty/tests/gabbi/fixtures.py b/cloudkitty/tests/gabbi/fixtures.py index f369aa01..53d86f90 100644 --- a/cloudkitty/tests/gabbi/fixtures.py +++ b/cloudkitty/tests/gabbi/fixtures.py @@ -18,10 +18,10 @@ import collections import datetime import decimal import os +from unittest import mock from dateutil import tz from gabbi import fixture -import mock from oslo_config import cfg from oslo_config import fixture as conf_fixture from oslo_db.sqlalchemy import utils diff --git a/cloudkitty/tests/storage/v1/test_hybrid_storage.py b/cloudkitty/tests/storage/v1/test_hybrid_storage.py index e28fa179..8d5db3e1 100644 --- a/cloudkitty/tests/storage/v1/test_hybrid_storage.py +++ b/cloudkitty/tests/storage/v1/test_hybrid_storage.py @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. # -import mock +from unittest import mock from gnocchiclient import exceptions as gexc diff --git a/cloudkitty/tests/storage/v1/test_storage.py b/cloudkitty/tests/storage/v1/test_storage.py index 52a24296..d18f8caa 100644 --- a/cloudkitty/tests/storage/v1/test_storage.py +++ b/cloudkitty/tests/storage/v1/test_storage.py @@ -15,8 +15,8 @@ # import copy import datetime +from unittest import mock -import mock import testscenarios from cloudkitty import storage diff --git a/cloudkitty/tests/storage/v2/elasticsearch/test_client.py b/cloudkitty/tests/storage/v2/elasticsearch/test_client.py index b81d9bc7..ac5dae05 100644 --- a/cloudkitty/tests/storage/v2/elasticsearch/test_client.py +++ b/cloudkitty/tests/storage/v2/elasticsearch/test_client.py @@ -15,9 +15,9 @@ import collections import datetime import unittest +from unittest import mock from dateutil import tz -import mock from cloudkitty import dataframe from cloudkitty.storage.v2.elasticsearch import client diff --git a/cloudkitty/tests/storage/v2/test_influxdb.py b/cloudkitty/tests/storage/v2/test_influxdb.py index f23ff100..54dbb479 100644 --- a/cloudkitty/tests/storage/v2/test_influxdb.py +++ b/cloudkitty/tests/storage/v2/test_influxdb.py @@ -17,9 +17,9 @@ import copy from datetime import datetime from datetime import timedelta import unittest +from unittest import mock from dateutil import tz -import mock from cloudkitty import dataframe from cloudkitty.storage.v2 import influx diff --git a/cloudkitty/tests/storage/v2/test_storage_unit.py b/cloudkitty/tests/storage/v2/test_storage_unit.py index 29dd5610..3b91619d 100644 --- a/cloudkitty/tests/storage/v2/test_storage_unit.py +++ b/cloudkitty/tests/storage/v2/test_storage_unit.py @@ -13,8 +13,8 @@ # under the License. # import datetime +from unittest import mock -import mock import testscenarios from cloudkitty import storage diff --git a/cloudkitty/tests/test_hacking.py b/cloudkitty/tests/test_hacking.py index ed45fb23..004b6423 100644 --- a/cloudkitty/tests/test_hacking.py +++ b/cloudkitty/tests/test_hacking.py @@ -14,9 +14,9 @@ import sys import textwrap +from unittest import mock import ddt -import mock import pep8 from cloudkitty.hacking import checks diff --git a/cloudkitty/tests/test_hashmap.py b/cloudkitty/tests/test_hashmap.py index 28e58041..f655af82 100644 --- a/cloudkitty/tests/test_hashmap.py +++ b/cloudkitty/tests/test_hashmap.py @@ -16,8 +16,8 @@ import copy import datetime import decimal +from unittest import mock -import mock from oslo_utils import uuidutils from cloudkitty import dataframe diff --git a/cloudkitty/tests/test_keystone_fetcher.py b/cloudkitty/tests/test_keystone_fetcher.py index 1fb289a4..41b63f1e 100644 --- a/cloudkitty/tests/test_keystone_fetcher.py +++ b/cloudkitty/tests/test_keystone_fetcher.py @@ -14,8 +14,8 @@ # under the License. # import unittest +from unittest import mock -import mock from oslo_utils import uuidutils from cloudkitty.fetcher import keystone diff --git a/cloudkitty/tests/test_orchestrator.py b/cloudkitty/tests/test_orchestrator.py index e3f07875..e8996bbf 100644 --- a/cloudkitty/tests/test_orchestrator.py +++ b/cloudkitty/tests/test_orchestrator.py @@ -14,8 +14,8 @@ # under the License. # import datetime +from unittest import mock -import mock from oslo_messaging import conffixture from stevedore import extension from tooz import coordination diff --git a/cloudkitty/tests/test_pyscripts.py b/cloudkitty/tests/test_pyscripts.py index 48a10ac9..4986e610 100644 --- a/cloudkitty/tests/test_pyscripts.py +++ b/cloudkitty/tests/test_pyscripts.py @@ -16,9 +16,9 @@ import copy import decimal import hashlib +from unittest import mock import zlib -import mock from oslo_utils import uuidutils import six diff --git a/cloudkitty/tests/test_rating.py b/cloudkitty/tests/test_rating.py index d642b685..c19902e4 100644 --- a/cloudkitty/tests/test_rating.py +++ b/cloudkitty/tests/test_rating.py @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. # -import mock +from unittest import mock from cloudkitty.db import api as ck_db_api from cloudkitty import tests diff --git a/cloudkitty/tests/test_storage_state.py b/cloudkitty/tests/test_storage_state.py index e13e51e8..7fddbb45 100644 --- a/cloudkitty/tests/test_storage_state.py +++ b/cloudkitty/tests/test_storage_state.py @@ -12,14 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. # -try: - from collections.abc import Iterable -except ImportError: - from collections import Iterable +from collections import abc from datetime import datetime import itertools - -import mock +from unittest import mock from cloudkitty import storage_state from cloudkitty import tests @@ -37,7 +33,7 @@ class StateManagerTest(tests.TestCase): def __init__(self, output, *args, **kwargs): super(StateManagerTest.QueryMock, self).__init__(*args, **kwargs) self.first_called = 0 - if not isinstance(output, Iterable): + if not isinstance(output, abc.Iterable): output = (output, ) self.output = itertools.cycle(output) diff --git a/cloudkitty/tests/utils_tests/test_tz.py b/cloudkitty/tests/utils_tests/test_tz.py index 90c6f250..6e5e2312 100644 --- a/cloudkitty/tests/utils_tests/test_tz.py +++ b/cloudkitty/tests/utils_tests/test_tz.py @@ -14,9 +14,9 @@ # import datetime import unittest +from unittest import mock from dateutil import tz -import mock from oslo_utils import timeutils from cloudkitty import utils diff --git a/cloudkitty/tests/utils_tests/test_utils.py b/cloudkitty/tests/utils_tests/test_utils.py index a587601f..c89e5b80 100644 --- a/cloudkitty/tests/utils_tests/test_utils.py +++ b/cloudkitty/tests/utils_tests/test_utils.py @@ -18,8 +18,8 @@ import decimal import fractions import itertools import unittest +from unittest import mock -import mock from oslo_utils import timeutils from cloudkitty import utils as ck_utils diff --git a/lower-constraints.txt b/lower-constraints.txt index 45ec38d2..412a79d2 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -39,7 +39,6 @@ ddt==1.0.1 # MIT gabbi==1.26.1 # Apache-2.0 testscenarios==0.4 # Apache-2.0/BSD stestr==2.0.0 # Apache-2.0 -mock==1.2 # BSD sphinx==1.8.0 # BSD openstackdocstheme==1.30.0 # Apache-2.0 oslotest==1.10.0 # Apache-2.0 diff --git a/test-requirements.txt b/test-requirements.txt index 74469c03..48a633d2 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -11,7 +11,6 @@ ddt>=1.0.1 # MIT gabbi>=1.26.1 # Apache-2.0 testscenarios>=0.4 # Apache-2.0/BSD stestr>=2.0.0 # Apache-2.0 -mock>=1.2 # BSD sphinx>=1.8.0,!=2.1.0 # BSD openstackdocstheme>=1.30.0 # Apache-2.0 oslotest>=1.10.0 # Apache-2.0