Unfinished attempt to adapt tests to new code
This commit is contained in:
parent
9060e2b4cf
commit
ebd122d4ac
|
@ -19,36 +19,45 @@ class TestConfig(TestCase):
|
|||
def test_vim(self):
|
||||
from powerline.vim import VimPowerline
|
||||
cfg_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'powerline', 'config_files')
|
||||
buffers = ((('bufoptions',), {'buftype': 'help'}), (('buffer', '[Command Line]'), {}), (('bufoptions',), {'buftype': 'quickfix'}))
|
||||
buffers = ((('bufoptions',), {'buftype': 'help'}), (('bufname', '[Command Line]'), {}), (('bufoptions',), {'buftype': 'quickfix'}))
|
||||
with open(os.path.join(cfg_path, 'config.json'), 'r') as f:
|
||||
self.assertEqual(len(buffers), len(json.load(f)['ext']['vim']['local_themes']))
|
||||
outputs = {}
|
||||
i = 0
|
||||
mode = None
|
||||
args = None
|
||||
kwargs = None
|
||||
|
||||
with VimPowerline() as powerline:
|
||||
def check_output(*args):
|
||||
out = powerline.render(*args + (0 if mode == 'nc' else 1,))
|
||||
if out in outputs:
|
||||
self.fail('Duplicate in set #{0} for mode {1!r} (previously defined in set #{2} for mode {3!r})'.format(i, mode, *outputs[out]))
|
||||
outputs[out] = (i, mode)
|
||||
with vim_module._with('split'):
|
||||
with VimPowerline() as powerline:
|
||||
def check_output(mode):
|
||||
if mode == 'nc':
|
||||
window = vim_module.windows[0]
|
||||
window_id = 2
|
||||
else:
|
||||
vim_module._start_mode(mode)
|
||||
window = vim_module.current.window
|
||||
window_id = 1
|
||||
winnr = window.number
|
||||
out = powerline.render(window, window_id, winnr)
|
||||
if out in outputs:
|
||||
self.fail('Duplicate in set #{0} ({1}) for mode {2!r} (previously defined in set #{3} ({4!r}) for mode {5!r})'.format(i, (args, kwargs), mode, *outputs[out]))
|
||||
outputs[out] = (i, (args, kwargs), mode)
|
||||
|
||||
with vim_module._with('buffer', 'foo.txt'):
|
||||
with vim_module._with('globals', powerline_config_path=cfg_path):
|
||||
exclude = set(('no', 'v', 'V', VBLOCK, 's', 'S', SBLOCK, 'R', 'Rv', 'c', 'cv', 'ce', 'r', 'rm', 'r?', '!'))
|
||||
try:
|
||||
for mode in ['n', 'nc', 'no', 'v', 'V', VBLOCK, 's', 'S', SBLOCK, 'i', 'R', 'Rv', 'c', 'cv', 'ce', 'r', 'rm', 'r?', '!']:
|
||||
if mode != 'nc':
|
||||
vim_module._start_mode(mode)
|
||||
check_output(1, 0)
|
||||
for args, kwargs in buffers:
|
||||
i += 1
|
||||
if mode in exclude:
|
||||
continue
|
||||
with vim_module._with(*args, **kwargs):
|
||||
check_output(1, 0)
|
||||
finally:
|
||||
vim_module._start_mode('n')
|
||||
with vim_module._with('bufname', 'foo.txt'):
|
||||
with vim_module._with('globals', powerline_config_path=cfg_path):
|
||||
exclude = set(('no', 'v', 'V', VBLOCK, 's', 'S', SBLOCK, 'R', 'Rv', 'c', 'cv', 'ce', 'r', 'rm', 'r?', '!'))
|
||||
try:
|
||||
for mode in ['n', 'nc', 'no', 'v', 'V', VBLOCK, 's', 'S', SBLOCK, 'i', 'R', 'Rv', 'c', 'cv', 'ce', 'r', 'rm', 'r?', '!']:
|
||||
check_output(mode)
|
||||
for args, kwargs in buffers:
|
||||
i += 1
|
||||
if mode in exclude:
|
||||
continue
|
||||
with vim_module._with(*args, **kwargs):
|
||||
check_output(mode)
|
||||
finally:
|
||||
vim_module._start_mode('n')
|
||||
|
||||
def test_tmux(self):
|
||||
from powerline.segments import common
|
||||
|
|
38
tests/vim.py
38
tests/vim.py
|
@ -284,6 +284,7 @@ class _Window(object):
|
|||
global _window_id
|
||||
self.cursor = cursor
|
||||
self.width = width
|
||||
self.number = len(windows) + 1
|
||||
if buffer:
|
||||
if type(buffer) is _Buffer:
|
||||
self.buffer = buffer
|
||||
|
@ -371,6 +372,10 @@ class _Current(object):
|
|||
def buffer(self):
|
||||
return buffers[_buffer()]
|
||||
|
||||
@property
|
||||
def window(self):
|
||||
return windows[_window - 1]
|
||||
|
||||
|
||||
current = _Current()
|
||||
|
||||
|
@ -453,6 +458,13 @@ def _new(name=None):
|
|||
_window = len(windows)
|
||||
|
||||
|
||||
@_vim
|
||||
def _split():
|
||||
global _window
|
||||
_Window(buffer=buffers[_buffer()])
|
||||
_window = len(windows)
|
||||
|
||||
|
||||
@_vim
|
||||
def _del_window(winnr):
|
||||
win = windows.pop(winnr - 1)
|
||||
|
@ -587,10 +599,34 @@ class _WithDict(object):
|
|||
self.d.pop(k)
|
||||
|
||||
|
||||
class _WithSplit(object):
|
||||
def __enter__(self):
|
||||
_split()
|
||||
|
||||
def __exit__(self, *args):
|
||||
_close(2, wipe=False)
|
||||
|
||||
|
||||
class _WithBufName(object):
|
||||
def __init__(self, new):
|
||||
self.new = new
|
||||
|
||||
def __enter__(self):
|
||||
buffer = buffers[_buffer()]
|
||||
self.buffer = buffer
|
||||
self.old = buffer.name
|
||||
buffer.name = self.new
|
||||
|
||||
def __exit__(self, *args):
|
||||
self.buffer.name = self.old
|
||||
|
||||
|
||||
@_vim
|
||||
def _with(key, *args, **kwargs):
|
||||
if key == 'buffer':
|
||||
return _WithNewBuffer(_edit, *args, **kwargs)
|
||||
elif key == 'bufname':
|
||||
return _WithBufName(*args, **kwargs)
|
||||
elif key == 'mode':
|
||||
return _WithMode(*args, **kwargs)
|
||||
elif key == 'bufoptions':
|
||||
|
@ -599,3 +635,5 @@ def _with(key, *args, **kwargs):
|
|||
return _WithDict(_options, **kwargs)
|
||||
elif key == 'globals':
|
||||
return _WithDict(_g, **kwargs)
|
||||
elif key == 'split':
|
||||
return _WithSplit()
|
||||
|
|
Loading…
Reference in New Issue