Skip to content

Commit 0ba2ca0

Browse files
Rohitth007neiljp
authored andcommitted
theme: Delete old themes and migrate to new themefiles.
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 427fead commit 0ba2ca0

File tree

4 files changed

+15
-608
lines changed

4 files changed

+15
-608
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: 3 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@
44
import pytest
55

66
from zulipterminal.config.themes import (
7-
NEW_THEMES,
87
REQUIRED_STYLES,
98
THEMES,
109
all_themes,
1110
complete_and_incomplete_themes,
12-
generate_theme,
1311
parse_themefile,
14-
theme_with_monochrome_added,
1512
)
1613

1714

@@ -20,7 +17,6 @@
2017
"gruvbox_dark",
2118
"zt_light",
2219
"zt_blue",
23-
"gruvbox_dark24",
2420
}
2521
aliases_16_color = [
2622
"default",
@@ -54,11 +50,11 @@ def test_all_themes():
5450
theme
5551
if theme in expected_complete_themes
5652
else pytest.param(theme, marks=pytest.mark.xfail(reason="incomplete"))
57-
for theme in NEW_THEMES
53+
for theme in THEMES
5854
],
5955
)
60-
def test_new_builtin_theme_completeness(theme_name):
61-
theme = NEW_THEMES[theme_name]
56+
def test_builtin_theme_completeness(theme_name):
57+
theme = THEMES[theme_name]
6258
theme_styles = theme.STYLES
6359
theme_colors = theme.Color
6460

@@ -92,60 +88,6 @@ def test_new_builtin_theme_completeness(theme_name):
9288
assert fg in theme_colors and bg in theme_colors
9389

9490

95-
# Check built-in themes are complete for quality-control purposes
96-
@pytest.mark.parametrize(
97-
"theme_name",
98-
[
99-
theme
100-
if theme in expected_complete_themes
101-
else pytest.param(theme, marks=pytest.mark.xfail(reason="incomplete"))
102-
for theme in THEMES
103-
],
104-
)
105-
def test_builtin_theme_completeness(theme_name):
106-
theme = THEMES[theme_name]
107-
styles_in_theme = {style[0] for style in theme}
108-
109-
assert len(styles_in_theme) == len(REQUIRED_STYLES)
110-
assert all(required_style in styles_in_theme for required_style in REQUIRED_STYLES)
111-
112-
113-
@pytest.mark.parametrize(
114-
"theme_name, depth",
115-
[
116-
("zt_dark", 1),
117-
("zt_dark", 16),
118-
("zt_dark", 256),
119-
("zt_light", 16),
120-
("zt_blue", 16),
121-
("gruvbox_dark", 16),
122-
("gruvbox_dark", 256),
123-
("gruvbox_dark24", 2 ** 24),
124-
("gruvbox_dark24", 2 ** 24),
125-
],
126-
)
127-
def test_migrated_themes(theme_name, depth):
128-
def split_and_strip(style):
129-
style = style.split(",")
130-
style = [s.strip() for s in style]
131-
return style
132-
133-
old_theme = theme_with_monochrome_added(THEMES[theme_name])
134-
135-
new_theme = generate_theme(theme_name.replace("24", ""), depth)
136-
137-
for new_style, old_style in zip(new_theme, old_theme):
138-
assert new_style[0] == old_style[0]
139-
if depth == 1:
140-
assert new_style[3] == old_style[3]
141-
elif depth == 16:
142-
assert split_and_strip(new_style[1]) == split_and_strip(old_style[1])
143-
assert split_and_strip(new_style[2]) == split_and_strip(old_style[2])
144-
else:
145-
assert split_and_strip(new_style[4]) == split_and_strip(old_style[4])
146-
assert split_and_strip(new_style[5]) == split_and_strip(old_style[5])
147-
148-
14991
def test_complete_and_incomplete_themes():
15092
# These are sorted to ensure reproducibility
15193
result = (
@@ -155,32 +97,6 @@ def test_complete_and_incomplete_themes():
15597
assert result == complete_and_incomplete_themes()
15698

15799

158-
@pytest.mark.parametrize(
159-
"theme, expected_new_theme, req_styles",
160-
[
161-
([("a", "another")], [], {}),
162-
([("a", "another")], [("a", "another")], {"a": ""}),
163-
([("a", "fg", "bg")], [("a", "fg", "bg", "x")], {"a": "x"}),
164-
([("a", "fg", "bg", "bold")], [("a", "fg", "bg", "x")], {"a": "x"}),
165-
(
166-
[("a", "fg", "bg", "bold", "h1", "h2")],
167-
[("a", "fg", "bg", "x", "h1", "h2")],
168-
{"a": "x"},
169-
),
170-
],
171-
ids=[
172-
"incomplete_theme",
173-
"one_to_one",
174-
"16_color_add_mono",
175-
"16_color_mono_overwrite",
176-
"256_color",
177-
],
178-
)
179-
def test_theme_with_monochrome_added(mocker, theme, expected_new_theme, req_styles):
180-
mocker.patch.dict("zulipterminal.config.themes.REQUIRED_STYLES", req_styles)
181-
assert theme_with_monochrome_added(theme) == expected_new_theme
182-
183-
184100
@pytest.mark.parametrize(
185101
"color_depth, expected_urwid_theme",
186102
[

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)