Coverage for tests / unit / tools / svelte_check / test_options.py: 100%
64 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 svelte-check plugin options and definition."""
3from __future__ import annotations
5import pytest
6from assertpy import assert_that
8from lintro.enums.tool_type import ToolType
9from lintro.tools.definitions.svelte_check import (
10 SVELTE_CHECK_DEFAULT_PRIORITY,
11 SVELTE_CHECK_DEFAULT_TIMEOUT,
12 SVELTE_CHECK_FILE_PATTERNS,
13 SvelteCheckPlugin,
14)
16# Tests for tool definition attributes
19def test_definition_name(svelte_check_plugin: SvelteCheckPlugin) -> None:
20 """Verify tool name is 'svelte-check'.
22 Args:
23 svelte_check_plugin: The SvelteCheckPlugin instance to test.
24 """
25 assert_that(svelte_check_plugin.definition.name).is_equal_to("svelte-check")
28def test_definition_description(svelte_check_plugin: SvelteCheckPlugin) -> None:
29 """Verify tool has a description.
31 Args:
32 svelte_check_plugin: The SvelteCheckPlugin instance to test.
33 """
34 assert_that(svelte_check_plugin.definition.description).is_not_empty()
37def test_definition_can_fix_is_false(svelte_check_plugin: SvelteCheckPlugin) -> None:
38 """Verify svelte-check cannot auto-fix issues.
40 Args:
41 svelte_check_plugin: The SvelteCheckPlugin instance to test.
42 """
43 assert_that(svelte_check_plugin.definition.can_fix).is_false()
46def test_definition_tool_type(svelte_check_plugin: SvelteCheckPlugin) -> None:
47 """Verify tool type is LINTER | TYPE_CHECKER.
49 Args:
50 svelte_check_plugin: The SvelteCheckPlugin instance to test.
51 """
52 expected_type = ToolType.LINTER | ToolType.TYPE_CHECKER
53 assert_that(svelte_check_plugin.definition.tool_type).is_equal_to(expected_type)
56def test_definition_file_patterns(svelte_check_plugin: SvelteCheckPlugin) -> None:
57 """Verify file patterns include .svelte files.
59 Args:
60 svelte_check_plugin: The SvelteCheckPlugin instance to test.
61 """
62 assert_that(svelte_check_plugin.definition.file_patterns).is_equal_to(
63 SVELTE_CHECK_FILE_PATTERNS,
64 )
65 assert_that(svelte_check_plugin.definition.file_patterns).contains("*.svelte")
68def test_definition_priority(svelte_check_plugin: SvelteCheckPlugin) -> None:
69 """Verify tool priority is set correctly.
71 Args:
72 svelte_check_plugin: The SvelteCheckPlugin instance to test.
73 """
74 assert_that(svelte_check_plugin.definition.priority).is_equal_to(
75 SVELTE_CHECK_DEFAULT_PRIORITY,
76 )
79def test_definition_native_configs(svelte_check_plugin: SvelteCheckPlugin) -> None:
80 """Verify native configs include svelte.config files.
82 Args:
83 svelte_check_plugin: The SvelteCheckPlugin instance to test.
84 """
85 native_configs = svelte_check_plugin.definition.native_configs
86 assert_that(native_configs).is_not_empty()
87 assert_that(native_configs).contains("svelte.config.js")
88 assert_that(native_configs).contains("svelte.config.ts")
89 assert_that(native_configs).contains("svelte.config.mjs")
92# Tests for default options
95@pytest.mark.parametrize(
96 ("option_name", "expected_value"),
97 [
98 ("timeout", SVELTE_CHECK_DEFAULT_TIMEOUT),
99 ("threshold", "error"),
100 ("tsconfig", None),
101 ],
102 ids=[
103 "timeout_equals_default",
104 "threshold_is_error",
105 "tsconfig_is_none",
106 ],
107)
108def test_default_options_values(
109 svelte_check_plugin: SvelteCheckPlugin,
110 option_name: str,
111 expected_value: object,
112) -> None:
113 """Default options have correct values.
115 Args:
116 svelte_check_plugin: The SvelteCheckPlugin instance to test.
117 option_name: The name of the option to check.
118 expected_value: The expected value for the option.
119 """
120 assert_that(
121 svelte_check_plugin.definition.default_options[option_name],
122 ).is_equal_to(expected_value)
125# Tests for set_options method - valid options
128def test_set_options_threshold_valid(
129 svelte_check_plugin: SvelteCheckPlugin,
130) -> None:
131 """Set threshold option with valid string value.
133 Args:
134 svelte_check_plugin: The SvelteCheckPlugin instance to test.
135 """
136 svelte_check_plugin.set_options(threshold="warning")
137 assert_that(svelte_check_plugin.options.get("threshold")).is_equal_to("warning")
140def test_set_options_tsconfig_valid(
141 svelte_check_plugin: SvelteCheckPlugin,
142) -> None:
143 """Set tsconfig option with valid string path.
145 Args:
146 svelte_check_plugin: The SvelteCheckPlugin instance to test.
147 """
148 svelte_check_plugin.set_options(tsconfig="./tsconfig.json")
149 assert_that(svelte_check_plugin.options.get("tsconfig")).is_equal_to(
150 "./tsconfig.json",
151 )
154def test_set_options_threshold_none(
155 svelte_check_plugin: SvelteCheckPlugin,
156) -> None:
157 """Set threshold option to None (keeps default).
159 Args:
160 svelte_check_plugin: The SvelteCheckPlugin instance to test.
161 """
162 svelte_check_plugin.set_options(threshold=None)
163 # None values are filtered out; threshold retains default "error"
164 assert_that(svelte_check_plugin.options.get("threshold")).is_equal_to("error")
167# Tests for set_options method - invalid types
170def test_set_options_threshold_invalid_type(
171 svelte_check_plugin: SvelteCheckPlugin,
172) -> None:
173 """Raise ValueError for invalid threshold type.
175 Args:
176 svelte_check_plugin: The SvelteCheckPlugin instance to test.
177 """
178 with pytest.raises(ValueError, match="threshold must be a string"):
179 svelte_check_plugin.set_options(threshold=123) # type: ignore[arg-type]
182def test_set_options_threshold_invalid_value(
183 svelte_check_plugin: SvelteCheckPlugin,
184) -> None:
185 """Raise ValueError for invalid threshold value.
187 Args:
188 svelte_check_plugin: The SvelteCheckPlugin instance to test.
189 """
190 with pytest.raises(
191 ValueError,
192 match="threshold must be 'error', 'warning', or 'hint'",
193 ):
194 svelte_check_plugin.set_options(threshold="invalid")
197def test_set_options_tsconfig_invalid_type(
198 svelte_check_plugin: SvelteCheckPlugin,
199) -> None:
200 """Raise ValueError for invalid tsconfig type.
202 Args:
203 svelte_check_plugin: The SvelteCheckPlugin instance to test.
204 """
205 with pytest.raises(ValueError, match="tsconfig must be a string path"):
206 svelte_check_plugin.set_options(tsconfig=123) # type: ignore[arg-type]
209# Tests for _build_command method
212def test_build_command_basic(svelte_check_plugin: SvelteCheckPlugin) -> None:
213 """Build basic command with default options.
215 Args:
216 svelte_check_plugin: The SvelteCheckPlugin instance to test.
217 """
218 cmd = svelte_check_plugin._build_command()
220 # Should contain machine-verbose output format
221 assert_that(cmd).contains("--output")
222 assert_that(cmd).contains("machine-verbose")
223 # First element should be svelte-check command (or bunx/npx wrapper)
224 assert_that(cmd[0]).is_in("svelte-check", "bunx", "npx")
225 # svelte-check must appear somewhere in the command
226 assert_that(cmd).contains("svelte-check")
229def test_build_command_with_threshold(
230 svelte_check_plugin: SvelteCheckPlugin,
231) -> None:
232 """Build command with threshold option.
234 Args:
235 svelte_check_plugin: The SvelteCheckPlugin instance to test.
236 """
237 svelte_check_plugin.set_options(threshold="warning")
238 cmd = svelte_check_plugin._build_command()
240 assert_that(cmd).contains("--threshold")
241 threshold_idx = cmd.index("--threshold")
242 assert_that(cmd[threshold_idx + 1]).is_equal_to("warning")
245def test_build_command_with_tsconfig(
246 svelte_check_plugin: SvelteCheckPlugin,
247) -> None:
248 """Build command with tsconfig option.
250 Args:
251 svelte_check_plugin: The SvelteCheckPlugin instance to test.
252 """
253 svelte_check_plugin.set_options(tsconfig="./tsconfig.app.json")
254 cmd = svelte_check_plugin._build_command()
256 assert_that(cmd).contains("--tsconfig")
257 tsconfig_idx = cmd.index("--tsconfig")
258 assert_that(cmd[tsconfig_idx + 1]).is_equal_to("./tsconfig.app.json")