Skip to content

Commit bee4909

Browse files
committed
fix: resolve pre-commit cspell, codespell, and pydoclint violations
- Add cspell:ignore directives for pytest fixture names and ANSI escape substrings that trigger false positives - Replace terminal name that triggered codespell false positive - Add Args sections to test docstrings for fixture parameters - Rename test db file to avoid cspell-flagged word
1 parent 1ef581a commit bee4909

5 files changed

Lines changed: 202 additions & 42 deletions

File tree

tests/unit/utils/test_ansi.py

Lines changed: 106 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# cspell:ignore capsys
12
"""Tests for the ansi module."""
23

34
from __future__ import annotations
@@ -22,7 +23,11 @@
2223

2324

2425
def test_changed_with_color(capsys: pytest.CaptureFixture[str]) -> None:
25-
"""Test changed output with color enabled."""
26+
"""Test changed output with color enabled.
27+
28+
Args:
29+
capsys: The capsys fixture
30+
"""
2631
changed(color=True, message="something changed")
2732
captured = capsys.readouterr()
2833
assert Color.YELLOW in captured.out
@@ -31,111 +36,175 @@ def test_changed_with_color(capsys: pytest.CaptureFixture[str]) -> None:
3136

3237

3338
def test_changed_without_color(capsys: pytest.CaptureFixture[str]) -> None:
34-
"""Test changed output without color."""
39+
"""Test changed output without color.
40+
41+
Args:
42+
capsys: The capsys fixture
43+
"""
3544
changed(color=False, message="something changed")
3645
captured = capsys.readouterr()
3746
assert captured.out.strip() == "something changed"
3847
assert Color.YELLOW not in captured.out
3948

4049

4150
def test_failed_with_color(capsys: pytest.CaptureFixture[str]) -> None:
42-
"""Test failed output with color enabled."""
51+
"""Test failed output with color enabled.
52+
53+
Args:
54+
capsys: The capsys fixture
55+
"""
4356
failed(color=True, message="it failed")
4457
captured = capsys.readouterr()
4558
assert Color.RED in captured.out
4659
assert "it failed" in captured.out
4760

4861

4962
def test_failed_without_color(capsys: pytest.CaptureFixture[str]) -> None:
50-
"""Test failed output without color."""
63+
"""Test failed output without color.
64+
65+
Args:
66+
capsys: The capsys fixture
67+
"""
5168
failed(color=False, message="it failed")
5269
assert capsys.readouterr().out.strip() == "it failed"
5370

5471

5572
def test_info_with_color(capsys: pytest.CaptureFixture[str]) -> None:
56-
"""Test info output with color enabled."""
73+
"""Test info output with color enabled.
74+
75+
Args:
76+
capsys: The capsys fixture
77+
"""
5778
info(color=True, message="some info")
5879
captured = capsys.readouterr()
5980
assert Color.CYAN in captured.out
6081
assert "some info" in captured.out
6182

6283

6384
def test_info_without_color(capsys: pytest.CaptureFixture[str]) -> None:
64-
"""Test info output without color."""
85+
"""Test info output without color.
86+
87+
Args:
88+
capsys: The capsys fixture
89+
"""
6590
info(color=False, message="some info")
6691
assert capsys.readouterr().out.strip() == "some info"
6792

6893

6994
def test_subtle_with_color(capsys: pytest.CaptureFixture[str]) -> None:
70-
"""Test subtle output with color enabled."""
95+
"""Test subtle output with color enabled.
96+
97+
Args:
98+
capsys: The capsys fixture
99+
"""
71100
subtle(color=True, message="subtle msg")
72101
captured = capsys.readouterr()
73102
assert Color.GREY in captured.out
74103
assert "subtle msg" in captured.out
75104

76105

77106
def test_subtle_without_color(capsys: pytest.CaptureFixture[str]) -> None:
78-
"""Test subtle output without color."""
107+
"""Test subtle output without color.
108+
109+
Args:
110+
capsys: The capsys fixture
111+
"""
79112
subtle(color=False, message="subtle msg")
80113
assert capsys.readouterr().out.strip() == "subtle msg"
81114

82115

83116
def test_success_with_color(capsys: pytest.CaptureFixture[str]) -> None:
84-
"""Test success output with color enabled."""
117+
"""Test success output with color enabled.
118+
119+
Args:
120+
capsys: The capsys fixture
121+
"""
85122
success(color=True, message="it worked")
86123
captured = capsys.readouterr()
87124
assert Color.GREEN in captured.out
88125
assert "it worked" in captured.out
89126

90127

91128
def test_success_without_color(capsys: pytest.CaptureFixture[str]) -> None:
92-
"""Test success output without color."""
129+
"""Test success output without color.
130+
131+
Args:
132+
capsys: The capsys fixture
133+
"""
93134
success(color=False, message="it worked")
94135
assert capsys.readouterr().out.strip() == "it worked"
95136

96137

97138
def test_warning_with_color(capsys: pytest.CaptureFixture[str]) -> None:
98-
"""Test warning output with color enabled."""
139+
"""Test warning output with color enabled.
140+
141+
Args:
142+
capsys: The capsys fixture
143+
"""
99144
warning(color=True, message="be careful")
100145
captured = capsys.readouterr()
101146
assert Color.YELLOW in captured.out
102147
assert "be careful" in captured.out
103148

104149

105150
def test_warning_without_color(capsys: pytest.CaptureFixture[str]) -> None:
106-
"""Test warning output without color."""
151+
"""Test warning output without color.
152+
153+
Args:
154+
capsys: The capsys fixture
155+
"""
107156
warning(color=False, message="be careful")
108157
assert capsys.readouterr().out.strip() == "be careful"
109158

110159

111160
def test_working_with_color(capsys: pytest.CaptureFixture[str]) -> None:
112-
"""Test working output with color enabled."""
161+
"""Test working output with color enabled.
162+
163+
Args:
164+
capsys: The capsys fixture
165+
"""
113166
working(color=True, message="processing")
114167
captured = capsys.readouterr()
115168
assert Color.GREY in captured.out
116169
assert "processing" in captured.out
117170

118171

119172
def test_working_without_color(capsys: pytest.CaptureFixture[str]) -> None:
120-
"""Test working output without color."""
173+
"""Test working output without color.
174+
175+
Args:
176+
capsys: The capsys fixture
177+
"""
121178
working(color=False, message="processing")
122179
assert capsys.readouterr().out.strip() == "processing"
123180

124181

125182
def test_blank_line(capsys: pytest.CaptureFixture[str]) -> None:
126-
"""Test blank line output."""
183+
"""Test blank line output.
184+
185+
Args:
186+
capsys: The capsys fixture
187+
"""
127188
blank_line()
128189
assert capsys.readouterr().out == "\n"
129190

130191

131192
def test_prompt_enter(monkeypatch: pytest.MonkeyPatch) -> None:
132-
"""Test prompt_enter with normal input."""
193+
"""Test prompt_enter with normal input.
194+
195+
Args:
196+
monkeypatch: The monkeypatch fixture
197+
"""
133198
monkeypatch.setattr("builtins.input", lambda _: "")
134199
prompt_enter()
135200

136201

137202
def test_prompt_enter_keyboard_interrupt(monkeypatch: pytest.MonkeyPatch) -> None:
138-
"""Test prompt_enter exits on KeyboardInterrupt."""
203+
"""Test prompt_enter exits on KeyboardInterrupt.
204+
205+
Args:
206+
monkeypatch: The monkeypatch fixture
207+
"""
139208
def raise_keyboard_interrupt(_: str) -> None:
140209
raise KeyboardInterrupt
141210

@@ -146,25 +215,41 @@ def raise_keyboard_interrupt(_: str) -> None:
146215

147216

148217
def test_prompt_yn_yes(monkeypatch: pytest.MonkeyPatch) -> None:
149-
"""Test prompt_yn returns True for 'y'."""
218+
"""Test prompt_yn returns True for 'y'.
219+
220+
Args:
221+
monkeypatch: The monkeypatch fixture
222+
"""
150223
monkeypatch.setattr("builtins.input", lambda _: "y")
151224
assert prompt_yn("Continue?") is True
152225

153226

154227
def test_prompt_yn_empty(monkeypatch: pytest.MonkeyPatch) -> None:
155-
"""Test prompt_yn returns True for empty input (default yes)."""
228+
"""Test prompt_yn returns True for empty input (default yes).
229+
230+
Args:
231+
monkeypatch: The monkeypatch fixture
232+
"""
156233
monkeypatch.setattr("builtins.input", lambda _: "")
157234
assert prompt_yn("Continue?") is True
158235

159236

160237
def test_prompt_yn_no(monkeypatch: pytest.MonkeyPatch) -> None:
161-
"""Test prompt_yn returns False for 'n'."""
238+
"""Test prompt_yn returns False for 'n'.
239+
240+
Args:
241+
monkeypatch: The monkeypatch fixture
242+
"""
162243
monkeypatch.setattr("builtins.input", lambda _: "n")
163244
assert prompt_yn("Continue?") is False
164245

165246

166247
def test_prompt_yn_keyboard_interrupt(monkeypatch: pytest.MonkeyPatch) -> None:
167-
"""Test prompt_yn exits on KeyboardInterrupt."""
248+
"""Test prompt_yn exits on KeyboardInterrupt.
249+
250+
Args:
251+
monkeypatch: The monkeypatch fixture
252+
"""
168253
def raise_keyboard_interrupt(_: str) -> None:
169254
raise KeyboardInterrupt
170255

tests/unit/utils/test_functions_extended.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# cspell:ignore capsys mred mcolored
12
"""Tests for additional functions in the functions module."""
23

34
from __future__ import annotations
@@ -30,7 +31,11 @@
3031

3132

3233
def test_check_for_ansible_found(monkeypatch: pytest.MonkeyPatch) -> None:
33-
"""Test check_for_ansible when ansible-playbook is found."""
34+
"""Test check_for_ansible when ansible-playbook is found.
35+
36+
Args:
37+
monkeypatch: The monkeypatch fixture
38+
"""
3439
monkeypatch.setattr(shutil, "which", lambda _: "/usr/bin/ansible-playbook")
3540
messages, exit_messages = check_for_ansible()
3641
assert len(messages) == 1
@@ -39,7 +44,11 @@ def test_check_for_ansible_found(monkeypatch: pytest.MonkeyPatch) -> None:
3944

4045

4146
def test_check_for_ansible_not_found(monkeypatch: pytest.MonkeyPatch) -> None:
42-
"""Test check_for_ansible when ansible-playbook is not found."""
47+
"""Test check_for_ansible when ansible-playbook is not found.
48+
49+
Args:
50+
monkeypatch: The monkeypatch fixture
51+
"""
4352
monkeypatch.setattr(shutil, "which", lambda _: None)
4453
messages, exit_messages = check_for_ansible()
4554
assert not messages
@@ -48,7 +57,11 @@ def test_check_for_ansible_not_found(monkeypatch: pytest.MonkeyPatch) -> None:
4857

4958

5059
def test_check_playbook_type_file(tmp_path: Path) -> None:
51-
"""Test check_playbook_type with an existing file."""
60+
"""Test check_playbook_type with an existing file.
61+
62+
Args:
63+
tmp_path: The tmp_path fixture
64+
"""
5265
playbook = tmp_path / "playbook.yml"
5366
playbook.write_text("---")
5467
assert check_playbook_type(str(playbook)) == "file"
@@ -68,7 +81,12 @@ def test_clear_screen_vscode(
6881
monkeypatch: pytest.MonkeyPatch,
6982
capsys: pytest.CaptureFixture[str],
7083
) -> None:
71-
"""Test clear_screen prints blank lines in vscode terminal."""
84+
"""Test clear_screen prints blank lines in vscode terminal.
85+
86+
Args:
87+
monkeypatch: The monkeypatch fixture
88+
capsys: The capsys fixture
89+
"""
7290
monkeypatch.setenv("TERM_PROGRAM", "vscode")
7391
fake_size = type("TermSize", (), {"lines": 5, "columns": 80})()
7492
with patch("ansible_navigator.utils.functions.shutil.get_terminal_size", return_value=fake_size):
@@ -81,8 +99,13 @@ def test_clear_screen_normal(
8199
monkeypatch: pytest.MonkeyPatch,
82100
capsys: pytest.CaptureFixture[str],
83101
) -> None:
84-
"""Test clear_screen does nothing in normal terminal."""
85-
monkeypatch.setenv("TERM_PROGRAM", "iterm")
102+
"""Test clear_screen does nothing in normal terminal.
103+
104+
Args:
105+
monkeypatch: The monkeypatch fixture
106+
capsys: The capsys fixture
107+
"""
108+
monkeypatch.setenv("TERM_PROGRAM", "gnome-terminal")
86109
clear_screen()
87110
captured = capsys.readouterr()
88111
assert captured.out == ""
@@ -293,7 +316,11 @@ def test_timestamp_to_iso_invalid_tz() -> None:
293316

294317

295318
def test_time_stamp_for_file_exists(tmp_path: Path) -> None:
296-
"""Test time_stamp_for_file with existing file."""
319+
"""Test time_stamp_for_file with existing file.
320+
321+
Args:
322+
tmp_path: The tmp_path fixture
323+
"""
297324
test_file = tmp_path / "test.txt"
298325
test_file.write_text("content")
299326
modified, iso_stamp = time_stamp_for_file(str(test_file), "UTC")

tests/unit/utils/test_key_value_store_extended.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,6 @@ def test_open_method(kvs: KeyValueStore) -> None:
164164

165165
def test_init_with_path_object(tmp_path: Path) -> None:
166166
"""Test initialization with a Path object."""
167-
kvs = KeyValueStore(tmp_path / "pathobj.db")
167+
kvs = KeyValueStore(tmp_path / "path_test.db")
168168
kvs["test"] = "value"
169169
assert kvs["test"] == "value"

0 commit comments

Comments
 (0)