Coverage for tests / unit / tools / oxfmt / test_set_options.py: 100%
36 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.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.oxfmt import OxfmtPlugin
14# =============================================================================
15# Tests for config and ignore_path options validation
16# =============================================================================
19def test_config_accepts_string(oxfmt_plugin: OxfmtPlugin) -> None:
20 """Config option accepts a string value.
22 Args:
23 oxfmt_plugin: The OxfmtPlugin instance to test.
24 """
25 oxfmt_plugin.set_options(config=".oxfmtrc.custom.json")
26 assert_that(oxfmt_plugin.options.get("config")).is_equal_to(
27 ".oxfmtrc.custom.json",
28 )
31def test_config_rejects_non_string(oxfmt_plugin: OxfmtPlugin) -> None:
32 """Config option rejects non-string values.
34 Args:
35 oxfmt_plugin: The OxfmtPlugin instance to test.
36 """
37 with pytest.raises(ValueError, match="config must be a string"):
38 # Intentionally passing wrong type to test validation
39 oxfmt_plugin.set_options(config=123) # type: ignore[arg-type]
42def test_ignore_path_accepts_string(oxfmt_plugin: OxfmtPlugin) -> None:
43 """Ignore_path option accepts a string value.
45 Args:
46 oxfmt_plugin: The OxfmtPlugin instance to test.
47 """
48 oxfmt_plugin.set_options(ignore_path=".oxfmtignore")
49 assert_that(oxfmt_plugin.options.get("ignore_path")).is_equal_to(
50 ".oxfmtignore",
51 )
54def test_ignore_path_rejects_non_string(oxfmt_plugin: OxfmtPlugin) -> None:
55 """Ignore_path option rejects non-string values.
57 Args:
58 oxfmt_plugin: The OxfmtPlugin instance to test.
59 """
60 with pytest.raises(ValueError, match="ignore_path must be a string"):
61 # Intentionally passing wrong type to test validation
62 oxfmt_plugin.set_options(ignore_path=True) # type: ignore[arg-type]
65# =============================================================================
66# Tests for setting multiple options
67# =============================================================================
70def test_set_multiple_options(oxfmt_plugin: OxfmtPlugin) -> None:
71 """Multiple options can be set in a single call.
73 Args:
74 oxfmt_plugin: The OxfmtPlugin instance to test.
75 """
76 oxfmt_plugin.set_options(
77 config=".oxfmtrc.json",
78 ignore_path=".oxfmtignore",
79 )
81 assert_that(oxfmt_plugin.options.get("config")).is_equal_to(".oxfmtrc.json")
82 assert_that(oxfmt_plugin.options.get("ignore_path")).is_equal_to(".oxfmtignore")
85# =============================================================================
86# Tests for _build_oxfmt_args(oxfmt_plugin.options) helper method
87# =============================================================================
90def test_build_args_empty_options(oxfmt_plugin: OxfmtPlugin) -> None:
91 """Empty options returns empty args list.
93 Args:
94 oxfmt_plugin: The OxfmtPlugin instance to test.
95 """
96 args = oxfmt_plugin._build_oxfmt_args(oxfmt_plugin.options)
97 assert_that(args).is_empty()
100def test_build_args_config_adds_flag(oxfmt_plugin: OxfmtPlugin) -> None:
101 """Config option adds --config flag.
103 Args:
104 oxfmt_plugin: The OxfmtPlugin instance to test.
105 """
106 oxfmt_plugin.set_options(config=".oxfmtrc.json")
107 args = oxfmt_plugin._build_oxfmt_args(oxfmt_plugin.options)
108 assert_that(args).contains("--config", ".oxfmtrc.json")
111def test_build_args_ignore_path_adds_flag(oxfmt_plugin: OxfmtPlugin) -> None:
112 """Ignore_path option adds --ignore-path flag.
114 Args:
115 oxfmt_plugin: The OxfmtPlugin instance to test.
116 """
117 oxfmt_plugin.set_options(ignore_path=".oxfmtignore")
118 args = oxfmt_plugin._build_oxfmt_args(oxfmt_plugin.options)
119 assert_that(args).contains("--ignore-path", ".oxfmtignore")
122def test_build_args_multiple_options_combine(oxfmt_plugin: OxfmtPlugin) -> None:
123 """Multiple options combine into a single args list.
125 Args:
126 oxfmt_plugin: The OxfmtPlugin instance to test.
127 """
128 oxfmt_plugin.set_options(
129 config=".oxfmtrc.json",
130 ignore_path=".oxfmtignore",
131 )
132 args = oxfmt_plugin._build_oxfmt_args(oxfmt_plugin.options)
134 assert_that(args).contains("--config", ".oxfmtrc.json")
135 assert_that(args).contains("--ignore-path", ".oxfmtignore")