2013-03-30 21:06:49 +01:00
|
|
|
|
# vim:fileencoding=utf-8:noet
|
2013-03-31 11:37:07 +02:00
|
|
|
|
from __future__ import unicode_literals
|
2013-03-30 21:06:49 +01:00
|
|
|
|
import powerline as powerline_module
|
|
|
|
|
import time
|
|
|
|
|
from tests import TestCase
|
|
|
|
|
from tests.lib import replace_item
|
2013-04-03 04:33:56 +02:00
|
|
|
|
from tests.lib.config_mock import swap_attributes, get_powerline, pop_events
|
2013-03-30 21:06:49 +01:00
|
|
|
|
from copy import deepcopy
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config = {
|
|
|
|
|
'config': {
|
|
|
|
|
'common': {
|
|
|
|
|
'dividers': {
|
2013-03-31 11:37:07 +02:00
|
|
|
|
"left": {
|
|
|
|
|
"hard": ">>",
|
|
|
|
|
"soft": ">",
|
|
|
|
|
},
|
|
|
|
|
"right": {
|
|
|
|
|
"hard": "<<",
|
|
|
|
|
"soft": "<",
|
|
|
|
|
},
|
2013-03-30 21:06:49 +01:00
|
|
|
|
},
|
|
|
|
|
'spaces': 0,
|
2013-04-04 20:57:14 +02:00
|
|
|
|
'interval': 0,
|
2013-03-30 21:06:49 +01:00
|
|
|
|
},
|
|
|
|
|
'ext': {
|
|
|
|
|
'test': {
|
|
|
|
|
'theme': 'default',
|
|
|
|
|
'colorscheme': 'default',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
'colors': {
|
|
|
|
|
'colors': {
|
2013-03-31 11:37:07 +02:00
|
|
|
|
"col1": 1,
|
|
|
|
|
"col2": 2,
|
|
|
|
|
"col3": 3,
|
|
|
|
|
"col4": 4,
|
2013-03-30 21:06:49 +01:00
|
|
|
|
},
|
|
|
|
|
'gradients': {
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
'colorschemes/test/default': {
|
|
|
|
|
'groups': {
|
2013-03-31 11:37:07 +02:00
|
|
|
|
"str1": {"fg": "col1", "bg": "col2", "attr": ["bold"]},
|
|
|
|
|
"str2": {"fg": "col3", "bg": "col4", "attr": ["underline"]},
|
2013-03-30 21:06:49 +01:00
|
|
|
|
},
|
|
|
|
|
},
|
2013-03-31 12:53:21 +02:00
|
|
|
|
'colorschemes/test/2': {
|
|
|
|
|
'groups': {
|
|
|
|
|
"str1": {"fg": "col2", "bg": "col3", "attr": ["bold"]},
|
|
|
|
|
"str2": {"fg": "col1", "bg": "col4", "attr": ["underline"]},
|
|
|
|
|
},
|
|
|
|
|
},
|
2013-03-30 21:06:49 +01:00
|
|
|
|
'themes/test/default': {
|
|
|
|
|
'segments': {
|
2013-03-31 11:37:07 +02:00
|
|
|
|
"left": [
|
|
|
|
|
{
|
|
|
|
|
"type": "string",
|
|
|
|
|
"contents": "s",
|
|
|
|
|
"highlight_group": ["str1"],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "string",
|
|
|
|
|
"contents": "g",
|
|
|
|
|
"highlight_group": ["str2"],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
"right": [
|
|
|
|
|
],
|
2013-03-30 21:06:49 +01:00
|
|
|
|
},
|
|
|
|
|
},
|
2013-03-31 12:53:21 +02:00
|
|
|
|
'themes/test/2': {
|
|
|
|
|
'segments': {
|
|
|
|
|
"left": [
|
|
|
|
|
{
|
|
|
|
|
"type": "string",
|
|
|
|
|
"contents": "t",
|
|
|
|
|
"highlight_group": ["str1"],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "string",
|
|
|
|
|
"contents": "b",
|
|
|
|
|
"highlight_group": ["str2"],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
"right": [
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
},
|
2013-03-30 21:06:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-03-31 11:37:07 +02:00
|
|
|
|
def sleep(interval):
|
2013-03-30 21:06:49 +01:00
|
|
|
|
time.sleep(interval)
|
|
|
|
|
|
|
|
|
|
|
2013-03-31 11:37:07 +02:00
|
|
|
|
def add_watcher_events(p, *args, **kwargs):
|
2013-04-04 20:57:14 +02:00
|
|
|
|
p.config_loader.watcher._reset(args)
|
2013-04-03 04:33:56 +02:00
|
|
|
|
while not p._will_create_renderer():
|
2013-03-31 11:37:07 +02:00
|
|
|
|
sleep(kwargs.get('interval', 0.000001))
|
|
|
|
|
if not kwargs.get('wait', True):
|
|
|
|
|
return
|
2013-03-30 21:06:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestConfigReload(TestCase):
|
|
|
|
|
def assertAccessEvents(self, *args):
|
2013-04-03 04:33:56 +02:00
|
|
|
|
self.assertEqual(set(pop_events()), set(args))
|
2013-03-30 21:06:49 +01:00
|
|
|
|
|
|
|
|
|
def test_noreload(self):
|
|
|
|
|
with get_powerline(run_once=True) as p:
|
|
|
|
|
with replace_item(globals(), 'config', deepcopy(config)):
|
2013-03-31 11:37:07 +02:00
|
|
|
|
self.assertEqual(p.render(), '<1 2 1> s<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
|
2013-04-03 04:33:56 +02:00
|
|
|
|
self.assertAccessEvents('config', 'colors', 'colorschemes/test/default', 'themes/test/default')
|
2013-03-30 21:06:49 +01:00
|
|
|
|
config['config']['common']['spaces'] = 1
|
2013-03-31 11:37:07 +02:00
|
|
|
|
add_watcher_events(p, 'config', wait=False, interval=0.05)
|
2013-03-30 21:06:49 +01:00
|
|
|
|
# When running once thread should not start
|
2013-03-31 11:37:07 +02:00
|
|
|
|
self.assertEqual(p.render(), '<1 2 1> s<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
|
2013-04-03 04:33:56 +02:00
|
|
|
|
self.assertAccessEvents()
|
2013-03-30 21:06:49 +01:00
|
|
|
|
self.assertEqual(p.logger._pop_msgs(), [])
|
2013-04-02 17:23:12 +02:00
|
|
|
|
# Without the following assertion test_reload_colors may fail for
|
|
|
|
|
# unknown reason (with AssertionError telling about “config” accessed
|
|
|
|
|
# one more time then needed)
|
2013-04-03 04:33:56 +02:00
|
|
|
|
pop_events()
|
2013-03-30 21:06:49 +01:00
|
|
|
|
|
|
|
|
|
def test_reload_main(self):
|
|
|
|
|
with get_powerline(run_once=False) as p:
|
|
|
|
|
with replace_item(globals(), 'config', deepcopy(config)):
|
2013-03-31 11:37:07 +02:00
|
|
|
|
self.assertEqual(p.render(), '<1 2 1> s<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
|
2013-04-06 14:32:38 +02:00
|
|
|
|
self.assertAccessEvents('config', 'colors', 'colorschemes/test/default', 'themes/test/default')
|
2013-03-30 21:06:49 +01:00
|
|
|
|
|
|
|
|
|
config['config']['common']['spaces'] = 1
|
2013-03-31 11:37:07 +02:00
|
|
|
|
add_watcher_events(p, 'config')
|
|
|
|
|
self.assertEqual(p.render(), '<1 2 1> s <2 4 False>>><3 4 4>g <4 False False>>><None None None>')
|
2013-04-03 04:33:56 +02:00
|
|
|
|
self.assertAccessEvents('config')
|
2013-03-30 21:06:49 +01:00
|
|
|
|
self.assertEqual(p.logger._pop_msgs(), [])
|
|
|
|
|
|
2013-03-31 12:53:21 +02:00
|
|
|
|
config['config']['ext']['test']['theme'] = 'nonexistent'
|
2013-03-31 11:37:07 +02:00
|
|
|
|
add_watcher_events(p, 'config')
|
|
|
|
|
self.assertEqual(p.render(), '<1 2 1> s <2 4 False>>><3 4 4>g <4 False False>>><None None None>')
|
2013-04-03 04:33:56 +02:00
|
|
|
|
self.assertAccessEvents('config', 'themes/test/nonexistent')
|
2013-03-30 21:06:49 +01:00
|
|
|
|
# It should normally handle file missing error
|
2013-04-03 04:33:56 +02:00
|
|
|
|
self.assertEqual(p.logger._pop_msgs(), ['exception:test:Failed to create renderer: themes/test/nonexistent'])
|
2013-03-30 21:06:49 +01:00
|
|
|
|
|
|
|
|
|
config['config']['ext']['test']['theme'] = 'default'
|
2013-03-31 11:37:07 +02:00
|
|
|
|
add_watcher_events(p, 'config')
|
|
|
|
|
self.assertEqual(p.render(), '<1 2 1> s <2 4 False>>><3 4 4>g <4 False False>>><None None None>')
|
2013-04-03 04:33:56 +02:00
|
|
|
|
self.assertAccessEvents('config', 'themes/test/default')
|
2013-03-30 21:06:49 +01:00
|
|
|
|
self.assertEqual(p.logger._pop_msgs(), [])
|
|
|
|
|
|
2013-03-31 12:53:21 +02:00
|
|
|
|
config['config']['ext']['test']['colorscheme'] = 'nonexistent'
|
2013-03-31 11:37:07 +02:00
|
|
|
|
add_watcher_events(p, 'config')
|
|
|
|
|
self.assertEqual(p.render(), '<1 2 1> s <2 4 False>>><3 4 4>g <4 False False>>><None None None>')
|
2013-04-03 04:33:56 +02:00
|
|
|
|
self.assertAccessEvents('config', 'colorschemes/test/nonexistent')
|
2013-03-30 21:06:49 +01:00
|
|
|
|
# It should normally handle file missing error
|
2013-04-03 04:33:56 +02:00
|
|
|
|
self.assertEqual(p.logger._pop_msgs(), ['exception:test:Failed to create renderer: colorschemes/test/nonexistent'])
|
2013-03-30 21:06:49 +01:00
|
|
|
|
|
2013-03-31 12:53:21 +02:00
|
|
|
|
config['config']['ext']['test']['colorscheme'] = '2'
|
2013-03-31 11:37:07 +02:00
|
|
|
|
add_watcher_events(p, 'config')
|
2013-03-31 12:53:21 +02:00
|
|
|
|
self.assertEqual(p.render(), '<2 3 1> s <3 4 False>>><1 4 4>g <4 False False>>><None None None>')
|
2013-04-03 04:33:56 +02:00
|
|
|
|
self.assertAccessEvents('config', 'colorschemes/test/2')
|
2013-03-31 12:53:21 +02:00
|
|
|
|
self.assertEqual(p.logger._pop_msgs(), [])
|
|
|
|
|
|
|
|
|
|
config['config']['ext']['test']['theme'] = '2'
|
|
|
|
|
add_watcher_events(p, 'config')
|
|
|
|
|
self.assertEqual(p.render(), '<2 3 1> t <3 4 False>>><1 4 4>b <4 False False>>><None None None>')
|
2013-04-03 04:33:56 +02:00
|
|
|
|
self.assertAccessEvents('config', 'themes/test/2')
|
2013-03-30 21:06:49 +01:00
|
|
|
|
self.assertEqual(p.logger._pop_msgs(), [])
|
|
|
|
|
|
|
|
|
|
self.assertEqual(p.renderer.local_themes, None)
|
|
|
|
|
config['config']['ext']['test']['local_themes'] = 'something'
|
2013-03-31 11:37:07 +02:00
|
|
|
|
add_watcher_events(p, 'config')
|
2013-03-31 12:53:21 +02:00
|
|
|
|
self.assertEqual(p.render(), '<2 3 1> t <3 4 False>>><1 4 4>b <4 False False>>><None None None>')
|
2013-04-03 04:33:56 +02:00
|
|
|
|
self.assertAccessEvents('config')
|
2013-03-30 21:06:49 +01:00
|
|
|
|
self.assertEqual(p.logger._pop_msgs(), [])
|
|
|
|
|
self.assertEqual(p.renderer.local_themes, 'something')
|
2013-04-03 04:33:56 +02:00
|
|
|
|
pop_events()
|
2013-03-30 21:06:49 +01:00
|
|
|
|
|
2013-04-01 22:27:54 +02:00
|
|
|
|
def test_reload_unexistent(self):
|
|
|
|
|
with get_powerline(run_once=False) as p:
|
|
|
|
|
with replace_item(globals(), 'config', deepcopy(config)):
|
|
|
|
|
self.assertEqual(p.render(), '<1 2 1> s<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
|
2013-04-03 04:33:56 +02:00
|
|
|
|
self.assertAccessEvents('config', 'colors', 'colorschemes/test/default', 'themes/test/default')
|
2013-04-01 22:27:54 +02:00
|
|
|
|
|
|
|
|
|
config['config']['ext']['test']['colorscheme'] = 'nonexistentraise'
|
|
|
|
|
add_watcher_events(p, 'config')
|
|
|
|
|
self.assertEqual(p.render(), '<1 2 1> s<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
|
2013-04-03 04:33:56 +02:00
|
|
|
|
self.assertAccessEvents('config')
|
2013-04-04 20:57:14 +02:00
|
|
|
|
self.assertIn('exception:test:Failed to create renderer: fcf:colorschemes/test/nonexistentraise', p.logger._pop_msgs())
|
2013-04-01 22:27:54 +02:00
|
|
|
|
|
|
|
|
|
config['colorschemes/test/nonexistentraise'] = {
|
|
|
|
|
'groups': {
|
|
|
|
|
"str1": {"fg": "col1", "bg": "col3", "attr": ["bold"]},
|
|
|
|
|
"str2": {"fg": "col2", "bg": "col4", "attr": ["underline"]},
|
|
|
|
|
},
|
|
|
|
|
}
|
2013-04-03 04:33:56 +02:00
|
|
|
|
while not p._will_create_renderer():
|
2013-04-01 22:27:54 +02:00
|
|
|
|
sleep(0.000001)
|
|
|
|
|
self.assertEqual(p.render(), '<1 3 1> s<3 4 False>>><2 4 4>g<4 False False>>><None None None>')
|
2013-04-03 04:33:56 +02:00
|
|
|
|
self.assertAccessEvents('colorschemes/test/nonexistentraise')
|
2013-04-01 22:27:54 +02:00
|
|
|
|
self.assertEqual(p.logger._pop_msgs(), [])
|
2013-04-03 04:33:56 +02:00
|
|
|
|
pop_events()
|
2013-04-01 22:27:54 +02:00
|
|
|
|
|
2013-03-31 11:37:07 +02:00
|
|
|
|
def test_reload_colors(self):
|
|
|
|
|
with get_powerline(run_once=False) as p:
|
|
|
|
|
with replace_item(globals(), 'config', deepcopy(config)):
|
|
|
|
|
self.assertEqual(p.render(), '<1 2 1> s<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
|
2013-04-03 04:33:56 +02:00
|
|
|
|
self.assertAccessEvents('config', 'colors', 'colorschemes/test/default', 'themes/test/default')
|
2013-03-31 11:37:07 +02:00
|
|
|
|
|
|
|
|
|
config['colors']['colors']['col1'] = 5
|
|
|
|
|
add_watcher_events(p, 'colors')
|
|
|
|
|
self.assertEqual(p.render(), '<5 2 1> s<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
|
2013-04-03 04:33:56 +02:00
|
|
|
|
self.assertAccessEvents('colors')
|
2013-04-01 22:27:54 +02:00
|
|
|
|
self.assertEqual(p.logger._pop_msgs(), [])
|
2013-04-03 04:33:56 +02:00
|
|
|
|
pop_events()
|
2013-03-31 11:37:07 +02:00
|
|
|
|
|
2013-03-31 12:57:43 +02:00
|
|
|
|
def test_reload_colorscheme(self):
|
|
|
|
|
with get_powerline(run_once=False) as p:
|
|
|
|
|
with replace_item(globals(), 'config', deepcopy(config)):
|
|
|
|
|
self.assertEqual(p.render(), '<1 2 1> s<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
|
2013-04-03 04:33:56 +02:00
|
|
|
|
self.assertAccessEvents('config', 'colors', 'colorschemes/test/default', 'themes/test/default')
|
2013-03-31 12:57:43 +02:00
|
|
|
|
|
|
|
|
|
config['colorschemes/test/default']['groups']['str1']['bg'] = 'col3'
|
|
|
|
|
add_watcher_events(p, 'colorschemes/test/default')
|
|
|
|
|
self.assertEqual(p.render(), '<1 3 1> s<3 4 False>>><3 4 4>g<4 False False>>><None None None>')
|
2013-04-03 04:33:56 +02:00
|
|
|
|
self.assertAccessEvents('colorschemes/test/default')
|
2013-04-01 22:27:54 +02:00
|
|
|
|
self.assertEqual(p.logger._pop_msgs(), [])
|
2013-04-03 04:33:56 +02:00
|
|
|
|
pop_events()
|
2013-03-31 12:57:43 +02:00
|
|
|
|
|
|
|
|
|
def test_reload_theme(self):
|
|
|
|
|
with get_powerline(run_once=False) as p:
|
|
|
|
|
with replace_item(globals(), 'config', deepcopy(config)):
|
|
|
|
|
self.assertEqual(p.render(), '<1 2 1> s<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
|
2013-04-03 04:33:56 +02:00
|
|
|
|
self.assertAccessEvents('config', 'colors', 'colorschemes/test/default', 'themes/test/default')
|
2013-03-31 12:57:43 +02:00
|
|
|
|
|
|
|
|
|
config['themes/test/default']['segments']['left'][0]['contents'] = 'col3'
|
|
|
|
|
add_watcher_events(p, 'themes/test/default')
|
|
|
|
|
self.assertEqual(p.render(), '<1 2 1> col3<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
|
2013-04-03 04:33:56 +02:00
|
|
|
|
self.assertAccessEvents('themes/test/default')
|
2013-04-01 22:27:54 +02:00
|
|
|
|
self.assertEqual(p.logger._pop_msgs(), [])
|
2013-04-03 04:33:56 +02:00
|
|
|
|
pop_events()
|
2013-03-31 12:57:43 +02:00
|
|
|
|
|
2013-04-06 16:09:45 +02:00
|
|
|
|
def test_reload_theme_main(self):
|
|
|
|
|
with replace_item(globals(), 'config', deepcopy(config)):
|
|
|
|
|
config['config']['common']['interval'] = None
|
|
|
|
|
with get_powerline(run_once=False) as p:
|
|
|
|
|
self.assertEqual(p.render(), '<1 2 1> s<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
|
|
|
|
|
self.assertAccessEvents('config', 'colors', 'colorschemes/test/default', 'themes/test/default')
|
|
|
|
|
|
|
|
|
|
config['themes/test/default']['segments']['left'][0]['contents'] = 'col3'
|
|
|
|
|
add_watcher_events(p, 'themes/test/default', wait=False)
|
|
|
|
|
self.assertEqual(p.render(), '<1 2 1> col3<2 4 False>>><3 4 4>g<4 False False>>><None None None>')
|
|
|
|
|
self.assertAccessEvents('themes/test/default')
|
|
|
|
|
self.assertEqual(p.logger._pop_msgs(), [])
|
|
|
|
|
pop_events()
|
|
|
|
|
|
2013-03-30 21:06:49 +01:00
|
|
|
|
|
2013-04-03 04:33:56 +02:00
|
|
|
|
replaces = {}
|
2013-03-30 21:06:49 +01:00
|
|
|
|
|
|
|
|
|
|
2013-04-03 04:33:56 +02:00
|
|
|
|
def setUpModule():
|
2013-03-30 21:06:49 +01:00
|
|
|
|
global replaces
|
2013-04-03 04:33:56 +02:00
|
|
|
|
replaces = swap_attributes(globals(), powerline_module, replaces)
|
2013-03-30 21:06:49 +01:00
|
|
|
|
|
|
|
|
|
|
2013-04-03 04:33:56 +02:00
|
|
|
|
tearDownModule = setUpModule
|
2013-03-30 21:06:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
from tests import main
|
|
|
|
|
main()
|