Commit 4ee641d9 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Add filter that filters todos with uncompleted child todos.

parent 4dbcc84d
class Filter(object):
# def __init__(self):
# pass
def filter(self, p_todos, p_limit=None):
"""
Filters a list of todos. Truncates the list after p_limit todo
......@@ -56,3 +53,23 @@ class RelevanceFilter(Filter):
is_due |= p_todo.priority() == 'C' and p_todo.days_till_due() <= 14
return p_todo.is_active() and is_due
class DependencyFilter(Filter):
""" Matches when a todo has no unfinished child tasks. """
def __init__(self, p_todolist):
"""
Constructor.
Pass on a TodoList instance such that the dependencies can be
looked up.
"""
self.todolist = p_todolist
def match(self, p_todo):
"""
Returns True when there are no children that are uncompleted yet.
"""
children = self.todolist.children(p_todo.number)
uncompleted = [todo for todo in children if not todo.is_completed()]
return not uncompleted
......@@ -4,14 +4,11 @@ import datetime
import unittest
import Filter
from TestFacilities import load_file, todolist_to_string
from TestFacilities import load_file, load_file_to_raw_list, todolist_to_string
import Todo
import TodoList
class FilterTest(unittest.TestCase):
def setUp(self):
# self.today = datetime.date.today()
pass
def test_filter1(self):
todo = Todo.Todo("(C) Relevant")
relevance = Filter.RelevanceFilter()
......@@ -65,3 +62,17 @@ class FilterTest(unittest.TestCase):
self.assertEquals(todolist_to_string(filtered_todos), \
todolist_to_string(reference))
def test_filter7(self):
""" Tests the dependency filter. """
todos_raw = load_file_to_raw_list('data/FilterTest2.txt')
todos = load_file('data/FilterTest2.txt')
todolist = TodoList.TodoList(todos_raw)
depfilter = Filter.DependencyFilter(todolist)
filtered_todos = depfilter.filter(todos)
reference = load_file('data/FilterTest2-result.txt')
self.assertEquals(todolist_to_string(filtered_todos), \
todolist_to_string(reference))
Baz p:2
Buzz id:5
x 2014-07-20 Blob p:5
Task 2 p:6
x 2014-07-20 Task 3 p:6
Foo id:1
Bar p:1 id:2
Baz p:2
Buzz id:5
x 2014-07-20 Blob p:5
Task 1 id:6
Task 2 p:6
x 2014-07-20 Task 3 p: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