Commit 3f59dae7 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Add tests for the ListCommand.

parent bded7f71
...@@ -11,12 +11,12 @@ class ListCommand(Command.Command): ...@@ -11,12 +11,12 @@ class ListCommand(Command.Command):
super(ListCommand, self).__init__(p_args, p_todolist, p_out, p_err, p_prompt) super(ListCommand, self).__init__(p_args, p_todolist, p_out, p_err, p_prompt)
def execute(self): def execute(self):
show_all = self.argumentShift("-x")
sorter = Sorter.Sorter(Config.SORT_STRING) sorter = Sorter.Sorter(Config.SORT_STRING)
filters = [] if show_all else [Filter.DependencyFilter(self.todolist), Filter.RelevanceFilter()]
filters = []
if len(self.args) > 0: if len(self.args) > 0:
filters = [Filter.GrepFilter(self.argument(0))] filters.append(Filter.GrepFilter(self.argument(0)))
else:
filters = [Filter.DependencyFilter(self.todolist), Filter.RelevanceFilter()]
self.out(self.todolist.view(sorter, filters).pretty_print()) self.out(self.todolist.view(sorter, filters).pretty_print())
import CommandTest
import ListCommand
import TestFacilities
class ListCommandTest(CommandTest.CommandTest):
def setUp(self):
self.todolist = TestFacilities.load_file_to_todolist("data/ListCommandTest.txt")
def test_list1(self):
command = ListCommand.ListCommand([""], self.todolist, self.out, self.error)
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.output, " 1 (C) Foo @Context2 Not@Context +Project1 Not+Project\n 4 (C) Drink beer @ home\n 5 (C) 13 + 29 = 42\n 2 (D) Bar @Context1 +Project2 p:1\n")
self.assertEquals(self.errors, "")
def test_list3(self):
command = ListCommand.ListCommand(["Context1"], self.todolist, self.out, self.error)
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.output, " 2 (D) Bar @Context1 +Project2 p:1\n")
self.assertEquals(self.errors, "")
def test_list4(self):
command = ListCommand.ListCommand(["-x", "Context1"], self.todolist, self.out, self.error)
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.output, " 3 (C) Baz @Context1 +Project1 key:value id:1\n 2 (D) Bar @Context1 +Project2 p:1\n")
self.assertEquals(self.errors, "")
def test_list5(self):
command = ListCommand.ListCommand(["-x"], self.todolist, self.out, self.error)
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.output, " 1 (C) Foo @Context2 Not@Context +Project1 Not+Project\n 3 (C) Baz @Context1 +Project1 key:value id:1\n 4 (C) Drink beer @ home\n 5 (C) 13 + 29 = 42\n 2 (D) Bar @Context1 +Project2 p:1\n")
self.assertEquals(self.errors, "")
def test_list6(self):
command = ListCommand.ListCommand(["Project3"], self.todolist, self.out, self.error)
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.output, "")
self.assertEquals(self.errors, "")
(C) Foo @Context2 Not@Context +Project1 Not+Project
(D) Bar @Context1 +Project2 p:1
(C) Baz @Context1 +Project1 key:value id:1
(C) Drink beer @ home
(C) 13 + 29 = 42
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