bumblebee-status/tests/test_theme.py
Tobi-wan Kenobi c1f1e1a939 [core/themes] Add separator customization
Add customized separators:
* The default separators are automatically disabled if custom separators
  are used (to "just" disable the default, use empty custom separators)
* Use previous background color as their background color and the
  current background color as foreground color
* Allow the separator-block-width to be configured

see #23
2016-12-09 12:55:16 +01:00

97 lines
3.6 KiB
Python

# pylint: disable=C0103,C0111,W0703
import unittest
from bumblebee.theme import Theme
from bumblebee.error import ThemeLoadError
from tests.util import MockWidget
class TestTheme(unittest.TestCase):
def setUp(self):
self.nonexistentThemeName = "no-such-theme"
self.invalidThemeName = "invalid"
self.validThemeName = "test"
self.themedWidget = MockWidget("foo")
self.theme = Theme(self.validThemeName)
self.cycleTheme = Theme("test_cycle")
self.anyWidget = MockWidget("bla")
self.anotherWidget = MockWidget("blub")
data = self.theme.data()
self.widgetTheme = "test-widget"
self.defaultColor = data["defaults"]["fg"]
self.defaultBgColor = data["defaults"]["bg"]
self.widgetColor = data[self.widgetTheme]["fg"]
self.widgetBgColor = data[self.widgetTheme]["bg"]
self.defaultPrefix = data["defaults"]["prefix"]
self.defaultSuffix = data["defaults"]["suffix"]
self.widgetPrefix = data[self.widgetTheme]["prefix"]
self.widgetSuffix = data[self.widgetTheme]["suffix"]
def test_load_valid_theme(self):
try:
Theme(self.validThemeName)
except Exception as e:
self.fail(e)
def test_load_nonexistent_theme(self):
with self.assertRaises(ThemeLoadError):
Theme(self.nonexistentThemeName)
def test_load_invalid_theme(self):
with self.assertRaises(ThemeLoadError):
Theme(self.invalidThemeName)
def test_default_prefix(self):
self.assertEquals(self.theme.prefix(self.themedWidget), self.defaultPrefix)
def test_default_suffix(self):
self.assertEquals(self.theme.suffix(self.themedWidget), self.defaultSuffix)
def test_widget_prefix(self):
self.themedWidget.module = self.widgetTheme
self.assertEquals(self.theme.prefix(self.themedWidget), self.widgetPrefix)
def test_widget_fg(self):
self.assertEquals(self.theme.fg(self.themedWidget), self.defaultColor)
self.themedWidget.module = self.widgetTheme
self.assertEquals(self.theme.fg(self.themedWidget), self.widgetColor)
def test_widget_bg(self):
self.assertEquals(self.theme.bg(self.themedWidget), self.defaultBgColor)
self.themedWidget.module = self.widgetTheme
self.assertEquals(self.theme.bg(self.themedWidget), self.widgetBgColor)
def test_absent_cycle(self):
theme = self.theme
try:
theme.fg(self.anyWidget)
theme.fg(self.anotherWidget)
except Exception as e:
self.fail(e)
def test_reset(self):
theme = self.cycleTheme
data = theme.data()
theme.reset()
self.assertEquals(theme.fg(self.anyWidget), data["cycle"][0]["fg"])
self.assertEquals(theme.fg(self.anotherWidget), data["cycle"][1]["fg"])
theme.reset()
self.assertEquals(theme.fg(self.anyWidget), data["cycle"][0]["fg"])
def test_separator_block_width(self):
theme = self.theme
data = theme.data()
self.assertEquals(theme.separator_block_width(self.anyWidget), data["defaults"]["separator-block-width"])
def test_separator(self):
for theme in [self.theme, self.cycleTheme]:
data = theme.data()
theme.reset()
prev_bg = theme.bg(self.anyWidget)
theme.bg(self.anotherWidget)
self.assertEquals(theme.separator_fg(self.anotherWidget), theme.bg(self.anotherWidget))
self.assertEquals(theme.separator_bg(self.anotherWidget), prev_bg)
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4