diff options
author | Matt Clay <matt@mystile.com> | 2022-05-23 11:04:56 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-23 11:04:56 -0700 |
commit | 3a9a23fb1a7e617479d0ae72dadba0f7a739d13a (patch) | |
tree | dc8ab7f0e2eae3631fe16ea596c3a4ba22f44acd | |
parent | 1eb7f71f0ebd1964bd108f75cb78adedfbfd9796 (diff) | |
download | ansible-3a9a23fb1a7e617479d0ae72dadba0f7a739d13a.tar.gz |
Use unittest.mock instead of mock. (#77883)
This can only be done for controller tests.
47 files changed, 48 insertions, 48 deletions
diff --git a/test/units/_vendor/test_vendor.py b/test/units/_vendor/test_vendor.py index cda0279d60..84b850e2d8 100644 --- a/test/units/_vendor/test_vendor.py +++ b/test/units/_vendor/test_vendor.py @@ -9,7 +9,7 @@ import pkgutil import pytest import sys -from mock import MagicMock, NonCallableMagicMock, patch +from unittest.mock import MagicMock, NonCallableMagicMock, patch def reset_internal_vendor_package(): diff --git a/test/units/cli/test_cli.py b/test/units/cli/test_cli.py index 262859552c..79c2b8fb98 100644 --- a/test/units/cli/test_cli.py +++ b/test/units/cli/test_cli.py @@ -20,7 +20,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type from units.compat import unittest -from mock import patch, MagicMock +from unittest.mock import patch, MagicMock from units.mock.loader import DictDataLoader diff --git a/test/units/cli/test_console.py b/test/units/cli/test_console.py index fb477bf392..4fc05dd36a 100644 --- a/test/units/cli/test_console.py +++ b/test/units/cli/test_console.py @@ -20,7 +20,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type from units.compat import unittest -from mock import patch +from unittest.mock import patch from ansible.cli.console import ConsoleCLI diff --git a/test/units/cli/test_galaxy.py b/test/units/cli/test_galaxy.py index 1a6bfe04b6..3b975beedd 100644 --- a/test/units/cli/test_galaxy.py +++ b/test/units/cli/test_galaxy.py @@ -41,7 +41,7 @@ from ansible.module_utils._text import to_bytes, to_native, to_text from ansible.utils import context_objects as co from ansible.utils.display import Display from units.compat import unittest -from mock import patch, MagicMock +from unittest.mock import patch, MagicMock @pytest.fixture(autouse='function') diff --git a/test/units/cli/test_vault.py b/test/units/cli/test_vault.py index 76ffba2f42..2304f4d5cd 100644 --- a/test/units/cli/test_vault.py +++ b/test/units/cli/test_vault.py @@ -24,7 +24,7 @@ import os import pytest from units.compat import unittest -from mock import patch, MagicMock +from unittest.mock import patch, MagicMock from units.mock.vault_helper import TextVaultSecret from ansible import context, errors diff --git a/test/units/errors/test_errors.py b/test/units/errors/test_errors.py index deb3dc0b1c..005be29e88 100644 --- a/test/units/errors/test_errors.py +++ b/test/units/errors/test_errors.py @@ -21,7 +21,7 @@ __metaclass__ = type from units.compat import unittest -from mock import mock_open, patch +from unittest.mock import mock_open, patch from ansible.errors import AnsibleError from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject diff --git a/test/units/executor/test_interpreter_discovery.py b/test/units/executor/test_interpreter_discovery.py index 5efdd37894..43db595056 100644 --- a/test/units/executor/test_interpreter_discovery.py +++ b/test/units/executor/test_interpreter_discovery.py @@ -6,7 +6,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -from mock import MagicMock +from unittest.mock import MagicMock from ansible.executor.interpreter_discovery import discover_interpreter from ansible.module_utils._text import to_text diff --git a/test/units/executor/test_play_iterator.py b/test/units/executor/test_play_iterator.py index 3f312d8dc1..386a76e28c 100644 --- a/test/units/executor/test_play_iterator.py +++ b/test/units/executor/test_play_iterator.py @@ -20,7 +20,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type from units.compat import unittest -from mock import patch, MagicMock +from unittest.mock import patch, MagicMock from ansible.executor.play_iterator import HostState, PlayIterator, IteratingStates, FailedStates from ansible.playbook import Playbook diff --git a/test/units/executor/test_playbook_executor.py b/test/units/executor/test_playbook_executor.py index 350f7c2dcf..6032dbb2ab 100644 --- a/test/units/executor/test_playbook_executor.py +++ b/test/units/executor/test_playbook_executor.py @@ -20,7 +20,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type from units.compat import unittest -from mock import MagicMock +from unittest.mock import MagicMock from ansible.executor.playbook_executor import PlaybookExecutor from ansible.playbook import Playbook diff --git a/test/units/executor/test_task_executor.py b/test/units/executor/test_task_executor.py index 30d609a1ab..29eb7898ce 100644 --- a/test/units/executor/test_task_executor.py +++ b/test/units/executor/test_task_executor.py @@ -19,10 +19,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import mock +from unittest import mock from units.compat import unittest -from mock import patch, MagicMock +from unittest.mock import patch, MagicMock from ansible.errors import AnsibleError from ansible.executor.task_executor import TaskExecutor, remove_omit from ansible.plugins.loader import action_loader, lookup_loader diff --git a/test/units/executor/test_task_queue_manager_callbacks.py b/test/units/executor/test_task_queue_manager_callbacks.py index b6b1159d17..c63385dc8b 100644 --- a/test/units/executor/test_task_queue_manager_callbacks.py +++ b/test/units/executor/test_task_queue_manager_callbacks.py @@ -19,7 +19,7 @@ from __future__ import (absolute_import, division, print_function) from units.compat import unittest -from mock import MagicMock +from unittest.mock import MagicMock from ansible.executor.task_queue_manager import TaskQueueManager from ansible.playbook import Playbook diff --git a/test/units/executor/test_task_result.py b/test/units/executor/test_task_result.py index ee5c71986f..8b79571f23 100644 --- a/test/units/executor/test_task_result.py +++ b/test/units/executor/test_task_result.py @@ -20,7 +20,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type from units.compat import unittest -from mock import patch, MagicMock +from unittest.mock import patch, MagicMock from ansible.executor.task_result import TaskResult diff --git a/test/units/galaxy/test_api.py b/test/units/galaxy/test_api.py index a2965012b1..1e291555ae 100644 --- a/test/units/galaxy/test_api.py +++ b/test/units/galaxy/test_api.py @@ -16,7 +16,7 @@ import tempfile import time from io import BytesIO, StringIO -from mock import MagicMock +from unittest.mock import MagicMock import ansible.constants as C from ansible import context diff --git a/test/units/galaxy/test_collection.py b/test/units/galaxy/test_collection.py index 6e87ed8c44..0286e0b36d 100644 --- a/test/units/galaxy/test_collection.py +++ b/test/units/galaxy/test_collection.py @@ -16,7 +16,7 @@ import uuid from hashlib import sha256 from io import BytesIO -from mock import MagicMock, mock_open, patch +from unittest.mock import MagicMock, mock_open, patch import ansible.constants as C from ansible import context diff --git a/test/units/galaxy/test_collection_install.py b/test/units/galaxy/test_collection_install.py index 7134e73ce1..b528601303 100644 --- a/test/units/galaxy/test_collection_install.py +++ b/test/units/galaxy/test_collection_install.py @@ -17,7 +17,7 @@ import tarfile import yaml from io import BytesIO, StringIO -from mock import MagicMock, patch +from unittest.mock import MagicMock, patch from unittest import mock import ansible.module_utils.six.moves.urllib.error as urllib_error diff --git a/test/units/galaxy/test_token.py b/test/units/galaxy/test_token.py index 98dec5bfab..24af386314 100644 --- a/test/units/galaxy/test_token.py +++ b/test/units/galaxy/test_token.py @@ -8,7 +8,7 @@ __metaclass__ = type import os import pytest -from mock import MagicMock +from unittest.mock import MagicMock import ansible.constants as C from ansible.cli.galaxy import GalaxyCLI, SERVER_DEF diff --git a/test/units/mock/path.py b/test/units/mock/path.py index dc51a143cb..c24ddf42dc 100644 --- a/test/units/mock/path.py +++ b/test/units/mock/path.py @@ -1,7 +1,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -from mock import MagicMock +from unittest.mock import MagicMock from ansible.utils.path import unfrackpath diff --git a/test/units/parsing/test_dataloader.py b/test/units/parsing/test_dataloader.py index ed365b130f..9ec49a8d31 100644 --- a/test/units/parsing/test_dataloader.py +++ b/test/units/parsing/test_dataloader.py @@ -22,7 +22,7 @@ __metaclass__ = type import os from units.compat import unittest -from mock import patch, mock_open +from unittest.mock import patch, mock_open from ansible.errors import AnsibleParserError, yaml_strings, AnsibleFileNotFound from ansible.parsing.vault import AnsibleVaultError from ansible.module_utils._text import to_text diff --git a/test/units/parsing/vault/test_vault.py b/test/units/parsing/vault/test_vault.py index f92d451c5e..7afd356008 100644 --- a/test/units/parsing/vault/test_vault.py +++ b/test/units/parsing/vault/test_vault.py @@ -30,7 +30,7 @@ from binascii import hexlify import pytest from units.compat import unittest -from mock import patch, MagicMock +from unittest.mock import patch, MagicMock from ansible import errors from ansible.module_utils import six diff --git a/test/units/parsing/vault/test_vault_editor.py b/test/units/parsing/vault/test_vault_editor.py index 3f19b893e8..77509f08aa 100644 --- a/test/units/parsing/vault/test_vault_editor.py +++ b/test/units/parsing/vault/test_vault_editor.py @@ -27,7 +27,7 @@ from io import BytesIO, StringIO import pytest from units.compat import unittest -from mock import patch +from unittest.mock import patch from ansible import errors from ansible.parsing import vault diff --git a/test/units/playbook/role/test_include_role.py b/test/units/playbook/role/test_include_role.py index 79821b40f3..5e7625ba14 100644 --- a/test/units/playbook/role/test_include_role.py +++ b/test/units/playbook/role/test_include_role.py @@ -20,7 +20,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type from units.compat import unittest -from mock import patch +from unittest.mock import patch from ansible.playbook import Play from ansible.playbook.role_include import IncludeRole diff --git a/test/units/playbook/role/test_role.py b/test/units/playbook/role/test_role.py index dacbc79cb2..5d47631fe2 100644 --- a/test/units/playbook/role/test_role.py +++ b/test/units/playbook/role/test_role.py @@ -22,7 +22,7 @@ __metaclass__ = type from collections.abc import Container from units.compat import unittest -from mock import patch, MagicMock +from unittest.mock import patch, MagicMock from ansible.errors import AnsibleError, AnsibleParserError from ansible.playbook.block import Block diff --git a/test/units/playbook/test_conditional.py b/test/units/playbook/test_conditional.py index 8729ba9e4b..8231d16c6f 100644 --- a/test/units/playbook/test_conditional.py +++ b/test/units/playbook/test_conditional.py @@ -3,7 +3,7 @@ __metaclass__ = type from units.compat import unittest from units.mock.loader import DictDataLoader -from mock import MagicMock +from unittest.mock import MagicMock from ansible.template import Templar from ansible import errors diff --git a/test/units/playbook/test_helpers.py b/test/units/playbook/test_helpers.py index 63795a496b..d7b1cf6532 100644 --- a/test/units/playbook/test_helpers.py +++ b/test/units/playbook/test_helpers.py @@ -22,7 +22,7 @@ __metaclass__ = type import os from units.compat import unittest -from mock import MagicMock +from unittest.mock import MagicMock from units.mock.loader import DictDataLoader from ansible import errors diff --git a/test/units/playbook/test_included_file.py b/test/units/playbook/test_included_file.py index bf79b9275f..7341dffa6b 100644 --- a/test/units/playbook/test_included_file.py +++ b/test/units/playbook/test_included_file.py @@ -23,7 +23,7 @@ import os import pytest -from mock import MagicMock +from unittest.mock import MagicMock from units.mock.loader import DictDataLoader from ansible.playbook.block import Block diff --git a/test/units/playbook/test_task.py b/test/units/playbook/test_task.py index 53a6670501..070d7aa761 100644 --- a/test/units/playbook/test_task.py +++ b/test/units/playbook/test_task.py @@ -20,7 +20,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type from units.compat import unittest -from mock import patch +from unittest.mock import patch from ansible.playbook.task import Task from ansible.parsing.yaml import objects from ansible import errors diff --git a/test/units/plugins/action/test_action.py b/test/units/plugins/action/test_action.py index d69f28df8a..74b08e38f6 100644 --- a/test/units/plugins/action/test_action.py +++ b/test/units/plugins/action/test_action.py @@ -25,7 +25,7 @@ import re from ansible import constants as C from units.compat import unittest -from mock import patch, MagicMock, mock_open +from unittest.mock import patch, MagicMock, mock_open from ansible.errors import AnsibleError, AnsibleAuthenticationFailure from ansible.module_utils.six import text_type diff --git a/test/units/plugins/action/test_gather_facts.py b/test/units/plugins/action/test_gather_facts.py index e8a607b7f8..20225aa958 100644 --- a/test/units/plugins/action/test_gather_facts.py +++ b/test/units/plugins/action/test_gather_facts.py @@ -19,7 +19,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type from units.compat import unittest -from mock import MagicMock, patch +from unittest.mock import MagicMock, patch from ansible import constants as C from ansible.playbook.task import Task diff --git a/test/units/plugins/action/test_raw.py b/test/units/plugins/action/test_raw.py index da21638511..33480516d7 100644 --- a/test/units/plugins/action/test_raw.py +++ b/test/units/plugins/action/test_raw.py @@ -22,7 +22,7 @@ import os from ansible.errors import AnsibleActionFail from units.compat import unittest -from mock import MagicMock, Mock +from unittest.mock import MagicMock, Mock from ansible.plugins.action.raw import ActionModule from ansible.playbook.task import Task from ansible.plugins.loader import connection_loader diff --git a/test/units/plugins/cache/test_cache.py b/test/units/plugins/cache/test_cache.py index 9241d85279..25b84c0624 100644 --- a/test/units/plugins/cache/test_cache.py +++ b/test/units/plugins/cache/test_cache.py @@ -23,7 +23,7 @@ import os import shutil import tempfile -import mock +from unittest import mock from units.compat import unittest from ansible.errors import AnsibleError diff --git a/test/units/plugins/callback/test_callback.py b/test/units/plugins/callback/test_callback.py index 81ee3745e8..ccfa4658e5 100644 --- a/test/units/plugins/callback/test_callback.py +++ b/test/units/plugins/callback/test_callback.py @@ -25,7 +25,7 @@ import textwrap import types from units.compat import unittest -from mock import MagicMock +from unittest.mock import MagicMock from ansible.executor.task_result import TaskResult from ansible.inventory.host import Host diff --git a/test/units/plugins/connection/test_psrp.py b/test/units/plugins/connection/test_psrp.py index 73516cc60b..38052e81d3 100644 --- a/test/units/plugins/connection/test_psrp.py +++ b/test/units/plugins/connection/test_psrp.py @@ -10,7 +10,7 @@ import pytest import sys from io import StringIO -from mock import MagicMock +from unittest.mock import MagicMock from ansible.playbook.play_context import PlayContext from ansible.plugins.loader import connection_loader diff --git a/test/units/plugins/connection/test_ssh.py b/test/units/plugins/connection/test_ssh.py index e7f4dd1271..662dff9192 100644 --- a/test/units/plugins/connection/test_ssh.py +++ b/test/units/plugins/connection/test_ssh.py @@ -27,7 +27,7 @@ import pytest from ansible import constants as C from ansible.errors import AnsibleAuthenticationFailure from units.compat import unittest -from mock import patch, MagicMock, PropertyMock +from unittest.mock import patch, MagicMock, PropertyMock from ansible.errors import AnsibleError, AnsibleConnectionFailure, AnsibleFileNotFound from ansible.module_utils.compat.selectors import SelectorKey, EVENT_READ from ansible.module_utils.six.moves import shlex_quote diff --git a/test/units/plugins/connection/test_winrm.py b/test/units/plugins/connection/test_winrm.py index c3245ccb01..cb52814b86 100644 --- a/test/units/plugins/connection/test_winrm.py +++ b/test/units/plugins/connection/test_winrm.py @@ -12,7 +12,7 @@ import pytest from io import StringIO -from mock import MagicMock +from unittest.mock import MagicMock from ansible.errors import AnsibleConnectionFailure from ansible.module_utils._text import to_bytes from ansible.playbook.play_context import PlayContext diff --git a/test/units/plugins/inventory/test_inventory.py b/test/units/plugins/inventory/test_inventory.py index 08148f8b62..df24607365 100644 --- a/test/units/plugins/inventory/test_inventory.py +++ b/test/units/plugins/inventory/test_inventory.py @@ -22,7 +22,7 @@ __metaclass__ = type import string import textwrap -import mock +from unittest import mock from ansible import constants as C from units.compat import unittest diff --git a/test/units/plugins/inventory/test_script.py b/test/units/plugins/inventory/test_script.py index 1a00946c56..9f75199f16 100644 --- a/test/units/plugins/inventory/test_script.py +++ b/test/units/plugins/inventory/test_script.py @@ -22,7 +22,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type import pytest -import mock +from unittest import mock from ansible import constants as C from ansible.errors import AnsibleError diff --git a/test/units/plugins/lookup/test_password.py b/test/units/plugins/lookup/test_password.py index c496ee6ed1..73b50418e1 100644 --- a/test/units/plugins/lookup/test_password.py +++ b/test/units/plugins/lookup/test_password.py @@ -32,7 +32,7 @@ import pytest from units.mock.loader import DictDataLoader from units.compat import unittest -from mock import mock_open, patch +from unittest.mock import mock_open, patch from ansible.errors import AnsibleError from ansible.module_utils.six import text_type from ansible.module_utils.six.moves import builtins diff --git a/test/units/plugins/strategy/test_linear.py b/test/units/plugins/strategy/test_linear.py index 3bce485613..2574e84fff 100644 --- a/test/units/plugins/strategy/test_linear.py +++ b/test/units/plugins/strategy/test_linear.py @@ -7,7 +7,7 @@ __metaclass__ = type from units.compat import unittest -from mock import patch, MagicMock +from unittest.mock import patch, MagicMock from ansible.executor.play_iterator import PlayIterator from ansible.playbook import Playbook diff --git a/test/units/plugins/strategy/test_strategy.py b/test/units/plugins/strategy/test_strategy.py index 750e806906..bc4bb54515 100644 --- a/test/units/plugins/strategy/test_strategy.py +++ b/test/units/plugins/strategy/test_strategy.py @@ -23,7 +23,7 @@ from units.mock.loader import DictDataLoader import uuid from units.compat import unittest -from mock import patch, MagicMock +from unittest.mock import patch, MagicMock from ansible.executor.process.worker import WorkerProcess from ansible.executor.task_queue_manager import TaskQueueManager from ansible.executor.task_result import TaskResult diff --git a/test/units/plugins/test_plugins.py b/test/units/plugins/test_plugins.py index 975fa420b1..46cd582d35 100644 --- a/test/units/plugins/test_plugins.py +++ b/test/units/plugins/test_plugins.py @@ -23,7 +23,7 @@ __metaclass__ = type import os from units.compat import unittest -from mock import patch, MagicMock +from unittest.mock import patch, MagicMock from ansible.plugins.loader import PluginLoader, PluginPathContext diff --git a/test/units/template/test_templar.py b/test/units/template/test_templar.py index e922f95f36..6747f76831 100644 --- a/test/units/template/test_templar.py +++ b/test/units/template/test_templar.py @@ -22,7 +22,7 @@ __metaclass__ = type from jinja2.runtime import Context from units.compat import unittest -from mock import patch +from unittest.mock import patch from ansible import constants as C from ansible.errors import AnsibleError, AnsibleUndefinedVariable diff --git a/test/units/template/test_vars.py b/test/units/template/test_vars.py index 3e04ba2fab..514104f23b 100644 --- a/test/units/template/test_vars.py +++ b/test/units/template/test_vars.py @@ -20,7 +20,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type from units.compat import unittest -from mock import MagicMock +from unittest.mock import MagicMock from ansible.template.vars import AnsibleJ2Vars diff --git a/test/units/utils/collection_loader/test_collection_loader.py b/test/units/utils/collection_loader/test_collection_loader.py index 3ae04cbd10..f7050dcd6d 100644 --- a/test/units/utils/collection_loader/test_collection_loader.py +++ b/test/units/utils/collection_loader/test_collection_loader.py @@ -17,7 +17,7 @@ from ansible.utils.collection_loader._collection_finder import ( _get_collection_name_from_path, _get_collection_role_path, _get_collection_metadata, _iter_modules_impl ) from ansible.utils.collection_loader._collection_config import _EventSource -from mock import MagicMock, NonCallableMagicMock, patch +from unittest.mock import MagicMock, NonCallableMagicMock, patch # fixture to ensure we always clean up the import stuff when we're done diff --git a/test/units/utils/display/test_broken_cowsay.py b/test/units/utils/display/test_broken_cowsay.py index e93065d8e0..d888010ae5 100644 --- a/test/units/utils/display/test_broken_cowsay.py +++ b/test/units/utils/display/test_broken_cowsay.py @@ -8,7 +8,7 @@ __metaclass__ = type from ansible.utils.display import Display -from mock import MagicMock +from unittest.mock import MagicMock def test_display_with_fake_cowsay_binary(capsys, mocker): diff --git a/test/units/utils/test_display.py b/test/units/utils/test_display.py index 8807b81675..4883a5becc 100644 --- a/test/units/utils/test_display.py +++ b/test/units/utils/test_display.py @@ -5,7 +5,7 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -from mock import MagicMock +from unittest.mock import MagicMock import pytest diff --git a/test/units/utils/test_vars.py b/test/units/utils/test_vars.py index 1df0eab32b..9be33de429 100644 --- a/test/units/utils/test_vars.py +++ b/test/units/utils/test_vars.py @@ -22,7 +22,7 @@ __metaclass__ = type from collections import defaultdict -import mock +from unittest import mock from units.compat import unittest from ansible.errors import AnsibleError diff --git a/test/units/vars/test_variable_manager.py b/test/units/vars/test_variable_manager.py index fa68fd3bdb..67ec120b1d 100644 --- a/test/units/vars/test_variable_manager.py +++ b/test/units/vars/test_variable_manager.py @@ -22,7 +22,7 @@ __metaclass__ = type import os from units.compat import unittest -from mock import MagicMock, patch +from unittest.mock import MagicMock, patch from ansible.inventory.manager import InventoryManager from ansible.module_utils.six import iteritems from ansible.playbook.play import Play |