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
dbaf20b4
Commit
dbaf20b4
authored
Oct 23, 2014
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add possibility to specify which value to replace.
parent
d8e76bc0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
3 deletions
+29
-3
lib/TodoBase.py
lib/TodoBase.py
+6
-2
test/TodoBaseTest.py
test/TodoBaseTest.py
+23
-1
No files found.
lib/TodoBase.py
View file @
dbaf20b4
...
...
@@ -75,7 +75,7 @@ class TodoBase(object):
""" Adds a tag to the todo. """
self
.
set_tag
(
p_key
,
p_value
,
True
)
def
set_tag
(
self
,
p_key
,
p_value
=
""
,
p_force_add
=
False
):
def
set_tag
(
self
,
p_key
,
p_value
=
""
,
p_force_add
=
False
,
p_old_value
=
None
):
"""
Sets a occurrence of the tag identified by p_key. Sets an arbitrary
instance of the tag when the todo contains multiple tags with this key.
...
...
@@ -85,13 +85,17 @@ class TodoBase(object):
When p_force_add is true, a tag will always be added to the todo, in
case there is already a tag with the given key.
When p_old_value is set, all tags having this value will be set to the
new value.
"""
if
p_value
==
""
:
self
.
remove_tag
(
p_key
)
return
value
=
self
.
tag_value
(
p_key
)
value
=
p_old_value
if
p_old_value
else
self
.
tag_value
(
p_key
)
if
not
p_force_add
and
value
:
# remove old value from the tags
self
.
fields
[
'tags'
]
=
[
t
for
t
in
self
.
fields
[
'tags'
]
\
...
...
test/TodoBaseTest.py
View file @
dbaf20b4
...
...
@@ -49,7 +49,7 @@ class TodoBaseTester(unittest.TestCase):
self
.
assertEquals
(
todo
.
source
(),
'(C) Foo id:1 id:2'
)
def
test_set_tag
(
self
):
def
test_set_tag
1
(
self
):
todo
=
TodoBase
.
TodoBase
(
"(C) Foo foo:bar"
)
todo
.
set_tag
(
'foo'
,
'baz'
)
...
...
@@ -60,6 +60,28 @@ class TodoBaseTester(unittest.TestCase):
self
.
assertTrue
(
re
.
search
(
r'\bfoo:baz\b'
,
todo
.
src
))
self
.
assertFalse
(
re
.
search
(
r'\bfoo:bar\b'
,
todo
.
src
))
def
test_set_tag2
(
self
):
todo
=
TodoBase
.
TodoBase
(
"(C) Foo foo:bar foo:baz"
)
todo
.
set_tag
(
'foo'
,
'bang'
,
False
,
'baz'
)
self
.
assertTrue
(
todo
.
has_tag
(
'foo'
))
self
.
assertTrue
(
todo
.
has_tag
(
'foo'
,
'bar'
))
self
.
assertTrue
(
todo
.
has_tag
(
'foo'
,
'bang'
))
self
.
assertFalse
(
todo
.
has_tag
(
'foo'
,
'baz'
))
self
.
assertTrue
(
re
.
search
(
r'\bfoo:bar\b'
,
todo
.
src
))
self
.
assertFalse
(
re
.
search
(
r'\bfoo:baz\b'
,
todo
.
src
))
def
test_set_tag3
(
self
):
todo
=
TodoBase
.
TodoBase
(
"(C) Foo foo:bar foo:bar"
)
todo
.
set_tag
(
'foo'
,
'bang'
,
False
,
'bar'
)
self
.
assertTrue
(
todo
.
has_tag
(
'foo'
))
self
.
assertTrue
(
todo
.
has_tag
(
'foo'
,
'bang'
))
self
.
assertFalse
(
todo
.
has_tag
(
'foo'
,
'bar'
))
self
.
assertTrue
(
re
.
search
(
r'\bfoo:bang foo:bang\b'
,
todo
.
src
))
def
test_set_tag_double_value
(
self
):
todo
=
TodoBase
.
TodoBase
(
"(C) Foo foo:bar baz:bar"
)
todo
.
set_tag
(
'foo'
,
'blah'
);
...
...
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