forked from balisujohn/localwriter
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtest_appearance.py
More file actions
58 lines (45 loc) · 2.04 KB
/
Copy pathtest_appearance.py
File metadata and controls
58 lines (45 loc) · 2.04 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
# WriterAgent - AI Writing Assistant for LibreOffice
# Copyright (c) 2026 KeithCu (modifications and relicensing)
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""Unit tests for shared LO appearance / theme detection (used by chat + Monaco editor)."""
from unittest.mock import MagicMock
import pytest
from plugin.framework import appearance
def test_get_monaco_theme_info_dark_from_field_color():
"""Dark when FieldColor luminance < 128."""
win = MagicMock()
# A fairly dark color (e.g. ~0x2d2d2d)
win.StyleSettings.FieldColor = 0x2D2D2D
win.StyleSettings.DialogColor = 0x1E1E1E
info = appearance.get_monaco_theme_info(style_window=win)
assert info["is_dark"] is True
assert info["monaco"] == "vs-dark"
assert isinstance(info["bg"], int)
def test_get_monaco_theme_info_light_from_field_color():
"""Light otherwise; uses darkened DialogColor for bg if present."""
win = MagicMock()
win.StyleSettings.FieldColor = 0xFFFFFF # bright
win.StyleSettings.DialogColor = 0xF0F0F0
info = appearance.get_monaco_theme_info(style_window=win)
assert info["is_dark"] is False
assert info["monaco"] == "vs"
# bg should be a darkened variant of dialog or fallback
assert info["bg"] != 0xFFFFFF
def test_get_monaco_theme_info_fallback_on_missing():
"""Safe light fallback when no StyleSettings."""
info = appearance.get_monaco_theme_info(style_window=None, doc=None, ctx=None)
assert info["monaco"] == "vs"
assert info["is_dark"] is False
def test_get_theme_colors_uses_shared_logic():
"""get_theme_colors (used by chat) should still work and be consistent with is_dark."""
win = MagicMock()
win.StyleSettings.FieldColor = 0x222222
win.StyleSettings.DialogColor = 0x111111
bg, user, assistant = appearance.get_theme_colors(style_window=win)
assert isinstance(bg, int)
# For dark we return field_color as first
assert bg == 0x222222
def test_get_style_window_prefers_explicit():
explicit = object()
assert appearance.get_style_window(style_window=explicit) is explicit