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:
|
||||
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,6 +112,14 @@ def main(attempts=3):
|
||||
|
||||
dim = MutableDimensions(rows=50, cols=200)
|
||||
|
||||
def prepare_test_1(p):
|
||||
sleep(5)
|
||||
|
||||
def prepare_test_2(p):
|
||||
dim.cols = 40
|
||||
p.resize(dim)
|
||||
sleep(5)
|
||||
|
||||
base_attrs = {
|
||||
((0, 0, 0), (243, 243, 243), 1, 0, 0): 'lead',
|
||||
((243, 243, 243), (11, 11, 11), 0, 0, 0): 'leadsep',
|
||||
@ -120,8 +128,9 @@ def main(attempts=3):
|
||||
((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(
|
||||
tests = (
|
||||
{
|
||||
'expected_result': get_expected_result(
|
||||
tmux_version,
|
||||
expected_result_old=(
|
||||
'{lead: 0 }{leadsep: }{bg: S2 string here }'
|
||||
@ -166,7 +175,10 @@ def main(attempts=3):
|
||||
((255, 255, 255), (0, 102, 153), 1, 0, 0): 10,
|
||||
})),
|
||||
),
|
||||
get_expected_result(
|
||||
'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=(
|
||||
@ -201,19 +213,9 @@ def main(attempts=3):
|
||||
((255, 255, 255), (0, 102, 153), 1, 0, 0): 7,
|
||||
})),
|
||||
),
|
||||
)
|
||||
|
||||
def prepare_test_1(p):
|
||||
sleep(5)
|
||||
|
||||
def prepare_test_2(p):
|
||||
dim.cols = 40
|
||||
p.resize(dim)
|
||||
sleep(5)
|
||||
|
||||
test_preps = (
|
||||
prepare_test_1,
|
||||
prepare_test_2,
|
||||
'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