Skip to content

Commit

Permalink
Change order of tests in inwer
Browse files Browse the repository at this point in the history
  • Loading branch information
MasloMaslane committed Sep 25, 2023
1 parent 1b16738 commit 74c882b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/sinol_make/commands/inwer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def verify_and_print_table(self) -> Dict[str, TestResult]:

has_terminal, terminal_width, terminal_height = util.get_terminal_size()

table_data = TableData(results, 0)
table_data = TableData(results, 0, self.task_id)
if has_terminal:
run_event = threading.Event()
run_event.set()
Expand Down
14 changes: 10 additions & 4 deletions src/sinol_make/commands/inwer/inwer_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ def compile_inwer(inwer_path: str, args: argparse.Namespace, weak_compilation_fl
return compile.compile_file(inwer_path, package_util.get_executable(inwer_path), compilers, weak_compilation_flags)


def sort_tests(tests, task_id):
# First sort by group, then by test name.
tests.sort(key=lambda test: [package_util.get_group(test, task_id), test])
return tests


def print_view(term_width, term_height, table_data: TableData):
"""
Prints current results of test verification.
Expand All @@ -48,12 +54,12 @@ def print_view(term_width, term_height, table_data: TableData):

results = table_data.results
column_lengths = [0, len('Group') + 1, len('Status') + 1, 0]
sorted_test_paths = []
tests = []
for result in results.values():
column_lengths[0] = max(column_lengths[0], len(result.test_name))
column_lengths[1] = max(column_lengths[1], len(result.test_group))
sorted_test_paths.append(result.test_path)
sorted_test_paths.sort()
tests.append(result.test_path)
tests = sort_tests(tests, table_data.task_id)

column_lengths[3] = max(10, term_width - column_lengths[0] - column_lengths[1] - column_lengths[2] - 9 - 3) # 9 is for " | " between columns, 3 for margin.
margin = " "
Expand All @@ -69,7 +75,7 @@ def print_line_separator():
" | " + "Output")
print_line_separator()

for test_path in sorted_test_paths:
for test_path in tests:
result = results[test_path]
print(margin + result.test_name.ljust(column_lengths[0]) + " | ", end='')
print(result.test_group.ljust(column_lengths[1] - 1) + " | ", end='')
Expand Down
3 changes: 3 additions & 0 deletions src/sinol_make/structs/inwer_structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class TableData:
# Number of executions finished
i: int

# Task id
task_id: str

@dataclass
class InwerExecution:
test_path: str
Expand Down
11 changes: 11 additions & 0 deletions tests/commands/inwer/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,14 @@ def test_asserting_inwer(create_package):
print(res.output)
print(assertion_re.match(res.output))
assert assertion_re.match(res.output) is not None


def test_tests_comparator():
for ti in ["abc", "long_task_id", ""]:
assert inwer_util.sort_tests([f"{ti}2a.in", f"{ti}1a.in"], ti) == [f"{ti}1a.in", f"{ti}2a.in"]
assert inwer_util.sort_tests([f"{ti}2a.in", f"{ti}1a.in", f"{ti}1b.in"], ti) == \
[f"{ti}1a.in", f"{ti}1b.in", f"{ti}2a.in"]
assert inwer_util.sort_tests([f"{ti}2a.in", f"{ti}1a.in", f"{ti}1b.in", f"{ti}10a.in"], ti) == \
[f"{ti}1a.in", f"{ti}1b.in", f"{ti}2a.in", f"{ti}10a.in"]
assert inwer_util.sort_tests([f"{ti}2a.in", f"{ti}1a.in", f"{ti}1b.in", f"{ti}10a.in", f"{ti}10b.in"], ti) == \
[f"{ti}1a.in", f"{ti}1b.in", f"{ti}2a.in", f"{ti}10a.in", f"{ti}10b.in"]

0 comments on commit 74c882b

Please sign in to comment.