Coverage for tests / integration / tools / svelte_check / test_check.py: 100%
37 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 svelte-check tool definition.
3These tests require svelte-check to be installed and available in PATH.
4They verify the SvelteCheckPlugin 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.svelte_check.conftest import svelte_check_is_available
18if TYPE_CHECKING:
19 from lintro.plugins.base import BaseToolPlugin
21# Skip all tests if svelte-check is not installed or not working
22pytestmark = pytest.mark.skipif(
23 not svelte_check_is_available(),
24 reason="svelte-check not installed or not working",
25)
28# --- Tests for SvelteCheckPlugin definition ---
31@pytest.mark.parametrize(
32 ("attr", "expected"),
33 [
34 ("name", "svelte-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 SvelteCheckPlugin 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 svelte_check_plugin = get_plugin("svelte-check")
55 assert_that(getattr(svelte_check_plugin.definition, attr)).is_equal_to(expected)
58def test_definition_file_patterns(
59 get_plugin: Callable[[str], BaseToolPlugin],
60) -> None:
61 """Verify SvelteCheckPlugin definition includes Svelte file patterns.
63 Tests that the plugin is configured to handle Svelte files (*.svelte).
65 Args:
66 get_plugin: Fixture factory to get plugin instances.
67 """
68 svelte_check_plugin = get_plugin("svelte-check")
69 assert_that(svelte_check_plugin.definition.file_patterns).contains("*.svelte")
72def test_definition_has_version_command(
73 get_plugin: Callable[[str], BaseToolPlugin],
74) -> None:
75 """Verify SvelteCheckPlugin definition has a version command.
77 Tests that the plugin exposes a version command for checking
78 the installed svelte-check version.
80 Args:
81 get_plugin: Fixture factory to get plugin instances.
82 """
83 svelte_check_plugin = get_plugin("svelte-check")
84 version_cmd = svelte_check_plugin.definition.version_command
85 assert_that(version_cmd).is_not_none()
86 assert_that(version_cmd).contains("--version")
87 assert_that(version_cmd).contains("svelte-check")
90# --- Integration tests for svelte check command ---
93def test_check_empty_directory(
94 get_plugin: Callable[[str], BaseToolPlugin],
95 tmp_path: Path,
96) -> None:
97 """Verify svelte-check handles empty directories gracefully.
99 Runs svelte-check on an empty directory and verifies a result is returned
100 without errors.
102 Args:
103 get_plugin: Fixture factory to get plugin instances.
104 tmp_path: Pytest fixture providing a temporary directory.
105 """
106 svelte_check_plugin = get_plugin("svelte-check")
107 result = svelte_check_plugin.check([str(tmp_path)], {})
109 assert_that(result).is_not_none()
110 assert_that(result.success).is_true()
111 assert_that(result.issues_count).is_equal_to(0)
114# --- Tests for SvelteCheckPlugin.set_options method ---
117@pytest.mark.parametrize(
118 ("option_name", "option_value", "expected"),
119 [
120 ("timeout", 60, 60),
121 ("threshold", "warning", "warning"),
122 ("tsconfig", "./tsconfig.json", "./tsconfig.json"),
123 ],
124 ids=["timeout", "threshold", "tsconfig"],
125)
126def test_set_options(
127 get_plugin: Callable[[str], BaseToolPlugin],
128 option_name: str,
129 option_value: object,
130 expected: object,
131) -> None:
132 """Verify SvelteCheckPlugin.set_options correctly sets various options.
134 Tests that plugin options can be set and retrieved correctly.
136 Args:
137 get_plugin: Fixture factory to get plugin instances.
138 option_name: Name of the option to set.
139 option_value: Value to set for the option.
140 expected: Expected value when retrieving the option.
141 """
142 svelte_check_plugin = get_plugin("svelte-check")
143 svelte_check_plugin.set_options(**{option_name: option_value})
144 assert_that(svelte_check_plugin.options.get(option_name)).is_equal_to(expected)
147def test_set_exclude_patterns(
148 get_plugin: Callable[[str], BaseToolPlugin],
149) -> None:
150 """Verify SvelteCheckPlugin.set_options correctly sets exclude_patterns.
152 Tests that exclude patterns can be set and retrieved correctly.
154 Args:
155 get_plugin: Fixture factory to get plugin instances.
156 """
157 svelte_check_plugin = get_plugin("svelte-check")
158 svelte_check_plugin.set_options(exclude_patterns=["node_modules", "dist"])
159 assert_that(svelte_check_plugin.exclude_patterns).contains("node_modules")
160 assert_that(svelte_check_plugin.exclude_patterns).contains("dist")