Commit 4074887e authored by Bram Schoenmakers's avatar Bram Schoenmakers

Deal with empty lines.

A line is considered a todo item when it contains at least one
non-whitespace character.
parent 23e7aa49
......@@ -2,6 +2,8 @@
A list of todo items.
"""
import re
import Todo
class TodoList(object):
......@@ -20,7 +22,7 @@ class TodoList(object):
"""
self._todos = []
for string in p_todostrings:
self._todos.append(Todo.Todo(string))
self.add(string)
def todo(self, p_number):
"""
......@@ -40,8 +42,10 @@ class TodoList(object):
"""
Given a todo string, parse it and put it to the end of the list.
"""
todo = Todo.Todo(p_src)
self._todos.append(todo)
if re.search(r'\S', p_src):
todo = Todo.Todo(p_src)
self._todos.append(todo)
def delete(self, p_number):
""" Deletes a todo item from the list. """
......
""" Tests for the TodoList class. """
import datetime
import re
import unittest
import TodoFile
......@@ -9,7 +10,8 @@ import TodoList
class TodoListTester(unittest.TestCase):
def setUp(self):
self.todofile = TodoFile.TodoFile('TodoListTest.txt')
lines = self.todofile.read()
lines = [line for line in self.todofile.read() \
if re.search(r'\S', line)]
self.text = ''.join(lines)
self.todolist = TodoList.TodoList(lines)
......@@ -86,3 +88,7 @@ class TodoListTester(unittest.TestCase):
# readlines() always ends a string with \n, but join() in str(todolist)
# doesn't necessarily.
self.assertEquals(str(self.todolist) + '\n', self.text)
def test_count(self):
""" Test that empty lines are not counted. """
self.assertEquals(self.todolist.count(), 5)
......@@ -2,4 +2,5 @@
(D) Bar @Context2 +Project2
(C) Baz @Context1 +Project1 key:value
(C) Drink beer @ home
(C) 13 + 29 = 42
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