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:
parent
3478863ef0
commit
ebf45260ce
17 changed files with 26 additions and 105 deletions
|
|
@ -6,18 +6,12 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import http.server
|
||||
import socketserver
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if sys.version_info[0] >= 3:
|
||||
import http.server
|
||||
import socketserver
|
||||
PORT = int(sys.argv[1])
|
||||
Handler = http.server.SimpleHTTPRequestHandler
|
||||
httpd = socketserver.TCPServer(("", PORT), Handler)
|
||||
httpd.serve_forever()
|
||||
else:
|
||||
import mimetypes
|
||||
mimetypes.init()
|
||||
mimetypes.add_type('application/json', '.json')
|
||||
import SimpleHTTPServer
|
||||
SimpleHTTPServer.test()
|
||||
PORT = int(sys.argv[1])
|
||||
Handler = http.server.SimpleHTTPRequestHandler
|
||||
httpd = socketserver.TCPServer(("", PORT), Handler)
|
||||
httpd.serve_forever()
|
||||
|
|
|
|||
|
|
@ -7,19 +7,15 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from xmlrpc.client import ServerProxy
|
||||
from urllib.parse import quote
|
||||
|
||||
|
||||
proc = sys.argv[1]
|
||||
value = sys.argv[2]
|
||||
username = sys.argv[3]
|
||||
password = sys.argv[4]
|
||||
|
||||
if sys.version_info[0] == 2:
|
||||
from xmlrpclib import ServerProxy
|
||||
from urllib import quote
|
||||
else:
|
||||
from xmlrpc.client import ServerProxy
|
||||
from urllib.parse import quote
|
||||
|
||||
if username:
|
||||
url = 'http://%s:%s@127.0.0.1:9001/RPC2' % (quote(username, safe=''), quote(password, safe=''))
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"))
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue