-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathtest_import_colors.py
More file actions
143 lines (110 loc) · 4.79 KB
/
Copy pathtest_import_colors.py
File metadata and controls
143 lines (110 loc) · 4.79 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
"""Tests for CLI colors in import command."""
from __future__ import annotations
import pathlib
from tests.cli.conftest import (
ANSI_BLUE,
ANSI_CYAN,
ANSI_GREEN,
ANSI_RED,
ANSI_RESET,
)
from tmuxp._internal.private_path import PrivatePath
from tmuxp.cli._colors import Colors
# Import command color output tests
def test_import_error_unknown_format(colors_always: Colors) -> None:
"""Verify unknown format error uses error color (red)."""
msg = "Unknown config format."
result = colors_always.error(msg)
assert ANSI_RED in result # red foreground
assert msg in result
assert result.endswith(ANSI_RESET) # reset at end
def test_import_success_message(colors_always: Colors) -> None:
"""Verify success messages use success color (green)."""
result = colors_always.success("Saved to ")
assert ANSI_GREEN in result # green foreground
assert "Saved to" in result
def test_import_file_path_uses_info(colors_always: Colors) -> None:
"""Verify file paths use info color (cyan)."""
path = "/path/to/config.yaml"
result = colors_always.info(path)
assert ANSI_CYAN in result # cyan foreground
assert path in result
def test_import_muted_for_banner(colors_always: Colors) -> None:
"""Verify banner text uses muted color (blue)."""
msg = "Configuration import does its best to convert files."
result = colors_always.muted(msg)
assert ANSI_BLUE in result # blue foreground
assert msg in result
def test_import_muted_for_separator(colors_always: Colors) -> None:
"""Verify separator uses muted color (blue)."""
separator = "---------------------------------------------------------------"
result = colors_always.muted(separator)
assert ANSI_BLUE in result # blue foreground
assert separator in result
def test_import_colors_disabled_plain_text(colors_never: Colors) -> None:
"""Verify disabled colors return plain text."""
assert colors_never.error("error") == "error"
assert colors_never.success("success") == "success"
assert colors_never.muted("muted") == "muted"
assert colors_never.info("info") == "info"
def test_import_combined_success_format(colors_always: Colors) -> None:
"""Verify combined success + info format for 'Saved to <path>' message."""
dest = "/home/user/.tmuxp/session.yaml"
output = colors_always.success("Saved to ") + colors_always.info(dest) + "."
# Should contain both green and cyan ANSI codes
assert ANSI_GREEN in output # green for "Saved to"
assert ANSI_CYAN in output # cyan for path
assert "Saved to" in output
assert dest in output
assert output.endswith(".")
def test_import_help_text_with_urls(colors_always: Colors) -> None:
"""Verify help text uses muted for text and info for URLs."""
url = "<http://tmuxp.git-pull.com/examples.html>"
help_text = colors_always.muted(
"tmuxp has examples in JSON and YAML format at "
) + colors_always.info(url)
assert ANSI_BLUE in help_text # blue for muted text
assert ANSI_CYAN in help_text # cyan for URL
assert url in help_text
def test_import_banner_with_separator(colors_always: Colors) -> None:
"""Verify banner format with separator and instruction text."""
config_content = "session_name: test\n"
separator = "---------------------------------------------------------------"
output = (
config_content
+ colors_always.muted(separator)
+ "\n"
+ colors_always.muted("Configuration import does its best to convert files.")
+ "\n"
)
# Should contain blue ANSI code for muted sections
assert ANSI_BLUE in output
assert separator in output
assert "Configuration import" in output
assert config_content in output
# Privacy masking tests
def test_import_masks_home_in_save_prompt(mock_home: pathlib.Path) -> None:
"""Import should mask home directory in save prompt."""
cwd = mock_home / "projects"
prompt = f"Save to [{PrivatePath(cwd)}]"
assert "[~/projects]" in prompt
assert "/home/testuser" not in prompt
def test_import_masks_home_in_confirm_prompt(mock_home: pathlib.Path) -> None:
"""Import should mask home directory in confirmation prompt."""
dest_path = mock_home / ".tmuxp/imported.yaml"
prompt = f"Save to {PrivatePath(dest_path)}?"
assert "~/.tmuxp/imported.yaml" in prompt
assert "/home/testuser" not in prompt
def test_import_masks_home_in_saved_message(
colors_always: Colors,
mock_home: pathlib.Path,
) -> None:
"""Import should mask home directory in 'Saved to' message."""
dest = mock_home / ".tmuxp/imported.yaml"
output = (
colors_always.success("Saved to ")
+ colors_always.info(str(PrivatePath(dest)))
+ "."
)
assert "~/.tmuxp/imported.yaml" in output
assert "/home/testuser" not in output