Commit 0b1d1139 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Add method to mark a todo as completed.

parent 391a7283
......@@ -2,6 +2,7 @@
This module contains the class that represents a single todo item.
"""
import datetime
import re
import TodoParser
......@@ -135,6 +136,18 @@ class TodoBase(object):
""" Returns True iff this todo has been completed. """
return self.fields['completed']
def set_completed(self):
"""
Marks the todo as complete.
Sets the completed flag and sets the completion date to today.
"""
self.fields['completed'] = True
today = datetime.date.today()
self.fields['completionDate'] = today
self.src = re.sub(r'^(\([A-Z]\) )?', \
'x ' + today.isoformat() + ' ', self.src)
def __print__(self):
""" A printer for the todo item. """
print self.src + "\n"
""" Tests for the TodoBase class. """
import datetime
import re
import unittest
......@@ -144,5 +145,37 @@ class TodoBaseTester(unittest.TestCase):
self.assertFalse(todo.is_completed())
def test_set_complete1(self):
todo = TodoBase.TodoBase("(A) Foo")
todo.set_completed()
today = datetime.date.today().isoformat()
self.assertTrue(re.match('^x ' + today + ' Foo', todo.src))
def test_set_complete2(self):
todo = TodoBase.TodoBase("2014-06-12 Foo")
todo.set_completed()
today = datetime.date.today().isoformat()
self.assertTrue(re.match('^x ' + today + ' 2014-06-12 Foo', todo.src))
def test_set_complete3(self):
todo = TodoBase.TodoBase("Foo")
todo.set_completed()
today = datetime.date.today().isoformat()
self.assertTrue(re.match('^x ' + today + ' Foo', todo.src))
def test_set_complete4(self):
todo = TodoBase.TodoBase("(A) 2014-06-12 Foo")
todo.set_completed()
today = datetime.date.today().isoformat()
self.assertTrue(re.match('^x ' + today + ' 2014-06-12 Foo', todo.src))
if __name__ == '__main__':
unittest.main()
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