Coverage for tests / unit / tools / core / test_version_checking.py: 100%
47 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
1"""Unit tests for version_checking module."""
3from __future__ import annotations
5import pytest
6from assertpy import assert_that
8from lintro.tools.core.version_checking import (
9 _get_version_timeout,
10 get_install_hints,
11 get_minimum_versions,
12)
14# Tests for _get_version_timeout
17def test_get_version_timeout_default(monkeypatch: pytest.MonkeyPatch) -> None:
18 """Return default timeout when env var not set.
20 Args:
21 monkeypatch: Pytest fixture for patching modules and attributes.
22 """
23 monkeypatch.delenv("LINTRO_VERSION_TIMEOUT", raising=False)
24 result = _get_version_timeout()
25 assert_that(result).is_equal_to(30)
28def test_get_version_timeout_valid(monkeypatch: pytest.MonkeyPatch) -> None:
29 """Return parsed timeout from env var.
31 Args:
32 monkeypatch: Pytest fixture for patching modules and attributes.
33 """
34 monkeypatch.setenv("LINTRO_VERSION_TIMEOUT", "60")
35 result = _get_version_timeout()
36 assert_that(result).is_equal_to(60)
39@pytest.mark.parametrize(
40 ("env_value", "expected"),
41 [
42 ("invalid", 30),
43 ("-5", 30),
44 ("0", 30),
45 ],
46 ids=["non_numeric", "negative", "zero"],
47)
48def test_get_version_timeout_invalid(
49 env_value: str,
50 expected: int,
51 monkeypatch: pytest.MonkeyPatch,
52) -> None:
53 """Return default on invalid timeout values.
55 Args:
56 env_value: The environment variable value to test.
57 expected: The expected timeout value.
58 monkeypatch: Pytest monkeypatch fixture for environment manipulation.
59 """
60 monkeypatch.setenv("LINTRO_VERSION_TIMEOUT", env_value)
61 result = _get_version_timeout()
62 assert_that(result).is_equal_to(expected)
65# Tests for get_minimum_versions
68def test_get_minimum_versions_returns_dict() -> None:
69 """Return a dictionary of tool versions."""
70 result = get_minimum_versions()
71 assert_that(result).is_instance_of(dict)
72 assert_that(result).is_not_empty()
75def test_get_minimum_versions_contains_expected_tools() -> None:
76 """Return versions for expected external tools."""
77 result = get_minimum_versions()
78 # Check for some expected tools
79 expected_tools = ["hadolint", "actionlint"]
80 for tool in expected_tools:
81 assert_that(tool in result).is_true()
84def test_get_minimum_versions_returns_copy() -> None:
85 """Return a copy, not the original dict."""
86 result1 = get_minimum_versions()
87 result2 = get_minimum_versions()
88 # Should be equal but not the same object
89 assert_that(result1).is_equal_to(result2)
90 # Modifying one shouldn't affect the other
91 result1["test_tool"] = "1.0.0"
92 assert_that("test_tool" in result2).is_false()
95# Tests for get_install_hints
98def test_get_install_hints_returns_dict() -> None:
99 """Return a dictionary of install hints."""
100 result = get_install_hints()
101 assert_that(result).is_instance_of(dict)
102 assert_that(result).is_not_empty()
105def test_get_install_hints_pip_for_python_tools() -> None:
106 """Python tools have pip/uv install hints."""
107 result = get_install_hints()
108 # pytest is a Python tool that should have pip/uv hints
109 assert_that("pip install" in result.get("pytest", "")).is_true()
110 assert_that("uv add" in result.get("pytest", "")).is_true()
113def test_get_install_hints_bun_for_node_tools() -> None:
114 """Node.js tools have bun install hints."""
115 result = get_install_hints()
116 assert_that("bun add" in result.get("markdownlint", "")).is_true()
119def test_get_install_hints_external_tools() -> None:
120 """External tools have appropriate install hints."""
121 result = get_install_hints()
122 assert_that("github" in result.get("hadolint", "").lower()).is_true()
123 assert_that("rustup" in result.get("clippy", "")).is_true()