2016-12-08 09:44:05 +01:00
|
|
|
# pylint: disable=C0103,C0111,W0703
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
from bumblebee.theme import Theme
|
|
|
|
from bumblebee.error import ThemeLoadError
|
2016-12-08 11:52:47 +01:00
|
|
|
from tests.util import MockWidget
|
2016-12-08 09:44:05 +01:00
|
|
|
|
|
|
|
class TestTheme(unittest.TestCase):
|
|
|
|
def setUp(self):
|
2016-12-08 10:17:25 +01:00
|
|
|
self.nonexistentThemeName = "no-such-theme"
|
|
|
|
self.invalidThemeName = "invalid"
|
2016-12-08 12:09:21 +01:00
|
|
|
self.validThemeName = "test"
|
2016-12-09 13:32:22 +01:00
|
|
|
self.themedWidget = MockWidget("bla")
|
2016-12-08 12:09:21 +01:00
|
|
|
self.theme = Theme(self.validThemeName)
|
2016-12-09 12:28:39 +01:00
|
|
|
self.cycleTheme = Theme("test_cycle")
|
|
|
|
self.anyWidget = MockWidget("bla")
|
|
|
|
self.anotherWidget = MockWidget("blub")
|
2016-12-08 12:09:21 +01:00
|
|
|
|
2016-12-09 12:28:39 +01:00
|
|
|
data = self.theme.data()
|
2016-12-08 12:09:21 +01:00
|
|
|
self.widgetTheme = "test-widget"
|
2016-12-09 13:32:22 +01:00
|
|
|
self.themedWidget.module = self.widgetTheme
|
2016-12-09 12:28:39 +01:00
|
|
|
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"]
|
2016-12-08 09:44:05 +01:00
|
|
|
|
|
|
|
def test_load_valid_theme(self):
|
|
|
|
try:
|
2016-12-08 11:52:47 +01:00
|
|
|
Theme(self.validThemeName)
|
2016-12-08 09:44:05 +01:00
|
|
|
except Exception as e:
|
|
|
|
self.fail(e)
|
|
|
|
|
|
|
|
def test_load_nonexistent_theme(self):
|
|
|
|
with self.assertRaises(ThemeLoadError):
|
2016-12-08 10:17:25 +01:00
|
|
|
Theme(self.nonexistentThemeName)
|
2016-12-08 09:44:05 +01:00
|
|
|
|
|
|
|
def test_load_invalid_theme(self):
|
|
|
|
with self.assertRaises(ThemeLoadError):
|
2016-12-08 10:17:25 +01:00
|
|
|
Theme(self.invalidThemeName)
|
2016-12-04 18:10:04 +01:00
|
|
|
|
2016-12-08 12:09:21 +01:00
|
|
|
def test_default_prefix(self):
|
2016-12-09 13:32:22 +01:00
|
|
|
self.assertEquals(self.theme.prefix(self.anyWidget), self.defaultPrefix)
|
2016-12-08 12:09:21 +01:00
|
|
|
|
|
|
|
def test_default_suffix(self):
|
2016-12-09 13:32:22 +01:00
|
|
|
self.assertEquals(self.theme.suffix(self.anyWidget), self.defaultSuffix)
|
2016-12-08 11:52:47 +01:00
|
|
|
|
2016-12-08 12:09:21 +01:00
|
|
|
def test_widget_prefix(self):
|
2016-12-09 12:28:39 +01:00
|
|
|
self.assertEquals(self.theme.prefix(self.themedWidget), self.widgetPrefix)
|
2016-12-08 11:52:47 +01:00
|
|
|
|
2016-12-09 08:58:45 +01:00
|
|
|
def test_widget_fg(self):
|
2016-12-09 13:32:22 +01:00
|
|
|
self.assertEquals(self.theme.fg(self.anyWidget), self.defaultColor)
|
|
|
|
self.anyWidget.module = self.widgetTheme
|
|
|
|
self.assertEquals(self.theme.fg(self.anyWidget), self.widgetColor)
|
2016-12-09 08:58:45 +01:00
|
|
|
|
|
|
|
def test_widget_bg(self):
|
2016-12-09 13:32:22 +01:00
|
|
|
self.assertEquals(self.theme.bg(self.anyWidget), self.defaultBgColor)
|
|
|
|
self.anyWidget.module = self.widgetTheme
|
|
|
|
self.assertEquals(self.theme.bg(self.anyWidget), self.widgetBgColor)
|
2016-12-09 12:28:39 +01:00
|
|
|
|
2016-12-09 12:55:16 +01:00
|
|
|
def test_absent_cycle(self):
|
|
|
|
theme = self.theme
|
|
|
|
try:
|
|
|
|
theme.fg(self.anyWidget)
|
|
|
|
theme.fg(self.anotherWidget)
|
|
|
|
except Exception as e:
|
|
|
|
self.fail(e)
|
|
|
|
|
2016-12-09 12:28:39 +01:00
|
|
|
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"])
|
2016-12-09 08:58:45 +01:00
|
|
|
|
2016-12-09 12:55:16 +01:00
|
|
|
def test_separator_block_width(self):
|
|
|
|
theme = self.theme
|
|
|
|
data = theme.data()
|
|
|
|
|
2016-12-09 16:33:29 +01:00
|
|
|
self.assertEquals(theme.separator_block_width(self.anyWidget),
|
|
|
|
data["defaults"]["separator-block-width"]
|
|
|
|
)
|
2016-12-09 12:55:16 +01:00
|
|
|
|
|
|
|
def test_separator(self):
|
|
|
|
for theme in [self.theme, self.cycleTheme]:
|
|
|
|
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)
|
|
|
|
|
2016-12-09 13:32:22 +01:00
|
|
|
def test_state(self):
|
|
|
|
theme = self.theme
|
|
|
|
data = theme.data()
|
|
|
|
|
|
|
|
self.assertEquals(theme.fg(self.anyWidget), data["defaults"]["fg"])
|
|
|
|
self.assertEquals(theme.bg(self.anyWidget), data["defaults"]["bg"])
|
|
|
|
|
2016-12-10 11:25:02 +01:00
|
|
|
self.anyWidget.attr_state = ["critical"]
|
2016-12-09 13:32:22 +01:00
|
|
|
self.assertEquals(theme.fg(self.anyWidget), data["defaults"]["critical"]["fg"])
|
|
|
|
self.assertEquals(theme.bg(self.anyWidget), data["defaults"]["critical"]["bg"])
|
|
|
|
|
2016-12-10 11:25:02 +01:00
|
|
|
self.themedWidget.attr_state = ["critical"]
|
2016-12-09 13:32:22 +01:00
|
|
|
self.assertEquals(theme.fg(self.themedWidget), data[self.widgetTheme]["critical"]["fg"])
|
|
|
|
# if elements are missing in the state theme, they are taken from the
|
|
|
|
# widget theme instead (i.e. no fallback to a more general state theme)
|
|
|
|
self.assertEquals(theme.bg(self.themedWidget), data[self.widgetTheme]["bg"])
|
|
|
|
|
2016-12-04 18:10:04 +01:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|