2020-02-15 14:05:27 +01:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
import core.theme
|
2020-02-22 13:42:44 +01:00
|
|
|
import core.event
|
2020-02-15 14:05:27 +01:00
|
|
|
|
|
|
|
class theme(unittest.TestCase):
|
|
|
|
def setUp(self):
|
2020-02-22 13:42:44 +01:00
|
|
|
core.event.clear()
|
2020-02-15 14:05:27 +01:00
|
|
|
self.invalidThemeName = 'this-theme-does-not-exist'
|
|
|
|
self.validThemeName = 'default'
|
2020-02-16 14:02:21 +01:00
|
|
|
self.defaultsTheme = {
|
2020-02-15 14:05:27 +01:00
|
|
|
'defaults': {
|
|
|
|
'fg': 'red', 'bg': 'black'
|
|
|
|
}
|
|
|
|
}
|
2020-02-16 14:02:21 +01:00
|
|
|
self.cycleTheme = {
|
|
|
|
'cycle': [
|
|
|
|
{ 'fg': 'red', 'bg': 'black' },
|
2020-02-16 14:39:10 +01:00
|
|
|
{ 'fg': 'black', 'bg': 'red' },
|
|
|
|
{ 'fg': 'white', 'bg': 'blue' }
|
2020-02-16 14:02:21 +01:00
|
|
|
]
|
|
|
|
}
|
2020-02-15 14:05:27 +01:00
|
|
|
|
|
|
|
def test_invalid_theme(self):
|
|
|
|
with self.assertRaises(RuntimeError):
|
|
|
|
core.theme.Theme(self.invalidThemeName)
|
|
|
|
|
|
|
|
def test_valid_theme(self):
|
|
|
|
theme = core.theme.Theme(self.validThemeName)
|
|
|
|
self.assertEqual(self.validThemeName, theme.name)
|
|
|
|
|
|
|
|
def test_defaults(self):
|
2020-02-16 14:02:21 +01:00
|
|
|
theme = core.theme.Theme(raw_data=self.defaultsTheme)
|
|
|
|
self.assertEqual(self.defaultsTheme['defaults']['fg'], theme.fg())
|
|
|
|
self.assertEqual(self.defaultsTheme['defaults']['bg'], theme.bg())
|
|
|
|
|
|
|
|
def test_cycle(self):
|
|
|
|
theme = core.theme.Theme(raw_data=self.cycleTheme)
|
2020-02-22 13:42:44 +01:00
|
|
|
self.assertEqual(None, theme.prev_bg(None))
|
2020-02-16 14:02:21 +01:00
|
|
|
self.assertEqual(self.cycleTheme['cycle'][0]['fg'], theme.fg())
|
|
|
|
self.assertEqual(self.cycleTheme['cycle'][0]['bg'], theme.bg())
|
2020-02-16 14:39:10 +01:00
|
|
|
core.event.trigger('next-widget')
|
2020-02-22 13:42:44 +01:00
|
|
|
self.assertEqual(self.cycleTheme['cycle'][0]['bg'], theme.prev_bg(None))
|
2020-02-16 14:39:10 +01:00
|
|
|
core.event.trigger('next-widget')
|
|
|
|
self.assertEqual(self.cycleTheme['cycle'][2]['fg'], theme.fg())
|
|
|
|
self.assertEqual(self.cycleTheme['cycle'][2]['bg'], theme.bg())
|
2020-02-22 13:42:44 +01:00
|
|
|
|
|
|
|
with unittest.mock.patch('core.output.sys.stdout'):
|
|
|
|
core.event.trigger('update')
|
|
|
|
self.assertEqual(self.cycleTheme['cycle'][0]['fg'], theme.fg())
|
|
|
|
self.assertEqual(self.cycleTheme['cycle'][0]['bg'], theme.bg())
|
2020-02-15 14:05:27 +01:00
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|