diff options
author | Matt Clay <mclay@redhat.com> | 2021-08-11 13:08:31 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-11 13:08:31 -0700 |
commit | 04009a77e67900f5f362a65892ffe3b9f456e0b5 (patch) | |
tree | 9acd7549df525e5a79a9f018fb2ef0802e80a835 | |
parent | ca2d2c5f38f2d4d4e6f6eed4f209520289c6f322 (diff) | |
download | ansible-04009a77e67900f5f362a65892ffe3b9f456e0b5.tar.gz |
Clean up unit tests to prepare for pylint update. (#75473)
* Fix argument name in mocked function.
* Use from import in unit tests.
* Remove unused imports.
7 files changed, 9 insertions, 12 deletions
diff --git a/test/units/mock/loader.py b/test/units/mock/loader.py index c47ec39e8c..f6ceb37903 100644 --- a/test/units/mock/loader.py +++ b/test/units/mock/loader.py @@ -47,12 +47,12 @@ class DictDataLoader(DataLoader): # TODO: the real _get_file_contents returns a bytestring, so we actually convert the # unicode/text it's created with to utf-8 - def _get_file_contents(self, path): - path = to_text(path) + def _get_file_contents(self, file_name): + path = to_text(file_name) if path in self._file_mapping: - return (to_bytes(self._file_mapping[path]), False) + return to_bytes(self._file_mapping[file_name]), False else: - raise AnsibleParserError("file not found: %s" % path) + raise AnsibleParserError("file not found: %s" % file_name) def path_exists(self, path): path = to_text(path) diff --git a/test/units/module_utils/common/arg_spec/test_module_validate.py b/test/units/module_utils/common/arg_spec/test_module_validate.py index 350e9da170..5041d521bd 100644 --- a/test/units/module_utils/common/arg_spec/test_module_validate.py +++ b/test/units/module_utils/common/arg_spec/test_module_validate.py @@ -5,7 +5,7 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -import ansible.module_utils.common.warnings as warnings +from ansible.module_utils.common import warnings from ansible.module_utils.common.arg_spec import ModuleArgumentSpecValidator, ValidationResult diff --git a/test/units/module_utils/common/arg_spec/test_validate_valid.py b/test/units/module_utils/common/arg_spec/test_validate_valid.py index b35b856f3a..7e41127e69 100644 --- a/test/units/module_utils/common/arg_spec/test_validate_valid.py +++ b/test/units/module_utils/common/arg_spec/test_validate_valid.py @@ -7,8 +7,6 @@ __metaclass__ = type import pytest -import ansible.module_utils.common.warnings as warnings - from ansible.module_utils.common.arg_spec import ArgumentSpecValidator, ValidationResult # Each item is id, argument_spec, parameters, expected, valid parameter names diff --git a/test/units/module_utils/common/warnings/test_deprecate.py b/test/units/module_utils/common/warnings/test_deprecate.py index 02bac7a629..08c1b35858 100644 --- a/test/units/module_utils/common/warnings/test_deprecate.py +++ b/test/units/module_utils/common/warnings/test_deprecate.py @@ -7,7 +7,7 @@ __metaclass__ = type import pytest -import ansible.module_utils.common.warnings as warnings +from ansible.module_utils.common import warnings from ansible.module_utils.common.warnings import deprecate, get_deprecation_messages from ansible.module_utils.six import PY3 diff --git a/test/units/module_utils/common/warnings/test_warn.py b/test/units/module_utils/common/warnings/test_warn.py index 020b062521..41e1a7b339 100644 --- a/test/units/module_utils/common/warnings/test_warn.py +++ b/test/units/module_utils/common/warnings/test_warn.py @@ -7,7 +7,7 @@ __metaclass__ = type import pytest -import ansible.module_utils.common.warnings as warnings +from ansible.module_utils.common import warnings from ansible.module_utils.common.warnings import warn, get_warning_messages from ansible.module_utils.six import PY3 diff --git a/test/units/module_utils/urls/test_channel_binding.py b/test/units/module_utils/urls/test_channel_binding.py index 05b461e07a..ea9cd01ceb 100644 --- a/test/units/module_utils/urls/test_channel_binding.py +++ b/test/units/module_utils/urls/test_channel_binding.py @@ -9,7 +9,7 @@ import base64 import os.path import pytest -import ansible.module_utils.urls as urls +from ansible.module_utils import urls @pytest.mark.skipif(not urls.HAS_CRYPTOGRAPHY, reason='Requires cryptography to be installed') diff --git a/test/units/plugins/action/test_gather_facts.py b/test/units/plugins/action/test_gather_facts.py index fa28fdce6b..8f860e4a5c 100644 --- a/test/units/plugins/action/test_gather_facts.py +++ b/test/units/plugins/action/test_gather_facts.py @@ -24,9 +24,8 @@ from units.compat.mock import MagicMock, patch from ansible import constants as C from ansible.playbook.task import Task from ansible.plugins.action.gather_facts import ActionModule as GatherFactsAction -from ansible.plugins import loader as plugin_loader from ansible.template import Templar -import ansible.executor.module_common as module_common +from ansible.executor import module_common from units.mock.loader import DictDataLoader |