Skip to content

Commit 691e7f4

Browse files
committed
theme: Delete old themes.
Old theme format used in themes.py is deleted from this commit. * Migrated to new themes in `run.py` * Mono theme generation is no longer required hence it is removed from both themes.py and run.py * NEW_THEMES is now the new THEMES dict. * `complete_and_incomplete_themes` is edited to make it use the new THEMES instead of the old one. A new `builtin_theme_completeness` test is added. Tests amended.
1 parent ec8d8e4 commit 691e7f4

File tree

4 files changed

+17
-577
lines changed

4 files changed

+17
-577
lines changed

tests/cli/test_run.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import pytest
66

77
from zulipterminal.cli.run import (
8-
THEMES,
98
_write_zuliprc,
109
exit_with_error,
1110
get_login_id,
@@ -140,7 +139,6 @@ def test_valid_zuliprc_but_no_connection(
140139
def test_warning_regarding_incomplete_theme(
141140
capsys,
142141
mocker,
143-
monkeypatch,
144142
minimal_zuliprc,
145143
bad_theme,
146144
server_connection_error="sce",
@@ -149,13 +147,12 @@ def test_warning_regarding_incomplete_theme(
149147
"zulipterminal.core.Controller.__init__",
150148
side_effect=ServerConnectionFailure(server_connection_error),
151149
)
152-
153-
monkeypatch.setitem(THEMES, bad_theme, [])
154150
mocker.patch("zulipterminal.cli.run.all_themes", return_value=("a", "b", "c", "d"))
155151
mocker.patch(
156152
"zulipterminal.cli.run.complete_and_incomplete_themes",
157153
return_value=(["a", "b"], ["c", "d"]),
158154
)
155+
mocker.patch("zulipterminal.cli.run.generate_theme")
159156

160157
with pytest.raises(SystemExit) as e:
161158
main(["-c", minimal_zuliprc, "-t", bad_theme])

tests/config/test_themes.py

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import pytest
44

55
from zulipterminal.config.themes import (
6-
NEW_THEMES,
76
THEMES,
87
all_themes,
98
complete_and_incomplete_themes,
@@ -17,7 +16,6 @@
1716
"gruvbox_dark",
1817
"zt_light",
1918
"zt_blue",
20-
"gruvbox_dark24",
2119
}
2220

2321

@@ -32,11 +30,11 @@ def test_all_themes():
3230
theme
3331
if theme in expected_complete_themes
3432
else pytest.param(theme, marks=pytest.mark.xfail(reason="incomplete"))
35-
for theme in NEW_THEMES
33+
for theme in THEMES
3634
],
3735
)
38-
def test_new_builtin_theme_completeness(theme_name):
39-
theme = NEW_THEMES[theme_name]
36+
def test_builtin_theme_completeness(theme_name):
37+
theme = THEMES[theme_name]
4038
theme_styles = theme.STYLES
4139
theme_colors = theme.Color
4240

@@ -53,55 +51,6 @@ def test_new_builtin_theme_completeness(theme_name):
5351
assert fg in theme_colors and bg in theme_colors
5452

5553

56-
# Check built-in themes are complete for quality-control purposes
57-
@pytest.mark.parametrize(
58-
"theme_name",
59-
[
60-
theme
61-
if theme in expected_complete_themes
62-
else pytest.param(theme, marks=pytest.mark.xfail(reason="incomplete"))
63-
for theme in THEMES
64-
],
65-
)
66-
def test_builtin_theme_completeness(theme_name):
67-
theme = THEMES[theme_name]
68-
styles_in_theme = {style[0] for style in theme}
69-
70-
assert len(styles_in_theme) == len(REQUIRED_STYLES)
71-
assert all(required_style in styles_in_theme for required_style in REQUIRED_STYLES)
72-
73-
74-
@pytest.mark.parametrize(
75-
"theme_name, depth",
76-
[
77-
("zt_dark", 16),
78-
("zt_dark", 256),
79-
("zt_light", 16),
80-
("zt_blue", 16),
81-
("gruvbox_dark", 16),
82-
("gruvbox_dark", 256),
83-
("gruvbox_dark24", 2 ** 24),
84-
("gruvbox_dark24", 2 ** 24),
85-
],
86-
)
87-
def test_migrated_themes(theme_name, depth):
88-
def split_and_strip(style):
89-
style = style.split(",")
90-
style = [s.strip() for s in style]
91-
return style
92-
93-
old_theme = THEMES[theme_name]
94-
new_theme = generate_theme(theme_name.replace("24", ""), depth)
95-
for new_style, old_style in zip(new_theme, old_theme):
96-
assert new_style[0] == old_style[0]
97-
if depth == 16:
98-
assert split_and_strip(new_style[1]) == split_and_strip(old_style[1])
99-
assert split_and_strip(new_style[2]) == split_and_strip(old_style[2])
100-
else:
101-
assert split_and_strip(new_style[4]) == split_and_strip(old_style[4])
102-
assert split_and_strip(new_style[5]) == split_and_strip(old_style[5])
103-
104-
10554
def test_complete_and_incomplete_themes():
10655
# These are sorted to ensure reproducibility
10756
result = (
@@ -157,7 +106,7 @@ class Color(Enum):
157106
],
158107
)
159108
def test_generate_theme(mocker, color_depth, expected_urwid_theme):
160-
mocker.patch.dict("zulipterminal.config.themes.NEW_THEMES", {"theme": theme})
109+
mocker.patch.dict("zulipterminal.config.themes.THEMES", {"theme": theme})
161110
req_styles = {"s1": "", "s2": "bold"}
162111
mocker.patch.dict("zulipterminal.themes.Common.REQUIRED_STYLES", req_styles)
163112
assert generate_theme("theme", color_depth) == expected_urwid_theme

zulipterminal/cli/run.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
from urwid import display_common, set_encoding
1313

1414
from zulipterminal.config.themes import (
15-
THEMES,
1615
aliased_themes,
1716
all_themes,
1817
complete_and_incomplete_themes,
19-
theme_with_monochrome_added,
18+
generate_theme,
2019
)
2120
from zulipterminal.core import Controller
2221
from zulipterminal.model import ServerConnectionFailure
@@ -486,10 +485,7 @@ def main(options: Optional[List[str]] = None) -> None:
486485
break
487486
boolean_settings[setting] = zterm[setting][0] == valid_values[0]
488487

489-
if color_depth == 1:
490-
theme_data = theme_with_monochrome_added(THEMES[theme_to_use[0]])
491-
else:
492-
theme_data = THEMES[theme_to_use[0]]
488+
theme_data = generate_theme(theme_to_use[0], color_depth)
493489

494490
Controller(
495491
zuliprc_path,

0 commit comments

Comments
 (0)