Skip to content

Commit

Permalink
Synchronise tox configuration between amazon.aws and community.aws (a…
Browse files Browse the repository at this point in the history
…nsible-collections#2486)

SUMMARY
tox configs needed a little cleanup to ensure that things were consistently in the import path when running pylint.
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
pyproject.toml
tests/unit/conftest.py
tox.ini
ADDITIONAL INFORMATION
See also: ansible-collections/community.aws#2219

Reviewed-by: Alina Buzachis
(cherry picked from commit 62ea880)
  • Loading branch information
tremble committed Feb 3, 2025
1 parent 5bef3a8 commit d08f835
Show file tree
Hide file tree
Showing 91 changed files with 908 additions and 86 deletions.
7 changes: 0 additions & 7 deletions .coveragerc

This file was deleted.

11 changes: 0 additions & 11 deletions check_mypy.sh

This file was deleted.

13 changes: 12 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,18 @@ disable_error_code = ["import-untyped"]
line-length = 120

[tool.ruff.lint]
# "F401" - unused-imports - We use these imports to maintaining historic Interfaces
# "F401" - unused-imports - We use these imports to maintain historic Interfaces
# "E402" - import not at top of file - General Ansible style puts the documentation at the top.
unfixable = ["F401"]
ignore = ["F401", "E402"]

[tool.pytest]
xfail_strict = true

[tool.coverage.report]
exclude_lines = [
# Have to re-enable the standard pragma
"pragma: no cover",
# Don't complain if tests don't hit defensive assertion code:
"raise NotImplementedError",
]
2 changes: 2 additions & 0 deletions tests/integration/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ virtualenv
awscli
# Used for comparing SSH Public keys to the Amazon fingerprints
cryptography
# Used for recordings
placebo
1 change: 1 addition & 0 deletions tests/integration/requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ collections:
- ansible.windows
- ansible.utils # ipv6 filter
- amazon.cloud # used by integration tests - rds_cluster_modify
- community.crypto # SSL certificate generation
12 changes: 6 additions & 6 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# -*- coding: utf-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)

# pylint: disable=unused-import

import pytest

from .utils.amazon_placebo_fixtures import fixture_maybe_sleep
from .utils.amazon_placebo_fixtures import fixture_placeboify
# While it may seem appropriate to import our custom fixtures here, the pytest_ansible pytest plugin
# isn't as agressive as the ansible_test._util.target.pytest.plugins.ansible_pytest_collections plugin
# when it comes to rewriting the import paths and as such we can't import fixtures via their
# absolute import path or across collections.
11 changes: 11 additions & 0 deletions tests/unit/plugins/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-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)

# pylint: disable=unused-import

import pytest

from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import fixture_maybe_sleep
from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import fixture_placeboify
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

# Copyright (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
92 changes: 92 additions & 0 deletions tests/unit/plugins/module_utils/s3/test_endpoints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# -*- coding: utf-8 -*-
#
# (c) 2021 Red Hat Inc.
#
# 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 unittest.mock import patch

import pytest

from ansible_collections.amazon.aws.plugins.module_utils import s3

mod_urlparse = "ansible_collections.amazon.aws.plugins.module_utils.s3.urlparse"


class UrlInfo:
def __init__(self, scheme=None, hostname=None, port=None):
self.hostname = hostname
self.scheme = scheme
self.port = port


@patch(mod_urlparse)
def test_is_fakes3_with_none_arg(m_urlparse):
m_urlparse.side_effect = SystemExit(1)
result = s3.is_fakes3(None)
assert not result
m_urlparse.assert_not_called()


@pytest.mark.parametrize(
"url,scheme,result",
[
("https://test-s3.amazon.com", "https", False),
("fakes3://test-s3.amazon.com", "fakes3", True),
("fakes3s://test-s3.amazon.com", "fakes3s", True),
],
)
@patch(mod_urlparse)
def test_is_fakes3(m_urlparse, url, scheme, result):
m_urlparse.return_value = UrlInfo(scheme=scheme)
assert result == s3.is_fakes3(url)
m_urlparse.assert_called_with(url)


@pytest.mark.parametrize(
"url,urlinfo,endpoint",
[
(
"fakes3://test-s3.amazon.com",
{"scheme": "fakes3", "hostname": "test-s3.amazon.com"},
{"endpoint": "http://test-s3.amazon.com:80", "use_ssl": False},
),
(
"fakes3://test-s3.amazon.com:8080",
{"scheme": "fakes3", "hostname": "test-s3.amazon.com", "port": 8080},
{"endpoint": "http://test-s3.amazon.com:8080", "use_ssl": False},
),
(
"fakes3s://test-s3.amazon.com",
{"scheme": "fakes3s", "hostname": "test-s3.amazon.com"},
{"endpoint": "https://test-s3.amazon.com:443", "use_ssl": True},
),
(
"fakes3s://test-s3.amazon.com:9096",
{"scheme": "fakes3s", "hostname": "test-s3.amazon.com", "port": 9096},
{"endpoint": "https://test-s3.amazon.com:9096", "use_ssl": True},
),
],
)
@patch(mod_urlparse)
def test_parse_fakes3_endpoint(m_urlparse, url, urlinfo, endpoint):
m_urlparse.return_value = UrlInfo(**urlinfo)
result = s3.parse_fakes3_endpoint(url)
assert endpoint == result
m_urlparse.assert_called_with(url)


@pytest.mark.parametrize(
"url,scheme,use_ssl",
[
("https://test-s3-ceph.amazon.com", "https", True),
("http://test-s3-ceph.amazon.com", "http", False),
],
)
@patch(mod_urlparse)
def test_parse_ceph_endpoint(m_urlparse, url, scheme, use_ssl):
m_urlparse.return_value = UrlInfo(scheme=scheme)
result = s3.parse_ceph_endpoint(url)
assert result == {"endpoint": url, "use_ssl": use_ssl}
m_urlparse.assert_called_with(url)
File renamed without changes.
Loading

0 comments on commit d08f835

Please sign in to comment.