Raise exceptions that are not intercepted when testing
Thus problems like in #1087 will result in build failure.
This commit is contained in:
parent
345025ed60
commit
c68eb56f7c
|
@ -15,6 +15,10 @@ from powerline.lib import mergedicts
|
|||
from powerline.lib.encoding import get_preferred_output_encoding
|
||||
|
||||
|
||||
class NotInterceptedError(BaseException):
|
||||
pass
|
||||
|
||||
|
||||
def _config_loader_condition(path):
|
||||
if path and os.path.isfile(path):
|
||||
return path
|
||||
|
|
|
@ -24,10 +24,11 @@ class RewriteResult(object):
|
|||
|
||||
|
||||
class IPythonPowerline(Powerline):
|
||||
def init(self):
|
||||
def init(self, **kwargs):
|
||||
super(IPythonPowerline, self).init(
|
||||
'ipython',
|
||||
use_daemon_threads=True
|
||||
use_daemon_threads=True,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
def get_config_paths(self):
|
||||
|
|
|
@ -7,18 +7,42 @@ from __future__ import (unicode_literals, division, absolute_import, print_funct
|
|||
import sys
|
||||
import os
|
||||
import json
|
||||
import logging
|
||||
|
||||
import tests.vim as vim_module
|
||||
|
||||
from tests.lib import Args, urllib_read, replace_attr
|
||||
from tests import TestCase
|
||||
|
||||
from powerline import NotInterceptedError
|
||||
from powerline.segments.common import wthr
|
||||
|
||||
|
||||
VBLOCK = chr(ord('V') - 0x40)
|
||||
SBLOCK = chr(ord('S') - 0x40)
|
||||
|
||||
|
||||
class FailingLogger(logging.Logger):
|
||||
def exception(self, *args, **kwargs):
|
||||
super(FailingLogger, self).exception(*args, **kwargs)
|
||||
raise NotInterceptedError('Unexpected exception occurred')
|
||||
|
||||
|
||||
def get_logger(stream=None):
|
||||
log_format = '%(asctime)s:%(levelname)s:%(message)s'
|
||||
formatter = logging.Formatter(log_format)
|
||||
|
||||
level = logging.WARNING
|
||||
handler = logging.StreamHandler(stream)
|
||||
handler.setLevel(level)
|
||||
handler.setFormatter(formatter)
|
||||
|
||||
logger = FailingLogger('powerline')
|
||||
logger.setLevel(level)
|
||||
logger.addHandler(handler)
|
||||
return logger
|
||||
|
||||
|
||||
class TestVimConfig(TestCase):
|
||||
def test_vim(self):
|
||||
from powerline.vim import VimPowerline
|
||||
|
@ -41,7 +65,7 @@ class TestVimConfig(TestCase):
|
|||
i = 0
|
||||
|
||||
with vim_module._with('split'):
|
||||
with VimPowerline() as powerline:
|
||||
with VimPowerline(logger=get_logger()) as powerline:
|
||||
def check_output(mode, args, kwargs):
|
||||
if mode == 'nc':
|
||||
window = vim_module.windows[0]
|
||||
|
@ -93,33 +117,33 @@ class TestConfig(TestCase):
|
|||
reload(common)
|
||||
from powerline.shell import ShellPowerline
|
||||
with replace_attr(common, 'urllib_read', urllib_read):
|
||||
with ShellPowerline(Args(ext=['tmux']), run_once=False) as powerline:
|
||||
with ShellPowerline(Args(ext=['tmux']), logger=get_logger(), run_once=False) as powerline:
|
||||
powerline.render()
|
||||
with ShellPowerline(Args(ext=['tmux']), run_once=False) as powerline:
|
||||
with ShellPowerline(Args(ext=['tmux']), logger=get_logger(), run_once=False) as powerline:
|
||||
powerline.render()
|
||||
|
||||
def test_zsh(self):
|
||||
from powerline.shell import ShellPowerline
|
||||
args = Args(last_pipe_status=[1, 0], jobnum=0, ext=['shell'], renderer_module='.zsh')
|
||||
segment_info = {'args': args}
|
||||
with ShellPowerline(args, run_once=False) as powerline:
|
||||
with ShellPowerline(args, logger=get_logger(), run_once=False) as powerline:
|
||||
powerline.render(segment_info=segment_info)
|
||||
with ShellPowerline(args, run_once=False) as powerline:
|
||||
with ShellPowerline(args, logger=get_logger(), run_once=False) as powerline:
|
||||
powerline.render(segment_info=segment_info)
|
||||
segment_info['local_theme'] = 'select'
|
||||
with ShellPowerline(args, run_once=False) as powerline:
|
||||
with ShellPowerline(args, logger=get_logger(), run_once=False) as powerline:
|
||||
powerline.render(segment_info=segment_info)
|
||||
segment_info['local_theme'] = 'continuation'
|
||||
segment_info['parser_state'] = 'if cmdsubst'
|
||||
with ShellPowerline(args, run_once=False) as powerline:
|
||||
with ShellPowerline(args, logger=get_logger(), run_once=False) as powerline:
|
||||
powerline.render(segment_info=segment_info)
|
||||
|
||||
def test_bash(self):
|
||||
from powerline.shell import ShellPowerline
|
||||
args = Args(last_exit_code=1, jobnum=0, ext=['shell'], renderer_module='.bash', config={'ext': {'shell': {'theme': 'default_leftonly'}}})
|
||||
with ShellPowerline(args, run_once=False) as powerline:
|
||||
with ShellPowerline(args, logger=get_logger(), run_once=False) as powerline:
|
||||
powerline.render(segment_info={'args': args})
|
||||
with ShellPowerline(args, run_once=False) as powerline:
|
||||
with ShellPowerline(args, logger=get_logger(), run_once=False) as powerline:
|
||||
powerline.render(segment_info={'args': args})
|
||||
|
||||
def test_ipython(self):
|
||||
|
@ -132,11 +156,11 @@ class TestConfig(TestCase):
|
|||
|
||||
segment_info = Args(prompt_count=1)
|
||||
|
||||
with IpyPowerline() as powerline:
|
||||
with IpyPowerline(logger=get_logger()) as powerline:
|
||||
for prompt_type in ['in', 'in2']:
|
||||
powerline.render(is_prompt=True, matcher_info=prompt_type, segment_info=segment_info)
|
||||
powerline.render(is_prompt=True, matcher_info=prompt_type, segment_info=segment_info)
|
||||
with IpyPowerline() as powerline:
|
||||
with IpyPowerline(logger=get_logger()) as powerline:
|
||||
for prompt_type in ['out', 'rewrite']:
|
||||
powerline.render(is_prompt=False, matcher_info=prompt_type, segment_info=segment_info)
|
||||
powerline.render(is_prompt=False, matcher_info=prompt_type, segment_info=segment_info)
|
||||
|
@ -147,7 +171,7 @@ class TestConfig(TestCase):
|
|||
reload(common)
|
||||
from powerline import Powerline
|
||||
with replace_attr(wthr, 'urllib_read', urllib_read):
|
||||
Powerline(ext='wm', renderer_module='pango_markup', run_once=True).render()
|
||||
Powerline(logger=get_logger(), ext='wm', renderer_module='pango_markup', run_once=True).render()
|
||||
reload(common)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue