mirror of
https://github.com/powerline/powerline.git
synced 2025-04-08 19:25:04 +02:00
Define tests via dictionaries, do not hardcode row number
This commit is contained in:
parent
9d7366436b
commit
255ff49def
@ -141,13 +141,12 @@ class ExpectProcess(threading.Thread):
|
||||
return '\n'.join(lines), attrs
|
||||
|
||||
|
||||
def test_expected_result(p, expected_result, last_attempt,
|
||||
last_attempt_cb=None):
|
||||
expected_text, attrs = expected_result
|
||||
def test_expected_result(p, test, last_attempt, last_attempt_cb=None):
|
||||
expected_text, attrs = test['expected_result']
|
||||
attempts = 3
|
||||
result = None
|
||||
while attempts:
|
||||
actual_text, all_attrs = p.get_row(p.dim.rows - 1, attrs)
|
||||
actual_text, all_attrs = p.get_row(test['row'], attrs)
|
||||
if actual_text == expected_text:
|
||||
return True
|
||||
attempts -= 1
|
||||
@ -236,11 +235,16 @@ def do_terminal_tests(tests, cmd, lib, dim, args, env, cwd=None, fin_cb=None,
|
||||
|
||||
ret = True
|
||||
|
||||
for test_prep, expected_result in tests:
|
||||
test_prep(p)
|
||||
for test in tests:
|
||||
try:
|
||||
test_prep = test['prep_cb']
|
||||
except KeyError:
|
||||
pass
|
||||
else:
|
||||
test_prep(p)
|
||||
ret = (
|
||||
ret
|
||||
and test_expected_result(p, expected_result, attempts == 0,
|
||||
and test_expected_result(p, test, attempts == 0,
|
||||
last_attempt_cb)
|
||||
)
|
||||
|
||||
|
@ -112,97 +112,6 @@ def main(attempts=3):
|
||||
|
||||
dim = MutableDimensions(rows=50, cols=200)
|
||||
|
||||
base_attrs = {
|
||||
((0, 0, 0), (243, 243, 243), 1, 0, 0): 'lead',
|
||||
((243, 243, 243), (11, 11, 11), 0, 0, 0): 'leadsep',
|
||||
((255, 255, 255), (11, 11, 11), 0, 0, 0): 'bg',
|
||||
((199, 199, 199), (88, 88, 88), 0, 0, 0): 'cwd',
|
||||
((88, 88, 88), (11, 11, 11), 0, 0, 0): 'cwdhsep',
|
||||
((0, 0, 0), (0, 224, 0), 0, 0, 0): 'defstl',
|
||||
}
|
||||
expected_results = (
|
||||
get_expected_result(
|
||||
tmux_version,
|
||||
expected_result_old=(
|
||||
'{lead: 0 }{leadsep: }{bg: S2 string here }'
|
||||
'{4: 0 }{cwdhsep:| }{6:bash }'
|
||||
'{bg: }{4: 1- }{cwdhsep:| }{6:bash }'
|
||||
'{bg: }{7: }{8:2* | }{9:bash }{10: }'
|
||||
'{bg:' + (' ' * 124) + '}'
|
||||
'{cwdhsep: }{cwd: S1 string here }', updated(base_attrs, {
|
||||
((133, 133, 133), (11, 11, 11), 0, 0, 0): 4,
|
||||
((188, 188, 188), (11, 11, 11), 0, 0, 0): 6,
|
||||
((11, 11, 11), (0, 102, 153), 0, 0, 0): 7,
|
||||
((102, 204, 255), (0, 102, 153), 0, 0, 0): 8,
|
||||
((255, 255, 255), (0, 102, 153), 1, 0, 0): 9,
|
||||
((0, 102, 153), (11, 11, 11), 0, 0, 0): 10,
|
||||
})),
|
||||
expected_result_1_8=(
|
||||
'{lead: 0 }{leadsep: }{bg: S2 string here }'
|
||||
'{4: 0 }{cwdhsep:| }{6:bash }'
|
||||
'{bg: }{4: 1- }{cwdhsep:| }{7:bash }'
|
||||
'{bg: }{8: }{9:2* | }{10:bash }{7: }'
|
||||
'{bg:' + (' ' * 124) + '}'
|
||||
'{cwdhsep: }{cwd: S1 string here }', updated(base_attrs, {
|
||||
((133, 133, 133), (11, 11, 11), 0, 0, 0): 4,
|
||||
((188, 188, 188), (11, 11, 11), 0, 0, 0): 6,
|
||||
((0, 102, 153), (11, 11, 11), 0, 0, 0): 7,
|
||||
((11, 11, 11), (0, 102, 153), 0, 0, 0): 8,
|
||||
((102, 204, 255), (0, 102, 153), 0, 0, 0): 9,
|
||||
((255, 255, 255), (0, 102, 153), 1, 0, 0): 10,
|
||||
})),
|
||||
expected_result_2_0=(
|
||||
'{lead: 0 }{leadsep: }{bg: S2 string here }'
|
||||
'{4: 0 }{cwdhsep:| }{6:bash }'
|
||||
'{bg: }{4: 1- }{cwdhsep:| }{7:bash }'
|
||||
'{bg: }{8: }{9:2* | }{10:bash }{7: }'
|
||||
'{bg:' + (' ' * 125) + '}'
|
||||
'{cwdhsep: }{cwd: S1 string here }', updated(base_attrs, {
|
||||
((133, 133, 133), (11, 11, 11), 0, 0, 0): 4,
|
||||
((188, 188, 188), (11, 11, 11), 0, 0, 0): 6,
|
||||
((0, 102, 153), (11, 11, 11), 0, 0, 0): 7,
|
||||
((11, 11, 11), (0, 102, 153), 0, 0, 0): 8,
|
||||
((102, 204, 255), (0, 102, 153), 0, 0, 0): 9,
|
||||
((255, 255, 255), (0, 102, 153), 1, 0, 0): 10,
|
||||
})),
|
||||
),
|
||||
get_expected_result(
|
||||
tmux_version,
|
||||
expected_result_old=('{bg:' + (' ' * 40) + '}', base_attrs),
|
||||
expected_result_1_7=(
|
||||
'{lead: 0 }'
|
||||
'{leadsep: }{bg: <}{4:h }{bg: }{5: }'
|
||||
'{6:2* | }{7:bash }{8: }{bg: }{cwdhsep: }'
|
||||
'{cwd: S1 string here }', updated(base_attrs, {
|
||||
((188, 188, 188), (11, 11, 11), 0, 0, 0): 4,
|
||||
((11, 11, 11), (0, 102, 153), 0, 0, 0): 5,
|
||||
((102, 204, 255), (0, 102, 153), 0, 0, 0): 6,
|
||||
((255, 255, 255), (0, 102, 153), 1, 0, 0): 7,
|
||||
((0, 102, 153), (11, 11, 11), 0, 0, 0): 8,
|
||||
})),
|
||||
expected_result_1_8=(
|
||||
'{lead: 0 }'
|
||||
'{leadsep: }{bg: <}{4:h }{bg: }{5: }'
|
||||
'{6:2* | }{7:bash }{4: }{bg: }{cwdhsep: }'
|
||||
'{cwd: S1 string here }', updated(base_attrs, {
|
||||
((0, 102, 153), (11, 11, 11), 0, 0, 0): 4,
|
||||
((11, 11, 11), (0, 102, 153), 0, 0, 0): 5,
|
||||
((102, 204, 255), (0, 102, 153), 0, 0, 0): 6,
|
||||
((255, 255, 255), (0, 102, 153), 1, 0, 0): 7,
|
||||
})),
|
||||
expected_result_2_0=(
|
||||
'{lead: 0 }'
|
||||
'{leadsep: }{bg:<}{4:ash }{bg: }{5: }'
|
||||
'{6:2* | }{7:bash }{4: }{cwdhsep: }'
|
||||
'{cwd: S1 string here }', updated(base_attrs, {
|
||||
((0, 102, 153), (11, 11, 11), 0, 0, 0): 4,
|
||||
((11, 11, 11), (0, 102, 153), 0, 0, 0): 5,
|
||||
((102, 204, 255), (0, 102, 153), 0, 0, 0): 6,
|
||||
((255, 255, 255), (0, 102, 153), 1, 0, 0): 7,
|
||||
})),
|
||||
),
|
||||
)
|
||||
|
||||
def prepare_test_1(p):
|
||||
sleep(5)
|
||||
|
||||
@ -211,9 +120,102 @@ def main(attempts=3):
|
||||
p.resize(dim)
|
||||
sleep(5)
|
||||
|
||||
test_preps = (
|
||||
prepare_test_1,
|
||||
prepare_test_2,
|
||||
base_attrs = {
|
||||
((0, 0, 0), (243, 243, 243), 1, 0, 0): 'lead',
|
||||
((243, 243, 243), (11, 11, 11), 0, 0, 0): 'leadsep',
|
||||
((255, 255, 255), (11, 11, 11), 0, 0, 0): 'bg',
|
||||
((199, 199, 199), (88, 88, 88), 0, 0, 0): 'cwd',
|
||||
((88, 88, 88), (11, 11, 11), 0, 0, 0): 'cwdhsep',
|
||||
((0, 0, 0), (0, 224, 0), 0, 0, 0): 'defstl',
|
||||
}
|
||||
tests = (
|
||||
{
|
||||
'expected_result': get_expected_result(
|
||||
tmux_version,
|
||||
expected_result_old=(
|
||||
'{lead: 0 }{leadsep: }{bg: S2 string here }'
|
||||
'{4: 0 }{cwdhsep:| }{6:bash }'
|
||||
'{bg: }{4: 1- }{cwdhsep:| }{6:bash }'
|
||||
'{bg: }{7: }{8:2* | }{9:bash }{10: }'
|
||||
'{bg:' + (' ' * 124) + '}'
|
||||
'{cwdhsep: }{cwd: S1 string here }', updated(base_attrs, {
|
||||
((133, 133, 133), (11, 11, 11), 0, 0, 0): 4,
|
||||
((188, 188, 188), (11, 11, 11), 0, 0, 0): 6,
|
||||
((11, 11, 11), (0, 102, 153), 0, 0, 0): 7,
|
||||
((102, 204, 255), (0, 102, 153), 0, 0, 0): 8,
|
||||
((255, 255, 255), (0, 102, 153), 1, 0, 0): 9,
|
||||
((0, 102, 153), (11, 11, 11), 0, 0, 0): 10,
|
||||
})),
|
||||
expected_result_1_8=(
|
||||
'{lead: 0 }{leadsep: }{bg: S2 string here }'
|
||||
'{4: 0 }{cwdhsep:| }{6:bash }'
|
||||
'{bg: }{4: 1- }{cwdhsep:| }{7:bash }'
|
||||
'{bg: }{8: }{9:2* | }{10:bash }{7: }'
|
||||
'{bg:' + (' ' * 124) + '}'
|
||||
'{cwdhsep: }{cwd: S1 string here }', updated(base_attrs, {
|
||||
((133, 133, 133), (11, 11, 11), 0, 0, 0): 4,
|
||||
((188, 188, 188), (11, 11, 11), 0, 0, 0): 6,
|
||||
((0, 102, 153), (11, 11, 11), 0, 0, 0): 7,
|
||||
((11, 11, 11), (0, 102, 153), 0, 0, 0): 8,
|
||||
((102, 204, 255), (0, 102, 153), 0, 0, 0): 9,
|
||||
((255, 255, 255), (0, 102, 153), 1, 0, 0): 10,
|
||||
})),
|
||||
expected_result_2_0=(
|
||||
'{lead: 0 }{leadsep: }{bg: S2 string here }'
|
||||
'{4: 0 }{cwdhsep:| }{6:bash }'
|
||||
'{bg: }{4: 1- }{cwdhsep:| }{7:bash }'
|
||||
'{bg: }{8: }{9:2* | }{10:bash }{7: }'
|
||||
'{bg:' + (' ' * 125) + '}'
|
||||
'{cwdhsep: }{cwd: S1 string here }', updated(base_attrs, {
|
||||
((133, 133, 133), (11, 11, 11), 0, 0, 0): 4,
|
||||
((188, 188, 188), (11, 11, 11), 0, 0, 0): 6,
|
||||
((0, 102, 153), (11, 11, 11), 0, 0, 0): 7,
|
||||
((11, 11, 11), (0, 102, 153), 0, 0, 0): 8,
|
||||
((102, 204, 255), (0, 102, 153), 0, 0, 0): 9,
|
||||
((255, 255, 255), (0, 102, 153), 1, 0, 0): 10,
|
||||
})),
|
||||
),
|
||||
'prep_cb': prepare_test_1,
|
||||
'row': dim.rows - 1,
|
||||
}, {
|
||||
'expected_result': get_expected_result(
|
||||
tmux_version,
|
||||
expected_result_old=('{bg:' + (' ' * 40) + '}', base_attrs),
|
||||
expected_result_1_7=(
|
||||
'{lead: 0 }'
|
||||
'{leadsep: }{bg: <}{4:h }{bg: }{5: }'
|
||||
'{6:2* | }{7:bash }{8: }{bg: }{cwdhsep: }'
|
||||
'{cwd: S1 string here }', updated(base_attrs, {
|
||||
((188, 188, 188), (11, 11, 11), 0, 0, 0): 4,
|
||||
((11, 11, 11), (0, 102, 153), 0, 0, 0): 5,
|
||||
((102, 204, 255), (0, 102, 153), 0, 0, 0): 6,
|
||||
((255, 255, 255), (0, 102, 153), 1, 0, 0): 7,
|
||||
((0, 102, 153), (11, 11, 11), 0, 0, 0): 8,
|
||||
})),
|
||||
expected_result_1_8=(
|
||||
'{lead: 0 }'
|
||||
'{leadsep: }{bg: <}{4:h }{bg: }{5: }'
|
||||
'{6:2* | }{7:bash }{4: }{bg: }{cwdhsep: }'
|
||||
'{cwd: S1 string here }', updated(base_attrs, {
|
||||
((0, 102, 153), (11, 11, 11), 0, 0, 0): 4,
|
||||
((11, 11, 11), (0, 102, 153), 0, 0, 0): 5,
|
||||
((102, 204, 255), (0, 102, 153), 0, 0, 0): 6,
|
||||
((255, 255, 255), (0, 102, 153), 1, 0, 0): 7,
|
||||
})),
|
||||
expected_result_2_0=(
|
||||
'{lead: 0 }'
|
||||
'{leadsep: }{bg:<}{4:ash }{bg: }{5: }'
|
||||
'{6:2* | }{7:bash }{4: }{cwdhsep: }'
|
||||
'{cwd: S1 string here }', updated(base_attrs, {
|
||||
((0, 102, 153), (11, 11, 11), 0, 0, 0): 4,
|
||||
((11, 11, 11), (0, 102, 153), 0, 0, 0): 5,
|
||||
((102, 204, 255), (0, 102, 153), 0, 0, 0): 6,
|
||||
((255, 255, 255), (0, 102, 153), 1, 0, 0): 7,
|
||||
})),
|
||||
),
|
||||
'prep_cb': prepare_test_2,
|
||||
'row': dim.rows - 1,
|
||||
}
|
||||
)
|
||||
|
||||
args = [
|
||||
@ -233,7 +235,7 @@ def main(attempts=3):
|
||||
]
|
||||
|
||||
return do_terminal_tests(
|
||||
tests=zip(test_preps, expected_results),
|
||||
tests=tests,
|
||||
cmd=tmux_exe,
|
||||
lib=lib,
|
||||
dim=dim,
|
||||
|
Loading…
x
Reference in New Issue
Block a user