[core/output] Add tests for pango formatting

This commit is contained in:
tobi-wan-kenobi 2020-04-07 20:59:26 +02:00
parent 2b8eda9d72
commit 32e5d633f4
2 changed files with 50 additions and 3 deletions

View file

@ -52,7 +52,7 @@ class block(object):
text = attr.get('full_text', '') text = attr.get('full_text', '')
if 'full_text' in attr: if 'full_text' in attr:
del attr['full_text'] del attr['full_text']
result = '<span ' result = '<span'
for key, value in attr.items(): for key, value in attr.items():
result = '{} {}="{}"'.format(result, key, value) result = '{} {}="{}"'.format(result, key, value)
result = '{}>{}</span>'.format(result, text) result = '{}>{}</span>'.format(result, text)

View file

@ -17,11 +17,16 @@ class i3(unittest.TestCase):
widgets=[widget, widget, widget]) widgets=[widget, widget, widget])
self.paddedTheme = core.theme.Theme(raw_data = { self.paddedTheme = core.theme.Theme(raw_data = {
'defaults': { 'padding': ' ' } 'defaults': { 'padding': ' ' }
}); })
self.separator = '***'; self.separator = '***';
self.separatorTheme = core.theme.Theme(raw_data = { self.separatorTheme = core.theme.Theme(raw_data = {
'defaults': { 'separator': self.separator, 'fg': 'red', 'bg': 'blue' } 'defaults': { 'separator': self.separator, 'fg': 'red', 'bg': 'blue' }
}); })
self.someBlock = core.output.block(
theme=self.separatorTheme,
module=self.someModule,
widget=self.someModule.widget()
)
def test_start(self): def test_start(self):
core.event.clear() core.event.clear()
@ -89,4 +94,46 @@ class i3(unittest.TestCase):
core.output.dump_json(obj) core.output.dump_json(obj)
obj.dict_assert_called_once_with() obj.dict_assert_called_once_with()
def test_assign(self):
src = {
'a': 'x', 'b': 'y', 'c': 'z'
}
dst = {}
core.output.assign(src, dst, 'a')
self.assertEqual(dst['a'], src['a'])
core.output.assign(src, dst, '123', 'b')
self.assertEqual(dst['123'], src['b'])
core.output.assign(src, dst, 'blub', default='def')
self.assertEqual('def', dst['blub'])
def test_pango_detection(self):
self.assertFalse(self.someBlock.is_pango({}))
self.assertTrue(self.someBlock.is_pango({ 'pango': {} }))
def test_pangoize(self):
self.assertEqual('test', self.someBlock.pangoize('test'))
self.assertFalse('markup' in self.someBlock.dict())
self.assertEqual('<span attr="blub" x="y">test</span>',
self.someBlock.pangoize({ 'pango': { 'attr': 'blub', 'x': 'y', 'full_text': 'test' } })
)
self.assertEqual('pango', self.someBlock.dict()['markup'])
def test_padding(self):
self.someBlock.set('padding', '***')
self.someBlock.set('full_text', 'test')
self.assertEqual('***test***', self.someBlock.dict()['full_text'])
def test_pre_suffix(self):
self.someBlock.set('padding', '*')
self.someBlock.set('prefix', 'pre')
self.someBlock.set('suffix', 'suf')
self.someBlock.set('full_text', 'test')
self.assertEqual('*pre*test*suf*', self.someBlock.dict()['full_text'])
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4