Add group aliasing and colorscheme hierarchy tests

This commit is contained in:
ZyX 2014-07-12 14:22:23 +04:00
parent 3ebf9c1a81
commit f5735148e8
1 changed files with 137 additions and 1 deletions

View File

@ -56,14 +56,39 @@ config = {
'col2': 2,
'col3': 3,
'col4': 4,
'col5': 5,
'col6': 6,
'col7': 7,
'col8': 8,
'col9': 9,
'col10': 10,
'col11': 11,
'col12': 12,
},
'gradients': {
},
},
'colorschemes/test/__main__': {
'groups': {
'm1': 'g1',
'm2': 'g3',
'm3': {'fg': 'col11', 'bg': 'col12', 'attr': []},
}
},
'colorschemes/default': {
'groups': {
'g1': {'fg': 'col5', 'bg': 'col6', 'attr': []},
'g2': {'fg': 'col7', 'bg': 'col8', 'attr': []},
'g3': {'fg': 'col9', 'bg': 'col10', 'attr': []},
}
},
'colorschemes/test/default': {
'groups': {
'str1': {'fg': 'col1', 'bg': 'col2', 'attr': ['bold']},
'str2': {'fg': 'col3', 'bg': 'col4', 'attr': ['underline']},
'd1': 'g2',
'd2': 'm2',
'd3': 'm3',
},
},
'colorschemes/vim/default': {
@ -106,13 +131,15 @@ def add_p_arg(func):
return f
class TestLines(TestCase):
class TestRender(TestCase):
def assertRenderEqual(self, p, output, **kwargs):
self.assertEqual(p.render(**kwargs).replace(' ', ' '), output)
def assertRenderLinesEqual(self, p, output, **kwargs):
self.assertEqual([l.replace(' ', ' ') for l in p.render_above_lines(**kwargs)], output)
class TestLines(TestRender):
@add_p_arg
def test_without_above(self, p):
self.assertRenderEqual(p, '{121} s{24}>>{344}g{34}>{34}<{344}f {--}')
@ -144,6 +171,115 @@ class TestLines(TestCase):
], width=10)
class TestColorschemesHierarchy(TestRender):
@add_p_arg
def test_group_redirects(self, p):
with replace_item(globals(), 'config', deepcopy(config)):
config['themes/test/default']['segments'] = {
'left': [
highlighted_string('a', 'd1', draw_hard_divider=False),
highlighted_string('b', 'd2', draw_hard_divider=False),
highlighted_string('c', 'd3', draw_hard_divider=False),
highlighted_string('A', 'm1', draw_hard_divider=False),
highlighted_string('B', 'm2', draw_hard_divider=False),
highlighted_string('C', 'm3', draw_hard_divider=False),
highlighted_string('1', 'g1', draw_hard_divider=False),
highlighted_string('2', 'g2', draw_hard_divider=False),
highlighted_string('3', 'g3', draw_hard_divider=False),
],
'right': [],
}
self.assertRenderEqual(p, '{78} a{910}b{1112}c{56}A{910}B{1112}C{56}1{78}2{910}3{--}')
@add_p_arg
def test_group_redirects_no_main(self, p):
with replace_item(globals(), 'config', deepcopy(config)):
del config['colorschemes/test/__main__']
config['themes/test/default']['segments'] = {
'left': [
highlighted_string('a', 'd1', draw_hard_divider=False),
highlighted_string('1', 'g1', draw_hard_divider=False),
highlighted_string('2', 'g2', draw_hard_divider=False),
highlighted_string('3', 'g3', draw_hard_divider=False),
],
'right': [],
}
self.assertRenderEqual(p, '{78} a{56}1{78}2{910}3{--}')
@add_p_arg
def test_group_redirects_no_top_default(self, p):
with replace_item(globals(), 'config', deepcopy(config)):
del config['colorschemes/default']
config['themes/test/default']['segments'] = {
'left': [
highlighted_string('c', 'd3', draw_soft_divider=False),
highlighted_string('C', 'm3', draw_hard_divider=False),
],
'right': [],
}
self.assertRenderEqual(p, '{1112} c{1112}C{--}')
@add_p_arg
def test_group_redirects_no_test_default(self, p):
with replace_item(globals(), 'config', deepcopy(config)):
del config['colorschemes/test/default']
config['themes/test/default']['segments'] = {
'left': [
highlighted_string('A', 'm1', draw_hard_divider=False),
highlighted_string('B', 'm2', draw_hard_divider=False),
highlighted_string('C', 'm3', draw_hard_divider=False),
highlighted_string('1', 'g1', draw_hard_divider=False),
highlighted_string('2', 'g2', draw_hard_divider=False),
highlighted_string('3', 'g3', draw_hard_divider=False),
],
'right': [],
}
self.assertRenderEqual(p, '{56} A{910}B{1112}C{56}1{78}2{910}3{--}')
@add_p_arg
def test_group_redirects_only_main(self, p):
with replace_item(globals(), 'config', deepcopy(config)):
del config['colorschemes/default']
del config['colorschemes/test/default']
config['themes/test/default']['segments'] = {
'left': [
highlighted_string('C', 'm3', draw_hard_divider=False),
],
'right': [],
}
# Powerline is not able to work without default colorscheme
# somewhere, thus it will output error string
self.assertRenderEqual(p, 'colorschemes/test/default')
@add_p_arg
def test_group_redirects_only_top_default(self, p):
with replace_item(globals(), 'config', deepcopy(config)):
del config['colorschemes/test/__main__']
del config['colorschemes/test/default']
config['themes/test/default']['segments'] = {
'left': [
highlighted_string('1', 'g1', draw_hard_divider=False),
highlighted_string('2', 'g2', draw_hard_divider=False),
highlighted_string('3', 'g3', draw_hard_divider=False),
],
'right': [],
}
self.assertRenderEqual(p, '{56} 1{78}2{910}3{--}')
@add_p_arg
def test_group_redirects_only_test_default(self, p):
with replace_item(globals(), 'config', deepcopy(config)):
del config['colorschemes/default']
del config['colorschemes/test/__main__']
config['themes/test/default']['segments'] = {
'left': [
highlighted_string('s', 'str1', draw_hard_divider=False),
],
'right': [],
}
self.assertRenderEqual(p, '{121} s{--}')
class TestVim(TestCase):
def test_environ_update(self):
# Regression test: test that segment obtains environment from vim, not