diff --git a/core/output.py b/core/output.py index 556d0c4..4b19260 100644 --- a/core/output.py +++ b/core/output.py @@ -34,7 +34,7 @@ class block(object): self.__attributes['name'] = module.id self.__attributes['instance'] = widget.id - self.__attributes['prev-bg'] = theme.get('bg', 'previous') + self.__attributes['prev-bg'] = theme.get('prev-bg') def set(self, key, value): self.__attributes[key] = value diff --git a/core/theme.py b/core/theme.py index c7d39b4..e32c70a 100644 --- a/core/theme.py +++ b/core/theme.py @@ -45,21 +45,6 @@ class Theme(object): core.event.register('update', self.__start) core.event.register('next-widget', self.__next_widget) - for attr, default in [ - ('fg', None), ('bg', None), - ('default-separators', True), - ('separator-block-width', 0), - ('separator', None), - ('border-top', 0), - ('border-bottom', 0), - ('border-left', 0), - ('border-right', 0), - ('padding', ''), - ('prefix', ''), ('suffix', ''), - ('pango', None), - ]: - setattr(self, attr.replace('-', '_'), lambda widget=None, default=default, attr=attr: self.__get(widget, attr, default)) - def keywords(self): return self.__keywords @@ -101,9 +86,6 @@ class Theme(object): self.__current.clear() def get(self, key, widget=None, default=None): - return self.__get(widget, key, default) - - def __get(self, widget, key, default=None): if not widget: widget = core.widget.Widget('') if isinstance(widget, str): @@ -126,11 +108,11 @@ class Theme(object): value = merge_replace(value, self.__data.get(key, value), key) if widget.module(): - value = merge_replace(value, self.__get(None, widget.module().name(), {}).get(key, value), key) + value = merge_replace(value, self.get(widget.module().name(), None, {}).get(key, value), key) if not key in widget.state(): for state in widget.state(): - theme = self.__get(widget, state, {}) + theme = self.get(state, widget, {}) value = merge_replace(value, theme.get(key, value), key) if not type(value) in (list, dict): diff --git a/tests/core/test_output.py b/tests/core/test_output.py index c400315..ea1750f 100644 --- a/tests/core/test_output.py +++ b/tests/core/test_output.py @@ -81,6 +81,12 @@ class i3(unittest.TestCase): self.assertEqual(1, len(result)) self.assertEqual('***', result[0].dict()['full_text']) self.assertTrue(result[0].dict().get('_decorator', False)) - self.assertEqual(self.separatorTheme.bg(self.someModule.widget()), result[0].dict()['color']) + self.assertEqual(self.separatorTheme.get('bg', self.someModule.widget()), result[0].dict()['color']) + + def test_dump_json(self): + obj = unittest.mock.MagicMock() + obj.dict = unittest.mock.MagicMock() + core.output.dump_json(obj) + obj.dict_assert_called_once_with() # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/tests/core/test_theme.py b/tests/core/test_theme.py index 891a6b3..324d892 100644 --- a/tests/core/test_theme.py +++ b/tests/core/test_theme.py @@ -50,32 +50,32 @@ class theme(unittest.TestCase): def test_defaults(self): theme = core.theme.Theme(raw_data=self.defaultsTheme) - self.assertEqual(self.defaultsTheme['defaults']['fg'], theme.fg()) - self.assertEqual(self.defaultsTheme['defaults']['bg'], theme.bg()) + self.assertEqual(self.defaultsTheme['defaults']['fg'], theme.get('fg')) + self.assertEqual(self.defaultsTheme['defaults']['bg'], theme.get('bg')) def test_cycle(self): theme = core.theme.Theme(raw_data=self.cycleTheme) - self.assertEqual(None, theme.bg('previous')) - self.assertEqual(self.cycleTheme['cycle'][0]['fg'], theme.fg()) - self.assertEqual(self.cycleTheme['cycle'][0]['bg'], theme.bg()) + self.assertEqual(None, theme.get('prev-bg')) + self.assertEqual(self.cycleTheme['cycle'][0]['fg'], theme.get('fg')) + self.assertEqual(self.cycleTheme['cycle'][0]['bg'], theme.get('bg')) core.event.trigger('next-widget') - self.assertEqual(self.cycleTheme['cycle'][0]['bg'], theme.bg('previous')) + self.assertEqual(self.cycleTheme['cycle'][0]['bg'], theme.get('bg', 'previous')) core.event.trigger('next-widget') - self.assertEqual(self.cycleTheme['cycle'][2]['fg'], theme.fg()) - self.assertEqual(self.cycleTheme['cycle'][2]['bg'], theme.bg()) + self.assertEqual(self.cycleTheme['cycle'][2]['fg'], theme.get('fg')) + self.assertEqual(self.cycleTheme['cycle'][2]['bg'], theme.get('bg')) with unittest.mock.patch('core.output.sys.stdout'): core.event.trigger('update') - self.assertEqual(self.cycleTheme['cycle'][0]['fg'], theme.fg()) - self.assertEqual(self.cycleTheme['cycle'][0]['bg'], theme.bg()) + self.assertEqual(self.cycleTheme['cycle'][0]['fg'], theme.get('fg')) + self.assertEqual(self.cycleTheme['cycle'][0]['bg'], theme.get('bg')) def test_custom_iconset(self): theme = core.theme.Theme(raw_data=self.defaultsTheme) - self.assertNotEqual('aaa', theme.padding()) + self.assertNotEqual('aaa', theme.get('padding')) theme = core.theme.Theme(raw_data=self.defaultsTheme, iconset={ 'defaults': { 'padding': 'aaa' } }) - self.assertEqual('aaa', theme.padding()) + self.assertEqual('aaa', theme.get('padding')) def test_colors(self): theme = core.theme.Theme(raw_data=self.defaultsTheme) @@ -107,18 +107,18 @@ class theme(unittest.TestCase): theme = core.theme.Theme(raw_data=self.cycleValueTheme) for i in range(0, len(expected)*3): - self.assertEqual(expected[i%len(expected)], theme.fg(widget)) + self.assertEqual(expected[i%len(expected)], theme.get('fg', widget)) def test_state(self): widget = core.widget.Widget() theme = core.theme.Theme(raw_data=self.stateTheme) - self.assertEqual(None, theme.fg(widget)) + self.assertEqual(None, theme.get('fg', widget)) widget.state = types.MethodType(lambda self: ['warning'], widget) - self.assertEqual(self.stateTheme['warning']['fg'], theme.fg(widget)) + self.assertEqual(self.stateTheme['warning']['fg'], theme.get('fg', widget)) widget.state = types.MethodType(lambda self: ['critical'], widget) - self.assertEqual(self.stateTheme['critical']['fg'], theme.fg(widget)) + self.assertEqual(self.stateTheme['critical']['fg'], theme.get('fg', widget)) # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4