Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,20 @@ hatch test -k iam_machine_user
```bash
hatch test --all
```

> [!WARNING] Testing Python 3.9
> Hatch currently has a dependency (`coverage[toml]`) that conflicts with Python 3.9. To test Python 3.9, run `pytest` in a standalone virtual environment. For example:

```bash
python3.9 -m venv cloudera-cloud-python3.9
```

Activate this virtual environment, and install the minimal requirements for testing.

```bash
pip install pytest pytest-mock ansible-core==2.15 "cdpy @ git+https://github.com/cloudera-labs/cdpy@main#egg=cdpy"
```

Then run `pytest` directly instead of `hatch test`.

All other requirements, like `PYTHONPATH`, are still valid.
16 changes: 10 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ validate-bump = true
detached = true
dependencies = [
"pre-commit",
"coverage[toml]",
# "coverage[toml]",
"pytest",
"pytest-mock",
# "pytest-cov",
Expand All @@ -44,15 +44,19 @@ lint = [
[tool.hatch.envs.hatch-test]
matrix-name-format = "{variable}_{value}"
extra-dependencies = [
"pytest",
"pytest-mock",
"molecule",
"molecule-plugins",
"molecule-plugins[ec2]",
# "ansible-core<2.17", # For RHEL 8 support
# "ansible-core<2.17", # Handled by matrix overrides
"cdpy @ git+https://github.com/cloudera-labs/cdpy@main#egg=cdpy",
]

[tool.hatch.envs.hatch-test.scripts]
run = [
"pip list --verbose",
"pytest{env:HATCH_TEST_ARGS:} {args}"
]

# Ansible 2.18 - Python >= 3.11
[[tool.hatch.envs.hatch-test.matrix]]
python = ["3.13", "3.12", "3.11"]
Expand All @@ -68,9 +72,9 @@ ansible = ["2.17"]
python = ["3.13", "3.12", "3.11", "3.10"]
ansible = ["2.16"]

# Ansible 2.15 - Python <= 3.12
# Ansible 2.15 - Python <= 3.12, >=3.10
[[tool.hatch.envs.hatch-test.matrix]]
python = ["3.12", "3.11", "3.10", "3.9"]
python = ["3.12", "3.11", "3.10"]
ansible = ["2.15"]

[tool.hatch.envs.hatch-test.overrides]
Expand Down
20 changes: 10 additions & 10 deletions tests/unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from email.utils import formatdate
from functools import wraps
from typing import Any, Dict
from typing import Any, Dict, Optional
from urllib.parse import urlencode
from urllib.error import HTTPError
from http.client import HTTPResponse
Expand Down Expand Up @@ -54,7 +54,7 @@ def __init__(self, kwargs):
self.__dict__.update(kwargs)

def __getattr__(self, attr):
return self.__dict__[attr]
return self.__dict__.get(attr, None)


def handle_response(func):
Expand Down Expand Up @@ -108,9 +108,9 @@ def set_credential_headers(


def prepare_body(
data: Dict[str, Any] | None = None,
json_data: Dict[str, Any] | None = None,
) -> str | None:
data: Optional[Dict[str, Any]] = None,
json_data: Optional[Dict[str, Any]] = None,
) -> Optional[str]:
if json_data is not None:
return json.dumps(json_data)
elif data is not None:
Expand All @@ -134,7 +134,7 @@ def __init__(
self.private_key = private_key

@handle_response
def get(self, path: str, params: Dict[str, Any] | None = None) -> Dict[str, Any]:
def get(self, path: str, params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
# Prepare query parameters
if params:
path += "?" + urlencode(params)
Expand All @@ -155,8 +155,8 @@ def get(self, path: str, params: Dict[str, Any] | None = None) -> Dict[str, Any]
def post(
self,
path: str,
data: Dict[str, Any] | None = None,
json_data: Dict[str, Any] | None = None,
data: Optional[Dict[str, Any]] = None,
json_data: Optional[Dict[str, Any]] = None,
squelch: Dict[int, Any] = {},
) -> Dict[str, Any]:
url = f"{self.endpoint}/{path.strip('/')}"
Expand All @@ -175,8 +175,8 @@ def post(
def put(
self,
path: str,
data: Dict[str, Any] | None = None,
json_data: Dict[str, Any] | None = None,
data: Optional[Dict[str, Any]] = None,
json_data: Optional[Dict[str, Any]] = None,
squelch: Dict[int, Any] = {},
) -> Dict[str, Any]:
url = f"{self.endpoint}/{path.strip('/')}"
Expand Down
1 change: 1 addition & 0 deletions tests/unit/plugins/modules/environment/env_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def test_freeipa_specified(self):
**expected,
)

@pytest.mark.skip(reason="Refactor to new structure")
def test_freeipa_default(self):
setup_module_args(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
setup_module_args,
)

pytestmark = pytest.mark.skip(reason="Refactor to new structure")


def test_get_single_role_details():
setup_module_args({"name": "crn:iam:us-west-1:role:ClassicClustersCreator"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
setup_module_args,
)

pytestmark = pytest.mark.skip(reason="Refactor to new structure")


def test_user_info_username():
setup_module_args({"user_name": "mike01"})
Expand Down
Loading