Commit 5b379050 authored by Michał Góral's avatar Michał Góral

Not working groupng test

parent 55a04e20
Pipeline #56864199 failed with stage
in 1 minute and 39 seconds
......@@ -96,27 +96,23 @@ def group_tasks(tasks):
Tasks are grouped by their `depends` field: parent tasks depend on
children.'''
grouped = OrderedDict([(t['uuid'], t) for t in tasks])
alldeps = set()
for t in tasks:
depth = t.setdefault('_depth', 0)
if 'depends' in t:
deps = t['depends'].split(',')
for dep_uuid in deps:
deps = t.get('depends')
if deps:
for dep_uuid in deps.split(','):
dep = grouped.get(dep_uuid)
if dep:
alldeps.add(dep_uuid)
dep['_depth'] = depth + 1
t.setdefault('_children', []).append(dep)
for dep in alldeps:
del grouped[dep]
del grouped[dep_uuid]
return grouped
def dfs(tasks):
'''Depth-first-search walk through tasks grouped by group_tasks()'''
stack = deque(list(tasks.values()))
stack = deque(tasks)
while stack:
task = stack.pop()
yield task
......
......@@ -71,7 +71,7 @@ class BlockView(urwid.BoxAdapter):
focus_map[None] = 'text-focus'
textboxes = []
for task in twutils.dfs(self.tasks):
for task in twutils.dfs(list(self.tasks.values())):
indent = ' ' * task['_depth'] * 2
fmt = indent + self.block.fmt
textboxes.append(
......
import copy
import itertools
from collections import OrderedDict
import pytest
import twc.twutils as twutils
def perms(*a, **kw):
return list(itertools.permutations(*a, **kw))
def _gen_tasks():
return perms([
{'uuid': '0'},
{'uuid': '1', 'depends': '2,3,4'}, # p
{'uuid': '2', 'depends': '5'}, # p, ch
{'uuid': '4'}, # ch
{'uuid': '5', 'depends': '6'}, # ch, 2nd level
{'uuid': '6'}, # ch, 3rd level
])
def _find_children_order(tasks, uuids):
i = 0
found = []
for t in tasks:
if t['uuid'] == str(uuids[i]):
found.append(t)
i += 1
return found
@pytest.fixture(params=_gen_tasks())
def tasks(request):
return request.param
def test_grouping(tasks):
tasks = copy.deepcopy(tasks)
td = {t['uuid']: t for t in tasks}
grouped = twutils.group_tasks(tasks)
assert tuple(grouped.keys()) in perms(['0', '1'])
assert grouped['0']['_depth'] == 0
assert '_children' not in grouped['0']
assert grouped['1']['_depth'] == 0
assert tuple(grouped['1']['_children']) in perms([td['2'], td['4']])
assert td['2']['_depth'] == 1
assert td['2']['_children'] == [td['5']]
assert td['4']['_depth'] == 1
assert '_children' not in td['4']
assert td['5']['_depth'] == 2
assert td['5']['_children'] == [td['6']]
assert td['6']['_depth'] == 3
assert '_children' not in td['6']
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment