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'})) 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 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('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')
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'}), (('bufname', '[Command Line]'), {}), (('bufoptions',), {'buftype': 'quickfix'}), (('bufname', 'NERD_tree_1'), {}), (('bufname', '__Gundo__'), {}), (('bufname', '__Gundo_Preview__'), {}), (('bufname', 'ControlP'), {}), # No Command-T tests here: requires +ruby or emulation # No tabline here: tablines are tested separately ) with open(os.path.join(cfg_path, 'config.json'), 'r') as f: local_themes_raw = json.load(f)['ext']['vim']['local_themes'] # Don’t run tests on external/plugin segments local_themes = dict((k, v) for (k, v) in local_themes_raw.items()) # See end of the buffers definition above for `- 2` self.assertEqual(len(buffers), len(local_themes) - 2) outputs = {} i = 0 with vim_module._with('split'): with VimPowerline(logger=get_logger()) as powerline: def check_output(mode, args, kwargs): 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('bufname', '/tmp/foo.txt'): out = powerline.render(vim_module.current.window, 1, vim_module.current.window.number, is_tabline=True) outputs[out] = (-1, (None, None), 'tab') with vim_module._with('globals', powerline_config_paths=[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, None, None) for args, kwargs in buffers: i += 1 if mode in exclude: continue if mode == 'nc' and args == ('bufname', 'ControlP'): # ControlP window is not supposed to not # be in the focus continue with vim_module._with(*args, **kwargs): check_output(mode, args, kwargs) finally: vim_module._start_mode('n')
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'}), (('bufname', '[Command Line]'), {}), (('bufoptions',), {'buftype': 'quickfix'}), (('bufname', 'NERD_tree_1'), {}), (('bufname', '__Gundo__'), {}), (('bufname', '__Gundo_Preview__'), {}), (('bufname', 'ControlP'), {}), ) with open(os.path.join(cfg_path, 'config.json'), 'r') as f: local_themes_raw = json.load(f)['ext']['vim']['local_themes'] # Don't run tests on external/plugin segments local_themes = dict((k, v) for (k, v) in local_themes_raw.items()) self.assertEqual(len(buffers), len(local_themes) - 1) outputs = {} i = 0 with vim_module._with('split'): with VimPowerline() as powerline: def check_output(mode, args, kwargs): 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('bufname', '/tmp/foo.txt'): out = powerline.render(vim_module.current.window, 1, vim_module.current.window.number, is_tabline=True) outputs[out] = (-1, (None, None), 'tab') with vim_module._with('globals', powerline_config_paths=[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, None, None) for args, kwargs in buffers: i += 1 if mode in exclude: continue if mode == 'nc' and args == ('bufname', 'ControlP'): # ControlP window is not supposed to not # be in the focus continue with vim_module._with(*args, **kwargs): check_output(mode, args, kwargs) finally: vim_module._start_mode('n')
def test_mode(self): segment_info = vim_module._get_segment_info() self.assertEqual(vim.mode(segment_info=segment_info), 'NORMAL') self.assertEqual(vim.mode(segment_info=segment_info, override={'i': 'INS'}), 'NORMAL') self.assertEqual(vim.mode(segment_info=segment_info, override={'n': 'NORM'}), 'NORM') with vim_module._with('mode', 'i') as segment_info: self.assertEqual(vim.mode(segment_info=segment_info), 'INSERT') with vim_module._with('mode', chr(ord('V') - 0x40)) as segment_info: self.assertEqual(vim.mode(segment_info=segment_info), 'V·BLCK') self.assertEqual(vim.mode(segment_info=segment_info, override={'^V': 'VBLK'}), 'VBLK')
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' }), (('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 with vim_module._with('split'): with VimPowerline() as powerline: def check_output(mode, args, kwargs): 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('bufname', '/tmp/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, None, None) for args, kwargs in buffers: i += 1 if mode in exclude: continue with vim_module._with(*args, **kwargs): check_output(mode, args, kwargs) finally: vim_module._start_mode('n')
def test_file_name(self): segment_info = vim_module._get_segment_info() self.assertEqual(vim.file_name(segment_info=segment_info), None) self.assertEqual(vim.file_name(segment_info=segment_info, display_no_file=True), [{'contents': '[No file]', 'highlight_group': ['file_name_no_file', 'file_name']}]) self.assertEqual(vim.file_name(segment_info=segment_info, display_no_file=True, no_file_text='X'), [{'contents': 'X', 'highlight_group': ['file_name_no_file', 'file_name']}]) with vim_module._with('buffer', '/tmp/abc') as segment_info: self.assertEqual(vim.file_name(segment_info=segment_info), 'abc') with vim_module._with('buffer', '/tmp/’’') as segment_info: self.assertEqual(vim.file_name(segment_info=segment_info), '’’')
def test_mode(self): pl = Pl() segment_info = vim_module._get_segment_info() self.assertEqual(vim.mode(pl=pl, segment_info=segment_info), 'NORMAL') self.assertEqual(vim.mode(pl=pl, segment_info=segment_info, override={'i': 'INS'}), 'NORMAL') self.assertEqual(vim.mode(pl=pl, segment_info=segment_info, override={'n': 'NORM'}), 'NORM') with vim_module._with('mode', 'i') as segment_info: self.assertEqual(vim.mode(pl=pl, segment_info=segment_info), 'INSERT') with vim_module._with('mode', chr(ord('V') - 0x40)) as segment_info: self.assertEqual(vim.mode(pl=pl, segment_info=segment_info), 'V·BLCK') self.assertEqual(vim.mode(pl=pl, segment_info=segment_info, override={'^V': 'VBLK'}), 'VBLK')
def test_file_vcs_status(self): pl = Pl() with vim_module._with('buffer', '/foo') as segment_info: with replace_attr(vim, 'guess', lambda path: Args(branch=lambda: os.path.basename(path), status=lambda file: 'M', directory=path)): self.assertEqual(vim.file_vcs_status(pl=pl, segment_info=segment_info), [{'highlight_group': ['file_vcs_status_M', 'file_vcs_status'], 'contents': 'M'}]) with replace_attr(vim, 'guess', lambda path: Args(branch=lambda: os.path.basename(path), status=lambda file: None, directory=path)): self.assertEqual(vim.file_vcs_status(pl=pl, segment_info=segment_info), None) with vim_module._with('buffer', '/bar') as segment_info: with vim_module._with('bufoptions', buftype='nofile'): with replace_attr(vim, 'guess', lambda path: Args(branch=lambda: os.path.basename(path), status=lambda file: 'M', directory=path)): self.assertEqual(vim.file_vcs_status(pl=pl, segment_info=segment_info), None)
def test_file_name(self): pl = Pl() segment_info = vim_module._get_segment_info() self.assertEqual(vim.file_name(pl=pl, segment_info=segment_info), None) self.assertEqual(vim.file_name(pl=pl, segment_info=segment_info, display_no_file=True), [{'contents': '[No file]', 'highlight_group': ['file_name_no_file', 'file_name']}]) self.assertEqual(vim.file_name(pl=pl, segment_info=segment_info, display_no_file=True, no_file_text='X'), [{'contents': 'X', 'highlight_group': ['file_name_no_file', 'file_name']}]) with vim_module._with('buffer', '/tmp/abc') as segment_info: self.assertEqual(vim.file_name(pl=pl, segment_info=segment_info), 'abc') with vim_module._with('buffer', '/tmp/’’') as segment_info: self.assertEqual(vim.file_name(pl=pl, segment_info=segment_info), '’’')
def test_file_directory(self): pl = Pl() segment_info = vim_module._get_segment_info() self.assertEqual(vim.file_directory(pl=pl, segment_info=segment_info), None) with replace_env('HOME', '/home/foo', os.environ): with vim_module._with('buffer', '/tmp/’’/abc') as segment_info: self.assertEqual(vim.file_directory(pl=pl, segment_info=segment_info), '/tmp/’’/') with vim_module._with('buffer', b'/tmp/\xFF\xFF/abc') as segment_info: self.assertEqual(vim.file_directory(pl=pl, segment_info=segment_info), '/tmp/<ff><ff>/') with vim_module._with('buffer', '/tmp/abc') as segment_info: self.assertEqual(vim.file_directory(pl=pl, segment_info=segment_info), '/tmp/') os.environ['HOME'] = '/tmp' self.assertEqual(vim.file_directory(pl=pl, segment_info=segment_info), '~/')
def test_file_vcs_status(self): pl = Pl() create_watcher = get_fallback_create_watcher() file_vcs_status = partial(vim.file_vcs_status, pl=pl, create_watcher=create_watcher) with vim_module._with('buffer', '/foo') as segment_info: with replace_attr(vim, 'guess', get_dummy_guess(status=lambda file: 'M')): self.assertEqual(file_vcs_status(segment_info=segment_info), [{'highlight_group': ['file_vcs_status_M', 'file_vcs_status'], 'contents': 'M'}]) with replace_attr(vim, 'guess', get_dummy_guess(status=lambda file: None)): self.assertEqual(file_vcs_status(segment_info=segment_info), None) with vim_module._with('buffer', '/bar') as segment_info: with vim_module._with('bufoptions', buftype='nofile'): with replace_attr(vim, 'guess', get_dummy_guess(status=lambda file: 'M')): self.assertEqual(file_vcs_status(segment_info=segment_info), None)
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' })) 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 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('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')
def test_environ_update(self): # Regression test: test that segment obtains environment from vim, not # from os.environ. import tests.vim as vim_module with vim_module._with('globals', powerline_config_paths=['/']): from powerline.vim import VimPowerline import powerline as powerline_module with swap_attributes(config, powerline_module): with vim_module._with('environ', TEST='abc'): with get_powerline_raw(config, VimPowerline) as powerline: window = vim_module.current.window window_id = 1 winnr = window.number self.assertEqual(powerline.render(window, window_id, winnr), b'%#Pl_3_8404992_4_192_underline#\xc2\xa0abc%#Pl_4_192_NONE_None_NONE#>>') vim_module._environ['TEST'] = 'def' self.assertEqual(powerline.render(window, window_id, winnr), b'%#Pl_3_8404992_4_192_underline#\xc2\xa0def%#Pl_4_192_NONE_None_NONE#>>')
def test_readonly_indicator(self): pl = Pl() segment_info = vim_module._get_segment_info() self.assertEqual(vim.readonly_indicator(pl=pl, segment_info=segment_info), None) with vim_module._with('bufoptions', readonly=1): self.assertEqual(vim.readonly_indicator(pl=pl, segment_info=segment_info), '') self.assertEqual(vim.readonly_indicator(pl=pl, segment_info=segment_info, text='L'), 'L')
def test_paste_indicator(self): pl = Pl() segment_info = vim_module._get_segment_info() self.assertEqual(vim.paste_indicator(pl=pl, segment_info=segment_info), None) with vim_module._with('options', paste=1): self.assertEqual(vim.paste_indicator(pl=pl, segment_info=segment_info), 'PASTE') self.assertEqual(vim.paste_indicator(pl=pl, segment_info=segment_info, text='P'), 'P')
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'}), (('bufname', '[Command Line]'), {}), (('bufoptions',), {'buftype': 'quickfix'}), ) with open(os.path.join(cfg_path, 'config.json'), 'r') as f: local_themes_raw = json.load(f)['ext']['vim']['local_themes'] # Don't run tests on external/plugin segments local_themes = dict((k, v) for (k, v) in local_themes_raw.items() if not '.' in k) self.assertEqual(len(buffers), len(local_themes)) outputs = {} i = 0 with vim_module._with('split'): with VimPowerline() as powerline: def check_output(mode, args, kwargs): 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('bufname', '/tmp/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, None, None) for args, kwargs in buffers: i += 1 if mode in exclude: continue with vim_module._with(*args, **kwargs): check_output(mode, args, kwargs) finally: vim_module._start_mode('n')
def test_file_directory(self): segment_info = vim_module._get_segment_info() self.assertEqual(vim.file_directory(segment_info=segment_info), None) with replace_env('HOME', '/home/foo'): with vim_module._with('buffer', '/tmp/abc') as segment_info: self.assertEqual(vim.file_directory(segment_info=segment_info), '/tmp/') os.environ['HOME'] = '/tmp' self.assertEqual(vim.file_directory(segment_info=segment_info), '~/')
def test_single_tab(self): pl = Pl() single_tab = partial(self.vim.single_tab, pl=pl, segment_info=None, mode=None) with vim_module._with('tabpage'): self.assertEqual(single_tab(), False) self.assertEqual(single_tab(), True)
def test_file_opts(self): segment_info = vim_module._get_segment_info() self.assertEqual(vim.file_format(segment_info=segment_info), [{'divider_highlight_group': 'background:divider', 'contents': 'unix'}]) self.assertEqual(vim.file_encoding(segment_info=segment_info), [{'divider_highlight_group': 'background:divider', 'contents': 'utf-8'}]) self.assertEqual(vim.file_type(segment_info=segment_info), None) with vim_module._with('bufoptions', filetype='python'): self.assertEqual(vim.file_type(segment_info=segment_info), [{'divider_highlight_group': 'background:divider', 'contents': 'python'}])
def test_file_opts(self): pl = Pl() segment_info = vim_module._get_segment_info() self.assertEqual(vim.file_format(pl=pl, segment_info=segment_info), [{'divider_highlight_group': 'background:divider', 'contents': 'unix'}]) self.assertEqual(vim.file_encoding(pl=pl, segment_info=segment_info), [{'divider_highlight_group': 'background:divider', 'contents': 'utf-8'}]) self.assertEqual(vim.file_type(pl=pl, segment_info=segment_info), None) with vim_module._with('bufoptions', filetype='python'): self.assertEqual(vim.file_type(pl=pl, segment_info=segment_info), [{'divider_highlight_group': 'background:divider', 'contents': 'python'}])
def test_environ_update(self): # Regression test: test that segment obtains environment from vim, not # from os.environ. from powerline.vim import VimPowerline with vim_module._with('environ', TEST='abc'): with get_powerline_raw(VimPowerline) as powerline: window = vim_module.current.window window_id = 1 winnr = window.number self.assertEqual(powerline.render(window, window_id, winnr), '%#Pl_3_8404992_4_192_underline#\xa0abc%#Pl_4_192_NONE_None_NONE#>>') 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_branch(self): pl = Pl() with vim_module._with('buffer', '/foo') as segment_info: with replace_attr(vim, 'guess', lambda path: Args(branch=lambda: os.path.basename(path), status=lambda: None, directory=path)): self.assertEqual(vim.branch(pl=pl, segment_info=segment_info), [{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch'], 'contents': 'foo'}]) self.assertEqual(vim.branch(pl=pl, segment_info=segment_info, status_colors=True), [{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch_clean', 'branch'], 'contents': 'foo'}]) with replace_attr(vim, 'guess', lambda path: Args(branch=lambda: os.path.basename(path), status=lambda: 'DU', directory=path)): self.assertEqual(vim.branch(pl=pl, segment_info=segment_info), [{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch'], 'contents': 'foo'}]) self.assertEqual(vim.branch(pl=pl, segment_info=segment_info, status_colors=True), [{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch_dirty', 'branch'], 'contents': 'foo'}])
def test_branch(self): pl = Pl() with vim_module._with('buffer', '/foo') as segment_info: with replace_attr(vim, 'guess', lambda path: Args(branch=lambda: os.path.basename(path), status=lambda: None, directory=path)): with replace_attr(vim, 'tree_status', lambda repo, pl: None): self.assertEqual(vim.branch(pl=pl, segment_info=segment_info, status_colors=False), [{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch'], 'contents': 'foo'}]) self.assertEqual(vim.branch(pl=pl, segment_info=segment_info, status_colors=True), [{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch_clean', 'branch'], 'contents': 'foo'}]) with replace_attr(vim, 'guess', lambda path: Args(branch=lambda: os.path.basename(path), status=lambda: 'DU', directory=path)): with replace_attr(vim, 'tree_status', lambda repo, pl: 'DU'): self.assertEqual(vim.branch(pl=pl, segment_info=segment_info, status_colors=False), [{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch'], 'contents': 'foo'}]) self.assertEqual(vim.branch(pl=pl, segment_info=segment_info, status_colors=True), [{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch_dirty', 'branch'], 'contents': 'foo'}])
def test_branch(self): pl = Pl() create_watcher = get_fallback_create_watcher() branch = partial(vim.branch, pl=pl, create_watcher=create_watcher) with vim_module._with('buffer', '/foo') as segment_info: with replace_attr(vim, 'guess', get_dummy_guess(status=lambda: None)): with replace_attr(vim, 'tree_status', lambda repo, pl: None): self.assertEqual(branch(segment_info=segment_info, status_colors=False), [{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch'], 'contents': 'foo'}]) self.assertEqual(branch(segment_info=segment_info, status_colors=True), [{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch_clean', 'branch'], 'contents': 'foo'}]) with replace_attr(vim, 'guess', get_dummy_guess(status=lambda: 'DU')): with replace_attr(vim, 'tree_status', lambda repo, pl: 'DU'): self.assertEqual(branch(segment_info=segment_info, status_colors=False), [{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch'], 'contents': 'foo'}]) self.assertEqual(branch(segment_info=segment_info, status_colors=True), [{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch_dirty', 'branch'], 'contents': 'foo'}])
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"}), (("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 with vim_module._with("split"): with VimPowerline() as powerline: def check_output(mode, args, kwargs): 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("bufname", "/tmp/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, None, None) for args, kwargs in buffers: i += 1 if mode in exclude: continue with vim_module._with(*args, **kwargs): check_output(mode, args, kwargs) finally: vim_module._start_mode("n")
def test_window_title(self): pl = Pl() segment_info = vim_module._get_segment_info() self.assertEqual(vim.window_title(pl=pl, segment_info=segment_info), None) with vim_module._with('wvars', quickfix_title='Abc'): self.assertEqual(vim.window_title(pl=pl, segment_info=segment_info), 'Abc')
def test_file_size(self): pl = Pl() segment_info = vim_module._get_segment_info() self.assertEqual(vim.file_size(pl=pl, segment_info=segment_info), '0 B') with vim_module._with('buffer', os.path.join(os.path.dirname(__file__), 'empty')) as segment_info: self.assertEqual(vim.file_size(pl=pl, segment_info=segment_info), '0 B')