[core/theme] State == "" causes backtraces

Empty states ("" rather than None) caused a backtrace in the theme
engine. Fix that by being a bit more robust, and add a test that checks
for regressions.

fixes #406
This commit is contained in:
Tobias Witek 2019-07-02 20:19:26 +02:00
parent 7ab15f33f0
commit 682d2f47dd
2 changed files with 10 additions and 1 deletions

View file

@ -241,7 +241,8 @@ class Theme(object):
states = widget.state() states = widget.state()
if name not in states: if name not in states:
for state in states: for state in states:
state_themes.append(self._get(widget, state, {})) if state:
state_themes.append(self._get(widget, state, {}))
value = self._defaults.get(name, default) value = self._defaults.get(name, default)
value = widget.get("theme.{}".format(name), value) value = widget.get("theme.{}".format(name), value)

View file

@ -118,6 +118,14 @@ class TestTheme(unittest.TestCase):
# widget theme instead (i.e. no fallback to a more general state theme) # widget theme instead (i.e. no fallback to a more general state theme)
self.assertEquals(theme.bg(self.themedWidget), data[self.widgetTheme]["bg"]) self.assertEquals(theme.bg(self.themedWidget), data[self.widgetTheme]["bg"])
def test_empty_state(self):
theme = self.theme
data = theme.data()
self.anyModule.state.return_value = ""
self.assertEquals(theme.fg(self.anyWidget), data["defaults"]["fg"])
self.assertEquals(theme.bg(self.anyWidget), data["defaults"]["bg"])
def test_separator(self): def test_separator(self):
self.assertEquals(self.validThemeSeparator, self.theme.separator(self.anyWidget)) self.assertEquals(self.validThemeSeparator, self.theme.separator(self.anyWidget))