From d95efda22ee321311e5cdd077dc50df0c09742a6 Mon Sep 17 00:00:00 2001 From: Rohitth Date: Sat, 12 Jun 2021 20:53:17 +0530 Subject: [PATCH] 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. --- tests/config/test_themes.py | 22 ++++++++++++++++++++++ zulipterminal/config/themes.py | 8 ++------ zulipterminal/themes/_template.py | 3 +++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/tests/config/test_themes.py b/tests/config/test_themes.py index 5e57552797..cca7bb3378 100644 --- a/tests/config/test_themes.py +++ b/tests/config/test_themes.py @@ -23,6 +23,28 @@ def test_all_themes(): assert all_themes() == list(THEMES.keys()) +# 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] + theme_styles = theme.STYLES + theme_colors = theme.Color + + 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(): # These are sorted to ensure reproducibility result = ( diff --git a/zulipterminal/config/themes.py b/zulipterminal/config/themes.py index 1069369596..75eae1972c 100644 --- a/zulipterminal/config/themes.py +++ b/zulipterminal/config/themes.py @@ -36,7 +36,7 @@ def complete_and_incomplete_themes() -> Tuple[List[str], List[str]]: complete = { name for name, theme in THEMES.items() - if {s for s in theme.STYLES}.issuperset(REQUIRED_STYLES) + if theme.STYLES.keys() == REQUIRED_STYLES.keys() } incomplete = list(set(THEMES) - complete) return sorted(list(complete)), sorted(incomplete) @@ -52,11 +52,7 @@ def generate_theme(theme_name: str, color_depth: int) -> ThemeSpec: bg_codes = bg.value.split() new_style: Tuple[Optional[str], ...] = tuple() if color_depth == 1: - # FIXME: Check for completeness of REQUIRED_STYLES - try: - new_style = (style_name, "", "", REQUIRED_STYLES[style_name]) - except KeyError: - continue + new_style = (style_name, "", "", REQUIRED_STYLES[style_name]) elif color_depth == 16: fg = " ".join([fg_codes[0]] + fg_codes[3:]).replace("_", " ") bg = " ".join([bg_codes[0]] + bg_codes[3:]).replace("_", " ") diff --git a/zulipterminal/themes/_template.py b/zulipterminal/themes/_template.py index 9ef9458b99..090f56c419 100644 --- a/zulipterminal/themes/_template.py +++ b/zulipterminal/themes/_template.py @@ -104,11 +104,14 @@ class Color(Enum): 'popup_category' : 'bold', 'unread_count' : 'bold', 'starred_count' : '', + 'table_head' : 'bold', 'filter_results' : 'bold', 'edit_topic' : 'standout', 'edit_tag' : 'standout', 'edit_author' : 'bold', 'edit_time' : 'bold', + 'current_user' : '', + 'muted' : 'bold', 'popup_border' : 'bold', 'area:help' : 'standout', 'area:msg' : 'standout',