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
1ed16cd0
Commit
1ed16cd0
authored
Oct 18, 2014
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add instance filter.
parent
c1674443
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
0 deletions
+49
-0
Filter.py
Filter.py
+22
-0
test/FilterTest.py
test/FilterTest.py
+27
-0
No files found.
Filter.py
View file @
1ed16cd0
...
...
@@ -73,3 +73,25 @@ class DependencyFilter(Filter):
uncompleted
=
[
todo
for
todo
in
children
if
not
todo
.
is_completed
()]
return
not
uncompleted
class
InstanceFilter
(
Filter
):
def
__init__
(
self
,
p_todos
):
"""
Constructor.
A filter which selects a number of Todo instances from a TodoList
instance.
This is handy for constructing a view given a plain list of Todo items.
"""
self
.
todos
=
p_todos
def
match
(
self
,
p_todo
):
"""
Returns True when p_todo appears in the list of given todos.
"""
try
:
self
.
todos
.
index
(
p_todo
)
return
True
except
ValueError
:
return
False
test/FilterTest.py
View file @
1ed16cd0
...
...
@@ -83,3 +83,30 @@ class FilterTest(unittest.TestCase):
self
.
assertEquals
(
todolist_to_string
(
filtered_todos
),
\
todolist_to_string
(
reference
))
def
test_filter9
(
self
):
""" Test instance filter """
todos
=
load_file
(
'data/FilterTest1.txt'
)
instance_filter
=
Filter
.
InstanceFilter
(
todos
[
2
:])
filtered_todos
=
instance_filter
.
filter
(
todos
)
self
.
assertEquals
(
todos
[
2
:],
filtered_todos
)
def
test_filter10
(
self
):
""" Test instance filter """
todos
=
load_file
(
'data/FilterTest1.txt'
)
instance_filter
=
Filter
.
InstanceFilter
([])
filtered_todos
=
instance_filter
.
filter
(
todos
)
self
.
assertEquals
([],
filtered_todos
)
def
test_filter11
(
self
):
""" Test instance filter """
todos
=
load_file
(
'data/FilterTest1.txt'
)
instance_filter
=
Filter
.
InstanceFilter
(
todos
[
2
:])
filtered_todos
=
instance_filter
.
filter
([])
self
.
assertEquals
([],
filtered_todos
)
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