diff --git a/core/theme.py b/core/theme.py index 63ca433..5b5efff 100644 --- a/core/theme.py +++ b/core/theme.py @@ -26,7 +26,6 @@ class Theme(object): for icons in self.__data.get('icons', []): util.algorithm.merge(self.__data, self.load(icons, 'icons')) if iconset != 'auto': - print("merging iconset") util.algorithm.merge(self.__data, self.load(iconset, 'icons')) for colors in self.__data.get('colors', []): util.algorithm.merge(self.__keywords, self.load_keywords(colors)) @@ -52,11 +51,7 @@ class Theme(object): return self.__keywords def load(self, name, subdir=''): - if isinstance(name, dict): - print("returning name") - return name # support plain data - else: - print("not returning name") + if isinstance(name, dict): return name # support plain data for path in PATHS: theme_file = os.path.join(path, subdir, '{}.json'.format(name)) if os.path.isfile(theme_file): @@ -69,7 +64,7 @@ class Theme(object): with io.open(os.path.expanduser(filename)) as data: colors = json.load(data) for field in sections: - for key in colors[field]: + for key in colors.get(field, []): result[key] = colors[field][key] return result diff --git a/tests/core/test_theme.py b/tests/core/test_theme.py index c362549..ebc4323 100644 --- a/tests/core/test_theme.py +++ b/tests/core/test_theme.py @@ -25,6 +25,9 @@ class theme(unittest.TestCase): 'red': '#ff0000', 'blue': '#0000ff' }] } + self.walTheme = { + 'colors': ['wal'] + } def test_invalid_theme(self): with self.assertRaises(RuntimeError): @@ -69,4 +72,22 @@ class theme(unittest.TestCase): theme = core.theme.Theme(raw_data=self.colorTheme) self.assertEqual(self.colorTheme['colors'][0], theme.keywords()) + def test_wal_colors(self): + with unittest.mock.patch('core.theme.io') as io: + io.open.return_value.__enter__.return_value.read.return_value=''' + { "colors": { "red": "#ff0000" } } + ''' + + theme = core.theme.Theme(raw_data=self.walTheme) + self.assertEqual({'red': '#ff0000'}, theme.keywords()) + + def test_wal_special(self): + with unittest.mock.patch('core.theme.io') as io: + io.open.return_value.__enter__.return_value.read.return_value=''' + { "special": { "background": "#ff0000" } } + ''' + + theme = core.theme.Theme(raw_data=self.walTheme) + self.assertEqual({'background': '#ff0000'}, theme.keywords()) + # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4