[theme] Add unit tests for WAL loading
This commit is contained in:
parent
18ea6d36d1
commit
2a93a001b2
2 changed files with 23 additions and 7 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue