Commit 94c2d5cb authored by Bram Schoenmakers's avatar Bram Schoenmakers

Add test for printing the todos.

Make sure the content is preserved byte by byte.
parent b53b24af
...@@ -161,4 +161,4 @@ class TodoBase(object): ...@@ -161,4 +161,4 @@ class TodoBase(object):
def __str__(self): def __str__(self):
""" A printer for the todo item. """ """ A printer for the todo item. """
print self.source() + "\n" return self.source()
...@@ -99,12 +99,9 @@ class TodoList(object): ...@@ -99,12 +99,9 @@ class TodoList(object):
defined by the end user. Todos is this list should not be modified, defined by the end user. Todos is this list should not be modified,
modifications should occur through this class. modifications should occur through this class.
""" """
# TODO: perhaps change list such that values are immutable?
return p_filter.filter(p_sorter.sort(self._todos)) return p_filter.filter(p_sorter.sort(self._todos))
def __str__(self): def __str__(self):
result = "" return '\n'.join([str(x) for x in self._todos])
for todo in self._todos:
result = "%s" % todo
return result
...@@ -9,7 +9,9 @@ import TodoList ...@@ -9,7 +9,9 @@ import TodoList
class TodoListTester(unittest.TestCase): class TodoListTester(unittest.TestCase):
def setUp(self): def setUp(self):
self.todofile = TodoFile.TodoFile('TodoListTest.txt') self.todofile = TodoFile.TodoFile('TodoListTest.txt')
self.todolist = TodoList.TodoList(self.todofile.read()) lines = self.todofile.read()
self.text = ''.join(lines)
self.todolist = TodoList.TodoList(lines)
def test_contexts(self): def test_contexts(self):
self.assertEquals(set(['Context1', 'Context2']), \ self.assertEquals(set(['Context1', 'Context2']), \
...@@ -78,3 +80,9 @@ class TodoListTester(unittest.TestCase): ...@@ -78,3 +80,9 @@ class TodoListTester(unittest.TestCase):
self.assertTrue(self.todolist.todo(1).is_completed()) self.assertTrue(self.todolist.todo(1).is_completed())
self.assertEquals(self.todolist.todo(1).source(), \ self.assertEquals(self.todolist.todo(1).source(), \
"x " + today + " Foo @Context1 Not@Context +Project1 Not+Project") "x " + today + " Foo @Context1 Not@Context +Project1 Not+Project")
def test_string(self):
# readlines() always ends a string with \n, but join() in str(todolist)
# doesn't necessarily.
self.assertEquals(str(self.todolist) + '\n', self.text)
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