File: test_edit_colors.py

package info (click to toggle)
tmuxp 1.64.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,500 kB
  • sloc: python: 17,788; sh: 22; makefile: 6
file content (101 lines) | stat: -rw-r--r-- 3,465 bytes parent folder | download | duplicates (2)
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
"""Tests for CLI colors in edit command."""

from __future__ import annotations

import pathlib

from tests.cli.conftest import ANSI_BLUE, ANSI_BOLD, ANSI_CYAN, ANSI_MAGENTA
from tmuxp._internal.private_path import PrivatePath
from tmuxp.cli._colors import Colors

# Edit command color output tests


def test_edit_opening_message_format(colors_always: Colors) -> None:
    """Verify opening message format with file path and editor."""
    workspace_file = "/home/user/.tmuxp/dev.yaml"
    editor = "vim"
    output = (
        colors_always.muted("Opening ")
        + colors_always.info(workspace_file)
        + colors_always.muted(" in ")
        + colors_always.highlight(editor, bold=False)
        + colors_always.muted("...")
    )
    # Should contain blue, cyan, and magenta ANSI codes
    assert ANSI_BLUE in output  # blue for muted
    assert ANSI_CYAN in output  # cyan for file path
    assert ANSI_MAGENTA in output  # magenta for editor
    assert workspace_file in output
    assert editor in output


def test_edit_file_path_uses_info(colors_always: Colors) -> None:
    """Verify file paths use info color (cyan)."""
    path = "/path/to/workspace.yaml"
    result = colors_always.info(path)
    assert ANSI_CYAN in result  # cyan foreground
    assert path in result


def test_edit_editor_highlighted(colors_always: Colors) -> None:
    """Verify editor name uses highlight color without bold."""
    for editor in ["vim", "nano", "code", "emacs", "nvim"]:
        result = colors_always.highlight(editor, bold=False)
        assert ANSI_MAGENTA in result  # magenta foreground
        assert ANSI_BOLD not in result  # no bold - subtle
        assert editor in result


def test_edit_muted_for_static_text(colors_always: Colors) -> None:
    """Verify static text uses muted color (blue)."""
    result = colors_always.muted("Opening ")
    assert ANSI_BLUE in result  # blue foreground
    assert "Opening" in result


def test_edit_colors_disabled_plain_text(colors_never: Colors) -> None:
    """Verify disabled colors return plain text."""
    workspace_file = "/home/user/.tmuxp/dev.yaml"
    editor = "vim"
    output = (
        colors_never.muted("Opening ")
        + colors_never.info(workspace_file)
        + colors_never.muted(" in ")
        + colors_never.highlight(editor, bold=False)
        + colors_never.muted("...")
    )
    # Should be plain text without ANSI codes
    assert "\033[" not in output
    assert output == f"Opening {workspace_file} in {editor}..."


def test_edit_various_editors(colors_always: Colors) -> None:
    """Verify common editors can be highlighted."""
    editors = ["vim", "nvim", "nano", "code", "emacs", "hx", "micro"]
    for editor in editors:
        result = colors_always.highlight(editor, bold=False)
        assert ANSI_MAGENTA in result
        assert editor in result


# Privacy masking tests


def test_edit_masks_home_in_opening_message(
    colors_always: Colors,
    mock_home: pathlib.Path,
) -> None:
    """Edit should mask home directory in 'Opening' message."""
    workspace_file = mock_home / ".tmuxp/dev.yaml"
    editor = "vim"
    output = (
        colors_always.muted("Opening ")
        + colors_always.info(str(PrivatePath(workspace_file)))
        + colors_always.muted(" in ")
        + colors_always.highlight(editor, bold=False)
        + colors_always.muted("...")
    )

    assert "~/.tmuxp/dev.yaml" in output
    assert "/home/testuser" not in output