Skip to content

Commit

Permalink
Improve test coverage (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Feb 1, 2023
1 parent c0d47e7 commit fb52b77
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ branch = true

[tool.coverage.report]
exclude_lines = ["pragma: no cover", "if TYPE_CHECKING:"]
fail_under = 92
fail_under = 93
skip_covered = true
show_missing = true

Expand Down
2 changes: 1 addition & 1 deletion src/ansible_compat/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def __getattribute__(self, attr_name: str) -> object:
return _dict[attr_name]

data = super().__getattribute__("data")
if attr_name == "data":
if attr_name == "data": # pragma: no cover
return data

name = attr_name.upper()
Expand Down
9 changes: 2 additions & 7 deletions src/ansible_compat/ports.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
"""Portability helpers."""
import sys

# Based on workarounds seen on https://github.com/python/mypy/issues/1362
if sys.version_info >= (3, 8):
from functools import cached_property
else:
from cached_property import cached_property
from functools import cached_property

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

cache = lru_cache(maxsize=None)
Expand Down
2 changes: 1 addition & 1 deletion src/ansible_compat/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def __init__(
# As CryptographyDeprecationWarning is not a builtin, we cannot use
# PYTHONWARNINGS to ignore it using category but we can use message.
# https://stackoverflow.com/q/68251969/99834
if "PYTHONWARNINGS" not in self.environ:
if "PYTHONWARNINGS" not in self.environ: # pragma: no cover
self.environ["PYTHONWARNINGS"] = "ignore:Blowfish has been deprecated"

if isolated:
Expand Down
8 changes: 8 additions & 0 deletions test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def test_config() -> None:
assert isinstance(config.collections_path, list)
assert config.collections_paths == config.collections_path

# check if we can access the special data member
assert config.ACTION_WARNINGS == config.data["ACTION_WARNINGS"]

with pytest.raises(AttributeError):
print(config.THIS_DOES_NOT_EXIST)

Expand Down Expand Up @@ -72,3 +75,8 @@ def test_ansible_version_missing(monkeypatch: MonkeyPatch) -> None:
def test_ansible_version() -> None:
"""Validate ansible_version behavior."""
assert ansible_version() >= Version("1.0")


def test_ansible_version_arg() -> None:
"""Validate ansible_version behavior."""
assert ansible_version("2.0") >= Version("1.0")
7 changes: 7 additions & 0 deletions test/test_loaders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Test for ansible_compat.loaders module."""
from ansible_compat.loaders import colpath_from_path


def test_colpath_from_path() -> None:
"""Test colpath_from_path non existing path."""
assert colpath_from_path("/foo/bar/") is None
7 changes: 6 additions & 1 deletion test/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pytest

from ansible_compat.schema import JsonSchemaError, validate
from ansible_compat.schema import JsonSchemaError, json_path, validate

expected_results = [
JsonSchemaError(
Expand Down Expand Up @@ -61,3 +61,8 @@ def test_schema(index: int) -> None:
assert (
found_errors_json == expected
), f"inconsistent returns: {found_errors_json}"


def test_json_path() -> None:
"""Test json_path function."""
assert json_path(["a", 1, "b"]) == "$.a[1].b"
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ setenv =
PIP_CONSTRAINT = {toxinidir}/requirements.txt
py38: PIP_CONSTRAINT = /dev/null
PRE_COMMIT_COLOR = always
PYTEST_REQPASS = 77
PYTEST_REQPASS = 80
FORCE_COLOR = 1
allowlist_externals =
ansible
Expand Down

0 comments on commit fb52b77

Please sign in to comment.