Coverage for tests / unit / tools / prettier / test_set_options.py: 100%
12 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 PrettierPlugin.set_options method."""
3from __future__ import annotations
5from typing import TYPE_CHECKING
7import pytest
8from assertpy import assert_that
10if TYPE_CHECKING:
11 from lintro.tools.definitions.prettier import PrettierPlugin
14# Tests for valid options
17@pytest.mark.parametrize(
18 ("option_name", "option_value"),
19 [
20 ("verbose_fix_output", True),
21 ("verbose_fix_output", False),
22 ("line_length", 80),
23 ("line_length", 120),
24 ],
25 ids=[
26 "verbose_fix_output_true",
27 "verbose_fix_output_false",
28 "line_length_80",
29 "line_length_120",
30 ],
31)
32def test_set_options_valid(
33 prettier_plugin: PrettierPlugin,
34 option_name: str,
35 option_value: object,
36) -> None:
37 """Set valid options correctly.
39 Args:
40 prettier_plugin: The prettier plugin instance to test.
41 option_name: Name of the option to set.
42 option_value: Value to set for the option.
43 """
44 prettier_plugin.set_options(**{option_name: option_value}) # type: ignore[arg-type]
45 assert_that(prettier_plugin.options.get(option_name)).is_equal_to(option_value)
48# Tests for invalid types
51@pytest.mark.parametrize(
52 ("option_name", "invalid_value", "error_match"),
53 [
54 ("verbose_fix_output", "yes", "verbose_fix_output must be a boolean"),
55 ("verbose_fix_output", 1, "verbose_fix_output must be a boolean"),
56 ("line_length", "eighty", "line_length must be an integer"),
57 ("line_length", 0, "line_length must be positive"),
58 ("line_length", -10, "line_length must be positive"),
59 ],
60 ids=[
61 "invalid_verbose_fix_output_string",
62 "invalid_verbose_fix_output_int",
63 "invalid_line_length_string",
64 "invalid_line_length_zero",
65 "invalid_line_length_negative",
66 ],
67)
68def test_set_options_invalid_type(
69 prettier_plugin: PrettierPlugin,
70 option_name: str,
71 invalid_value: object,
72 error_match: str,
73) -> None:
74 """Raise ValueError for invalid option types.
76 Args:
77 prettier_plugin: The prettier plugin instance to test.
78 option_name: Name of the option being tested.
79 invalid_value: Invalid value that should cause an error.
80 error_match: Expected error message substring.
81 """
82 with pytest.raises(ValueError, match=error_match):
83 prettier_plugin.set_options(**{option_name: invalid_value}) # type: ignore[arg-type]