Commit d9c983ff authored by Bram Schoenmakers's avatar Bram Schoenmakers

Merge branch 'cleandeps'

parents 3927ddf7 7ff76a2d
......@@ -200,6 +200,24 @@ class TodoList(object):
self._depgraph.outgoing_neighbors(p_number, not p_only_direct)
return [self.todo(child) for child in children]
def clean_dependencies(self):
"""
Cleans the dependency graph.
This is achieved by performing a transitive reduction on the dependency
graph and removing unused dependency ids from the graph (in that
order).
"""
def clean_by_tag(tag_name):
for todo in [todo for todo in self._todos if todo.has_tag(tag_name)]:
value = todo.tag_value(tag_name)
if not self._depgraph.has_edge_id(value):
todo.remove_tag(tag_name, value)
self._depgraph.transitively_reduce()
clean_by_tag('p')
clean_by_tag('id')
def __str__(self):
return '\n'.join(pretty_print(self._todos))
......@@ -180,3 +180,18 @@ class TodoListDependencyTester(unittest.TestCase):
self.assertEqual(self.todolist.todo(1).source(), 'Foo id:1')
self.assertEqual(self.todolist.todo(2).source(), 'Bar p:1')
class TodoListCleanDependencyTester(unittest.TestCase):
def setUp(self):
self.todolist = TodoList.TodoList([])
self.todolist.add("Bar p:1")
self.todolist.add("Baz p:1 id:2")
self.todolist.add("Buzz p:2")
def test_clean_dependencies(self):
self.todolist.clean_dependencies()
self.assertFalse(self.todolist.todo(1).has_tag('p'))
self.assertFalse(self.todolist.todo(2).has_tag('p'))
self.assertTrue(self.todolist.todo(2).has_tag('id', '2'))
self.assertTrue(self.todolist.todo(3).has_tag('p', '2'))
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