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
f5d8302b
Commit
f5d8302b
authored
Oct 18, 2014
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for the 'do' subcommand.
parent
1f594ca6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
122 additions
and
16 deletions
+122
-16
AppendCommand.py
AppendCommand.py
+11
-8
DoCommand.py
DoCommand.py
+20
-7
Utils.py
Utils.py
+4
-1
test/DoCommandTest.py
test/DoCommandTest.py
+87
-0
No files found.
AppendCommand.py
View file @
f5d8302b
import
Command
from
PrettyPrinter
import
pretty_print
import
TodoList
from
Utils
import
convert_todo_number
from
Utils
import
convert_todo_number
,
InvalidTodoNumberException
class
AppendCommand
(
Command
.
Command
):
def
__init__
(
self
,
p_args
,
p_todolist
,
...
...
@@ -13,15 +13,18 @@ class AppendCommand(Command.Command):
def
execute
(
self
):
number
=
self
.
argument
(
0
)
if
number
:
number
=
convert_todo_number
(
number
)
text
=
" "
.
join
(
self
.
args
[
1
:])
try
:
number
=
convert_todo_number
(
number
)
text
=
" "
.
join
(
self
.
args
[
1
:])
if
number
and
text
:
try
:
if
text
:
todo
=
self
.
todolist
.
todo
(
number
)
self
.
todolist
.
append
(
todo
,
text
)
self
.
out
(
pretty_print
(
todo
,
[
self
.
todolist
.
pp_number
()]))
e
xcept
TodoList
.
InvalidTodoException
:
self
.
error
(
"Invalid todo number given."
)
e
lse
:
e
lse
:
self
.
error
(
self
.
usage
()
)
e
xcept
InvalidTodoNumberException
:
self
.
error
(
self
.
usage
())
except
TodoList
.
InvalidTodoException
:
self
.
error
(
"Invalid todo number given."
)
DoCommand.py
View file @
f5d8302b
...
...
@@ -3,7 +3,8 @@ import re
import
Command
from
PrettyPrinter
import
*
from
Recurrence
import
advance_recurring_todo
from
Utils
import
convert_todo_number
from
TodoList
import
InvalidTodoException
from
Utils
import
convert_todo_number
,
InvalidTodoNumberException
class
DoCommand
(
Command
.
Command
):
def
__init__
(
self
,
p_args
,
p_todolist
,
...
...
@@ -11,11 +12,17 @@ class DoCommand(Command.Command):
p_err
=
lambda
a
:
None
,
p_prompt
=
lambda
a
:
None
):
super
(
DoCommand
,
self
).
__init__
(
p_args
,
p_todolist
,
p_out
,
p_err
,
p_prompt
)
self
.
number
=
convert_todo_number
(
self
.
argument
(
0
))
self
.
todo
=
self
.
todolist
.
todo
(
self
.
number
)
self
.
number
=
None
try
:
self
.
number
=
convert_todo_number
(
self
.
argument
(
0
))
self
.
todo
=
self
.
todolist
.
todo
(
self
.
number
)
except
(
InvalidTodoNumberException
,
InvalidTodoException
):
self
.
todo
=
None
def
_complete_children
(
self
):
children
=
[
t
for
t
in
self
.
todolist
.
children
(
self
.
todo
)
if
not
t
.
is_completed
()]
children
=
sorted
([
t
for
t
in
self
.
todolist
.
children
(
self
.
todo
)
if
not
t
.
is_completed
()])
if
children
:
self
.
out
(
"
\
n
"
.
join
(
pretty_print_list
(
children
,
[
self
.
todolist
.
pp_number
()])))
...
...
@@ -24,7 +31,7 @@ class DoCommand(Command.Command):
if
re
.
match
(
'^y(es)?$'
,
confirmation
,
re
.
I
):
for
child
in
children
:
self
.
todolist
.
set_todo_completed
(
child
)
self
.
out
(
pretty_print
(
child
,
[
self
.
todolist
.
pp_number
()]
))
self
.
out
(
pretty_print
(
child
))
def
_handle_recurrence
(
self
):
if
self
.
todo
.
has_tag
(
'rec'
):
...
...
@@ -33,8 +40,14 @@ class DoCommand(Command.Command):
self
.
out
(
pretty_print
(
new_todo
,
[
self
.
todolist
.
pp_number
()]))
def
execute
(
self
):
if
self
.
todo
and
not
self
.
todo
.
is_completed
():
if
not
self
.
number
:
self
.
error
(
self
.
usage
())
elif
self
.
todo
and
not
self
.
todo
.
is_completed
():
self
.
_complete_children
()
self
.
_handle_recurrence
()
self
.
todolist
.
set_todo_completed
(
self
.
number
)
self
.
todolist
.
set_todo_completed
(
self
.
todo
)
self
.
out
(
pretty_print
(
self
.
todo
))
elif
not
self
.
todo
:
self
.
error
(
"Invalid todo number given."
)
else
:
self
.
error
(
"Todo has already been completed."
)
Utils.py
View file @
f5d8302b
...
...
@@ -26,12 +26,15 @@ def date_string_to_date(p_date):
return
result
class
InvalidTodoNumberException
(
Exception
):
pass
def
convert_todo_number
(
p_number
):
""" Converts a string number to an integer. """
try
:
p_number
=
int
(
p_number
)
except
ValueError
:
p_number
=
None
raise
InvalidTodoNumberException
return
p_number
...
...
test/DoCommandTest.py
0 → 100644
View file @
f5d8302b
from
datetime
import
date
import
CommandTest
import
DoCommand
import
TodoList
def
_yes_prompt
(
self
):
return
"y"
def
_no_prompt
(
self
):
return
"n"
class
DoCommandTest
(
CommandTest
.
CommandTest
):
def
setUp
(
self
):
self
.
todolist
=
TodoList
.
TodoList
([])
self
.
today
=
date
.
today
().
isoformat
()
self
.
todolist
.
add
(
"Foo id:1"
)
self
.
todolist
.
add
(
"Bar p:1"
)
self
.
todolist
.
add
(
"Baz p:1"
)
self
.
todolist
.
add
(
"Recurring! rec:1d"
)
self
.
todolist
.
add
(
"x 2014-10-18 Already complete"
)
def
test_do1
(
self
):
command
=
DoCommand
.
DoCommand
([
"3"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
_no_prompt
)
command
.
execute
()
self
.
assertEquals
(
self
.
output
,
"x %s Baz p:1
\
n
"
%
self
.
today
)
self
.
assertEquals
(
self
.
errors
,
""
)
def
test_do_children1
(
self
):
command
=
DoCommand
.
DoCommand
([
"1"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
_yes_prompt
)
command
.
execute
()
result
=
" 2 Bar p:1
\
n
3 Baz p:1
\
n
x %s Bar p:1
\
n
x %s Baz p:1
\
n
x %s Foo id:1
\
n
"
%
(
self
.
today
,
self
.
today
,
self
.
today
)
self
.
assertEquals
(
self
.
output
,
result
)
self
.
assertEquals
(
self
.
errors
,
""
)
def
test_do_children2
(
self
):
command
=
DoCommand
.
DoCommand
([
"1"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
_no_prompt
)
command
.
execute
()
result
=
" 2 Bar p:1
\
n
3 Baz p:1
\
n
x %s Foo id:1
\
n
"
%
self
.
today
self
.
assertEquals
(
self
.
output
,
result
)
self
.
assertEquals
(
self
.
errors
,
""
)
def
test_recurrence
(
self
):
command
=
DoCommand
.
DoCommand
([
"4"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
result
=
" 6 2014-10-18 Recurring! rec:1d due:2014-10-19
\
n
x 2014-10-18 Recurring! rec:1d
\
n
"
self
.
assertEquals
(
self
.
output
,
result
)
self
.
assertEquals
(
self
.
errors
,
""
)
self
.
assertEquals
(
self
.
todolist
.
count
(),
6
)
self
.
assertTrue
(
self
.
todolist
.
todo
(
4
).
is_completed
())
self
.
assertFalse
(
self
.
todolist
.
todo
(
6
).
is_completed
())
def
test_invalid1
(
self
):
command
=
DoCommand
.
DoCommand
([
"99"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
self
.
assertFalse
(
self
.
output
)
self
.
assertEquals
(
self
.
errors
,
"Invalid todo number given.
\
n
"
)
def
test_invalid2
(
self
):
command
=
DoCommand
.
DoCommand
([
"A"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
self
.
assertFalse
(
self
.
output
)
self
.
assertEquals
(
self
.
errors
,
command
.
usage
()
+
"
\
n
"
)
def
test_already_complete
(
self
):
command
=
DoCommand
.
DoCommand
([
"5"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
self
.
assertFalse
(
self
.
output
)
self
.
assertEquals
(
self
.
errors
,
"Todo has already been completed.
\
n
"
)
def
test_empty
(
self
):
command
=
DoCommand
.
DoCommand
([
""
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
self
.
assertFalse
(
self
.
output
)
self
.
assertEquals
(
self
.
errors
,
command
.
usage
()
+
"
\
n
"
)
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