-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathchkwer_util.py
More file actions
74 lines (60 loc) · 2.45 KB
/
chkwer_util.py
File metadata and controls
74 lines (60 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import sys
from io import StringIO
from sinol_make import util
from sinol_make.commands.inwer.inwer_util import sort_tests
from sinol_make.structs.chkwer_structs import TableData
def print_view(term_width, term_height, table_data: TableData):
"""
Prints current results of test verification.
"""
previous_stdout = sys.stdout
new_stdout = StringIO()
sys.stdout = new_stdout
results = table_data.results
column_lengths = [0, len('Points') + 1, 0]
tests = []
for result in results.values():
column_lengths[0] = max(column_lengths[0], len(result.test_name))
tests.append(result.test_path)
tests = sort_tests(tests, table_data.task_id)
# 6 is for " | " between columns, 3 for margin.
column_lengths[2] = max(10, term_width - column_lengths[0] - column_lengths[1] - 6 - 3)
margin = " "
def print_line_separator():
res = "-" * (column_lengths[0] + 3) + "+" + "-" * (column_lengths[1] + 1) + "+"
res += "-" * (term_width - len(res) - 1)
print(res)
print_line_separator()
print(margin + "Test".ljust(column_lengths[0]) + " | " + "Points" + " | " + "Comment")
print_line_separator()
last_group = None
for test_path in tests:
result = results[test_path]
if last_group is not None and last_group != result.test_group:
print_line_separator()
last_group = result.test_group
print(margin + result.test_name.ljust(column_lengths[0]) + " | ", end='')
if result.run:
if result.ok:
if result.points == table_data.max_score:
print(util.info(str(result.points).ljust(column_lengths[1] - 1)), end='')
else:
print(util.warning(str(result.points).ljust(column_lengths[1] - 1)), end='')
else:
print(util.error(str(result.points).ljust(column_lengths[1] - 1)), end='')
else:
print(util.warning("...".ljust(column_lengths[1] - 1)), end='')
print(" | ", end='')
output = []
if result.run:
if result.stderr != "":
print(util.error("stderr:"), result.stderr, end=' | ')
elif result.comment:
print(result.comment)
else:
print(util.color_gray("No comment"))
print_line_separator()
print()
print()
sys.stdout = previous_stdout
return new_stdout.getvalue().splitlines(), None, "Use arrows to move."