-
Notifications
You must be signed in to change notification settings - Fork 238
Expand file tree
/
Copy pathconftest.py
More file actions
63 lines (48 loc) · 1.78 KB
/
conftest.py
File metadata and controls
63 lines (48 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""Shared pytest fixtures for CLI tests."""
from __future__ import annotations
import pathlib
import pytest
from tmuxp._internal.colors import ColorMode, Colors
# ANSI escape codes for test assertions
# These constants improve test readability by giving semantic names to color codes
ANSI_GREEN = "\033[32m"
ANSI_RED = "\033[31m"
ANSI_YELLOW = "\033[33m"
ANSI_BLUE = "\033[34m"
ANSI_MAGENTA = "\033[35m"
ANSI_CYAN = "\033[36m"
ANSI_RESET = "\033[0m"
ANSI_BOLD = "\033[1m"
@pytest.fixture
def colors_always(monkeypatch: pytest.MonkeyPatch) -> Colors:
"""Colors instance with ALWAYS mode and NO_COLOR cleared."""
monkeypatch.delenv("NO_COLOR", raising=False)
return Colors(ColorMode.ALWAYS)
@pytest.fixture
def colors_never() -> Colors:
"""Colors instance with colors disabled."""
return Colors(ColorMode.NEVER)
@pytest.fixture
def mock_home(monkeypatch: pytest.MonkeyPatch) -> pathlib.Path:
"""Mock home directory for privacy tests.
Sets pathlib.Path.home() to return /home/testuser.
"""
home = pathlib.Path("/home/testuser")
monkeypatch.setattr(pathlib.Path, "home", lambda: home)
return home
@pytest.fixture
def isolated_home(
monkeypatch: pytest.MonkeyPatch,
tmp_path: pathlib.Path,
) -> pathlib.Path:
"""Isolate test from user's home directory and environment.
Sets up tmp_path as HOME with XDG_CONFIG_HOME, clears TMUXP_CONFIGDIR
and NO_COLOR, and changes the working directory to tmp_path.
"""
monkeypatch.setenv("HOME", str(tmp_path))
monkeypatch.setenv("XDG_CONFIG_HOME", str(tmp_path / ".config"))
monkeypatch.delenv("TMUXP_CONFIGDIR", raising=False)
monkeypatch.delenv("NO_COLOR", raising=False)
monkeypatch.chdir(tmp_path)
monkeypatch.setattr(pathlib.Path, "home", lambda: tmp_path)
return tmp_path