[core/theme] Add some unit tests
This commit is contained in:
parent
d5820160dc
commit
5ade8e47f0
2 changed files with 35 additions and 10 deletions
|
@ -22,13 +22,11 @@ class Theme(object):
|
||||||
self.__previous = {}
|
self.__previous = {}
|
||||||
self.__current = {}
|
self.__current = {}
|
||||||
self.__keywords = {}
|
self.__keywords = {}
|
||||||
if raw_data:
|
self.__data = raw_data if raw_data else self.load(name)
|
||||||
self.__data = raw_data
|
for icons in self.__data.get('icons', []):
|
||||||
else:
|
|
||||||
self.__data = self.load(name)
|
|
||||||
for icons in self.__data['icons']:
|
|
||||||
util.algorithm.merge(self.__data, self.load(icons, 'icons'))
|
util.algorithm.merge(self.__data, self.load(icons, 'icons'))
|
||||||
if iconset != 'auto':
|
if iconset != 'auto':
|
||||||
|
print("merging iconset")
|
||||||
util.algorithm.merge(self.__data, self.load(iconset, 'icons'))
|
util.algorithm.merge(self.__data, self.load(iconset, 'icons'))
|
||||||
for colors in self.__data.get('colors', []):
|
for colors in self.__data.get('colors', []):
|
||||||
util.algorithm.merge(self.__keywords, self.load_keywords(colors))
|
util.algorithm.merge(self.__keywords, self.load_keywords(colors))
|
||||||
|
@ -50,7 +48,15 @@ class Theme(object):
|
||||||
]:
|
]:
|
||||||
setattr(self, attr.replace('-', '_'), lambda widget=None, default=default, attr=attr: self.__get(widget, attr, default))
|
setattr(self, attr.replace('-', '_'), lambda widget=None, default=default, attr=attr: self.__get(widget, attr, default))
|
||||||
|
|
||||||
|
def keywords(self):
|
||||||
|
return self.__keywords
|
||||||
|
|
||||||
def load(self, name, subdir=''):
|
def load(self, name, subdir=''):
|
||||||
|
if isinstance(name, dict):
|
||||||
|
print("returning name")
|
||||||
|
return name # support plain data
|
||||||
|
else:
|
||||||
|
print("not returning name")
|
||||||
for path in PATHS:
|
for path in PATHS:
|
||||||
theme_file = os.path.join(path, subdir, '{}.json'.format(name))
|
theme_file = os.path.join(path, subdir, '{}.json'.format(name))
|
||||||
if os.path.isfile(theme_file):
|
if os.path.isfile(theme_file):
|
||||||
|
|
|
@ -20,6 +20,11 @@ class theme(unittest.TestCase):
|
||||||
{ 'fg': 'white', 'bg': 'blue' }
|
{ 'fg': 'white', 'bg': 'blue' }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
self.colorTheme = {
|
||||||
|
'colors': [{
|
||||||
|
'red': '#ff0000', 'blue': '#0000ff'
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
|
||||||
def test_invalid_theme(self):
|
def test_invalid_theme(self):
|
||||||
with self.assertRaises(RuntimeError):
|
with self.assertRaises(RuntimeError):
|
||||||
|
@ -50,4 +55,18 @@ class theme(unittest.TestCase):
|
||||||
self.assertEqual(self.cycleTheme['cycle'][0]['fg'], theme.fg())
|
self.assertEqual(self.cycleTheme['cycle'][0]['fg'], theme.fg())
|
||||||
self.assertEqual(self.cycleTheme['cycle'][0]['bg'], theme.bg())
|
self.assertEqual(self.cycleTheme['cycle'][0]['bg'], theme.bg())
|
||||||
|
|
||||||
|
def test_custom_iconset(self):
|
||||||
|
theme = core.theme.Theme(raw_data=self.defaultsTheme)
|
||||||
|
self.assertNotEqual('aaa', theme.padding())
|
||||||
|
theme = core.theme.Theme(raw_data=self.defaultsTheme, iconset={
|
||||||
|
'defaults': { 'padding': 'aaa' }
|
||||||
|
})
|
||||||
|
self.assertEqual('aaa', theme.padding())
|
||||||
|
|
||||||
|
def test_colors(self):
|
||||||
|
theme = core.theme.Theme(raw_data=self.defaultsTheme)
|
||||||
|
self.assertEqual({}, theme.keywords())
|
||||||
|
theme = core.theme.Theme(raw_data=self.colorTheme)
|
||||||
|
self.assertEqual(self.colorTheme['colors'][0], theme.keywords())
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue