Skip to content

Commit 1724211

Browse files
Totktonadaylobankov
authored andcommitted
Adjust test result report width to terminal size
Now the test configuration name is not trimmed if the terminal width allows it. The idea can be illustrated this way: ``` +----------------------------------------------------------------------+ | Wide terminal | +----------------------------------------------------------------------+ | suite/mytest_test.lua my_configuration [ pass ] | +----------------------------------------------------------------------+ +-------------------------------------------------+ | Narrow terminal | +-------------------------------------------------+ | suite/mytest_test.lua my_configur> [ pass ] | +-------------------------------------------------+ ``` I want to add support for ability to run test cases as separate parallel tasks for luatest based tests with reporting of the test case name as a test configuration to the terminal. The test case names sometimes are quite long and it is convenient to see as much symbols from it as possible. At the same time, the configuration name is stripped if the terminal has a low width. This way the output look good as on a wide as well as on a narrow terminal. The feature works on Python 3.3+.
1 parent 81259c4 commit 1724211

File tree

4 files changed

+55
-25
lines changed

4 files changed

+55
-25
lines changed

lib/colorer.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,28 @@ def final_report(*args, **kwargs):
6363
f.write(data)
6464

6565

66+
def separator(sep):
67+
# Import from the function to avoid recursive import.
68+
from lib.utils import terminal_columns
69+
70+
columns = terminal_columns()
71+
color_stdout(sep * columns, '\n', schema='separator')
72+
73+
74+
def test_line(name, conf=None):
75+
# Import from the function to avoid recursive import.
76+
from lib.utils import terminal_columns
77+
from lib.utils import just_and_trim
78+
79+
columns = terminal_columns()
80+
81+
color_stdout(just_and_trim(name, 47) + ' ', schema='t_name')
82+
83+
if conf is None:
84+
conf = ''
85+
color_stdout(just_and_trim(conf, columns - 67) + ' ', schema='test_var')
86+
87+
6688
class CSchema(object):
6789
objects = {}
6890

lib/test_suite.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
from lib.app_server import AppServer
1616
from lib.luatest_server import LuatestServer
1717
from lib.colorer import color_stdout
18+
from lib.colorer import test_line
1819
from lib.inspector import TarantoolInspector
1920
from lib.server import Server
2021
from lib.tarantool_server import TarantoolServer
2122
from lib.unittest_server import UnittestServer
22-
from lib.utils import just_and_trim
2323

2424

2525
class ConfigurationError(RuntimeError):
@@ -217,7 +217,7 @@ def gen_server(self):
217217

218218
def is_test_enabled(self, test, conf, server):
219219
test_name = os.path.basename(test.name)
220-
tconf = '%s:%s' % (test_name, conf)
220+
tconf = '%s:%s' % (test_name, conf or '')
221221
checks = [
222222
(True, self.ini["disabled"]),
223223
(not server.debug, self.ini["release_disabled"]),
@@ -264,16 +264,10 @@ def run_test(self, test, server, inspector):
264264
test.inspector = inspector
265265
test_name = os.path.basename(test.name)
266266
full_test_name = os.path.join(self.ini['suite'], test_name)
267-
color_stdout(just_and_trim(full_test_name, 47) + ' ', schema='t_name')
268-
# for better diagnostics in case of a long-running test
269-
270-
conf = ''
271-
if test.run_params:
272-
conf = test.conf_name
273-
color_stdout(just_and_trim(conf, 15) + ' ', schema='test_var')
267+
test_line(full_test_name, test.conf_name)
274268

275269
start_time = time.time()
276-
if self.is_test_enabled(test, conf, server):
270+
if self.is_test_enabled(test, test.conf_name, server):
277271
short_status = test.run(server)
278272
else:
279273
color_stdout("[ disabled ]\n", schema='t_name')

lib/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
# Python 2.7.
2525
from pipes import quote as _shlex_quote
2626

27+
try:
28+
# Python 3.3+.
29+
from shutil import get_terminal_size
30+
except ImportError:
31+
# Python 2.7.
32+
get_terminal_size = None
2733

2834
UNIX_SOCKET_LEN_LIMIT = 107
2935

@@ -372,3 +378,9 @@ def prepend_path(p):
372378

373379
def shlex_quote(s):
374380
return _shlex_quote(s)
381+
382+
383+
def terminal_columns():
384+
if get_terminal_size:
385+
return get_terminal_size().columns
386+
return 80

test-run.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
from lib import Options
5757
from lib import saved_env
5858
from lib.colorer import color_stdout
59+
from lib.colorer import separator
60+
from lib.colorer import test_line
5961
from lib.utils import find_tags
6062
from lib.utils import shlex_quote
6163
from lib.error import TestRunInitError
@@ -114,18 +116,18 @@ def main_loop_parallel():
114116

115117
print_greetings()
116118

117-
color_stdout("\n", '=' * 86, "\n", schema='separator')
118-
color_stdout("WORKR".ljust(6), schema='t_name')
119-
color_stdout("TEST".ljust(48), schema='t_name')
120-
color_stdout("PARAMS".ljust(16), schema='test_var')
121-
color_stdout("RESULT\n", schema='test_pass')
122-
color_stdout('-' * 81, "\n", schema='separator')
119+
color_stdout('\n')
120+
separator('=')
121+
color_stdout('WORKR ', schema='t_name')
122+
test_line('TEST', 'RARAMS')
123+
color_stdout('RESULT\n', schema='test_pass')
124+
separator('-')
123125

124126
try:
125127
is_force = Options().args.is_force
126128
dispatcher.wait()
127129
dispatcher.wait_processes()
128-
color_stdout('-' * 81, "\n", schema='separator')
130+
separator('-')
129131
has_failed, has_flaked = dispatcher.statistics.print_statistics()
130132
has_undone = dispatcher.report_undone(
131133
verbose=bool(is_force or not has_failed))
@@ -136,12 +138,12 @@ def main_loop_parallel():
136138
if has_undone:
137139
return EXIT_NOTDONE_TEST
138140
except KeyboardInterrupt:
139-
color_stdout('-' * 81, "\n", schema='separator')
141+
separator('-')
140142
dispatcher.statistics.print_statistics()
141143
dispatcher.report_undone(verbose=False)
142144
raise
143145
except HangError:
144-
color_stdout('-' * 81, "\n", schema='separator')
146+
separator('-')
145147
dispatcher.statistics.print_statistics()
146148
dispatcher.report_undone(verbose=False)
147149
return EXIT_HANG
@@ -167,11 +169,11 @@ def main_loop_consistent(failed_test_ids):
167169

168170
for name, task_group in task_groups:
169171
# print information about current test suite
170-
color_stdout("\n", '=' * 80, "\n", schema='separator')
171-
color_stdout("TEST".ljust(48), schema='t_name')
172-
color_stdout("PARAMS".ljust(16), schema='test_var')
173-
color_stdout("RESULT\n", schema='test_pass')
174-
color_stdout('-' * 75, "\n", schema='separator')
172+
color_stdout('\n')
173+
separator('=')
174+
test_line('TEST', 'RARAMS')
175+
color_stdout("RESULT\n", schema='test_pass')
176+
separator('-')
175177

176178
task_ids = task_group['task_ids']
177179
show_reproduce_content = task_group['show_reproduce_content']
@@ -198,7 +200,7 @@ def main_loop_consistent(failed_test_ids):
198200
worker.stop_server(cleanup=False)
199201
return
200202

201-
color_stdout('-' * 75, "\n", schema='separator')
203+
separator('-')
202204

203205
worker.stop_server(silent=False)
204206
color_stdout()

0 commit comments

Comments
 (0)