Merge pull request #1004 from ZyX-I/fix-1003

Fix incorrect include/exclude_modes handling
This commit is contained in:
Nikolai Aleksandrovich Pavlov 2014-08-21 23:52:36 +04:00
commit 0ea1cd6f7b
3 changed files with 47 additions and 5 deletions

View File

@ -349,7 +349,7 @@ class Powerline(object):
shutdown_event=None, shutdown_event=None,
config_loader=None): config_loader=None):
'''Do actual initialization. '''Do actual initialization.
__init__ function only stores the arguments and runs this function. This __init__ function only stores the arguments and runs this function. This
function exists for powerline to be able to reload itself: it is easier function exists for powerline to be able to reload itself: it is easier
to make ``__init__`` store arguments and call overriddable ``init`` than to make ``__init__`` store arguments and call overriddable ``init`` than
@ -773,7 +773,6 @@ class Powerline(object):
Not guaranteed to work properly, use it at your own risk. It Not guaranteed to work properly, use it at your own risk. It
may break your python code. may break your python code.
''' '''
from imp import reload
import sys import sys
modules = self.imported_modules | set((module for module in sys.modules if module.startswith('powerline'))) modules = self.imported_modules | set((module for module in sys.modules if module.startswith('powerline')))
modules_holder = [] modules_holder = []

View File

@ -257,9 +257,9 @@ class Renderer(object):
segments = theme.get_segments(side, line, self.get_segment_info(segment_info, mode)) segments = theme.get_segments(side, line, self.get_segment_info(segment_info, mode))
# Handle excluded/included segments for the current mode # Handle excluded/included segments for the current mode
segments = [ segments = [
self._get_highlighting(segment, segment['mode'] or mode) self._get_highlighting(segment, segment_mode)
for segment, segment_mode in ( for segment, segment_mode in (
(segment, segment['mode']) (segment, segment['mode'] or mode)
for segment in segments for segment in segments
) if ( ) if (
segment_mode not in segment['exclude_modes'] segment_mode not in segment['exclude_modes']

View File

@ -384,6 +384,50 @@ class TestThemeHierarchy(TestRender):
]) ])
class TestModes(TestRender):
@add_args
def test_include_modes(self, p, config):
config['themes/test/default']['segments'] = {
'left': [
highlighted_string('s1', 'g1', include_modes=['m1']),
highlighted_string('s2', 'g1', include_modes=['m1', 'm2']),
highlighted_string('s3', 'g1', include_modes=['m3']),
]
}
self.assertRenderEqual(p, '{--}')
self.assertRenderEqual(p, '{56} s1{56}>{56}s2{6-}>>{--}', mode='m1')
self.assertRenderEqual(p, '{56} s2{6-}>>{--}', mode='m2')
self.assertRenderEqual(p, '{56} s3{6-}>>{--}', mode='m3')
@add_args
def test_exclude_modes(self, p, config):
config['themes/test/default']['segments'] = {
'left': [
highlighted_string('s1', 'g1', exclude_modes=['m1']),
highlighted_string('s2', 'g1', exclude_modes=['m1', 'm2']),
highlighted_string('s3', 'g1', exclude_modes=['m3']),
]
}
self.assertRenderEqual(p, '{56} s1{56}>{56}s2{56}>{56}s3{6-}>>{--}')
self.assertRenderEqual(p, '{56} s3{6-}>>{--}', mode='m1')
self.assertRenderEqual(p, '{56} s1{56}>{56}s3{6-}>>{--}', mode='m2')
self.assertRenderEqual(p, '{56} s1{56}>{56}s2{6-}>>{--}', mode='m3')
@add_args
def test_exinclude_modes(self, p, config):
config['themes/test/default']['segments'] = {
'left': [
highlighted_string('s1', 'g1', exclude_modes=['m1'], include_modes=['m2']),
highlighted_string('s2', 'g1', exclude_modes=['m1', 'm2'], include_modes=['m3']),
highlighted_string('s3', 'g1', exclude_modes=['m3'], include_modes=['m3']),
]
}
self.assertRenderEqual(p, '{--}')
self.assertRenderEqual(p, '{--}', mode='m1')
self.assertRenderEqual(p, '{56} s1{6-}>>{--}', mode='m2')
self.assertRenderEqual(p, '{56} s2{6-}>>{--}', mode='m3')
class TestVim(TestCase): class TestVim(TestCase):
def test_environ_update(self): def test_environ_update(self):
# Regression test: test that segment obtains environment from vim, not # Regression test: test that segment obtains environment from vim, not
@ -406,7 +450,6 @@ class TestVim(TestCase):
# Regression test: VimPowerline.add_local_theme did not work properly. # Regression test: VimPowerline.add_local_theme did not work properly.
from powerline.vim import VimPowerline from powerline.vim import VimPowerline
import powerline as powerline_module import powerline as powerline_module
import vim
with swap_attributes(config, powerline_module): with swap_attributes(config, powerline_module):
with get_powerline_raw(config, VimPowerline) as powerline: with get_powerline_raw(config, VimPowerline) as powerline:
powerline.add_local_theme('tests.matchers.always_true', { powerline.add_local_theme('tests.matchers.always_true', {