From 682d2f47dd231628346684a77af0bd59dcff1868 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Tue, 2 Jul 2019 20:19:26 +0200 Subject: [PATCH] [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 --- bumblebee/theme.py | 3 ++- tests/test_theme.py | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/bumblebee/theme.py b/bumblebee/theme.py index 946da59..7e6a8c5 100644 --- a/bumblebee/theme.py +++ b/bumblebee/theme.py @@ -241,7 +241,8 @@ class Theme(object): states = widget.state() if name not 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 = widget.get("theme.{}".format(name), value) diff --git a/tests/test_theme.py b/tests/test_theme.py index 747d749..ebfe055 100644 --- a/tests/test_theme.py +++ b/tests/test_theme.py @@ -118,6 +118,14 @@ class TestTheme(unittest.TestCase): # widget theme instead (i.e. no fallback to a more general state theme) 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): self.assertEquals(self.validThemeSeparator, self.theme.separator(self.anyWidget))