Add some working dash tests

This commit is contained in:
Foo 2017-10-22 21:05:20 +03:00
parent 870de7be21
commit eb17b5374b
5 changed files with 98 additions and 17 deletions

View File

@ -159,7 +159,8 @@ username = False
_geteuid = getattr(os, 'geteuid', lambda: 1)
def user(pl, hide_user=None, hide_domain=False):
@requires_segment_info
def user(pl, segment_info, hide_user=None, hide_domain=False):
'''Return the current user.
:param str hide_user:
@ -172,6 +173,11 @@ def user(pl, hide_user=None, hide_domain=False):
Highlight groups used: ``superuser`` or ``user``. It is recommended to define all highlight groups.
'''
global username
if (
segment_info['environ'].get('_POWERLINE_RUNNING_SHELL_TESTS')
== 'ee5bcdc6-b749-11e7-9456-50465d597777'
):
return 'user'
if username is False:
username = _get_user()
if username is None:

View File

@ -22,6 +22,11 @@ def hostname(pl, segment_info, only_if_ssh=False, exclude_domain=False):
:param bool exclude_domain:
return the hostname without domain if there is one
'''
if (
segment_info['environ'].get('_POWERLINE_RUNNING_SHELL_TESTS')
== 'ee5bcdc6-b749-11e7-9456-50465d597777'
):
return 'hostname'
if only_if_ssh and not segment_info['environ'].get('SSH_CLIENT'):
return None
if exclude_domain:

View File

@ -6,7 +6,11 @@ set_theme_option() {
set_theme() {
export POWERLINE_CONFIG_OVERRIDES="ext.shell.theme=$1"
}
set_virtual_env() {
export VIRTUAL_ENV="$HOME/.virtenvs/$1"
}
set_theme_option default_leftonly.segment_data.hostname.args.only_if_ssh false
set_theme default_leftonly
. "$ROOT/powerline/bindings/shell/powerline.sh"
export VIRTUAL_ENV=
cd "$TEST_ROOT/3rd"

View File

@ -53,6 +53,8 @@ def main(argv):
env['TEST_TYPE'] = script_args.type
env['TEST_CLIENT'] = script_args.client
env['LANG'] = 'en_US.UTF_8'
env['_POWERLINE_RUNNING_SHELL_TESTS'] = (
'ee5bcdc6-b749-11e7-9456-50465d597777')
dim = MutableDimensions(rows=50, cols=200)
@ -65,33 +67,79 @@ def main(argv):
def init(p):
for line in binding_opts['init']:
p.send(line + '\n')
while not p[dim.rows - 1, 0].text:
p.send('\n')
sleep(0.01)
sleep(1)
return init
def gen_feed(line):
def feed(p):
p.send(line + '\n')
sleep(0.1)
return feed
base_attrs = {
((255, 204,0), (204, 51, 0), 0, 0, 0): 'N',
((204, 51, 0), (0, 102, 153), 0, 0, 0): 'H',
((255, 255, 255), (0, 102, 153), 1, 0, 0): 'sHU',
((0, 102, 153), (44, 44, 44), 0, 0, 0): 'U',
((199, 199, 199), (44, 44, 44), 0, 0, 0): 'sUB',
((44, 44, 44), (88, 88, 88), 0, 0, 0): 'B',
((199, 199, 199), (88, 88, 88), 0, 0, 0): 'sBD',
((144, 144, 144), (88, 88, 88), 0, 0, 0): 'D',
((221, 221, 221), (88, 88, 88), 1, 0, 0): 'sD',
((88, 88, 88), (0, 0, 0), 0, 0, 0): 'C',
((240, 240, 240), (0, 0, 0), 0, 0, 0): 'sCp',
((255, 204,0), (204, 51, 0), 0, 0, 0): 'H',
((204, 51, 0), (0, 102, 153), 0, 0, 0): 'sHU',
((255, 255, 255), (0, 102, 153), 1, 0, 0): 'U',
((0, 102, 153), (44, 44, 44), 0, 0, 0): 'sUB',
((199, 199, 199), (44, 44, 44), 0, 0, 0): 'B',
((44, 44, 44), (88, 88, 88), 0, 0, 0): 'sBD',
((199, 199, 199), (88, 88, 88), 0, 0, 0): 'D',
((144, 144, 144), (88, 88, 88), 0, 0, 0): 'sD',
((221, 221, 221), (88, 88, 88), 1, 0, 0): 'C',
((88, 88, 88), (0, 0, 0), 0, 0, 0): 'sDN',
((240, 240, 240), (0, 0, 0), 0, 0, 0): 'N',
((0, 102, 153), (51, 153, 204), 0, 0, 0): 'sUE',
((255, 255, 255), (51, 153, 204), 0, 0, 0): 'E',
((51, 153, 204), (44, 44, 44), 0, 0, 0): 'sEB',
}
tests = (
{
'expected_result': (
'', base_attrs
'{H:  hostname }{sHU: }'
'{U:user }{sUB: }'
'{B: BRANCH }{sBD: }'
'{D:… }{sD: }{D:tmp }{sD: }{D:vshells }{sD: }{C:3rd }{sDN: }'
'{N:}',
base_attrs,
),
'prep_cb': gen_init(script_args.binding),
'row': dim.rows - 1,
},
{
'expected_result': (
'{H:  hostname }{sHU: }'
'{U:user }{sUB: }'
'{B: BRANCH }{sBD: }'
'{D:… }{sD: }{D:vshells }{sD: }{D:3rd }{sD: }{C:.git }{sDN: }'
'{N:}',
base_attrs
),
'prep_cb': gen_feed('cd .git'),
},
{
'expected_result': (
'{H:  hostname }{sHU: }'
'{U:user }{sUB: }'
'{B: BRANCH }{sBD: }'
'{D:… }{sD: }{D:tmp }{sD: }{D:vshells }{sD: }{C:3rd }{sDN: }'
'{N:}',
base_attrs,
),
'prep_cb': gen_feed('cd ..'),
},
{
'expected_result': (
'{H:  hostname }{sHU: }'
'{U:user }{sUE: }'
'{E:(e) some-venv }{sEB: }'
'{B: BRANCH }{sBD: }'
'{D:… }{sD: }{D:tmp }{sD: }{D:vshells }{sD: }{C:3rd }{sDN: }'
'{N:}',
base_attrs,
),
'prep_cb': gen_feed('set_virtual_env some-venv'),
},
)

View File

@ -9,6 +9,24 @@ vterm_setup
HAS_SOCAT=
HAS_C_CLIENT=
git init "$TEST_ROOT/3rd"
git --git-dir="$TEST_ROOT/3rd/.git" checkout -b BRANCH
export DIR1=""
export DIR2=""
mkdir "$TEST_ROOT/3rd/$DIR1"
mkdir "$TEST_ROOT/3rd/$DIR2"
mkdir "$TEST_ROOT"/3rd/'\[\]'
mkdir "$TEST_ROOT"/3rd/'%%'
mkdir "$TEST_ROOT"/3rd/'#[bold]'
mkdir "$TEST_ROOT"/3rd/'(echo)'
mkdir "$TEST_ROOT"/3rd/'$(echo)'
mkdir "$TEST_ROOT"/3rd/'`echo`'
mkdir "$TEST_ROOT"/3rd/'«Unicode!»'
mkdir "$TEST_ROOT/fish_home"
mkdir "$TEST_ROOT/fish_home/fish"
mkdir "$TEST_ROOT/fish_home/fish/generated_completions"
cp -r "$ROOT/tests/test_shells/ipython_home" "$TEST_ROOT"
ln -s "$(which env)" "$TEST_ROOT/path"
ln -s "$(which git)" "$TEST_ROOT/path"
ln -s "$(which sleep)" "$TEST_ROOT/path"