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
4a245b12
Commit
4a245b12
authored
May 04, 2015
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #17 from mruwek/EditCommandTest
Add tests for EditCommand
parents
3b8dc67c
23eb51fe
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
109 additions
and
0 deletions
+109
-0
setup.py
setup.py
+1
-0
test/EditCommandTest.py
test/EditCommandTest.py
+108
-0
No files found.
setup.py
View file @
4a245b12
...
@@ -10,6 +10,7 @@ setup(
...
@@ -10,6 +10,7 @@ setup(
url
=
"https://github.com/bram85/topydo"
,
url
=
"https://github.com/bram85/topydo"
,
extras_require
=
{
extras_require
=
{
'ical'
:
[
'icalendar'
],
'ical'
:
[
'icalendar'
],
'edit-cmd-tests'
:
[
'mock'
],
},
},
entry_points
=
{
entry_points
=
{
'console_scripts'
:
[
'topydo = topydo.cli.Main:main'
],
'console_scripts'
:
[
'topydo = topydo.cli.Main:main'
],
...
...
test/EditCommandTest.py
0 → 100644
View file @
4a245b12
# Topydo - A todo.txt client written in Python.
# Copyright (C) 2014 - 2015 Bram Schoenmakers <me@bramschoenmakers.nl>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
unittest
import
mock
import
CommandTest
from
topydo.lib.EditCommand
import
EditCommand
from
topydo.lib.TodoList
import
TodoList
from
topydo.lib.Todo
import
Todo
class
EditCommandTest
(
CommandTest
.
CommandTest
):
def
setUp
(
self
):
super
(
EditCommandTest
,
self
).
setUp
()
todos
=
[
"Foo id:1"
,
"Bar p:1 @test"
,
"Baz @test"
,
]
self
.
todolist
=
TodoList
(
todos
)
@
mock
.
patch
(
'topydo.lib.EditCommand.EditCommand._open_in_editor'
)
def
test_edit1
(
self
,
mock_open_in_editor
):
""" Preserve dependencies after editing. """
mock_open_in_editor
.
return_value
=
0
command
=
EditCommand
([
"1"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEquals
(
self
.
errors
,
""
)
self
.
assertEquals
(
str
(
self
.
todolist
),
"Bar p:1 @test
\
n
Baz @test
\
n
Foo id:1"
)
@
mock
.
patch
(
'topydo.lib.EditCommand.EditCommand._todos_from_temp'
)
@
mock
.
patch
(
'topydo.lib.EditCommand.EditCommand._open_in_editor'
)
def
test_edit2
(
self
,
mock_open_in_editor
,
mock_todos_from_temp
):
""" Edit some todo. """
mock_open_in_editor
.
return_value
=
0
mock_todos_from_temp
.
return_value
=
[
Todo
(
'Lazy Cat'
)]
command
=
EditCommand
([
"Bar"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEquals
(
self
.
errors
,
""
)
self
.
assertEquals
(
str
(
self
.
todolist
),
"Foo id:1
\
n
Baz @test
\
n
Lazy Cat"
)
def
test_edit3
(
self
):
""" Throw an error after invalid todo number given as argument. """
command
=
EditCommand
([
"FooBar"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
self
.
assertFalse
(
self
.
todolist
.
is_dirty
())
self
.
assertEquals
(
self
.
errors
,
"Invalid todo number given.
\
n
"
)
def
test_edit4
(
self
):
""" Throw an error with pointing invalid argument. """
command
=
EditCommand
([
"Bar"
,
"4"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
self
.
assertFalse
(
self
.
todolist
.
is_dirty
())
self
.
assertEquals
(
self
.
errors
,
"Invalid todo number given: 4.
\
n
"
)
@
mock
.
patch
(
'topydo.lib.EditCommand.EditCommand._todos_from_temp'
)
@
mock
.
patch
(
'topydo.lib.EditCommand.EditCommand._open_in_editor'
)
def
test_edit5
(
self
,
mock_open_in_editor
,
mock_todos_from_temp
):
""" Don't let to delete todos acidentally while editing. """
mock_open_in_editor
.
return_value
=
0
mock_todos_from_temp
.
return_value
=
[
Todo
(
'Only one line'
)]
command
=
EditCommand
([
"1"
,
"Bar"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
self
.
assertFalse
(
self
.
todolist
.
is_dirty
())
self
.
assertEquals
(
self
.
errors
,
"Number of edited todos is not equal to number of supplied todo IDs.
\
n
"
)
self
.
assertEquals
(
str
(
self
.
todolist
),
"Foo id:1
\
n
Bar p:1 @test
\
n
Baz @test"
)
@
mock
.
patch
(
'topydo.lib.EditCommand.EditCommand._todos_from_temp'
)
@
mock
.
patch
(
'topydo.lib.EditCommand.EditCommand._open_in_editor'
)
def
test_edit_expr
(
self
,
mock_open_in_editor
,
mock_todos_from_temp
):
""" Edit todos matching expression. """
mock_open_in_editor
.
return_value
=
0
mock_todos_from_temp
.
return_value
=
[
Todo
(
'Lazy Cat'
),
Todo
(
'Lazy Dog'
)]
command
=
EditCommand
([
"-e"
,
"@test"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEquals
(
self
.
errors
,
""
)
self
.
assertEquals
(
str
(
self
.
todolist
),
"Foo id:1
\
n
Lazy Cat
\
n
Lazy Dog"
)
if
__name__
==
'__main__'
:
unittest
.
main
()
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