Skip to content

Commit fb52b77

Browse files
authored
Improve test coverage (#220)
1 parent c0d47e7 commit fb52b77

File tree

8 files changed

+27
-12
lines changed

8 files changed

+27
-12
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ branch = true
7575

7676
[tool.coverage.report]
7777
exclude_lines = ["pragma: no cover", "if TYPE_CHECKING:"]
78-
fail_under = 92
78+
fail_under = 93
7979
skip_covered = true
8080
show_missing = true
8181

src/ansible_compat/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def __getattribute__(self, attr_name: str) -> object:
431431
return _dict[attr_name]
432432

433433
data = super().__getattribute__("data")
434-
if attr_name == "data":
434+
if attr_name == "data": # pragma: no cover
435435
return data
436436

437437
name = attr_name.upper()

src/ansible_compat/ports.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
"""Portability helpers."""
22
import sys
3-
4-
# Based on workarounds seen on https://github.com/python/mypy/issues/1362
5-
if sys.version_info >= (3, 8):
6-
from functools import cached_property
7-
else:
8-
from cached_property import cached_property
3+
from functools import cached_property
94

105
if sys.version_info >= (3, 9):
116
from functools import cache # pylint: disable=no-name-in-module
12-
else:
7+
else: # pragma: no cover
138
from functools import lru_cache
149

1510
cache = lru_cache(maxsize=None)

src/ansible_compat/runtime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def __init__(
9191
# As CryptographyDeprecationWarning is not a builtin, we cannot use
9292
# PYTHONWARNINGS to ignore it using category but we can use message.
9393
# https://stackoverflow.com/q/68251969/99834
94-
if "PYTHONWARNINGS" not in self.environ:
94+
if "PYTHONWARNINGS" not in self.environ: # pragma: no cover
9595
self.environ["PYTHONWARNINGS"] = "ignore:Blowfish has been deprecated"
9696

9797
if isolated:

test/test_config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ def test_config() -> None:
2525
assert isinstance(config.collections_path, list)
2626
assert config.collections_paths == config.collections_path
2727

28+
# check if we can access the special data member
29+
assert config.ACTION_WARNINGS == config.data["ACTION_WARNINGS"]
30+
2831
with pytest.raises(AttributeError):
2932
print(config.THIS_DOES_NOT_EXIST)
3033

@@ -72,3 +75,8 @@ def test_ansible_version_missing(monkeypatch: MonkeyPatch) -> None:
7275
def test_ansible_version() -> None:
7376
"""Validate ansible_version behavior."""
7477
assert ansible_version() >= Version("1.0")
78+
79+
80+
def test_ansible_version_arg() -> None:
81+
"""Validate ansible_version behavior."""
82+
assert ansible_version("2.0") >= Version("1.0")

test/test_loaders.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""Test for ansible_compat.loaders module."""
2+
from ansible_compat.loaders import colpath_from_path
3+
4+
5+
def test_colpath_from_path() -> None:
6+
"""Test colpath_from_path non existing path."""
7+
assert colpath_from_path("/foo/bar/") is None

test/test_schema.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import pytest
77

8-
from ansible_compat.schema import JsonSchemaError, validate
8+
from ansible_compat.schema import JsonSchemaError, json_path, validate
99

1010
expected_results = [
1111
JsonSchemaError(
@@ -61,3 +61,8 @@ def test_schema(index: int) -> None:
6161
assert (
6262
found_errors_json == expected
6363
), f"inconsistent returns: {found_errors_json}"
64+
65+
66+
def test_json_path() -> None:
67+
"""Test json_path function."""
68+
assert json_path(["a", 1, "b"]) == "$.a[1].b"

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ setenv =
5959
PIP_CONSTRAINT = {toxinidir}/requirements.txt
6060
py38: PIP_CONSTRAINT = /dev/null
6161
PRE_COMMIT_COLOR = always
62-
PYTEST_REQPASS = 77
62+
PYTEST_REQPASS = 80
6363
FORCE_COLOR = 1
6464
allowlist_externals =
6565
ansible

0 commit comments

Comments
 (0)