Coverage for tests / unit / tools / assertions / conftest.py: 48%
31 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"""Assertion helper fixtures for tool definition testing.
3These fixtures provide reusable assertion helpers for testing
4tool plugin definitions across multiple tools.
5"""
7from __future__ import annotations
9from collections.abc import Callable
10from typing import Any
12import pytest
13from assertpy import assert_that
16@pytest.fixture
17def assert_definition_has_name() -> Callable[[Any, str], None]:
18 """Helper to assert a definition has the expected name.
20 Returns:
21 A callable that asserts definition.name equals expected value.
23 Example:
24 def test_definition_name(plugin, assert_definition_has_name):
25 assert_definition_has_name(plugin.definition, "ruff")
26 """
28 def _assert(definition: Any, expected_name: str) -> None:
29 assert_that(definition.name).is_equal_to(expected_name)
31 return _assert
34@pytest.fixture
35def assert_definition_has_description() -> Callable[[Any], None]:
36 """Helper to assert a definition has a non-empty description.
38 Returns:
39 A callable that asserts definition.description is not empty.
41 Example:
42 def test_definition_description(plugin, assert_definition_has_description):
43 assert_definition_has_description(plugin.definition)
44 """
46 def _assert(definition: Any) -> None:
47 assert_that(definition.description).is_not_empty()
49 return _assert
52@pytest.fixture
53def assert_definition_file_patterns() -> Callable[[Any, list[str]], None]:
54 """Helper to assert a definition has expected file patterns.
56 Returns:
57 A callable that asserts definition.file_patterns contains expected patterns.
59 Example:
60 def test_definition_patterns(plugin, assert_definition_file_patterns):
61 assert_definition_file_patterns(plugin.definition, ["*.py"])
62 """
64 def _assert(definition: Any, expected_patterns: list[str]) -> None:
65 for pattern in expected_patterns:
66 assert_that(definition.file_patterns).contains(pattern)
68 return _assert
71@pytest.fixture
72def assert_definition_can_fix() -> Callable[[Any, bool], None]:
73 """Helper to assert a definition's can_fix value.
75 Returns:
76 A callable that asserts definition.can_fix equals expected value.
78 Example:
79 def test_definition_can_fix(plugin, assert_definition_can_fix):
80 assert_definition_can_fix(plugin.definition, True)
81 """
83 def _assert(definition: Any, expected_can_fix: bool) -> None:
84 assert_that(definition.can_fix).is_equal_to(expected_can_fix)
86 return _assert
89@pytest.fixture
90def assert_definition_timeout() -> Callable[[Any, int], None]:
91 """Helper to assert a definition's default timeout.
93 Returns:
94 A callable that asserts definition.default_timeout equals expected value.
96 Example:
97 def test_definition_timeout(plugin, assert_definition_timeout):
98 assert_definition_timeout(plugin.definition, 30)
99 """
101 def _assert(definition: Any, expected_timeout: int) -> None:
102 assert_that(definition.default_timeout).is_equal_to(expected_timeout)
104 return _assert