Skip to content

Commit

Permalink
Synchronise tox configuration between amazon.aws and community.aws (#…
Browse files Browse the repository at this point in the history
…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 authored and GomathiselviS committed Jan 31, 2025
1 parent 9db670e commit c0cebeb
Show file tree
Hide file tree
Showing 89 changed files with 893 additions and 39 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.

33 changes: 33 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,36 @@ transform-joins = true
exclude = [
"ec2_metadata_facts",
]
<<<<<<< HEAD
=======

[tool.flake8]
# E123, E125 skipped as they are invalid PEP-8.
show-source = true
ignore = ["E123", "E125", "E203", "E402", "E501", "E741", "F401", "F811", "F841", "W503"]
max-line-length = 160
builtins = "_"

[tool.mypy]
disable_error_code = ["import-untyped"]

[tool.ruff]
line-length = 120

[tool.ruff.lint]
# "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",
]
>>>>>>> 62ea880c (Synchronise tox configuration between amazon.aws and community.aws (#2486))
9 changes: 9 additions & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +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)

# 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 c0cebeb

Please sign in to comment.