Commit d9b100eb authored by Bram Schoenmakers's avatar Bram Schoenmakers

Merge pull request #18 from mruwek/multi-depri

Remove priorities from multiple todo items at once
parents 22358bb2 c61e881a
......@@ -26,20 +26,21 @@ class DepriCommandTest(CommandTest.CommandTest):
todos = [
"(A) Foo",
"Bar",
"(B) Baz",
]
self.todolist = TodoList(todos)
def test_set_prio1(self):
def test_depri1(self):
command = DepriCommand(["1"], self.todolist, self.out, self.error)
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.todolist.todo(1).priority(), None)
self.assertEquals(self.output, "Priority removed.\nFoo\n")
self.assertEquals(self.output, "Priority removed.\n| 1| Foo\n")
self.assertEquals(self.errors, "")
def test_set_prio2(self):
def test_depri2(self):
command = DepriCommand(["2"], self.todolist, self.out, self.error)
command.execute()
......@@ -48,15 +49,26 @@ class DepriCommandTest(CommandTest.CommandTest):
self.assertEquals(self.output, "")
self.assertEquals(self.errors, "")
def test_set_prio3(self):
def test_depri3(self):
command = DepriCommand(["Foo"], self.todolist, self.out, self.error)
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.todolist.todo(1).priority(), None)
self.assertEquals(self.output, "Priority removed.\nFoo\n")
self.assertEquals(self.output, "Priority removed.\n| 1| Foo\n")
self.assertEquals(self.errors, "")
def test_depri4(self):
command = DepriCommand(["1","Baz"], self.todolist, self.out, self.error)
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.todolist.todo(1).priority(), None)
self.assertEquals(self.todolist.todo(3).priority(), None)
self.assertEquals(self.output, "Priority removed.\n| 1| Foo\nPriority removed.\n| 3| Baz\n")
self.assertEquals(self.errors, "")
def test_invalid1(self):
command = DepriCommand(["99"], self.todolist, self.out, self.error)
command.execute()
......@@ -65,6 +77,22 @@ class DepriCommandTest(CommandTest.CommandTest):
self.assertFalse(self.output)
self.assertEquals(self.errors, "Invalid todo number given.\n")
def test_invalid2(self):
command = DepriCommand(["99", "1"], 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: 99.\n")
def test_invalid3(self):
command = DepriCommand(["99", "FooBar"], 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: 99.\nInvalid todo number given: FooBar.\n")
def test_empty(self):
command = DepriCommand([], self.todolist, self.out, self.error)
command.execute()
......
......@@ -39,6 +39,7 @@ Available commands:
* append (app)
* del (rm)
* dep
* depri
* do
* edit
* ical
......
......@@ -14,10 +14,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from topydo.lib.Command import Command, InvalidCommandArgument
from topydo.lib.TodoListBase import InvalidTodoException
from topydo.lib.MultiCommand import MultiCommand
from topydo.lib.PrettyPrinterFilter import PrettyPrinterNumbers
class DepriCommand(Command):
class DepriCommand(MultiCommand):
def __init__(self, p_args, p_todolist,
p_out=lambda a: None,
p_err=lambda a: None,
......@@ -25,28 +25,23 @@ class DepriCommand(Command):
super(DepriCommand, self).__init__(
p_args, p_todolist, p_out, p_err, p_prompt)
def execute(self):
if not super(DepriCommand, self).execute():
return False
self.get_todos(self.args)
todo = None
def execute_multi_specific(self):
try:
todo = self.todolist.todo(self.argument(0))
self.printer.add_filter(PrettyPrinterNumbers(self.todolist))
for todo in self.todos:
if todo.priority() != None:
self.todolist.set_priority(todo, None)
self.out("Priority removed.")
self.out(self.printer.print_todo(todo))
except InvalidCommandArgument:
self.error(self.usage())
except (InvalidTodoException):
if not todo:
self.error( "Invalid todo number given.")
else:
except IndexError:
self.error(self.usage())
def usage(self):
return """Synopsis: depri <NUMBER>"""
return """Synopsis: depri <NUMBER1> [<NUMBER2> ...]"""
def help(self):
return """Removes the priority of the given todo item."""
return """Removes the priority of the given todo item(s)."""
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment