Coverage for tests / unit / tools / oxfmt / test_default_options.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"""Tests for OxfmtPlugin default options."""
3from __future__ import annotations
5from typing import TYPE_CHECKING, Any
7import pytest
8from assertpy import assert_that
10from lintro.enums.tool_type import ToolType
11from lintro.tools.definitions.oxfmt import (
12 OXFMT_DEFAULT_PRIORITY,
13 OXFMT_DEFAULT_TIMEOUT,
14 OxfmtPlugin,
15)
17if TYPE_CHECKING:
18 pass
21# =============================================================================
22# Tests for ToolDefinition attributes
23# =============================================================================
26@pytest.mark.parametrize(
27 ("attr", "expected"),
28 [
29 ("name", "oxfmt"),
30 (
31 "description",
32 "Fast JavaScript/TypeScript formatter (30x faster than Prettier)",
33 ),
34 ("can_fix", True),
35 ("tool_type", ToolType.FORMATTER),
36 ("priority", OXFMT_DEFAULT_PRIORITY),
37 ("default_timeout", OXFMT_DEFAULT_TIMEOUT),
38 ("min_version", "0.42.0"),
39 ],
40 ids=[
41 "name_equals_oxfmt",
42 "description_is_set",
43 "can_fix_is_true",
44 "tool_type_is_formatter",
45 "priority_equals_80",
46 "default_timeout_equals_30",
47 "min_version_is_0.42.0",
48 ],
49)
50def test_definition_attributes(
51 oxfmt_plugin: OxfmtPlugin,
52 attr: str,
53 expected: object,
54) -> None:
55 """Definition attributes have correct values.
57 Args:
58 oxfmt_plugin: The OxfmtPlugin instance to test.
59 attr: The attribute name to check.
60 expected: The expected value for the attribute.
61 """
62 assert_that(getattr(oxfmt_plugin.definition, attr)).is_equal_to(expected)
65def test_definition_file_patterns(oxfmt_plugin: OxfmtPlugin) -> None:
66 """Definition includes JavaScript/TypeScript/Vue file patterns.
68 Args:
69 oxfmt_plugin: The OxfmtPlugin instance to test.
70 """
71 patterns = oxfmt_plugin.definition.file_patterns
72 assert_that(patterns).contains("*.js")
73 assert_that(patterns).contains("*.ts")
74 assert_that(patterns).contains("*.jsx")
75 assert_that(patterns).contains("*.tsx")
76 assert_that(patterns).contains("*.vue")
79def test_definition_native_configs(oxfmt_plugin: OxfmtPlugin) -> None:
80 """Definition includes native config files.
82 Args:
83 oxfmt_plugin: The OxfmtPlugin instance to test.
84 """
85 configs = oxfmt_plugin.definition.native_configs
86 assert_that(configs).contains(".oxfmtrc.json")
87 assert_that(configs).contains(".oxfmtrc.jsonc")
90def test_definition_version_command(oxfmt_plugin: OxfmtPlugin) -> None:
91 """Definition has a version command.
93 Args:
94 oxfmt_plugin: The OxfmtPlugin instance to test.
95 """
96 assert_that(oxfmt_plugin.definition.version_command).is_not_none()
97 assert_that(oxfmt_plugin.definition.version_command).contains("oxfmt")
98 assert_that(oxfmt_plugin.definition.version_command).contains("--version")
101def test_definition_conflicts_with(oxfmt_plugin: OxfmtPlugin) -> None:
102 """Definition specifies conflicting tools.
104 Args:
105 oxfmt_plugin: The OxfmtPlugin instance to test.
106 """
107 conflicts = oxfmt_plugin.definition.conflicts_with
108 assert_that(conflicts).is_empty()
111# =============================================================================
112# Tests for default options
113# =============================================================================
116def test_default_options_timeout(oxfmt_plugin: OxfmtPlugin) -> None:
117 """Default timeout option has correct value.
119 Args:
120 oxfmt_plugin: The OxfmtPlugin instance to test.
121 """
122 assert_that(
123 oxfmt_plugin.definition.default_options["timeout"],
124 ).is_equal_to(OXFMT_DEFAULT_TIMEOUT)
127@pytest.mark.parametrize(
128 ("option_name", "expected_value"),
129 [
130 ("verbose_fix_output", False),
131 ],
132 ids=[
133 "verbose_fix_output_is_false",
134 ],
135)
136def test_default_options_values(
137 oxfmt_plugin: OxfmtPlugin,
138 option_name: str,
139 expected_value: Any,
140) -> None:
141 """Default options have correct values.
143 Args:
144 oxfmt_plugin: The OxfmtPlugin instance to test.
145 option_name: The name of the option to check.
146 expected_value: The expected value for the option.
147 """
148 assert_that(
149 oxfmt_plugin.definition.default_options[option_name],
150 ).is_equal_to(expected_value)