Add tests for various shell escapes variants

This commit is contained in:
ZyX 2014-12-06 16:53:00 +03:00
parent af9420b89f
commit 033422aff2
1 changed files with 108 additions and 0 deletions

View File

@ -39,6 +39,10 @@ config = {
'theme': 'default',
'colorscheme': 'default',
},
'shell': {
'theme': 'default',
'colorscheme': 'default',
},
},
},
'colors': {
@ -131,6 +135,14 @@ config = {
],
},
},
'themes/shell/default': {
'default_module': 'powerline.segments.common',
'segments': {
'left': [
highlighted_string('s', 'g1', width='auto'),
],
},
},
}
@ -639,6 +651,102 @@ class TestSegmentData(TestRender):
self.assertRenderEqual(p, '{56} 1S{56}>{56}3S{610}>>{910}3S{910}>{910}2S{10-}>>{--}')
class TestShellEscapes(TestCase):
@with_new_config
def test_escapes(self, config):
from powerline.shell import ShellPowerline
import powerline as powerline_module
with swap_attributes(config, powerline_module):
with get_powerline_raw(config, ShellPowerline, args=Args(config_path=[''])) as powerline:
self.assertEqual(powerline.render(segment_info={}, side='left'), '\x1b[0;38;5;5;48;5;6m\xa0s\x1b[0;38;5;6;49;22m>>\x1b[0m')
@with_new_config
def test_tmux_escapes(self, config):
from powerline.shell import ShellPowerline
import powerline as powerline_module
config['config']['common']['additional_escapes'] = 'tmux'
with swap_attributes(config, powerline_module):
with get_powerline_raw(config, ShellPowerline, args=Args(config_path=[''])) as powerline:
self.assertEqual(powerline.render(segment_info={}, side='left'), '\x1bPtmux;\x1b\x1b[0;38;5;5;48;5;6m\x1b\\\xa0s\x1bPtmux;\x1b\x1b[0;38;5;6;49;22m\x1b\\>>\x1bPtmux;\x1b\x1b[0m\x1b\\')
@with_new_config
def test_screen_escapes(self, config):
from powerline.shell import ShellPowerline
import powerline as powerline_module
config['config']['common']['additional_escapes'] = 'screen'
with swap_attributes(config, powerline_module):
with get_powerline_raw(config, ShellPowerline, args=Args(config_path=[''])) as powerline:
self.assertEqual(powerline.render(segment_info={}, side='left'), '\x1bP\x1b\x1b[0;38;5;5;48;5;6m\x1b\\\xa0s\x1bP\x1b\x1b[0;38;5;6;49;22m\x1b\\>>\x1bP\x1b\x1b[0m\x1b\\')
@with_new_config
def test_fbterm_escapes(self, config):
from powerline.shell import ShellPowerline
import powerline as powerline_module
config['config']['common']['term_escape_style'] = 'fbterm'
with swap_attributes(config, powerline_module):
with get_powerline_raw(config, ShellPowerline, args=Args(config_path=[''])) as powerline:
self.assertEqual(powerline.render(segment_info={}, side='left'), '\x1b[0m\x1b[1;5}\x1b[2;6}\xa0s\x1b[0m\x1b[1;6}\x1b[49m\x1b[22m>>\x1b[0m')
@with_new_config
def test_fbterm_tmux_escapes(self, config):
from powerline.shell import ShellPowerline
import powerline as powerline_module
config['config']['common']['term_escape_style'] = 'fbterm'
config['config']['common']['additional_escapes'] = 'tmux'
with swap_attributes(config, powerline_module):
with get_powerline_raw(config, ShellPowerline, args=Args(config_path=[''])) as powerline:
self.assertEqual(powerline.render(segment_info={}, side='left'), '\x1bPtmux;\x1b\x1b[0m\x1b\x1b[1;5}\x1b\x1b[2;6}\x1b\\\xa0s\x1bPtmux;\x1b\x1b[0m\x1b\x1b[1;6}\x1b\x1b[49m\x1b\x1b[22m\x1b\\>>\x1bPtmux;\x1b\x1b[0m\x1b\\')
@with_new_config
def test_fbterm_screen_escapes(self, config):
from powerline.shell import ShellPowerline
import powerline as powerline_module
config['config']['common']['term_escape_style'] = 'fbterm'
config['config']['common']['additional_escapes'] = 'screen'
with swap_attributes(config, powerline_module):
with get_powerline_raw(config, ShellPowerline, args=Args(config_path=[''])) as powerline:
self.assertEqual(powerline.render(segment_info={}, side='left'), '\x1bP\x1b\x1b[0m\x1b\x1b[1;5}\x1b\x1b[2;6}\x1b\\\xa0s\x1bP\x1b\x1b[0m\x1b\x1b[1;6}\x1b\x1b[49m\x1b\x1b[22m\x1b\\>>\x1bP\x1b\x1b[0m\x1b\\')
@with_new_config
def test_term_truecolor_escapes(self, config):
from powerline.shell import ShellPowerline
import powerline as powerline_module
config['config']['common']['term_truecolor'] = True
with swap_attributes(config, powerline_module):
with get_powerline_raw(config, ShellPowerline, args=Args(config_path=[''])) as powerline:
self.assertEqual(powerline.render(segment_info={}, side='left'), '\x1b[0;38;2;192;0;192;48;2;0;128;128m\xa0s\x1b[0;38;2;0;128;128;49;22m>>\x1b[0m')
@with_new_config
def test_term_truecolor_fbterm_escapes(self, config):
from powerline.shell import ShellPowerline
import powerline as powerline_module
config['config']['common']['term_escape_style'] = 'fbterm'
config['config']['common']['term_truecolor'] = True
with swap_attributes(config, powerline_module):
with get_powerline_raw(config, ShellPowerline, args=Args(config_path=[''])) as powerline:
self.assertEqual(powerline.render(segment_info={}, side='left'), '\x1b[0m\x1b[1;5}\x1b[2;6}\xa0s\x1b[0m\x1b[1;6}\x1b[49m\x1b[22m>>\x1b[0m')
@with_new_config
def test_term_truecolor_tmux_escapes(self, config):
from powerline.shell import ShellPowerline
import powerline as powerline_module
config['config']['common']['term_truecolor'] = True
config['config']['common']['additional_escapes'] = 'tmux'
with swap_attributes(config, powerline_module):
with get_powerline_raw(config, ShellPowerline, args=Args(config_path=[''])) as powerline:
self.assertEqual(powerline.render(segment_info={}, side='left'), '\x1bPtmux;\x1b\x1b[0;38;2;192;0;192;48;2;0;128;128m\x1b\\\xa0s\x1bPtmux;\x1b\x1b[0;38;2;0;128;128;49;22m\x1b\\>>\x1bPtmux;\x1b\x1b[0m\x1b\\')
@with_new_config
def test_term_truecolor_screen_escapes(self, config):
from powerline.shell import ShellPowerline
import powerline as powerline_module
config['config']['common']['term_truecolor'] = True
config['config']['common']['additional_escapes'] = 'screen'
with swap_attributes(config, powerline_module):
with get_powerline_raw(config, ShellPowerline, args=Args(config_path=[''])) as powerline:
self.assertEqual(powerline.render(segment_info={}, side='left'), '\x1bP\x1b\x1b[0;38;2;192;0;192;48;2;0;128;128m\x1b\\\xa0s\x1bP\x1b\x1b[0;38;2;0;128;128;49;22m\x1b\\>>\x1bP\x1b\x1b[0m\x1b\\')
class TestVim(TestCase):
def test_environ_update(self):
# Regression test: test that segment obtains environment from vim, not