Skip to content

Commit

Permalink
theme: Delete old themes.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Rohitth007 committed Jun 19, 2021
1 parent e2a66f4 commit 56e6dd1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 558 deletions.
5 changes: 1 addition & 4 deletions tests/cli/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import pytest

from zulipterminal.cli.run import (
THEMES,
_write_zuliprc,
exit_with_error,
get_login_id,
Expand Down Expand Up @@ -140,7 +139,6 @@ def test_valid_zuliprc_but_no_connection(
def test_warning_regarding_incomplete_theme(
capsys,
mocker,
monkeypatch,
minimal_zuliprc,
bad_theme,
server_connection_error="sce",
Expand All @@ -149,13 +147,12 @@ def test_warning_regarding_incomplete_theme(
"zulipterminal.core.Controller.__init__",
side_effect=ServerConnectionFailure(server_connection_error),
)

monkeypatch.setitem(THEMES, bad_theme, [])
mocker.patch("zulipterminal.cli.run.all_themes", return_value=("a", "b", "c", "d"))
mocker.patch(
"zulipterminal.cli.run.complete_and_incomplete_themes",
return_value=(["a", "b"], ["c", "d"]),
)
mocker.patch("zulipterminal.cli.run.generate_theme")

with pytest.raises(SystemExit) as e:
main(["-c", minimal_zuliprc, "-t", bad_theme])
Expand Down
44 changes: 8 additions & 36 deletions tests/config/test_themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"gruvbox_dark",
"zt_light",
"zt_blue",
"gruvbox_dark24",
}


Expand All @@ -36,41 +35,14 @@ def test_all_themes():
)
def test_builtin_theme_completeness(theme_name):
theme = THEMES[theme_name]
styles_in_theme = {style[0] for style in theme}
theme_styles = theme.STYLES
theme_colors = theme.Color

assert len(styles_in_theme) == len(REQUIRED_STYLES)
assert all(required_style in styles_in_theme for required_style in REQUIRED_STYLES)


@pytest.mark.parametrize(
"theme_name, depth",
[
("zt_dark", 16),
("zt_dark", 256),
("zt_light", 16),
("zt_blue", 16),
("gruvbox_dark", 16),
("gruvbox_dark", 256),
("gruvbox_dark24", 2 ** 24),
("gruvbox_dark24", 2 ** 24),
],
)
def test_migrated_themes(theme_name, depth):
def split_and_strip(style):
style = style.split(",")
style = [s.strip() for s in style]
return style

old_theme = THEMES[theme_name]
new_theme = generate_theme(theme_name.replace("24", ""), depth)
for new_style, old_style in zip(new_theme, old_theme):
assert new_style[0] == old_style[0]
if depth == 16:
assert split_and_strip(new_style[1]) == split_and_strip(old_style[1])
assert split_and_strip(new_style[2]) == split_and_strip(old_style[2])
else:
assert split_and_strip(new_style[4]) == split_and_strip(old_style[4])
assert split_and_strip(new_style[5]) == split_and_strip(old_style[5])
assert len(theme_styles) == len(REQUIRED_STYLES)
assert all(required_style in theme_styles for required_style in REQUIRED_STYLES)
for style_name, style_conf in theme_styles.items():
fg, bg = style_conf
assert fg in theme_colors and bg in theme_colors


def test_complete_and_incomplete_themes():
Expand Down Expand Up @@ -128,7 +100,7 @@ class Color(Enum):
],
)
def test_generate_theme(mocker, color_depth, expected_urwid_theme):
mocker.patch.dict("zulipterminal.config.themes.NEW_THEMES", {"theme": theme})
mocker.patch.dict("zulipterminal.config.themes.THEMES", {"theme": theme})
req_styles = {"s1": "", "s2": "bold"}
mocker.patch.dict("zulipterminal.themes._template.REQUIRED_STYLES", req_styles)
assert generate_theme("theme", color_depth) == expected_urwid_theme
8 changes: 2 additions & 6 deletions zulipterminal/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
from urwid import display_common, set_encoding

from zulipterminal.config.themes import (
THEMES,
aliased_themes,
all_themes,
complete_and_incomplete_themes,
theme_with_monochrome_added,
generate_theme,
)
from zulipterminal.core import Controller
from zulipterminal.model import ServerConnectionFailure
Expand Down Expand Up @@ -486,10 +485,7 @@ def main(options: Optional[List[str]] = None) -> None:
break
boolean_settings[setting] = zterm[setting][0] == valid_values[0]

if color_depth == 1:
theme_data = theme_with_monochrome_added(THEMES[theme_to_use[0]])
else:
theme_data = THEMES[theme_to_use[0]]
theme_data = generate_theme(theme_to_use[0], color_depth)

Controller(
zuliprc_path,
Expand Down
Loading

0 comments on commit 56e6dd1

Please sign in to comment.