feat(theme): load themes from TOML and apply syntax palette mapping
This commit is contained in:
+43
-5
@@ -1,19 +1,18 @@
|
||||
import pytest
|
||||
from unittest.mock import MagicMock
|
||||
from src import theme_2 as theme
|
||||
from src import paths as paths_mod
|
||||
|
||||
|
||||
def test_theme_apply_sets_rounding_and_padding(monkeypatch):
|
||||
# Mock imgui
|
||||
mock_style = MagicMock()
|
||||
mock_imgui = MagicMock()
|
||||
mock_imgui.get_style.return_value = mock_style
|
||||
mock_imgui.ImVec2.side_effect = lambda x, y: (x, y)
|
||||
monkeypatch.setattr(theme, "imgui", mock_imgui)
|
||||
|
||||
# Call apply with the default palette
|
||||
theme.apply("ImGui Dark")
|
||||
|
||||
# Verify subtle rounding styles
|
||||
assert mock_style.window_rounding == 6.0
|
||||
assert mock_style.child_rounding == 4.0
|
||||
assert mock_style.frame_rounding == 4.0
|
||||
@@ -22,14 +21,53 @@ def test_theme_apply_sets_rounding_and_padding(monkeypatch):
|
||||
assert mock_style.grab_rounding == 4.0
|
||||
assert mock_style.tab_rounding == 4.0
|
||||
|
||||
# Verify borders
|
||||
assert mock_style.window_border_size == 1.0
|
||||
assert mock_style.frame_border_size == 1.0
|
||||
assert mock_style.popup_border_size == 1.0
|
||||
|
||||
# Verify padding/spacing
|
||||
assert mock_style.window_padding == (8.0, 8.0)
|
||||
assert mock_style.frame_padding == (8.0, 4.0)
|
||||
assert mock_style.item_spacing == (8.0, 4.0)
|
||||
assert mock_style.item_inner_spacing == (4.0, 4.0)
|
||||
assert mock_style.scrollbar_size == 14.0
|
||||
|
||||
|
||||
def test_themes_load_from_toml(tmp_path, monkeypatch):
|
||||
from src import paths as paths_mod
|
||||
themes_dir = tmp_path / "themes"
|
||||
themes_dir.mkdir()
|
||||
(themes_dir / "solarized_dark.toml").write_text(
|
||||
'syntax_palette = "dark"\n'
|
||||
'[colors]\n'
|
||||
'window_bg = [0, 43, 54]\n'
|
||||
'text = [147, 161, 161]\n'
|
||||
)
|
||||
(themes_dir / "broken.toml").write_text('syntax_palette = "dark"\n')
|
||||
|
||||
monkeypatch.setattr(theme, "get_global_themes_path", lambda: themes_dir)
|
||||
theme.load_themes_from_disk()
|
||||
names = theme.get_palette_names()
|
||||
assert "solarized_dark" in names
|
||||
assert "broken" not in names
|
||||
|
||||
|
||||
def test_get_syntax_palette_for_theme(tmp_path, monkeypatch):
|
||||
from src import paths as paths_mod
|
||||
themes_dir = tmp_path / "themes"
|
||||
themes_dir.mkdir()
|
||||
(themes_dir / "solarized_light.toml").write_text(
|
||||
'syntax_palette = "light"\n[colors]\nwindow_bg = [253, 246, 227]\n'
|
||||
)
|
||||
monkeypatch.setattr(theme, "get_global_themes_path", lambda: themes_dir)
|
||||
theme.load_themes_from_disk()
|
||||
assert theme.get_syntax_palette_for_theme("solarized_light") == "light"
|
||||
assert theme.get_syntax_palette_for_theme("ImGui Dark") == "dark"
|
||||
|
||||
|
||||
def test_get_syntax_palette_for_unknown_theme_returns_default(tmp_path, monkeypatch):
|
||||
from src import paths as paths_mod
|
||||
themes_dir = tmp_path / "themes"
|
||||
themes_dir.mkdir()
|
||||
monkeypatch.setattr(theme, "get_global_themes_path", lambda: themes_dir)
|
||||
theme.load_themes_from_disk()
|
||||
assert theme.get_syntax_palette_for_theme("NonExistent") == "dark"
|
||||
|
||||
Reference in New Issue
Block a user