Fix python tests by abstracting away default theme name

This commit is contained in:
Foo 2016-10-29 15:58:53 +03:00
parent 23f663f228
commit 19f9885825
5 changed files with 51 additions and 37 deletions

View File

@ -298,6 +298,18 @@ def create_logger(common_config, use_daemon_threads=True, ext='__unknown__',
return logger, pl, get_module_attr
def get_default_theme(is_unicode=True):
'''Get default theme used by powerline
:param bool is_unicode:
If true, return theme for unicode environments, otherwise return theme
that is supposed to be ASCII-only.
:return: theme name.
'''
return 'powerline_terminus' if is_unicode else 'ascii'
def finish_common_config(encoding, common_config):
'''Add default values to common config and expand ~ in paths
@ -309,10 +321,8 @@ def finish_common_config(encoding, common_config):
paths.
'''
encoding = encoding.lower()
if encoding.startswith('utf') or encoding.startswith('ucs'):
default_top_theme = 'powerline_terminus'
else:
default_top_theme = 'ascii'
default_top_theme = get_default_theme(
encoding.startswith('utf') or encoding.startswith('ucs'))
common_config = common_config.copy()
common_config.setdefault('default_top_theme', default_top_theme)

View File

@ -10,11 +10,15 @@ from functools import wraps
from powerline.renderer import Renderer
from powerline.lib.config import ConfigLoader
from powerline import Powerline
from powerline import Powerline, get_default_theme
from tests.lib import Args, replace_attr
UT = get_default_theme(is_unicode=True)
AT = get_default_theme(is_unicode=False)
class TestHelpers(object):
def __init__(self, config):
self.config = config

View File

@ -12,7 +12,7 @@ from powerline.lib.dict import mergedicts_copy as mdc
from powerline import Powerline
from tests import TestCase
from tests.lib.config_mock import select_renderer
from tests.lib.config_mock import select_renderer, UT
CONFIG_DIR = 'tests/config'
@ -88,7 +88,7 @@ main_tree = lambda: {
'1/colors': colors_config(),
'1/colorschemes/default': colorscheme_config(),
'1/themes/test/default': theme_config(),
'1/themes/powerline': top_theme_config(),
'1/themes/' + UT: top_theme_config(),
'1/themes/other1': mdc(top_theme_config(), {
'dividers': {
'left': {
@ -193,10 +193,10 @@ class TestMerging(TestCase):
def test_top_theme_merging(self):
with WithConfigTree(mdc(main_tree(), {
'2/themes/powerline': {
'2/themes/' + UT: {
'spaces': 1,
},
'3/themes/powerline': {
'3/themes/' + UT: {
'dividers': {
'left': {
'hard': '>>',

View File

@ -6,7 +6,7 @@ from copy import deepcopy
from functools import wraps
from tests import TestCase
from tests.lib.config_mock import get_powerline, add_watcher_events
from tests.lib.config_mock import get_powerline, add_watcher_events, UT
config = {
@ -62,7 +62,7 @@ config = {
],
},
},
'themes/powerline': {
'themes/' + UT: {
'dividers': {
"left": {
"hard": ">>",
@ -131,7 +131,7 @@ class TestConfigReload(TestCase):
def test_noreload(self, config):
with get_powerline(config, run_once=True) 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(p, 'config', 'colors', 'check:colorschemes/default', 'check:colorschemes/test/__main__', 'colorschemes/test/default', 'themes/test/default', 'themes/powerline', 'check:themes/test/__main__')
self.assertAccessEvents(p, 'config', 'colors', 'check:colorschemes/default', 'check:colorschemes/test/__main__', 'colorschemes/test/default', 'themes/test/default', 'themes/' + UT, 'check:themes/test/__main__')
config['config']['common']['spaces'] = 1
add_watcher_events(p, 'config', wait=False, interval=0.05)
# When running once thread should not start
@ -143,7 +143,7 @@ class TestConfigReload(TestCase):
def test_reload_main(self, config):
with get_powerline(config, 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(p, 'config', 'colors', 'check:colorschemes/default', 'check:colorschemes/test/__main__', 'colorschemes/test/default', 'themes/test/default', 'themes/powerline', 'check:themes/test/__main__')
self.assertAccessEvents(p, 'config', 'colors', 'check:colorschemes/default', 'check:colorschemes/test/__main__', 'colorschemes/test/default', 'themes/test/default', 'themes/' + UT, 'check:themes/test/__main__')
config['config']['common']['default_top_theme'] = 'other'
add_watcher_events(p, 'config')
@ -205,7 +205,7 @@ class TestConfigReload(TestCase):
def test_reload_unexistent(self, config):
with get_powerline(config, 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(p, 'config', 'colors', 'check:colorschemes/default', 'check:colorschemes/test/__main__', 'colorschemes/test/default', 'themes/test/default', 'themes/powerline', 'check:themes/test/__main__')
self.assertAccessEvents(p, 'config', 'colors', 'check:colorschemes/default', 'check:colorschemes/test/__main__', 'colorschemes/test/default', 'themes/test/default', 'themes/' + UT, 'check:themes/test/__main__')
config['config']['ext']['test']['colorscheme'] = 'nonexistentraise'
add_watcher_events(p, 'config')
@ -242,7 +242,7 @@ class TestConfigReload(TestCase):
def test_reload_colors(self, config):
with get_powerline(config, 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(p, 'config', 'colors', 'check:colorschemes/default', 'check:colorschemes/test/__main__', 'colorschemes/test/default', 'themes/test/default', 'themes/powerline', 'check:themes/test/__main__')
self.assertAccessEvents(p, 'config', 'colors', 'check:colorschemes/default', 'check:colorschemes/test/__main__', 'colorschemes/test/default', 'themes/test/default', 'themes/' + UT, 'check:themes/test/__main__')
config['colors']['colors']['col1'] = 5
add_watcher_events(p, 'colors')
@ -254,7 +254,7 @@ class TestConfigReload(TestCase):
def test_reload_colorscheme(self, config):
with get_powerline(config, 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(p, 'config', 'colors', 'check:colorschemes/default', 'check:colorschemes/test/__main__', 'colorschemes/test/default', 'themes/test/default', 'themes/powerline', 'check:themes/test/__main__')
self.assertAccessEvents(p, 'config', 'colors', 'check:colorschemes/default', 'check:colorschemes/test/__main__', 'colorschemes/test/default', 'themes/test/default', 'themes/' + UT, 'check:themes/test/__main__')
config['colorschemes/test/default']['groups']['str1']['bg'] = 'col3'
add_watcher_events(p, 'colorschemes/test/default')
@ -266,24 +266,24 @@ class TestConfigReload(TestCase):
def test_reload_theme(self, config):
with get_powerline(config, 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(p, 'config', 'colors', 'check:colorschemes/default', 'check:colorschemes/test/__main__', 'colorschemes/test/default', 'themes/test/default', 'themes/powerline', 'check:themes/test/__main__')
self.assertAccessEvents(p, 'config', 'colors', 'check:colorschemes/default', 'check:colorschemes/test/__main__', 'colorschemes/test/default', 'themes/test/default', 'themes/' + UT, 'check:themes/test/__main__')
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>')
self.assertAccessEvents(p, 'themes/test/default', 'themes/powerline', 'check:themes/test/__main__')
self.assertAccessEvents(p, 'themes/test/default', 'themes/' + UT, 'check:themes/test/__main__')
self.assertEqual(p.logger._pop_msgs(), [])
@with_new_config
def test_reload_top_theme(self, config):
with get_powerline(config, 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(p, 'config', 'colors', 'check:colorschemes/default', 'check:colorschemes/test/__main__', 'colorschemes/test/default', 'themes/test/default', 'themes/powerline', 'check:themes/test/__main__')
self.assertAccessEvents(p, 'config', 'colors', 'check:colorschemes/default', 'check:colorschemes/test/__main__', 'colorschemes/test/default', 'themes/test/default', 'themes/' + UT, 'check:themes/test/__main__')
config['themes/powerline']['dividers']['left']['hard'] = '|>'
add_watcher_events(p, 'themes/powerline')
config['themes/' + UT]['dividers']['left']['hard'] = '|>'
add_watcher_events(p, 'themes/' + UT)
self.assertEqual(p.render(), '<1 2 1> s<2 4 False>|><3 4 4>g<4 False False>|><None None None>')
self.assertAccessEvents(p, 'themes/test/default', 'themes/powerline', 'check:themes/test/__main__')
self.assertAccessEvents(p, 'themes/test/default', 'themes/' + UT, 'check:themes/test/__main__')
self.assertEqual(p.logger._pop_msgs(), [])
@with_new_config
@ -291,12 +291,12 @@ class TestConfigReload(TestCase):
config['config']['common']['interval'] = None
with get_powerline(config, 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(p, 'config', 'colors', 'check:colorschemes/default', 'check:colorschemes/test/__main__', 'colorschemes/test/default', 'themes/test/default', 'themes/powerline', 'check:themes/test/__main__')
self.assertAccessEvents(p, 'config', 'colors', 'check:colorschemes/default', 'check:colorschemes/test/__main__', 'colorschemes/test/default', 'themes/test/default', 'themes/' + UT, 'check:themes/test/__main__')
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(p, 'themes/test/default', 'themes/powerline', 'check:themes/test/__main__')
self.assertAccessEvents(p, 'themes/test/default', 'themes/' + UT, 'check:themes/test/__main__')
self.assertEqual(p.logger._pop_msgs(), [])
self.assertTrue(p._watcher._calls)
@ -305,7 +305,7 @@ class TestConfigReload(TestCase):
config['config']['common']['interval'] = None
with get_powerline(config, run_once=True) 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(p, 'config', 'colors', 'check:colorschemes/default', 'check:colorschemes/test/__main__', 'colorschemes/test/default', 'themes/test/default', 'themes/powerline', 'check:themes/test/__main__')
self.assertAccessEvents(p, 'config', 'colors', 'check:colorschemes/default', 'check:colorschemes/test/__main__', 'colorschemes/test/default', 'themes/test/default', 'themes/' + UT, 'check:themes/test/__main__')
config['themes/test/default']['segments']['left'][0]['contents'] = 'col3'
add_watcher_events(p, 'themes/test/default', wait=False)

View File

@ -10,7 +10,7 @@ from copy import deepcopy
import tests.vim as vim_module
from tests import TestCase
from tests.lib.config_mock import get_powerline, get_powerline_raw, swap_attributes
from tests.lib.config_mock import get_powerline, get_powerline_raw, swap_attributes, UT
from tests.lib import Args, replace_item
@ -114,7 +114,7 @@ config = {
],
},
},
'themes/powerline': {
'themes/' + UT: {
'dividers': {
'left': {
'hard': '>>',
@ -362,9 +362,9 @@ class TestThemeHierarchy(TestRender):
@add_args
def test_no_powerline(self, p, config):
config['themes/test/__main__']['dividers'] = config['themes/powerline']['dividers']
config['themes/test/__main__']['dividers'] = config['themes/' + UT]['dividers']
config['themes/test/__main__']['spaces'] = 1
del config['themes/powerline']
del config['themes/' + UT]
self.assertRenderEqual(p, '{121} s {24}>>{344}g {34}>{34}<{344} f {--}')
self.assertEqual(p.logger._pop_msgs(), [])
@ -380,19 +380,19 @@ class TestThemeHierarchy(TestRender):
@add_args
def test_only_default(self, p, config):
config['themes/test/default']['dividers'] = config['themes/powerline']['dividers']
config['themes/test/default']['dividers'] = config['themes/' + UT]['dividers']
config['themes/test/default']['spaces'] = 1
del config['themes/test/__main__']
del config['themes/powerline']
del config['themes/' + UT]
self.assertRenderEqual(p, '{121} s {24}>>{344}g {34}>{34}<{344} f {--}')
@add_args
def test_only_main(self, p, config):
del config['themes/test/default']
del config['themes/powerline']
del config['themes/' + UT]
self.assertRenderEqual(p, 'themes/test/default')
self.assertEqual(p.logger._pop_msgs(), [
'exception:test:powerline:Failed to load theme: themes/powerline',
'exception:test:powerline:Failed to load theme: themes/' + UT,
'exception:test:powerline:Failed to load theme: themes/test/default',
'exception:test:powerline:Failed to create renderer: themes/test/default',
'exception:test:powerline:Failed to render: themes/test/default',
@ -413,11 +413,11 @@ class TestThemeHierarchy(TestRender):
@add_args
def test_nothing(self, p, config):
del config['themes/test/default']
del config['themes/powerline']
del config['themes/' + UT]
del config['themes/test/__main__']
self.assertRenderEqual(p, 'themes/test/default')
self.assertEqual(p.logger._pop_msgs(), [
'exception:test:powerline:Failed to load theme: themes/powerline',
'exception:test:powerline:Failed to load theme: themes/' + UT,
'exception:test:powerline:Failed to load theme: themes/test/__main__',
'exception:test:powerline:Failed to load theme: themes/test/default',
'exception:test:powerline:Failed to create renderer: themes/test/default',
@ -570,7 +570,7 @@ class TestSegmentAttributes(TestRender):
def m1(divider=',', **kwargs):
return divider.join(kwargs.keys()) + divider
m1.powerline_segment_datas = {
'powerline': {
UT: {
'args': {
'divider': ';'
}
@ -640,7 +640,7 @@ class TestSegmentData(TestRender):
def m2(**kwargs):
return 'S'
sys.modules['bar'] = Args(m1=m1, m2=m2)
config['themes/powerline']['segment_data'] = {
config['themes/' + UT]['segment_data'] = {
'm1': {
'before': '1'
},