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
fc880278
Commit
fc880278
authored
Oct 18, 2014
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for the priority command.
parent
2d4fff19
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
98 additions
and
14 deletions
+98
-14
PriorityCommand.py
PriorityCommand.py
+29
-13
Utils.py
Utils.py
+1
-1
test/PriorityCommandTest.py
test/PriorityCommandTest.py
+68
-0
No files found.
PriorityCommand.py
View file @
fc880278
import
Command
from
Command
import
*
from
PrettyPrinter
import
pretty_print
from
PrettyPrinter
import
pretty_print
from
Utils
import
convert_todo_number
,
is_valid_priority
from
TodoList
import
InvalidTodoException
from
Utils
import
*
class
PriorityCommand
(
Command
.
Command
):
class
PriorityCommand
(
Command
):
def
__init__
(
self
,
p_args
,
p_todolist
,
def
__init__
(
self
,
p_args
,
p_todolist
,
p_out
=
lambda
a
:
None
,
p_out
=
lambda
a
:
None
,
p_err
=
lambda
a
:
None
,
p_err
=
lambda
a
:
None
,
p_prompt
=
lambda
a
:
None
):
p_prompt
=
lambda
a
:
None
):
super
(
PriorityCommand
,
self
).
__init__
(
p_args
,
p_todolist
,
p_out
,
p_err
,
p_prompt
)
super
(
PriorityCommand
,
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
.
priority
=
self
.
argument
(
1
)
def
execute
(
self
):
def
execute
(
self
):
if
is_valid_priority
(
self
.
priority
):
number
=
None
old_priority
=
self
.
todo
.
priority
()
priority
=
None
self
.
todolist
.
set_priority
(
self
.
number
,
self
.
priority
)
try
:
number
=
convert_todo_number
(
self
.
argument
(
0
))
priority
=
self
.
argument
(
1
)
todo
=
self
.
todolist
.
todo
(
number
)
self
.
out
(
"Priority changed from %s to %s"
%
(
old_priority
,
self
.
priority
))
if
is_valid_priority
(
priority
):
self
.
out
(
pretty_print
(
self
.
todo
))
old_priority
=
todo
.
priority
()
else
:
self
.
todolist
.
set_priority
(
todo
,
priority
)
self
.
error
(
"Invalid priority given."
)
if
old_priority
and
priority
:
self
.
out
(
"Priority changed from %s to %s"
%
(
old_priority
,
priority
))
else
:
self
.
out
(
"Priority set to %s."
%
priority
)
self
.
out
(
pretty_print
(
todo
))
else
:
self
.
error
(
"Invalid priority given."
)
except
InvalidCommandArgument
:
self
.
error
(
self
.
usage
())
except
(
InvalidTodoNumberException
,
InvalidTodoException
):
if
number
and
priority
:
self
.
error
(
"Invalid todo number given."
)
else
:
self
.
error
(
self
.
usage
())
Utils.py
View file @
fc880278
...
@@ -39,4 +39,4 @@ def convert_todo_number(p_number):
...
@@ -39,4 +39,4 @@ def convert_todo_number(p_number):
return
p_number
return
p_number
def
is_valid_priority
(
p_priority
):
def
is_valid_priority
(
p_priority
):
return
re
.
match
(
r'^[A-Z]$'
,
p_priority
)
!=
None
return
p_priority
!=
None
and
re
.
match
(
r'^[A-Z]$'
,
p_priority
)
!=
None
test/PriorityCommandTest.py
0 → 100644
View file @
fc880278
import
CommandTest
import
PriorityCommand
import
TodoList
class
PriorityCommandTest
(
CommandTest
.
CommandTest
):
def
setUp
(
self
):
todos
=
[
"(A) Foo"
,
"Bar"
,
]
self
.
todolist
=
TodoList
.
TodoList
(
todos
)
def
test_set_prio1
(
self
):
command
=
PriorityCommand
.
PriorityCommand
([
"1"
,
"B"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEquals
(
self
.
output
,
"Priority changed from A to B
\
n
(B) Foo
\
n
"
)
self
.
assertEquals
(
self
.
errors
,
""
)
def
test_set_prio2
(
self
):
command
=
PriorityCommand
.
PriorityCommand
([
"2"
,
"Z"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEquals
(
self
.
output
,
"Priority set to Z.
\
n
(Z) Bar
\
n
"
)
self
.
assertEquals
(
self
.
errors
,
""
)
def
test_invalid1
(
self
):
command
=
PriorityCommand
.
PriorityCommand
([
"99"
,
"A"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
self
.
assertFalse
(
self
.
todolist
.
is_dirty
())
self
.
assertFalse
(
self
.
output
)
self
.
assertEquals
(
self
.
errors
,
"Invalid todo number given.
\
n
"
)
def
test_invalid2
(
self
):
command
=
PriorityCommand
.
PriorityCommand
([
"1"
,
"ZZ"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
self
.
assertFalse
(
self
.
todolist
.
is_dirty
())
self
.
assertFalse
(
self
.
output
)
self
.
assertEquals
(
self
.
errors
,
"Invalid priority given.
\
n
"
)
def
test_invalid3
(
self
):
command
=
PriorityCommand
.
PriorityCommand
([
"A"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
self
.
assertFalse
(
self
.
todolist
.
is_dirty
())
self
.
assertFalse
(
self
.
output
)
self
.
assertEquals
(
self
.
errors
,
command
.
usage
()
+
"
\
n
"
)
def
test_invalid4
(
self
):
command
=
PriorityCommand
.
PriorityCommand
([
"1"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
self
.
assertFalse
(
self
.
todolist
.
is_dirty
())
self
.
assertFalse
(
self
.
output
)
self
.
assertEquals
(
self
.
errors
,
command
.
usage
()
+
"
\
n
"
)
def
test_empty
(
self
):
command
=
PriorityCommand
.
PriorityCommand
([],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
self
.
assertFalse
(
self
.
todolist
.
is_dirty
())
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