mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-17 15:50:53 +07:00
When we see test runner in "commands" section of tox, we substitute it with our test runners so user may benefit from test trees. We also pass "offset" because test runners must use it as "parent node". Set "_jb_do_not_patch_test_runners" to disable this substitution (cherry picked from commit c7d469e1fed52f2d7fe3aec6d96b665c4aa80a4e) GitOrigin-RevId: b9eec43a6d26fecb72270b733266ef31989fec2c
74 lines
2.4 KiB
Python
74 lines
2.4 KiB
Python
# coding=utf-8
|
|
|
|
|
|
class ParallelTreeManager(object):
|
|
"""
|
|
Manages output tree by building it from flat test names.
|
|
"""
|
|
|
|
def __init__(self, offset):
|
|
super(ParallelTreeManager, self).__init__()
|
|
self._max_node_id = offset
|
|
self.offset = offset
|
|
self._branches = dict() # key is test name as tuple, value is tuple of test_id, parent_id
|
|
|
|
def _next_node_id(self):
|
|
self._max_node_id += 1
|
|
return self._max_node_id
|
|
|
|
def level_opened(self, test_as_list, func_to_open):
|
|
"""
|
|
To be called on test start.
|
|
|
|
:param test_as_list: test name splitted as list
|
|
:param func_to_open: func to be called if test can open new level
|
|
:return: None if new level opened, or tuple of command client should execute and try opening level again
|
|
Command is "open" (open provided level) or "close" (close it). Second item is test name as list
|
|
"""
|
|
|
|
if tuple(test_as_list) in self._branches:
|
|
# We have parent, ok
|
|
func_to_open()
|
|
return None
|
|
elif len(test_as_list) == 1:
|
|
self._branches[tuple(test_as_list)] = (self._next_node_id(), self.offset)
|
|
func_to_open()
|
|
return None
|
|
|
|
commands = []
|
|
|
|
parent_id = self.offset
|
|
for i in range(len(test_as_list)):
|
|
tmp_parent_as_list = test_as_list[0:i + 1]
|
|
try:
|
|
parent_id, _ = self._branches[tuple(tmp_parent_as_list)]
|
|
except KeyError:
|
|
node_id = self._next_node_id()
|
|
self._branches[tuple(tmp_parent_as_list)] = (node_id, parent_id)
|
|
parent_id = node_id
|
|
if tmp_parent_as_list != test_as_list: # Different test opened
|
|
commands.append(("open", tmp_parent_as_list))
|
|
if commands:
|
|
return commands
|
|
else:
|
|
func_to_open()
|
|
|
|
def level_closed(self, test_as_list, func_to_close):
|
|
"""
|
|
To be called on test end or failure.
|
|
|
|
See level_opened doc.
|
|
"""
|
|
func_to_close()
|
|
|
|
# Part of contract
|
|
def get_node_ids(self, test_name):
|
|
"""
|
|
|
|
:return: (current_node_id, parent_node_id) or None, None if message must be ignored
|
|
"""
|
|
try:
|
|
return self._branches[tuple(test_name.split("."))]
|
|
except KeyError:
|
|
return None, None
|