Commit 57e89685 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Throw InvalidTodoException when the regex doesn't have exactly 1 hit.

parent a7d51550
......@@ -86,7 +86,7 @@ class DeleteCommandTest(CommandTest.CommandTest):
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n")
self.assertEquals(self.errors, "Invalid todo number given.\n")
def test_empty(self):
command = DeleteCommand.DeleteCommand([], self.todolist, self.out, self.error)
......
......@@ -138,7 +138,7 @@ class DoCommandTest(CommandTest.CommandTest):
self.assertFalse(self.todolist.is_dirty())
self.assertFalse(self.output)
self.assertEquals(self.errors, command.usage() + "\n")
self.assertEquals(self.errors, "Invalid todo number given.\n")
def test_activated_todos1(self):
command = DoCommand.DoCommand(["2"], self.todolist, self.out, self.error)
......
......@@ -182,11 +182,11 @@ class TodoListTester(unittest.TestCase):
self.assertTrue(self.todolist.is_dirty())
def test_regex1(self):
self.assertFalse(self.todolist.todo("1"))
self.assertRaises(TodoList.InvalidTodoException, self.todolist.todo, "1")
def test_regex2(self):
""" Multiple hits should result in None. """
self.assertFalse(self.todolist.todo("Project1"))
self.assertRaises(TodoList.InvalidTodoException, self.todolist.todo, "Project1")
def test_regex3(self):
todo = self.todolist.todo("project2")
......
......@@ -41,9 +41,11 @@ class DCommand(Command):
except (InvalidCommandArgument, InvalidTodoException):
self.todo = None
except InvalidTodoNumberException:
self.todo = self.todolist.todo(self.argument(0))
if self.todo:
try:
self.todo = self.todolist.todo(self.argument(0))
self.number = self.todolist.number(self.todo)
except InvalidTodoException:
self.todo = None
def _uncompleted_children(self, p_todo):
return sorted([t for t in self.todolist.children(p_todo) if not t.is_completed()])
......@@ -115,16 +117,16 @@ class DCommand(Command):
if not super(DCommand, self).execute():
return False
if not self.number:
if len(self.args) == 0:
self.error(self.usage())
elif not self.todo:
self.error("Invalid todo number given.")
elif self.todo and self.condition():
old_active = self._active_todos()
self._process_subtasks()
self.execute_specific()
current_active = self._active_todos()
self._print_unlocked_todos(old_active, current_active)
elif not self.todo:
self.error("Invalid todo number given.")
else:
self.error(self.condition_failed_text())
......@@ -78,6 +78,8 @@ class TodoList(object):
if len(candidates) == 1:
result = candidates[0]
else:
raise InvalidTodoException
return result
......
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