Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
topydo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
topydo
Commits
1f594ca6
Commit
1f594ca6
authored
Oct 12, 2014
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Let TodoList throw an exception when invalid todos are requested.
parent
09584282
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
12 deletions
+20
-12
AddCommand.py
AddCommand.py
+5
-3
AppendCommand.py
AppendCommand.py
+4
-3
TodoList.py
TodoList.py
+8
-2
test/TodoListTest.py
test/TodoListTest.py
+3
-4
No files found.
AddCommand.py
View file @
1f594ca6
...
...
@@ -7,6 +7,7 @@ import Config
import
Command
from
PrettyPrinter
import
pretty_print
from
RelativeDate
import
relative_date_to_date
import
TodoList
class
AddCommand
(
Command
.
Command
):
def
__init__
(
self
,
p_args
,
p_todolist
,
...
...
@@ -46,14 +47,15 @@ class AddCommand(Command.Command):
try
:
value
=
int
(
raw_value
)
dep
=
self
.
todolist
.
todo
(
value
)
except
ValueError
:
continue
if
dep
:
if
p_tag
==
'after'
:
self
.
todolist
.
add_dependency
(
self
.
todo
,
dep
)
elif
p_tag
==
'before'
or
p_tag
==
'partof'
:
self
.
todolist
.
add_dependency
(
dep
,
self
.
todo
)
except
ValueError
:
continue
except
TodoList
.
InvalidTodoException
:
pass
self
.
todo
.
remove_tag
(
p_tag
,
raw_value
)
...
...
AppendCommand.py
View file @
1f594ca6
import
Command
from
PrettyPrinter
import
pretty_print
import
TodoList
from
Utils
import
convert_todo_number
class
AppendCommand
(
Command
.
Command
):
...
...
@@ -16,11 +17,11 @@ class AppendCommand(Command.Command):
text
=
" "
.
join
(
self
.
args
[
1
:])
if
number
and
text
:
t
odo
=
self
.
todolist
.
todo
(
number
)
if
todo
:
t
ry
:
todo
=
self
.
todolist
.
todo
(
number
)
self
.
todolist
.
append
(
todo
,
text
)
self
.
out
(
pretty_print
(
todo
,
[
self
.
todolist
.
pp_number
()]))
e
lse
:
e
xcept
TodoList
.
InvalidTodoException
:
self
.
error
(
"Invalid todo number given."
)
else
:
self
.
error
(
self
.
usage
())
TodoList.py
View file @
1f594ca6
...
...
@@ -9,6 +9,9 @@ from PrettyPrinter import pretty_print_list
import
Todo
import
View
class
InvalidTodoException
(
Exception
):
pass
class
TodoList
(
object
):
"""
Provides operations for a todo list, such as adding items, removing them,
...
...
@@ -41,7 +44,7 @@ class TodoList(object):
try
:
result
=
self
.
_todos
[
p_number
-
1
]
except
IndexError
:
r
esult
=
None
r
aise
InvalidTodoException
return
result
...
...
@@ -284,7 +287,10 @@ class TodoList(object):
self.dirty = True
def number(self, p_todo):
return self._todos.index(p_todo) + 1
try:
return self._todos.index(p_todo) + 1
except ValueError:
raise InvalidTodoException
def pp_number(self):
"""
...
...
test/TodoListTest.py
View file @
1f594ca6
...
...
@@ -78,7 +78,7 @@ class TodoListTester(unittest.TestCase):
"(C) Baz @Context1 +Project1 key:value")
self.assertEquals(self.todolist.count(), count - 1)
self.assertTrue(self.todolist.is_dirty())
self.assertRaises(
ValueError
, self.todolist.number, todo)
self.assertRaises(
TodoList.InvalidTodoException
, self.todolist.number, todo)
def test_append1(self):
todo = self.todolist.todo(3)
...
...
@@ -108,9 +108,8 @@ class TodoListTester(unittest.TestCase):
def test_todo(self):
count = self.todolist.count()
todo = self.todolist.todo(count+100)
self.assert
Equals(todo, None
)
self.assert
Raises(TodoList.InvalidTodoException, self.todolist.todo, count + 100
)
self.assertFalse(self.todolist.is_dirty())
def test_string(self):
...
...
@@ -139,7 +138,7 @@ class TodoListTester(unittest.TestCase):
def
test_todo_number2
(
self
):
todo
=
Todo
.
Todo
(
"Non-existent"
)
self
.
assertRaises
(
ValueError
,
self
.
todolist
.
number
,
todo
)
self
.
assertRaises
(
TodoList
.
InvalidTodoException
,
self
.
todolist
.
number
,
todo
)
def
test_todo_complete
(
self
):
todo
=
self
.
todolist
.
todo
(
1
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment