Skip to content

Commit

Permalink
theme: Add missing styles to REQUIRED_STYLES and check completeness.
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Rohitth007 committed Jun 13, 2021
1 parent a24c431 commit d95efda
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
22 changes: 22 additions & 0 deletions tests/config/test_themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
8 changes: 2 additions & 6 deletions zulipterminal/config/themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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("_", " ")
Expand Down
3 changes: 3 additions & 0 deletions zulipterminal/themes/_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit d95efda

Please sign in to comment.