1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-02-04 07:51:50 +00:00

remove conditional code for old snakes (#11048)

* remove conditional code for old snakes

* remove conditional code for old snakes

* reformat

* add changelog frag
This commit is contained in:
Alexei Znamensky 2025-11-09 05:21:46 +13:00 committed by GitHub
parent 3478863ef0
commit ebf45260ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 26 additions and 105 deletions

View file

@ -4,7 +4,6 @@
from __future__ import annotations
import sys
import unittest
from collections import OrderedDict
from unittest.mock import patch, MagicMock, Mock
@ -13,14 +12,10 @@ from ansible.playbook.task import Task
from ansible.executor.task_result import TaskResult
from ansible_collections.community.general.plugins.callback.elastic import ElasticSource, TaskData
ELASTIC_MINIMUM_PYTHON_VERSION = (3, 6)
class TestOpentelemetry(unittest.TestCase):
@patch("ansible_collections.community.general.plugins.callback.elastic.socket")
def setUp(self, mock_socket):
if sys.version_info < ELASTIC_MINIMUM_PYTHON_VERSION:
self.skipTest(f"Python {'.'.join(map(str, ELASTIC_MINIMUM_PYTHON_VERSION))}+ is needed for Elastic")
mock_socket.gethostname.return_value = "my-host"
mock_socket.gethostbyname.return_value = "1.2.3.4"
self.elastic = ElasticSource(display=None)

View file

@ -4,7 +4,6 @@
from __future__ import annotations
import sys
import unittest
from collections import OrderedDict
from unittest.mock import patch, MagicMock, Mock
@ -13,18 +12,10 @@ from ansible.playbook.task import Task
from ansible.executor.task_result import TaskResult
from ansible_collections.community.general.plugins.callback.opentelemetry import OpenTelemetrySource, TaskData
OPENTELEMETRY_MINIMUM_PYTHON_VERSION = (3, 7)
class TestOpentelemetry(unittest.TestCase):
@patch("ansible_collections.community.general.plugins.callback.opentelemetry.socket")
def setUp(self, mock_socket):
# TODO: this python version validation won't be needed as long as the _time_ns call is mocked.
if sys.version_info < OPENTELEMETRY_MINIMUM_PYTHON_VERSION:
self.skipTest(
f"Python {'.'.join(map(str, OPENTELEMETRY_MINIMUM_PYTHON_VERSION))}+ is needed for OpenTelemetry"
)
mock_socket.gethostname.return_value = "my-host"
mock_socket.gethostbyname.return_value = "1.2.3.4"
self.opentelemetry = OpenTelemetrySource(display=None)

View file

@ -4,7 +4,6 @@
from __future__ import annotations
import sys
import unittest
from httmock import response # noqa
@ -27,22 +26,11 @@ class FakeAnsibleModule:
class GitlabModuleTestCase(unittest.TestCase):
def setUp(self):
unitest_python_version_check_requirement(self)
self.mock_module = FakeAnsibleModule()
self.gitlab_instance = gitlab.Gitlab("http://localhost", private_token="private_token", api_version=4)
# Python 2.7+ is needed for python-gitlab
GITLAB_MINIMUM_PYTHON_VERSION = (2, 7)
# Verify if the current Python version is higher than GITLAB_MINIMUM_PYTHON_VERSION
def python_version_match_requirement():
return sys.version_info >= GITLAB_MINIMUM_PYTHON_VERSION
def python_gitlab_module_version():
return gitlab.__version__
@ -51,14 +39,6 @@ def python_gitlab_version_match_requirement():
return "2.3.0"
# Skip unittest test case if python version don't match requirement
def unitest_python_version_check_requirement(unittest_testcase):
if not python_version_match_requirement():
unittest_testcase.skipTest(
f"Python {'.'.join(map(str, GITLAB_MINIMUM_PYTHON_VERSION))}+ is needed for python-gitlab"
)
"""
USER API
"""

View file

@ -12,12 +12,8 @@ from ansible_collections.community.internal_test_tools.tests.unit.plugins.module
)
from unittest.mock import patch
import pytest
import sys
dnsimple = pytest.importorskip("dnsimple")
mandatory_py_version = pytest.mark.skipif(
sys.version_info < (3, 6), reason="The dnsimple dependency requires python3.6 or higher"
)
from dnsimple import DNSimpleException

View file

@ -19,7 +19,6 @@ pytestmark = []
try:
from .gitlab import (
GitlabModuleTestCase,
python_version_match_requirement,
resp_get_project,
resp_find_project_deploy_key,
resp_create_project_deploy_key,
@ -27,8 +26,7 @@ try:
)
# GitLab module requirements
if python_version_match_requirement():
from gitlab.v4.objects import ProjectKey
from gitlab.v4.objects import ProjectKey
except ImportError:
pytestmark.append(pytest.mark.skip("Could not load gitlab module required for testing"))
# Need to set these to something so that we don't fail when parsing

View file

@ -19,7 +19,6 @@ pytestmark = []
try:
from .gitlab import (
GitlabModuleTestCase,
python_version_match_requirement,
resp_get_group,
resp_get_missing_group,
resp_create_group,
@ -29,8 +28,7 @@ try:
)
# GitLab module requirements
if python_version_match_requirement():
from gitlab.v4.objects import Group
from gitlab.v4.objects import Group
except ImportError:
pytestmark.append(pytest.mark.skip("Could not load gitlab module required for testing"))
# Need to set these to something so that we don't fail when parsing

View file

@ -19,7 +19,6 @@ pytestmark = []
try:
from .gitlab import (
GitlabModuleTestCase,
python_version_match_requirement,
resp_get_project,
resp_find_project_hook,
resp_create_project_hook,
@ -27,8 +26,7 @@ try:
)
# GitLab module requirements
if python_version_match_requirement():
from gitlab.v4.objects import ProjectHook
from gitlab.v4.objects import ProjectHook
except ImportError:
pytestmark.append(pytest.mark.skip("Could not load gitlab module required for testing"))
# Need to set these to something so that we don't fail when parsing

View file

@ -19,7 +19,6 @@ pytestmark = []
try:
from .gitlab import (
GitlabModuleTestCase,
python_version_match_requirement,
resp_get_group,
resp_get_project_by_name,
resp_create_project,
@ -29,8 +28,7 @@ try:
)
# GitLab module requirements
if python_version_match_requirement():
from gitlab.v4.objects import Project
from gitlab.v4.objects import Project
except ImportError:
pytestmark.append(pytest.mark.skip("Could not load gitlab module required for testing"))
# Need to set these to something so that we don't fail when parsing

View file

@ -21,7 +21,6 @@ pytestmark = []
try:
from .gitlab import (
GitlabModuleTestCase,
python_version_match_requirement,
python_gitlab_module_version,
python_gitlab_version_match_requirement,
resp_get_protected_branch,
@ -32,12 +31,12 @@ try:
)
# GitLab module requirements
if python_version_match_requirement():
from gitlab.v4.objects import Project # noqa: F401, pylint: disable=unused-import
from gitlab.v4.objects import Project # noqa: F401, pylint: disable=unused-import
gitlab_req_version = python_gitlab_version_match_requirement()
gitlab_module_version = python_gitlab_module_version()
if LooseVersion(gitlab_module_version) < LooseVersion(gitlab_req_version):
pytestmark.append(pytest.mark.skip("Could not load gitlab module required for testing (Wrong version)"))
pytestmark.append(pytest.mark.skip("Could not load gitlab module required for testing (Wrong version)"))
except ImportError:
pytestmark.append(pytest.mark.skip("Could not load gitlab module required for testing"))

View file

@ -22,7 +22,6 @@ try:
from .gitlab import (
FakeAnsibleModule,
GitlabModuleTestCase,
python_version_match_requirement,
resp_find_runners_all,
resp_find_runners_list,
resp_find_project_runners,
@ -35,8 +34,7 @@ try:
)
# GitLab module requirements
if python_version_match_requirement():
from gitlab.v4.objects import Runner
from gitlab.v4.objects import Runner
except ImportError:
pytestmark.append(pytest.mark.skip("Could not load gitlab module required for testing"))
# Need to set these to something so that we don't fail when parsing

View file

@ -19,7 +19,6 @@ pytestmark = []
try:
from .gitlab import (
GitlabModuleTestCase,
python_version_match_requirement,
resp_find_user,
resp_get_user,
resp_get_user_keys,
@ -34,8 +33,7 @@ try:
)
# GitLab module requirements
if python_version_match_requirement():
from gitlab.v4.objects import User
from gitlab.v4.objects import User
except ImportError:
pytestmark.append(pytest.mark.skip("Could not load gitlab module required for testing"))
# Need to set these to something so that we don't fail when parsing

View file

@ -4,7 +4,6 @@
from __future__ import annotations
import sys
from unittest.mock import patch, Mock, mock_open
from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
ModuleTestCase,
@ -152,9 +151,6 @@ class TestUnloadModule(ModuleTestCase):
class TestModuleIsLoadedPersistently(ModuleTestCase):
def setUp(self):
if sys.version_info[0] == 3 and sys.version_info[1] < 7:
self.skipTest("open_mock doesn't support readline in earlier python versions")
super().setUp()
self.mock_get_bin_path = patch("ansible.module_utils.basic.AnsibleModule.get_bin_path")
@ -216,8 +212,6 @@ class TestModuleIsLoadedPersistently(ModuleTestCase):
class TestPermanentParams(ModuleTestCase):
def setUp(self):
if sys.version_info[0] == 3 and sys.version_info[1] < 7:
self.skipTest("open_mock doesn't support readline in earlier python versions")
super().setUp()
self.mock_get_bin_path = patch("ansible.module_utils.basic.AnsibleModule.get_bin_path")