Skip to content

Commit 299f249

Browse files
committed
theme: Add missing styles to REQUIRED_STYLES and check completeness.
* 3 missing styles: 'muted', 'current_user', 'table_head' were added to REQUIRED_STYLES. * `complete_and_incomplete_themes` was amended to check for equality instead of the superset criteria * The completeness test for builtin themes was added to check for equality with REQUIRED_STYLES and existance of Colors. * The FIXME in `generate_themes` that bypassed undefined styles in REQUIRED_STYLES removed.
1 parent 0da8a25 commit 299f249

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

tests/config/test_themes.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
complete_and_incomplete_themes,
99
generate_theme,
1010
)
11+
from zulipterminal.themes import gruvbox, zt_blue, zt_dark, zt_light
1112
from zulipterminal.themes._template import REQUIRED_STYLES
1213

1314

@@ -23,6 +24,28 @@ def test_all_themes():
2324
assert all_themes() == list(THEMES.keys())
2425

2526

27+
# Check built-in themes are complete for quality-control purposes
28+
@pytest.mark.parametrize(
29+
"theme_name",
30+
[
31+
theme
32+
if theme in expected_complete_themes
33+
else pytest.param(theme, marks=pytest.mark.xfail(reason="incomplete"))
34+
for theme in THEMES
35+
],
36+
)
37+
def test_builtin_theme_completeness(theme_name):
38+
theme = THEMES[theme_name]
39+
theme_styles = theme.STYLES
40+
theme_colors = theme.Color
41+
42+
assert len(theme_styles) == len(REQUIRED_STYLES)
43+
assert all(required_style in theme_styles for required_style in REQUIRED_STYLES)
44+
for style_name, style_conf in theme_styles.items():
45+
fg, bg = style_conf
46+
assert fg in theme_colors and bg in theme_colors
47+
48+
2649
def test_complete_and_incomplete_themes():
2750
# These are sorted to ensure reproducibility
2851
result = (

zulipterminal/config/themes.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def complete_and_incomplete_themes() -> Tuple[List[str], List[str]]:
3636
complete = {
3737
name
3838
for name, theme in THEMES.items()
39-
if {s for s in theme.STYLES}.issuperset(REQUIRED_STYLES)
39+
if theme.STYLES.keys() == REQUIRED_STYLES.keys()
4040
}
4141
incomplete = list(set(THEMES) - complete)
4242
return sorted(list(complete)), sorted(incomplete)
@@ -52,11 +52,7 @@ def generate_theme(theme_name: str, color_depth: int) -> ThemeSpec:
5252
bg_codes = bg.value.split()
5353
new_style: Tuple[Optional[str], ...] = tuple()
5454
if color_depth == 1:
55-
# FIXME: Check for completeness of REQUIRED_STYLES
56-
try:
57-
new_style = (style_name, "", "", REQUIRED_STYLES[style_name])
58-
except:
59-
continue
55+
new_style = (style_name, "", "", REQUIRED_STYLES[style_name])
6056
elif color_depth == 16:
6157
fg = " ".join([fg_codes[0]] + fg_codes[3:]).replace("_", " ")
6258
bg = " ".join([bg_codes[0]] + bg_codes[3:]).replace("_", " ")

zulipterminal/themes/_template.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,14 @@ class Color(Enum):
103103
'popup_category' : 'bold',
104104
'unread_count' : 'bold',
105105
'starred_count' : '',
106+
'table_head' : 'bold',
106107
'filter_results' : 'bold',
107108
'edit_topic' : 'standout',
108109
'edit_tag' : 'standout',
109110
'edit_author' : 'bold',
110111
'edit_time' : 'bold',
112+
'current_user' : '',
113+
'muted' : 'bold',
111114
'popup_border' : 'bold',
112115
'area:help' : 'standout',
113116
'area:msg' : 'standout',

0 commit comments

Comments
 (0)