Skip to content
Browse files

Raise TaskNotFound exception on closing wrond task id.

  • Loading branch information...
1 parent a6c432e commit d4cc2bee83a548b12f3c22f2f534c82b148a775b @svetlyak40wt committed
Showing with 18 additions and 2 deletions.
  1. +7 −2 gtd
  2. +6 −0 gtdzen/__init__.py
  3. +1 −0 gtdzen/exceptions.py
  4. +4 −0 tests/task_tests.py
View
9 gtd
@@ -13,6 +13,8 @@ from ConfigParser import ConfigParser
from datetime import date
from pdb import set_trace
+from gtdzen.exceptions import *
+
_language, _encoding = locale.getdefaultlocale()
def output(text):
@@ -165,8 +167,11 @@ class CommandUI:
"Close task or tasks."
for task_id in _parse_ids(task_ids):
- self.gtd.closeTask(task_id)
- output(u'Task %s was closed' % task_id)
+ try:
+ self.gtd.closeTask(task_id)
+ output(u'Task %s was closed' % task_id)
+ except TaskNotFound:
+ output(u'Task %s not found' % task_id)
def cmd_del_task(self, task_ids):
"Close task or tasks."
View
6 gtdzen/__init__.py
@@ -9,7 +9,10 @@
from utils import get_or_create, make_list
from pdb import set_trace
+from exceptions import *
+
__version__ = '0.1.1'
+__all__ = ['GTD']
class GTD(object):
def __init__(self, filename):
@@ -84,6 +87,9 @@ def save(self, obj):
def closeTask(self, task_id):
task = self.getTaskById(task_id)
+ if task is None:
+ raise TaskNotFound
+
task.done = True
self.save(task)
View
1 gtdzen/exceptions.py
@@ -0,0 +1 @@
+class TaskNotFound(Exception): pass
View
4 tests/task_tests.py
@@ -6,6 +6,7 @@
from pdb import set_trace
from unittest import TestCase
from gtdzen import GTD
+from gtdzen.exceptions import *
TEST_DB = 'testsuite.sqlite'
@@ -135,6 +136,9 @@ def testCloseTask(self):
self.assertEqual(u'First', tasks[0].title)
self.assertEqual(u'Second', tasks[1].title)
+ def testCloseUnknown(self):
+ self.assertRaises(TaskNotFound, self.gtd.closeTask, 12345)
+
def testDeleteTask(self):
task1 = self.gtd.addTask(title = u'First', priority = 10)

0 comments on commit d4cc2be

Please sign in to comment.
Something went wrong with that request. Please try again.