From feedfb51db3ed975235e313bfad504a413e7ab15 Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Wed, 5 Jul 2023 14:31:53 +0200 Subject: [PATCH] Varous fixes Signed-off-by: Alina Buzachis --- tests/unit/module_utils/cloud/test_cloud_retry.py | 3 --- .../unit/module_utils/cloud/test_decorator_generation.py | 8 +++----- tests/unit/module_utils/cloud/test_retry_func.py | 8 +++----- tests/unit/module_utils/test_elbv2.py | 5 ++--- tests/unit/module_utils/test_iam.py | 5 +---- tests/unit/module_utils/test_rds.py | 9 +-------- tests/unit/module_utils/test_s3.py | 5 +---- .../module_utils/transformation/test_map_complex_type.py | 5 +---- .../modules/ec2_instance/test_build_run_instance_spec.py | 6 +----- .../modules/ec2_instance/test_determine_iam_role.py | 8 ++------ tests/unit/plugins/modules/test_ec2_vpc_dhcp_option.py | 4 +--- tests/unit/plugins/modules/utils.py | 7 +++---- 12 files changed, 19 insertions(+), 54 deletions(-) diff --git a/tests/unit/module_utils/cloud/test_cloud_retry.py b/tests/unit/module_utils/cloud/test_cloud_retry.py index ce5f03f119..e6d362ad43 100644 --- a/tests/unit/module_utils/cloud/test_cloud_retry.py +++ b/tests/unit/module_utils/cloud/test_cloud_retry.py @@ -3,9 +3,6 @@ # This file is part of Ansible # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - import random from datetime import datetime import pytest diff --git a/tests/unit/module_utils/cloud/test_decorator_generation.py b/tests/unit/module_utils/cloud/test_decorator_generation.py index 23b4467634..b1f19c7554 100644 --- a/tests/unit/module_utils/cloud/test_decorator_generation.py +++ b/tests/unit/module_utils/cloud/test_decorator_generation.py @@ -3,16 +3,14 @@ # This file is part of Ansible # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - import pytest import sys +from unittest.mock import MagicMock +from unittest.mock import sentinel + from ansible_collections.amazon.aws.plugins.module_utils.cloud import CloudRetry from ansible_collections.amazon.aws.plugins.module_utils.cloud import BackoffIterator -from ansible_collections.amazon.aws.tests.unit.compat.mock import MagicMock -from ansible_collections.amazon.aws.tests.unit.compat.mock import sentinel if sys.version_info < (3, 8): pytest.skip("accessing call_args.kwargs by keyword (instead of index) was introduced in Python 3.8", allow_module_level=True) diff --git a/tests/unit/module_utils/cloud/test_retry_func.py b/tests/unit/module_utils/cloud/test_retry_func.py index 609c0718bb..79ae33e1e5 100644 --- a/tests/unit/module_utils/cloud/test_retry_func.py +++ b/tests/unit/module_utils/cloud/test_retry_func.py @@ -3,15 +3,13 @@ # This file is part of Ansible # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - import pytest import sys +from unittest.mock import Mock +from unittest.mock import sentinel + import ansible_collections.amazon.aws.plugins.module_utils.cloud as cloud_utils -from ansible_collections.amazon.aws.tests.unit.compat.mock import Mock -from ansible_collections.amazon.aws.tests.unit.compat.mock import sentinel if sys.version_info < (3, 8): pytest.skip("accessing call_args.kwargs by keyword (instead of index) was introduced in Python 3.8", allow_module_level=True) diff --git a/tests/unit/module_utils/test_elbv2.py b/tests/unit/module_utils/test_elbv2.py index 48c32c78ec..4b76c53b72 100644 --- a/tests/unit/module_utils/test_elbv2.py +++ b/tests/unit/module_utils/test_elbv2.py @@ -4,11 +4,10 @@ # This file is part of Ansible # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from unittest.mock import MagicMock from ansible_collections.amazon.aws.plugins.module_utils import elbv2 -from ansible_collections.amazon.aws.tests.unit.compat.mock import MagicMock + one_action = [ { diff --git a/tests/unit/module_utils/test_iam.py b/tests/unit/module_utils/test_iam.py index 4ce4302628..69da99f281 100644 --- a/tests/unit/module_utils/test_iam.py +++ b/tests/unit/module_utils/test_iam.py @@ -4,9 +4,6 @@ # This file is part of Ansible # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - import pytest try: @@ -15,7 +12,7 @@ # Handled by HAS_BOTO3 pass -from ansible_collections.amazon.aws.tests.unit.compat.mock import MagicMock +from unittest.mock import MagicMock import ansible_collections.amazon.aws.plugins.module_utils.iam as utils_iam from ansible_collections.amazon.aws.plugins.module_utils.ec2 import HAS_BOTO3 diff --git a/tests/unit/module_utils/test_rds.py b/tests/unit/module_utils/test_rds.py index 9d96d44a8d..b3ceb5de4e 100644 --- a/tests/unit/module_utils/test_rds.py +++ b/tests/unit/module_utils/test_rds.py @@ -3,15 +3,8 @@ # This file is part of Ansible # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -from __future__ import absolute_import, division, print_function -__metaclass__ = type - import sys import pytest - -if sys.version_info < (3, 7): - pytest.skip("contextlib.nullcontext was introduced in Python 3.7", allow_module_level=True) - from contextlib import nullcontext try: @@ -20,7 +13,7 @@ # Handled by HAS_BOTO3 pass -from ansible_collections.amazon.aws.tests.unit.compat.mock import MagicMock +from unittest.mock import MagicMock from ansible_collections.amazon.aws.plugins.module_utils import rds from ansible_collections.amazon.aws.plugins.module_utils.botocore import HAS_BOTO3 diff --git a/tests/unit/module_utils/test_s3.py b/tests/unit/module_utils/test_s3.py index cd73a6c2e4..d742aa796a 100644 --- a/tests/unit/module_utils/test_s3.py +++ b/tests/unit/module_utils/test_s3.py @@ -4,11 +4,8 @@ # This file is part of Ansible # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -from __future__ import (absolute_import, division, print_function) +from unittest.mock import MagicMock -__metaclass__ = type - -from ansible_collections.amazon.aws.tests.unit.compat.mock import MagicMock from ansible_collections.amazon.aws.plugins.module_utils import s3 from ansible.module_utils.basic import AnsibleModule diff --git a/tests/unit/module_utils/transformation/test_map_complex_type.py b/tests/unit/module_utils/transformation/test_map_complex_type.py index 2300e2351d..2c737c8a8a 100644 --- a/tests/unit/module_utils/transformation/test_map_complex_type.py +++ b/tests/unit/module_utils/transformation/test_map_complex_type.py @@ -3,13 +3,10 @@ # This file is part of Ansible # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from unittest.mock import sentinel from ansible_collections.amazon.aws.plugins.module_utils.transformation import map_complex_type -from ansible_collections.amazon.aws.tests.unit.compat.mock import sentinel - def test_map_complex_type_over_dict(): type_map = {'minimum_healthy_percent': 'int', 'maximum_percent': 'int'} diff --git a/tests/unit/plugins/modules/ec2_instance/test_build_run_instance_spec.py b/tests/unit/plugins/modules/ec2_instance/test_build_run_instance_spec.py index e889b676a7..6b9921bddd 100644 --- a/tests/unit/plugins/modules/ec2_instance/test_build_run_instance_spec.py +++ b/tests/unit/plugins/modules/ec2_instance/test_build_run_instance_spec.py @@ -3,12 +3,8 @@ # This file is part of Ansible # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - import pytest - -from ansible_collections.amazon.aws.tests.unit.compat.mock import sentinel +from unittest.mock import sentinel import ansible_collections.amazon.aws.plugins.modules.ec2_instance as ec2_instance_module diff --git a/tests/unit/plugins/modules/ec2_instance/test_determine_iam_role.py b/tests/unit/plugins/modules/ec2_instance/test_determine_iam_role.py index cdde74c97e..0ac755a74d 100644 --- a/tests/unit/plugins/modules/ec2_instance/test_determine_iam_role.py +++ b/tests/unit/plugins/modules/ec2_instance/test_determine_iam_role.py @@ -3,14 +3,10 @@ # This file is part of Ansible # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - import pytest import sys - -from ansible_collections.amazon.aws.tests.unit.compat.mock import MagicMock -from ansible_collections.amazon.aws.tests.unit.compat.mock import sentinel +from unittest.mock import MagicMock +from unittest.mock import sentinel import ansible_collections.amazon.aws.plugins.modules.ec2_instance as ec2_instance_module import ansible_collections.amazon.aws.plugins.module_utils.arn as utils_arn from ansible_collections.amazon.aws.plugins.module_utils.botocore import HAS_BOTO3 diff --git a/tests/unit/plugins/modules/test_ec2_vpc_dhcp_option.py b/tests/unit/plugins/modules/test_ec2_vpc_dhcp_option.py index 73726590f2..7f7a9cec44 100644 --- a/tests/unit/plugins/modules/test_ec2_vpc_dhcp_option.py +++ b/tests/unit/plugins/modules/test_ec2_vpc_dhcp_option.py @@ -3,12 +3,10 @@ # This file is part of Ansible # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from unittest.mock import patch # Magic... Incorrectly identified by pylint as unused from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import placeboify # pylint: disable=unused-import -from ansible_collections.amazon.aws.tests.unit.compat.mock import patch from ansible_collections.amazon.aws.plugins.modules import ec2_vpc_dhcp_option as dhcp_module from ansible_collections.amazon.aws.tests.unit.plugins.modules.utils import ModuleTestCase diff --git a/tests/unit/plugins/modules/utils.py b/tests/unit/plugins/modules/utils.py index 058a5b6057..c8eacc8db9 100644 --- a/tests/unit/plugins/modules/utils.py +++ b/tests/unit/plugins/modules/utils.py @@ -1,10 +1,9 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) import json -from ansible_collections.amazon.aws.tests.unit.compat import unittest -from ansible_collections.amazon.aws.tests.unit.compat.mock import patch +import unittest +from unittest.mock import patch from ansible.module_utils import basic from ansible.module_utils._text import to_bytes