mirror of
https://github.com/powerline/powerline.git
synced 2025-07-30 09:15:19 +02:00
Unfinished attempt to adapt tests to new code
This commit is contained in:
parent
9060e2b4cf
commit
ebd122d4ac
@ -19,34 +19,43 @@ class TestConfig(TestCase):
|
|||||||
def test_vim(self):
|
def test_vim(self):
|
||||||
from powerline.vim import VimPowerline
|
from powerline.vim import VimPowerline
|
||||||
cfg_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'powerline', 'config_files')
|
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:
|
with open(os.path.join(cfg_path, 'config.json'), 'r') as f:
|
||||||
self.assertEqual(len(buffers), len(json.load(f)['ext']['vim']['local_themes']))
|
self.assertEqual(len(buffers), len(json.load(f)['ext']['vim']['local_themes']))
|
||||||
outputs = {}
|
outputs = {}
|
||||||
i = 0
|
i = 0
|
||||||
mode = None
|
mode = None
|
||||||
|
args = None
|
||||||
|
kwargs = None
|
||||||
|
|
||||||
|
with vim_module._with('split'):
|
||||||
with VimPowerline() as powerline:
|
with VimPowerline() as powerline:
|
||||||
def check_output(*args):
|
def check_output(mode):
|
||||||
out = powerline.render(*args + (0 if mode == 'nc' else 1,))
|
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:
|
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]))
|
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, mode)
|
outputs[out] = (i, (args, kwargs), mode)
|
||||||
|
|
||||||
with vim_module._with('buffer', 'foo.txt'):
|
with vim_module._with('bufname', 'foo.txt'):
|
||||||
with vim_module._with('globals', powerline_config_path=cfg_path):
|
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?', '!'))
|
exclude = set(('no', 'v', 'V', VBLOCK, 's', 'S', SBLOCK, 'R', 'Rv', 'c', 'cv', 'ce', 'r', 'rm', 'r?', '!'))
|
||||||
try:
|
try:
|
||||||
for mode in ['n', 'nc', 'no', 'v', 'V', VBLOCK, 's', 'S', SBLOCK, 'i', 'R', 'Rv', 'c', 'cv', 'ce', 'r', 'rm', 'r?', '!']:
|
for mode in ['n', 'nc', 'no', 'v', 'V', VBLOCK, 's', 'S', SBLOCK, 'i', 'R', 'Rv', 'c', 'cv', 'ce', 'r', 'rm', 'r?', '!']:
|
||||||
if mode != 'nc':
|
check_output(mode)
|
||||||
vim_module._start_mode(mode)
|
|
||||||
check_output(1, 0)
|
|
||||||
for args, kwargs in buffers:
|
for args, kwargs in buffers:
|
||||||
i += 1
|
i += 1
|
||||||
if mode in exclude:
|
if mode in exclude:
|
||||||
continue
|
continue
|
||||||
with vim_module._with(*args, **kwargs):
|
with vim_module._with(*args, **kwargs):
|
||||||
check_output(1, 0)
|
check_output(mode)
|
||||||
finally:
|
finally:
|
||||||
vim_module._start_mode('n')
|
vim_module._start_mode('n')
|
||||||
|
|
||||||
|
38
tests/vim.py
38
tests/vim.py
@ -284,6 +284,7 @@ class _Window(object):
|
|||||||
global _window_id
|
global _window_id
|
||||||
self.cursor = cursor
|
self.cursor = cursor
|
||||||
self.width = width
|
self.width = width
|
||||||
|
self.number = len(windows) + 1
|
||||||
if buffer:
|
if buffer:
|
||||||
if type(buffer) is _Buffer:
|
if type(buffer) is _Buffer:
|
||||||
self.buffer = buffer
|
self.buffer = buffer
|
||||||
@ -371,6 +372,10 @@ class _Current(object):
|
|||||||
def buffer(self):
|
def buffer(self):
|
||||||
return buffers[_buffer()]
|
return buffers[_buffer()]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def window(self):
|
||||||
|
return windows[_window - 1]
|
||||||
|
|
||||||
|
|
||||||
current = _Current()
|
current = _Current()
|
||||||
|
|
||||||
@ -453,6 +458,13 @@ def _new(name=None):
|
|||||||
_window = len(windows)
|
_window = len(windows)
|
||||||
|
|
||||||
|
|
||||||
|
@_vim
|
||||||
|
def _split():
|
||||||
|
global _window
|
||||||
|
_Window(buffer=buffers[_buffer()])
|
||||||
|
_window = len(windows)
|
||||||
|
|
||||||
|
|
||||||
@_vim
|
@_vim
|
||||||
def _del_window(winnr):
|
def _del_window(winnr):
|
||||||
win = windows.pop(winnr - 1)
|
win = windows.pop(winnr - 1)
|
||||||
@ -587,10 +599,34 @@ class _WithDict(object):
|
|||||||
self.d.pop(k)
|
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
|
@_vim
|
||||||
def _with(key, *args, **kwargs):
|
def _with(key, *args, **kwargs):
|
||||||
if key == 'buffer':
|
if key == 'buffer':
|
||||||
return _WithNewBuffer(_edit, *args, **kwargs)
|
return _WithNewBuffer(_edit, *args, **kwargs)
|
||||||
|
elif key == 'bufname':
|
||||||
|
return _WithBufName(*args, **kwargs)
|
||||||
elif key == 'mode':
|
elif key == 'mode':
|
||||||
return _WithMode(*args, **kwargs)
|
return _WithMode(*args, **kwargs)
|
||||||
elif key == 'bufoptions':
|
elif key == 'bufoptions':
|
||||||
@ -599,3 +635,5 @@ def _with(key, *args, **kwargs):
|
|||||||
return _WithDict(_options, **kwargs)
|
return _WithDict(_options, **kwargs)
|
||||||
elif key == 'globals':
|
elif key == 'globals':
|
||||||
return _WithDict(_g, **kwargs)
|
return _WithDict(_g, **kwargs)
|
||||||
|
elif key == 'split':
|
||||||
|
return _WithSplit()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user