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
51bf164f
Commit
51bf164f
authored
May 27, 2015
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #29 from mruwek/fix-edit-regressions_
5562ed7d
Fix EditCommand inheritance problems
parents
61a35f8f
6ab221a5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
97 additions
and
41 deletions
+97
-41
test/EditCommandTest.py
test/EditCommandTest.py
+20
-1
topydo/commands/EditCommand.py
topydo/commands/EditCommand.py
+2
-2
topydo/commands/ListCommand.py
topydo/commands/ListCommand.py
+2
-38
topydo/lib/ExpressionCommand.py
topydo/lib/ExpressionCommand.py
+73
-0
No files found.
test/EditCommandTest.py
View file @
51bf164f
...
@@ -17,11 +17,13 @@
...
@@ -17,11 +17,13 @@
import
unittest
import
unittest
import
mock
import
mock
from
six
import
u
from
six
import
u
import
os
from
topydo.commands.EditCommand
import
EditCommand
from
topydo.commands.EditCommand
import
EditCommand
from
test.CommandTest
import
CommandTest
,
utf8
from
test.CommandTest
import
CommandTest
,
utf8
from
topydo.lib.TodoList
import
TodoList
from
topydo.lib.TodoList
import
TodoList
from
topydo.lib.Todo
import
Todo
from
topydo.lib.Todo
import
Todo
from
topydo.lib.Config
import
config
class
EditCommandTest
(
CommandTest
):
class
EditCommandTest
(
CommandTest
):
def
setUp
(
self
):
def
setUp
(
self
):
...
@@ -114,7 +116,6 @@ class EditCommandTest(CommandTest):
...
@@ -114,7 +116,6 @@ class EditCommandTest(CommandTest):
self
.
assertEqual
(
self
.
errors
,
""
)
self
.
assertEqual
(
self
.
errors
,
""
)
self
.
assertEqual
(
str
(
self
.
todolist
),
utf8
(
u
(
"Foo id:1
\
n
Bar p:1 @test
\
n
Baz @test
\
n
Lazy Cat"
)))
self
.
assertEqual
(
str
(
self
.
todolist
),
utf8
(
u
(
"Foo id:1
\
n
Bar p:1 @test
\
n
Baz @test
\
n
Lazy Cat"
)))
@
mock
.
patch
(
'topydo.commands.EditCommand.EditCommand._todos_from_temp'
)
@
mock
.
patch
(
'topydo.commands.EditCommand.EditCommand._todos_from_temp'
)
@
mock
.
patch
(
'topydo.commands.EditCommand.EditCommand._open_in_editor'
)
@
mock
.
patch
(
'topydo.commands.EditCommand.EditCommand._open_in_editor'
)
def
test_edit_expr
(
self
,
mock_open_in_editor
,
mock_todos_from_temp
):
def
test_edit_expr
(
self
,
mock_open_in_editor
,
mock_todos_from_temp
):
...
@@ -125,9 +126,27 @@ class EditCommandTest(CommandTest):
...
@@ -125,9 +126,27 @@ class EditCommandTest(CommandTest):
command
=
EditCommand
([
"-e"
,
"@test"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
=
EditCommand
([
"-e"
,
"@test"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
command
.
execute
()
expected
=
utf8
(
u
(
"| 3| Lazy Cat
\
n
| 4| Lazy Dog
\
n
"
))
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEqual
(
self
.
errors
,
""
)
self
.
assertEqual
(
self
.
errors
,
""
)
self
.
assertEqual
(
self
.
output
,
expected
)
self
.
assertEqual
(
str
(
self
.
todolist
),
utf8
(
u
(
"Foo id:1
\
n
Fo
\
u00f3
B
\
u0105
\
u017a
\
n
Lazy Cat
\
n
Lazy Dog"
)))
self
.
assertEqual
(
str
(
self
.
todolist
),
utf8
(
u
(
"Foo id:1
\
n
Fo
\
u00f3
B
\
u0105
\
u017a
\
n
Lazy Cat
\
n
Lazy Dog"
)))
@
mock
.
patch
(
'topydo.commands.EditCommand.call'
)
def
test_edit_archive
(
self
,
mock_call
):
""" Edit archive file. """
mock_call
.
return_value
=
0
editor
=
'vi'
os
.
environ
[
'EDITOR'
]
=
editor
archive
=
config
().
archive
()
command
=
EditCommand
([
u
(
"-d"
)],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
self
.
assertEqual
(
self
.
errors
,
""
)
mock_call
.
assert_called_once_with
([
editor
,
archive
])
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
topydo/commands/EditCommand.py
View file @
51bf164f
...
@@ -20,7 +20,7 @@ import tempfile
...
@@ -20,7 +20,7 @@ import tempfile
from
six
import
text_type
,
u
from
six
import
text_type
,
u
from
topydo.
commands.ListCommand
import
List
Command
from
topydo.
lib.ExpressionCommand
import
Expression
Command
from
topydo.lib.MultiCommand
import
MultiCommand
from
topydo.lib.MultiCommand
import
MultiCommand
from
topydo.lib.Config
import
config
from
topydo.lib.Config
import
config
from
topydo.lib.Todo
import
Todo
from
topydo.lib.Todo
import
Todo
...
@@ -32,7 +32,7 @@ from topydo.lib.PrettyPrinterFilter import PrettyPrinterNumbers
...
@@ -32,7 +32,7 @@ from topydo.lib.PrettyPrinterFilter import PrettyPrinterNumbers
# cannot use super() inside the class itself
# cannot use super() inside the class itself
BASE_TODOLIST
=
lambda
tl
:
super
(
TodoList
,
tl
)
BASE_TODOLIST
=
lambda
tl
:
super
(
TodoList
,
tl
)
class
EditCommand
(
MultiCommand
,
List
Command
):
class
EditCommand
(
MultiCommand
,
Expression
Command
):
def
__init__
(
self
,
p_args
,
p_todolist
,
p_output
,
p_error
,
p_input
):
def
__init__
(
self
,
p_args
,
p_todolist
,
p_output
,
p_error
,
p_input
):
super
(
EditCommand
,
self
).
__init__
(
p_args
,
p_todolist
,
p_output
,
super
(
EditCommand
,
self
).
__init__
(
p_args
,
p_todolist
,
p_output
,
p_error
,
p_input
)
p_error
,
p_input
)
...
...
topydo/commands/ListCommand.py
View file @
51bf164f
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
import
re
import
re
from
topydo.lib.
Command
import
Command
from
topydo.lib.
ExpressionCommand
import
Expression
Command
from
topydo.lib.Config
import
config
from
topydo.lib.Config
import
config
from
topydo.lib
import
Filter
from
topydo.lib
import
Filter
from
topydo.lib.PrettyPrinterFilter
import
(
from
topydo.lib.PrettyPrinterFilter
import
(
...
@@ -26,7 +26,7 @@ from topydo.lib.PrettyPrinterFilter import (
...
@@ -26,7 +26,7 @@ from topydo.lib.PrettyPrinterFilter import (
from
topydo.lib.Sorter
import
Sorter
from
topydo.lib.Sorter
import
Sorter
from
topydo.lib.View
import
View
from
topydo.lib.View
import
View
class
ListCommand
(
Command
):
class
ListCommand
(
Expression
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
,
...
@@ -48,42 +48,6 @@ class ListCommand(Command):
...
@@ -48,42 +48,6 @@ class ListCommand(Command):
self
.
args
=
args
self
.
args
=
args
def
_filters
(
self
):
filters
=
[]
def
arg_filters
():
result
=
[]
for
arg
in
self
.
args
:
if
re
.
match
(
Filter
.
ORDINAL_TAG_MATCH
,
arg
):
argfilter
=
Filter
.
OrdinalTagFilter
(
arg
)
elif
len
(
arg
)
>
1
and
arg
[
0
]
==
'-'
:
# when a word starts with -, exclude it
argfilter
=
Filter
.
GrepFilter
(
arg
[
1
:])
argfilter
=
Filter
.
NegationFilter
(
argfilter
)
else
:
argfilter
=
Filter
.
GrepFilter
(
arg
)
result
.
append
(
argfilter
)
return
result
if
not
self
.
show_all
:
filters
.
append
(
Filter
.
DependencyFilter
(
self
.
todolist
))
filters
.
append
(
Filter
.
RelevanceFilter
())
filters
+=
arg_filters
()
if
not
self
.
show_all
:
filters
.
append
(
Filter
.
LimitFilter
(
config
().
list_limit
()))
return
filters
def
_view
(
self
):
sorter
=
Sorter
(
self
.
sort_expression
)
filters
=
self
.
_filters
()
return
View
(
sorter
,
filters
,
self
.
todolist
,
self
.
printer
)
def
_print
(
self
):
def
_print
(
self
):
""" Prints the todos. """
""" Prints the todos. """
indent
=
config
().
list_indent
()
indent
=
config
().
list_indent
()
...
...
topydo/lib/ExpressionCommand.py
0 → 100644
View file @
51bf164f
# 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
re
from
topydo.lib.Command
import
Command
from
topydo.lib.Config
import
config
from
topydo.lib
import
Filter
from
topydo.lib.Sorter
import
Sorter
from
topydo.lib.View
import
View
class
ExpressionCommand
(
Command
):
"""
A common class for commands operating on todos selected by expressions.
"""
def
__init__
(
self
,
p_args
,
p_todolist
,
p_out
=
lambda
a
:
None
,
p_err
=
lambda
a
:
None
,
p_prompt
=
lambda
a
:
None
):
super
(
ExpressionCommand
,
self
).
__init__
(
p_args
,
p_todolist
,
p_out
,
p_err
,
p_prompt
)
self
.
sort_expression
=
config
().
sort_string
()
self
.
show_all
=
False
def
_filters
(
self
):
filters
=
[]
def
arg_filters
():
result
=
[]
for
arg
in
self
.
args
:
if
re
.
match
(
Filter
.
ORDINAL_TAG_MATCH
,
arg
):
argfilter
=
Filter
.
OrdinalTagFilter
(
arg
)
elif
len
(
arg
)
>
1
and
arg
[
0
]
==
'-'
:
# when a word starts with -, exclude it
argfilter
=
Filter
.
GrepFilter
(
arg
[
1
:])
argfilter
=
Filter
.
NegationFilter
(
argfilter
)
else
:
argfilter
=
Filter
.
GrepFilter
(
arg
)
result
.
append
(
argfilter
)
return
result
if
not
self
.
show_all
:
filters
.
append
(
Filter
.
DependencyFilter
(
self
.
todolist
))
filters
.
append
(
Filter
.
RelevanceFilter
())
filters
+=
arg_filters
()
if
not
self
.
show_all
:
filters
.
append
(
Filter
.
LimitFilter
(
config
().
list_limit
()))
return
filters
def
_view
(
self
):
sorter
=
Sorter
(
self
.
sort_expression
)
filters
=
self
.
_filters
()
return
View
(
sorter
,
filters
,
self
.
todolist
,
self
.
printer
)
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