Skip to content

Commit

Permalink
theme: Delete old themes and migrate to new themefiles.
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 Jul 3, 2021
1 parent 7c45c88 commit 3478bcb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 582 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
64 changes: 3 additions & 61 deletions tests/config/test_themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
import pytest

from zulipterminal.config.themes import (
NEW_THEMES,
REQUIRED_STYLES,
THEMES,
all_themes,
complete_and_incomplete_themes,
generate_theme,
parse_themefile,
theme_with_monochrome_added,
)


Expand All @@ -20,7 +17,6 @@
"gruvbox_dark",
"zt_light",
"zt_blue",
"gruvbox_dark24",
}
aliases_16_color = [
"default",
Expand Down Expand Up @@ -54,11 +50,11 @@ def test_all_themes():
theme
if theme in expected_complete_themes
else pytest.param(theme, marks=pytest.mark.xfail(reason="incomplete"))
for theme in NEW_THEMES
for theme in THEMES
],
)
def test_new_builtin_theme_completeness(theme_name):
theme = NEW_THEMES[theme_name]
def test_builtin_theme_completeness(theme_name):
theme = THEMES[theme_name]
theme_styles = theme.STYLES
theme_colors = theme.Color

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


# Check built-in themes are complete for quality-control purposes
@pytest.mark.parametrize(
"theme_name",
[
theme
if theme in expected_complete_themes
else pytest.param(theme, marks=pytest.mark.xfail(reason="incomplete"))
for theme in THEMES
],
)
def test_builtin_theme_completeness(theme_name):
theme = THEMES[theme_name]
styles_in_theme = {style[0] for style in theme}

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", 1),
("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 = theme_with_monochrome_added(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 == 1:
assert new_style[3] == old_style[3]
elif 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])


def test_complete_and_incomplete_themes():
# These are sorted to ensure reproducibility
result = (
Expand Down
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 3478bcb

Please sign in to comment.