Use unittest.mock instead of mock

The mock third party library was needed for mock support in py2
runtimes. Since we now only support py36 and later, we can use the
standard lib unittest.mock module instead.

Change-Id: I90d966a150d128e177f157e292035cfb71d89ad1
This commit is contained in:
Hervé Beraud 2020-06-09 10:52:02 +02:00
parent 37ed9303c9
commit 6f9cd3f7a7
70 changed files with 127 additions and 145 deletions

View File

@ -14,7 +14,6 @@ jsonpointer==1.13
jsonschema==3.2.0
keystoneauth1==3.18.0
linecache2==1.0.0
mock==3.0.0
munch==2.1.0
netifaces==0.10.4
os-service-types==1.7.0

View File

@ -15,8 +15,8 @@
import json
import os
from unittest import mock
import mock
import testtools
from openstack.baremetal import configdrive

View File

@ -10,8 +10,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
from keystoneauth1 import adapter
import mock
from openstack.baremetal.v1 import allocation
from openstack import exceptions

View File

@ -10,8 +10,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
from keystoneauth1 import adapter
import mock
from openstack.baremetal.v1 import _common
from openstack.baremetal.v1 import node
@ -790,7 +791,7 @@ class TestNodePatch(base.TestCase):
patch = {'path': 'test'}
self.node.patch(self.session, patch=patch)
mock_patch.assert_called_once()
kwargs = mock_patch.call_args.kwargs
kwargs = mock_patch.call_args[1]
self.assertEqual(kwargs['patch'], {'path': 'test'})
@mock.patch.object(resource.Resource, '_prepare_request', autospec=True)
@ -801,12 +802,12 @@ class TestNodePatch(base.TestCase):
self.node.patch(self.session, patch=patch, retry_on_conflict=True,
reset_interfaces=True)
mock_prepreq.assert_called_once()
prepreq_kwargs = mock_prepreq.call_args.kwargs
prepreq_kwargs = mock_prepreq.call_args[1]
self.assertEqual(prepreq_kwargs['params'],
[('reset_interfaces', True)])
mock__commit.assert_called_once()
commit_args = mock__commit.call_args.args
commit_kwargs = mock__commit.call_args.kwargs
commit_args = mock__commit.call_args[0]
commit_kwargs = mock__commit.call_args[1]
self.assertIn('1.45', commit_args)
self.assertEqual(commit_kwargs['retry_on_conflict'], True)
mock_patch.assert_not_called()

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 openstack.baremetal.v1 import _proxy
from openstack.baremetal.v1 import allocation

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 keystoneauth1 import adapter

View File

@ -10,14 +10,13 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from keystoneauth1 import adapter
from openstack.tests.unit import base
from openstack import exceptions
from openstack.block_storage.v2 import backup
from openstack.tests.unit import base
FAKE_ID = "6685584b-1eac-4da6-b5c3-555430cf68ff"

View File

@ -9,9 +9,7 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from openstack import exceptions
from unittest import mock
from openstack.block_storage.v2 import _proxy
from openstack.block_storage.v2 import backup
@ -19,6 +17,7 @@ from openstack.block_storage.v2 import snapshot
from openstack.block_storage.v2 import stats
from openstack.block_storage.v2 import type
from openstack.block_storage.v2 import volume
from openstack import exceptions
from openstack.tests.unit import test_proxy_base

View File

@ -10,11 +10,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from openstack.tests.unit import base
from unittest import mock
from openstack.block_storage.v2 import volume
from openstack.tests.unit import base
FAKE_ID = "6685584b-1eac-4da6-b5c3-555430cf68ff"
IMAGE_METADATA = {

View File

@ -10,14 +10,13 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from keystoneauth1 import adapter
from openstack.tests.unit import base
from openstack import exceptions
from openstack.block_storage.v3 import backup
from openstack.tests.unit import base
FAKE_ID = "6685584b-1eac-4da6-b5c3-555430cf68ff"

View File

@ -9,9 +9,7 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from openstack import exceptions
from unittest import mock
from openstack.block_storage.v3 import _proxy
from openstack.block_storage.v3 import backup
@ -19,6 +17,7 @@ from openstack.block_storage.v3 import snapshot
from openstack.block_storage.v3 import stats
from openstack.block_storage.v3 import type
from openstack.block_storage.v3 import volume
from openstack import exceptions
from openstack.tests.unit import test_proxy_base

View File

@ -10,11 +10,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from openstack.tests.unit import base
from unittest import mock
from openstack.block_storage.v3 import volume
from openstack.tests.unit import base
FAKE_ID = "6685584b-1eac-4da6-b5c3-555430cf68ff"
IMAGE_METADATA = {

View File

@ -12,16 +12,15 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
from uuid import uuid4
import mock
import testtools
from openstack.cloud import _utils
from openstack.cloud import exc
from openstack.tests.unit import base
RANGE_DATA = [
dict(id=1, key1=1, key2=5),
dict(id=2, key1=1, key2=20),

View File

@ -17,10 +17,9 @@ test_create_server
Tests for the `create_server` command.
"""
import base64
from unittest import mock
import uuid
import mock
from openstack import connection
from openstack.cloud import exc
from openstack.cloud import meta

View File

@ -19,7 +19,7 @@ test_floating_ip_common
Tests floating IP resource methods for Neutron and Nova-network.
"""
from mock import patch
from unittest.mock import patch
from openstack import connection
from openstack.cloud import meta

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from copy import deepcopy
import mock
from unittest import mock
from openstack import exceptions
from openstack.network.v2.firewall_group import FirewallGroup

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 openstack.cloud import inventory
import openstack.config

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
from unittest import mock
from openstack import connection
from openstack.cloud import meta

View File

@ -13,16 +13,16 @@
# under the License.
import tempfile
from unittest import mock
import mock
import testtools
import openstack.cloud
import openstack.cloud.openstackcloud as oc_oc
from openstack.cloud import exc
from openstack import exceptions
from openstack.tests.unit import base
from openstack.object_store.v1 import _proxy
from openstack.tests.unit import base
class BaseTestObject(base.TestCase):

View File

@ -11,8 +11,8 @@
# under the License.
import uuid
from unittest import mock
import mock
import testtools
from openstack.cloud import exc

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
import uuid
import testtools

View File

@ -10,11 +10,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from openstack.tests.unit import base
from unittest import mock
from openstack.clustering.v1 import cluster
from openstack.tests.unit import base
FAKE_ID = '092d0955-2645-461a-b8fa-6a44655cdb2c'
FAKE_NAME = 'test_cluster'

View File

@ -10,11 +10,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from openstack.tests.unit import base
from unittest import mock
from openstack.clustering.v1 import node
from openstack.tests.unit import base
FAKE_ID = '123d0955-0099-aabb-b8fa-6a44655ceeff'
FAKE_NAME = 'test_node'

View File

@ -10,11 +10,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from openstack.tests.unit import base
from unittest import mock
from openstack.clustering.v1 import profile_type
from openstack.tests.unit import base
FAKE = {
'name': 'FAKE_PROFILE_TYPE',

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 openstack.clustering.v1 import _proxy
from openstack.clustering.v1 import action

View File

@ -10,10 +10,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from openstack.tests.unit import base
from unittest import mock
from openstack.clustering.v1 import service
from openstack.tests.unit import base
IDENTIFIER = 'IDENTIFIER'
EXAMPLE = {

View File

@ -10,10 +10,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from openstack.tests.unit import base
from unittest import mock
from openstack.compute.v2 import aggregate
from openstack.tests.unit import base
EXAMPLE = {
"name": "m-family",

View File

@ -11,12 +11,12 @@
# under the License.
import copy
from unittest import mock
from keystoneauth1 import adapter
import mock
from openstack.tests.unit import base
from openstack.compute.v2 import limits
from openstack.tests.unit import base
ABSOLUTE_LIMITS = {
"maxImageMeta": 128,

View File

@ -10,11 +10,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from openstack import exceptions
from openstack.tests.unit import base
from unittest import mock
from openstack.compute.v2 import server
from openstack import exceptions
from openstack.tests.unit import base
IDENTIFIER = 'IDENTIFIER'

View File

@ -9,7 +9,7 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from openstack.compute.v2 import _proxy
from openstack.compute.v2 import availability_zone as az

View File

@ -10,11 +10,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from openstack.tests.unit import base
from unittest import mock
from openstack.image.v2 import image
from openstack.compute.v2 import server
from openstack.image.v2 import image
from openstack.tests.unit import base
IDENTIFIER = 'IDENTIFIER'
EXAMPLE = {

View File

@ -10,10 +10,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from openstack.tests.unit import base
from unittest import mock
from openstack.compute.v2 import server_ip
from openstack.tests.unit import base
IDENTIFIER = 'IDENTIFIER'
EXAMPLE = {

View File

@ -10,10 +10,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from openstack.tests.unit import base
from unittest import mock
from openstack.compute.v2 import service
from openstack.tests.unit import base
IDENTIFIER = 'IDENTIFIER'
EXAMPLE = {

View File

@ -11,17 +11,16 @@
# under the License.
import copy
from unittest import mock
from keystoneauth1 import exceptions as ksa_exceptions
from keystoneauth1 import session as ksa_session
import mock
from openstack import version as openstack_version
from openstack.config import cloud_region
from openstack.config import defaults
from openstack import exceptions
from openstack.tests.unit.config import base
from openstack import version as openstack_version
fake_config_dict = {'a': 1, 'os_b': 2, 'c': 3, 'os_c': 4}
fake_services_dict = {

View File

@ -10,10 +10,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from openstack.tests.unit import base
from unittest import mock
from openstack.database.v1 import instance
from openstack.tests.unit import base
IDENTIFIER = 'IDENTIFIER'
EXAMPLE = {

View File

@ -10,13 +10,12 @@
# License for the specific language governing permissions and limitations
# under the License.
from keystoneauth1 import adapter
import mock
from unittest import mock
from openstack.tests.unit import base
from keystoneauth1 import adapter
from openstack.dns.v2 import zone
from openstack.tests.unit import base
IDENTIFIER = 'NAME'
EXAMPLE = {

View File

@ -9,11 +9,12 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from keystoneauth1 import adapter
from openstack.tests.unit import base
from openstack.dns.v2 import zone_export
from openstack.tests.unit import base
IDENTIFIER = '074e805e-fe87-4cbb-b10b-21a06e215d41'

View File

@ -9,12 +9,12 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from keystoneauth1 import adapter
from openstack.tests.unit import base
from openstack.dns.v2 import zone_import
from openstack.tests.unit import base
IDENTIFIER = '074e805e-fe87-4cbb-b10b-21a06e215d41'
EXAMPLE = {

View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
class FakeTransport(mock.Mock):

View File

@ -10,10 +10,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from openstack.tests.unit import base
from unittest import mock
from openstack.identity import version
from openstack.tests.unit import base
IDENTIFIER = 'IDENTIFIER'
EXAMPLE = {

View File

@ -10,10 +10,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from openstack.tests.unit import base
from unittest import mock
from openstack.identity.v2 import extension
from openstack.tests.unit import base
IDENTIFIER = 'IDENTIFIER'
EXAMPLE = {

View File

@ -13,15 +13,15 @@ import hashlib
import io
import operator
import tempfile
from unittest import mock
from keystoneauth1 import adapter
import mock
import requests
from openstack.tests.unit import base
from openstack import _log
from openstack import exceptions
from openstack.image.v2 import image
from openstack.tests.unit import base
IDENTIFIER = 'IDENTIFIER'
EXAMPLE = {

View File

@ -10,8 +10,9 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
import io
from unittest import mock
import requests
from openstack import exceptions

View File

@ -10,10 +10,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from openstack.tests.unit import base
from unittest import mock
from openstack.key_manager.v1 import secret
from openstack.tests.unit import base
ID_VAL = "123"
IDENTIFIER = 'http://localhost:9311/v1/secrets/%s' % ID_VAL

View File

@ -10,11 +10,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from openstack.tests.unit import base
from unittest import mock
import uuid
from openstack.load_balancer.v2 import load_balancer
from openstack.tests.unit import base
IDENTIFIER = 'IDENTIFIER'
EXAMPLE = {

View File

@ -11,7 +11,7 @@
# under the License.
import uuid
import mock
from unittest import mock
from openstack.load_balancer.v2 import _proxy
from openstack.load_balancer.v2 import amphora

View File

@ -11,12 +11,11 @@
# under the License.
import copy
import mock
from openstack.tests.unit import base
from unittest import mock
import uuid
from openstack.message.v2 import claim
from openstack.tests.unit import base
FAKE1 = {
"age": 1632,

View File

@ -10,12 +10,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from openstack.tests.unit import base
from unittest import mock
import uuid
from openstack.message.v2 import message
from openstack.tests.unit import base
FAKE1 = {
'age': 456,

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 openstack.message.v2 import _proxy
from openstack.message.v2 import claim

View File

@ -10,12 +10,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from openstack.tests.unit import base
from unittest import mock
import uuid
from openstack.message.v2 import queue
from openstack.tests.unit import base
FAKE1 = {
'name': 'test_queue',

View File

@ -11,11 +11,11 @@
# under the License.
import copy
import mock
from openstack.tests.unit import base
from unittest import mock
import uuid
from openstack.message.v2 import subscription
from openstack.tests.unit import base
FAKE1 = {

View File

@ -10,10 +10,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from openstack.tests.unit import base
from unittest import mock
from openstack.network.v2 import agent
from openstack.tests.unit import base
IDENTIFIER = 'IDENTIFIER'
EXAMPLE = {

View File

@ -10,10 +10,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from openstack.tests.unit import base
from unittest import mock
from openstack.network.v2 import flavor
from openstack.tests.unit import base
IDENTIFIER = 'IDENTIFIER'
EXAMPLE_WITH_OPTIONAL = {

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 openstack import proxy
from openstack.network.v2 import floating_ip

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
import uuid
from openstack import exceptions

View File

@ -10,13 +10,13 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
import testtools
from openstack import exceptions
from openstack.tests.unit import base
from openstack.network.v2 import router
from openstack.tests.unit import base
IDENTIFIER = 'IDENTIFIER'
EXAMPLE = {

View File

@ -10,7 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
import testtools
from openstack import exceptions

View File

@ -12,11 +12,11 @@
from testscenarios import load_tests_apply_scenarios as load_tests # noqa
from hashlib import sha1
import mock
import random
import string
import tempfile
import time
from unittest import mock
from openstack.object_store.v1 import account
from openstack.object_store.v1 import container

View File

@ -11,7 +11,7 @@
# under the License.
from testscenarios import load_tests_apply_scenarios as load_tests # noqa
import mock
from unittest import mock
from openstack import exceptions
from openstack.orchestration.v1 import _proxy

View File

@ -10,15 +10,13 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from openstack.tests.unit import base
from openstack.tests.unit import test_resource
from unittest import mock
from openstack import exceptions
from openstack.orchestration.v1 import stack
from openstack import resource
from openstack.tests.unit import base
from openstack.tests.unit import test_resource
FAKE_ID = 'ce8ae86c-9810-4cb1-8888-7fb53bc523bf'
FAKE_NAME = 'test_stack'

View File

@ -10,11 +10,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from openstack.tests.unit import base
from unittest import mock
from openstack.orchestration.v1 import stack_files as sf
from openstack import resource
from openstack.tests.unit import base
FAKE = {
'stack_id': 'ID',

View File

@ -10,12 +10,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from openstack.tests.unit import base
from unittest import mock
from openstack.orchestration.v1 import template
from openstack import resource
from openstack.tests.unit import base
FAKE = {
'Description': 'Blah blah',

View File

@ -11,10 +11,10 @@
# under the License.
import os
from unittest import mock
import fixtures
from keystoneauth1 import session
import mock
from testtools import matchers
from openstack import connection

View File

@ -13,12 +13,11 @@
# under the License.
import json
import mock
from openstack.tests.unit import base
from unittest import mock
import uuid
from openstack import exceptions
from openstack.tests.unit import base
class Test_Exception(base.TestCase):

View File

@ -11,13 +11,14 @@
# under the License.
from testscenarios import load_tests_apply_scenarios as load_tests # noqa
import mock
from unittest import mock
import munch
from openstack.tests.unit import base
from openstack import exceptions
from openstack import proxy
from openstack import resource
from openstack.tests.unit import base
class DeleteableResource(resource.Resource):

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 openstack.tests.unit import base

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 openstack.tests.unit import base

View File

@ -12,9 +12,9 @@
import itertools
import json
from unittest import mock
from keystoneauth1 import adapter
import mock
import munch
import requests

View File

@ -12,20 +12,18 @@
# License for the specific language governing permissions and limitations
# under the License.
import logging
import mock
import sys
from openstack.tests.unit import base
import concurrent.futures
import testtools
import logging
from unittest import mock
import sys
import fixtures
import os_service_types
import testtools
import openstack
from openstack import exceptions
from openstack.tests.unit import base
from openstack import utils

View File

@ -7,7 +7,6 @@ coverage!=4.4,>=4.0 # Apache-2.0
ddt>=1.0.1 # MIT
fixtures>=3.0.0 # Apache-2.0/BSD
jsonschema>=3.2.0 # MIT
mock>=3.0.0 # BSD
prometheus-client>=0.4.2 # Apache-2.0
oslo.config>=6.1.0 # Apache-2.0
oslotest>=3.2.0 # Apache-2.0