Coverage for tests / integration / tools / astro_check / test_check.py: 100%
32 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"""Integration tests for astro-check tool definition.
3These tests require astro to be installed and available in PATH.
4They verify the AstroCheckPlugin definition, check command, and set_options method.
5"""
7from __future__ import annotations
9from collections.abc import Callable
10from pathlib import Path
11from typing import TYPE_CHECKING
13import pytest
14from assertpy import assert_that
16from tests.integration.tools.astro_check.conftest import astro_check_is_available
18if TYPE_CHECKING:
19 from lintro.plugins.base import BaseToolPlugin
21# Skip all tests if astro is not installed or not working
22pytestmark = pytest.mark.skipif(
23 not astro_check_is_available(),
24 reason="astro not installed or not working",
25)
28# --- Tests for AstroCheckPlugin definition ---
31@pytest.mark.parametrize(
32 ("attr", "expected"),
33 [
34 ("name", "astro-check"),
35 ("can_fix", False),
36 ],
37 ids=["name", "can_fix"],
38)
39def test_definition_attributes(
40 get_plugin: Callable[[str], BaseToolPlugin],
41 attr: str,
42 expected: object,
43) -> None:
44 """Verify AstroCheckPlugin definition has correct attribute values.
46 Tests that the plugin definition exposes the expected values for
47 name and can_fix attributes.
49 Args:
50 get_plugin: Fixture factory to get plugin instances.
51 attr: The attribute name to check on the definition.
52 expected: The expected value of the attribute.
53 """
54 astro_check_plugin = get_plugin("astro-check")
55 assert_that(getattr(astro_check_plugin.definition, attr)).is_equal_to(expected)
58def test_definition_file_patterns(
59 get_plugin: Callable[[str], BaseToolPlugin],
60) -> None:
61 """Verify AstroCheckPlugin definition includes Astro file patterns.
63 Tests that the plugin is configured to handle Astro files (*.astro).
65 Args:
66 get_plugin: Fixture factory to get plugin instances.
67 """
68 astro_check_plugin = get_plugin("astro-check")
69 assert_that(astro_check_plugin.definition.file_patterns).contains("*.astro")
72def test_definition_has_version_command(
73 get_plugin: Callable[[str], BaseToolPlugin],
74) -> None:
75 """Verify AstroCheckPlugin definition has a version command.
77 Tests that the plugin exposes a version command for checking
78 the installed Astro version.
80 Args:
81 get_plugin: Fixture factory to get plugin instances.
82 """
83 astro_check_plugin = get_plugin("astro-check")
84 assert_that(astro_check_plugin.definition.version_command).is_not_none()
87# --- Integration tests for astro check command ---
90def test_check_empty_directory(
91 get_plugin: Callable[[str], BaseToolPlugin],
92 tmp_path: Path,
93) -> None:
94 """Verify astro check handles empty directories gracefully.
96 Runs astro check on an empty directory and verifies a result is returned
97 without errors.
99 Args:
100 get_plugin: Fixture factory to get plugin instances.
101 tmp_path: Pytest fixture providing a temporary directory.
102 """
103 astro_check_plugin = get_plugin("astro-check")
104 result = astro_check_plugin.check([str(tmp_path)], {})
106 assert_that(result).is_not_none()
109# --- Tests for AstroCheckPlugin.set_options method ---
112@pytest.mark.parametrize(
113 ("option_name", "option_value", "expected"),
114 [
115 ("timeout", 60, 60),
116 ("root", "./packages/web", "./packages/web"),
117 ],
118 ids=["timeout", "root"],
119)
120def test_set_options(
121 get_plugin: Callable[[str], BaseToolPlugin],
122 option_name: str,
123 option_value: object,
124 expected: object,
125) -> None:
126 """Verify AstroCheckPlugin.set_options correctly sets various options.
128 Tests that plugin options can be set and retrieved correctly.
130 Args:
131 get_plugin: Fixture factory to get plugin instances.
132 option_name: Name of the option to set.
133 option_value: Value to set for the option.
134 expected: Expected value when retrieving the option.
135 """
136 astro_check_plugin = get_plugin("astro-check")
137 astro_check_plugin.set_options(**{option_name: option_value})
138 assert_that(astro_check_plugin.options.get(option_name)).is_equal_to(expected)
141def test_set_exclude_patterns(
142 get_plugin: Callable[[str], BaseToolPlugin],
143) -> None:
144 """Verify AstroCheckPlugin.set_options correctly sets exclude_patterns.
146 Tests that exclude patterns can be set and retrieved correctly.
148 Args:
149 get_plugin: Fixture factory to get plugin instances.
150 """
151 astro_check_plugin = get_plugin("astro-check")
152 astro_check_plugin.set_options(exclude_patterns=["node_modules", "dist"])
153 assert_that(astro_check_plugin.exclude_patterns).contains("node_modules")
154 assert_that(astro_check_plugin.exclude_patterns).contains("dist")