Skip to content

Commit

Permalink
improved ftest, but still couldn't manage to reproduce some bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tobixen committed Sep 6, 2023
1 parent 9ecf8da commit 190fa54
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 32 deletions.
3 changes: 1 addition & 2 deletions plann/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def _list(objs, ics=False, template="{DTSTART:?{DUE:?(date missing)?}?%F %H:%M:%
TODO: will crash if there are loops in the relationships
TODO: if there are parent/child-relationships that aren't bidrectionally linked, we may get problems
"""
if indent>8:
if indent>32:
import pdb; pdb.set_trace()
if ics:
if not objs:
Expand Down Expand Up @@ -1253,7 +1253,6 @@ def interactive_split_task(obj, partially_complete=False, too_big=True):
break
new_estimate_suggestion = f"{estimate.total_seconds()//3600//cnt+1}h"
new_estimate = click.prompt("what is the remaining estimate for the parent task?", default=new_estimate_suggestion)
import pdb; pdb.set_trace()
obj.set_duration(parse_add_dur(None, new_estimate), movable_attr='DTSTART') ## TODO: verify
new_summary = click.prompt("Summary of the parent task?", default=obj.icalendar_component['SUMMARY'])
obj.icalendar_component['SUMMARY'] = new_summary
Expand Down
1 change: 1 addition & 0 deletions plann/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ def _relships_by_type(obj, reltype_wanted=None):
## Inconsistency will be automatically fixed: no related-to property pointing from other to obj
## adding the missing back rel
other.icalendar_component.add('RELATED-TO', str(obj.icalendar_component['UID']), parameters={'RELTYPE': backreltypes[reltype]})
other.save()
else:
if back_rel_types != { backreltypes[reltype] }:
import pdb; pdb.set_trace()
Expand Down
65 changes: 35 additions & 30 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,19 @@ def test_plann():
ctx.obj = dict()
ctx.obj['calendars'] = find_calendars(conn_details, raise_errors=True)

def dag(obj, reltype, observed=None):
if not hasattr(obj, 'get_relatives'):
obj = ctx.obj['calendars'][0].object_by_uid(obj)
if not observed:
observed = set()
ret = {}
relatives = obj.get_relatives(reltypes={reltype}, fetch_objects=False)
for x in relatives[reltype]:
assert x not in observed
observed.add(x)
ret[x] = dag(x, reltype, observed)
return ret

## We create two tasks todo1 and todo2, todo2 being a child of todo1
todo1 = _add_todo(ctx, summary=['make plann good'], set_due='2012-12-20 23:15:00', set_dtstart='2012-12-20 22:15:00')
uid1 = str(todo1.icalendar_component['uid'])
Expand All @@ -177,6 +190,8 @@ def test_plann():
## assert that relations are as expected
todo1.load()
todo2.load()
assert(dag(todo1, 'CHILD') == {uid2: {}})
assert(dag(todo2, 'PARENT') == {uid1: {}})
assert(not _adjust_ical_relations(todo1, {'CHILD': {uid2}, 'PARENT': set()}))
assert(not _adjust_ical_relations(todo2, {'PARENT': {uid1}, 'CHILD': set()}))

Expand Down Expand Up @@ -271,44 +286,34 @@ def test_plann():
## Let's add some more tasks
todo3 = _add_todo(ctx, summary=['fix some more features in plann'], set_parent=[uid1], set_due='2012-12-21 23:15:00', set_dtstart='2012-12-21 22:15:00')
todo4 = _add_todo(ctx, summary=['make plann even better'], set_parent=[uid1], set_due='2012-12-21 23:15:00', set_dtstart='2012-12-21 22:15:00')
#todo5 = _add_todo(ctx, summary=['use plann on a daily basis to find more bugs and missing features'], set_parent=[uid1], set_due='2012-12-21 23:15:00', set_dtstart='2012-12-21 22:15:00')
todo5 = _add_todo(ctx, summary=['use plann on a daily basis to find more bugs and missing features'], set_parent=[uid1], set_due='2012-12-21 23:15:00', set_dtstart='2012-12-21 22:15:00')

uid3 = str(todo2.icalendar_component['uid'])
uid4 = str(todo3.icalendar_component['uid'])
#uid5 = str(todo4.icalendar_component['uid'])
uid3 = str(todo3.icalendar_component['uid'])
uid4 = str(todo4.icalendar_component['uid'])
uid5 = str(todo5.icalendar_component['uid'])

_select(ctx, todo=True)
cal_post_interactive_relation_edit = "\n".join([x.data for x in ctx.obj['objs']])

## Let's add some incremental indentation to all lines - making every task except one having one child
todo1.load()
assert(dag(todo1, 'CHILD') == {uid2: {}, uid3: {}, uid4: {}, uid5: {}})
assert(dag(todo4, 'PARENT') == {uid1: {}})

## Let's add some incremental indentation to the last lines.
## This one will leave todo1 with two children, then the next lines are indented more.
def add_indent(text):
i = 0
ret = ""
for x in text.split("\n"):
ret += " "*i
ret += x
ret += "\n"
i += 1
return ret
return f"{uid1}: todo1\n {uid2}: todo2\n {uid3}: todo3\n {uid4}: todo4\n {uid5}: todo5"
with patch('plann.cli._editor', new=add_indent) as _editor:
_interactive_relation_edit((ctx.obj['objs']))
_interactive_relation_edit([todo1])

for obj in ctx.obj['objs']:
## Reload the object list
for obj in (todo1, todo2, todo3, todo4, todo5):
obj.load()

cal_post_interactive_relation_edit = "\n".join([x.data for x in ctx.obj['objs']])
assert cal_post_interactive_relation_edit != cal_pre_interactive_relation_edit
assert(dag(todo1, 'CHILD') == {uid2: {}, uid3: {uid4: {uid5: {}}}})
assert(dag(todo2, 'PARENT') == {uid1: {}})
assert(dag(todo5, 'PARENT') == {uid4: {uid3: {uid1: {}}}})

## This should not throw one into the debugger
list_td = _list(ctx, top_down=True)

## Check that, except for one root node and one leaf node, all tasks have a child and a parent
termcnt = 0
for obj in ctx.obj['objs']:
rels = obj.get_relatives(fetch_objects=False)
rel_num = len(rels.get('CHILD', set()).union(rels.get('PARENT', set())))
assert rel_num in (1,2)
if rel_num == 1:
termcnt += 1
assert termcnt == 2

finally:
stop_xandikos_server(conn_details)

Expand Down

0 comments on commit 190fa54

Please sign in to comment.