From 1afab26cecfe369f0d56a2b77dad0a2b4b7c1657 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 12 Aug 2014 20:48:49 +0400 Subject: [PATCH] Test that VimPowerline.add_local_theme works --- powerline/vim.py | 3 ++- tests/matchers.py | 7 +++++++ tests/test_configuration.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 tests/matchers.py diff --git a/powerline/vim.py b/powerline/vim.py index 29afa9b9..df009856 100644 --- a/powerline/vim.py +++ b/powerline/vim.py @@ -78,10 +78,11 @@ class VimPowerline(Powerline): 'powerline_theme_overrides__' + name) def get_local_themes(self, local_themes): + self.get_matcher = gen_matcher_getter(self.ext, self.import_paths) + if not local_themes: return {} - self.get_matcher = gen_matcher_getter(self.ext, self.import_paths) return dict(((None if key == '__tabline__' else self.get_matcher(key), {'config': self.load_theme_config(val)}) for key, val in local_themes.items())) diff --git a/tests/matchers.py b/tests/matchers.py new file mode 100644 index 00000000..3937f2f1 --- /dev/null +++ b/tests/matchers.py @@ -0,0 +1,7 @@ +# vim:fileencoding=utf-8:noet + +from __future__ import (unicode_literals, division, absolute_import, print_function) + + +def always_true(matcher_info): + return True diff --git a/tests/test_configuration.py b/tests/test_configuration.py index 6a64ce36..ec05dab4 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -402,6 +402,34 @@ class TestVim(TestCase): vim_module._environ['TEST'] = 'def' self.assertEqual(powerline.render(window, window_id, winnr), '%#Pl_3_8404992_4_192_underline#\xa0def%#Pl_4_192_NONE_None_NONE#>>') + def test_local_themes(self): + # Regression test: VimPowerline.add_local_theme did not work properly. + from powerline.vim import VimPowerline + import powerline as powerline_module + import vim + with swap_attributes(config, powerline_module): + with get_powerline_raw(config, VimPowerline) as powerline: + powerline.add_local_theme('tests.matchers.always_true', { + 'segment_data': { + 'foo': { + 'contents': '“bar”' + } + }, + 'segments': { + 'left': [ + { + 'type': 'string', + 'name': 'foo', + 'highlight_group': ['g1'] + } + ] + } + }) + window = vim_module.current.window + window_id = 1 + winnr = window.number + self.assertEqual(powerline.render(window, window_id, winnr), '%#Pl_5_12583104_6_32896_NONE#\xa0\u201cbar\u201d%#Pl_6_32896_NONE_None_NONE#>>') + def setUpModule(): sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), 'path')))