class DepriCommandTest(CommandTest.CommandTest): def setUp(self): super(DepriCommandTest, self).setUp() todos = [ "(A) Foo", "Bar", ] self.todolist = TodoList(todos) def test_set_prio1(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.errors, "") def test_set_prio2(self): command = DepriCommand(["2"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEquals(self.todolist.todo(2).priority(), None) self.assertEquals(self.output, "") self.assertEquals(self.errors, "") def test_set_prio3(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.errors, "") def test_invalid1(self): command = DepriCommand(["99"], 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.\n") def test_empty(self): command = DepriCommand([], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEquals(self.errors, command.usage() + "\n") def test_help(self): command = DepriCommand(["help"], self.todolist, self.out, self.error) command.execute() self.assertEquals(self.output, "") self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n")
def test_archive(self): todolist = load_file_to_todolist("test/data/ArchiveCommandTest.txt") archive = TodoList([]) command = ArchiveCommand(todolist, archive) command.execute() self.assertTrue(todolist.is_dirty()) self.assertTrue(archive.is_dirty()) self.assertEqual(todolist.print_todos(), "x Not complete\n(C) Active") self.assertEqual(archive.print_todos(), "x 2014-10-19 Complete\nx 2014-10-20 Another one complete")
def test_archive(self): todolist = load_file_to_todolist("test/data/ArchiveCommandTest.txt") archive = TodoList([]) command = ArchiveCommand(todolist, archive) command.execute() self.assertTrue(todolist.is_dirty()) self.assertTrue(archive.is_dirty()) self.assertEqual(todolist.print_todos(), "x Not complete\n(C) Active") self.assertEqual( archive.print_todos(), "x 2014-10-19 Complete\nx 2014-10-20 Another one complete")
class TodoListTester(TopydoTest): def setUp(self): super(TodoListTester, self).setUp() self.todofile = TodoFile('test/data/TodoListTest.txt') lines = [line for line in self.todofile.read() \ if re.search(r'\S', line)] self.text = ''.join(lines) self.todolist = TodoList(lines) def test_contexts(self): self.assertEquals(set(['Context1', 'Context2']), \ self.todolist.contexts()) self.assertFalse(self.todolist.is_dirty()) def test_projects(self): self.assertEquals(set(['Project1', 'Project2']), \ self.todolist.projects()) self.assertFalse(self.todolist.is_dirty()) def test_add1(self): text = "(C) Adding a new task @Context3 +Project3" count = self.todolist.count() todo = self.todolist.add(text) self.assertEquals(self.todolist.todo(count + 1).source(), text) self.assertEquals(set(['Project1', 'Project2', 'Project3']), \ self.todolist.projects()) self.assertEquals(set(['Context1', 'Context2', 'Context3']), \ self.todolist.contexts()) self.assertEquals(self.todolist.number(todo), 6) self.assertTrue(self.todolist.is_dirty()) def test_add2(self): text = str(self.todolist) self.todolist.add('') self.assertEquals(str(self.todolist), text) def test_add3a(self): count = self.todolist.count() self.todolist.add('\n(C) New task') self.assertEqual(self.todolist.count(), count + 1) self.assertEqual( self.todolist.todo(count + 1).source(), '(C) New task') self.assertEqual(self.todolist.todo(count + 1).priority(), 'C') def test_add3b(self): count = self.todolist.count() self.todolist.add('(C) New task\n') self.assertEqual(self.todolist.count(), count + 1) self.assertEqual( self.todolist.todo(count + 1).source(), '(C) New task') self.assertEqual(self.todolist.todo(count + 1).priority(), 'C') def test_add4(self): text = str(self.todolist) self.todolist.add(' ') self.assertEquals(str(self.todolist), text) def test_add5(self): text = str(self.todolist) self.todolist.add("\n") self.assertEquals(str(self.todolist), text) def test_delete1(self): count = self.todolist.count() todo = self.todolist.todo(2) self.todolist.delete(todo) self.assertEquals(self.todolist.todo(2).source(), \ "(C) Baz @Context1 +Project1 key:value") self.assertEquals(self.todolist.count(), count - 1) self.assertTrue(self.todolist.is_dirty()) self.assertRaises(InvalidTodoException, self.todolist.number, todo) def test_append1(self): todo = self.todolist.todo(3) self.todolist.append(todo, "@Context3") self.assertEquals(todo.source(), \ "(C) Baz @Context1 +Project1 key:value @Context3") self.assertEquals(set(['Context1', 'Context2', 'Context3']), \ self.todolist.contexts()) self.assertTrue(self.todolist.is_dirty()) def test_append2(self): todo = self.todolist.todo(3) text = todo.text() self.todolist.append(todo, "foo:bar") self.assertEquals(todo.text(), text) self.assertEquals(todo.source(), \ "(C) Baz @Context1 +Project1 key:value foo:bar") def test_append3(self): todo = self.todolist.todo(3) text = todo.text() self.todolist.append(todo, '') self.assertEquals(todo.text(), text) def test_todo(self): count = self.todolist.count() self.assertRaises(InvalidTodoException, self.todolist.todo, count + 100) self.assertFalse(self.todolist.is_dirty()) def test_string(self): # readlines() always ends a string with \n, but join() in str(todolist) # doesn't necessarily. self.assertEquals(str(self.todolist) + '\n', self.text) def test_count(self): """ Test that empty lines are not counted. """ self.assertEquals(self.todolist.count(), 5) def test_todo_by_dep_id(self): """ Tests that todos can be retrieved by their id tag. """ self.todolist.add("(C) Foo id:1") self.assertTrue(self.todolist.todo_by_dep_id('1')) self.assertFalse(self.todolist.todo_by_dep_id('2')) def test_todo_number1(self): todo = Todo("No number") self.todolist.add_todo(todo) todo = self.todolist.todo(6) self.assertIsInstance(todo, Todo) self.assertEquals(todo.text(), "No number") def test_todo_number2(self): todo = Todo("Non-existent") self.assertRaises(InvalidTodoException, self.todolist.number, todo) def test_todo_complete(self): todo = self.todolist.todo(1) self.todolist.set_todo_completed(todo) self.assertTrue(self.todolist.todo(1).is_completed()) self.assertTrue(self.todolist.is_dirty()) def test_todo_priority1(self): todo = self.todolist.todo(1) self.todolist.set_priority(todo, 'F') self.assertEquals(self.todolist.todo(1).priority(), 'F') self.assertTrue(self.todolist.is_dirty()) def test_todo_priority2(self): todo = self.todolist.todo(1) self.todolist.set_priority(todo, 'C') self.assertFalse(self.todolist.is_dirty()) def test_erase(self): self.todolist.erase() self.assertEquals(self.todolist.count(), 0) self.assertTrue(self.todolist.is_dirty()) def test_regex1(self): """ Multiple hits should result in None. """ self.assertRaises(InvalidTodoException, self.todolist.todo, "Project1") def test_regex3(self): todo = self.todolist.todo("project2") self.assertTrue(todo) self.assertEquals(todo.source(), "(D) Bar @Context1 +Project2") def test_uid1(self): config("test/data/todolist-uid.conf") self.assertEquals( self.todolist.todo('6iu').source(), "(C) Foo @Context2 Not@Context +Project1 Not+Project") def test_uid2(self): """ Changing the priority should not change the identifier. """ config("test/data/todolist-uid.conf") todo = self.todolist.todo('6iu') self.todolist.set_priority(todo, 'B') self.assertEquals( self.todolist.todo('6iu').source(), "(B) Foo @Context2 Not@Context +Project1 Not+Project") def test_uid3(self): """ Must be able to handle integers when text identifiers are enabled. """ config("test/data/todolist-uid.conf") self.assertRaises(InvalidTodoException, self.todolist.todo, 1) def test_new_uid(self): """ Make sure that item has new text ID after append. """ config("test/data/todolist-uid.conf") todo = self.todolist.todo('6iu') self.todolist.append(todo, "A") self.assertNotEquals(self.todolist.number(todo), '6iu')
class EditCommandTest(CommandTest): def setUp(self): super(EditCommandTest, self).setUp() todos = ["Foo id:1", "Bar p:1 @test", "Baz @test", u("Fo\u00f3B\u0105\u017a")] self.todolist = TodoList(todos) @mock.patch("topydo.commands.EditCommand.EditCommand._open_in_editor") def test_edit1(self, mock_open_in_editor): """ Preserve dependencies after editing. """ mock_open_in_editor.return_value = 0 command = EditCommand(["1"], self.todolist, self.out, self.error, None) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.errors, "") self.assertEqual(self.todolist.print_todos(), u("Bar p:1 @test\nBaz @test\nFo\u00f3B\u0105\u017a\nFoo id:1")) @mock.patch("topydo.commands.EditCommand.EditCommand._todos_from_temp") @mock.patch("topydo.commands.EditCommand.EditCommand._open_in_editor") def test_edit2(self, mock_open_in_editor, mock_todos_from_temp): """ Edit some todo. """ mock_open_in_editor.return_value = 0 mock_todos_from_temp.return_value = [Todo("Lazy Cat")] command = EditCommand(["Bar"], self.todolist, self.out, self.error, None) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.errors, "") self.assertEqual(self.todolist.print_todos(), u("Foo id:1\nBaz @test\nFo\u00f3B\u0105\u017a\nLazy Cat")) def test_edit3(self): """ Throw an error after invalid todo number given as argument. """ command = EditCommand(["FooBar"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.errors, "Invalid todo number given.\n") def test_edit4(self): """ Throw an error with pointing invalid argument. """ command = EditCommand(["Bar", "5"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.errors, "Invalid todo number given: 5.\n") @mock.patch("topydo.commands.EditCommand.EditCommand._todos_from_temp") @mock.patch("topydo.commands.EditCommand.EditCommand._open_in_editor") def test_edit5(self, mock_open_in_editor, mock_todos_from_temp): """ Don't let to delete todos acidentally while editing. """ mock_open_in_editor.return_value = 0 mock_todos_from_temp.return_value = [Todo("Only one line")] command = EditCommand(["1", "Bar"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.errors, "Number of edited todos is not equal to number of supplied todo IDs.\n") self.assertEqual(self.todolist.print_todos(), u("Foo id:1\nBar p:1 @test\nBaz @test\nFo\u00f3B\u0105\u017a")) def test_edit6(self): """ Throw an error with invalid argument containing special characters. """ command = EditCommand([u("Fo\u00d3B\u0105r"), "Bar"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.errors, u("Invalid todo number given: Fo\u00d3B\u0105r.\n")) @mock.patch("topydo.commands.EditCommand.EditCommand._todos_from_temp") @mock.patch("topydo.commands.EditCommand.EditCommand._open_in_editor") def test_edit7(self, mock_open_in_editor, mock_todos_from_temp): """ Edit todo with special characters. """ mock_open_in_editor.return_value = 0 mock_todos_from_temp.return_value = [Todo("Lazy Cat")] command = EditCommand([u("Fo\u00f3B\u0105\u017a")], self.todolist, self.out, self.error, None) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.errors, "") self.assertEqual(self.todolist.print_todos(), u("Foo id:1\nBar p:1 @test\nBaz @test\nLazy Cat")) @mock.patch("topydo.commands.EditCommand.EditCommand._todos_from_temp") @mock.patch("topydo.commands.EditCommand.EditCommand._open_in_editor") def test_edit_expr(self, mock_open_in_editor, mock_todos_from_temp): """ Edit todos matching expression. """ mock_open_in_editor.return_value = 0 mock_todos_from_temp.return_value = [Todo("Lazy Cat"), Todo("Lazy Dog")] command = EditCommand(["-e", "@test"], self.todolist, self.out, self.error, None) command.execute() expected = u("| 3| Lazy Cat\n| 4| Lazy Dog\n") self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.errors, "") self.assertEqual(self.output, expected) self.assertEqual(self.todolist.print_todos(), u("Foo id:1\nFo\u00f3B\u0105\u017a\nLazy Cat\nLazy Dog")) @mock.patch("topydo.commands.EditCommand.check_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(["-d"], self.todolist, self.out, self.error, None) command.execute() self.assertEqual(self.errors, "") mock_call.assert_called_once_with([editor, archive]) @mock.patch("topydo.commands.EditCommand.check_call") def test_edit_todotxt(self, mock_call): """ Edit todo file. """ mock_call.return_value = 0 editor = "vi" os.environ["EDITOR"] = editor todotxt = config().todotxt() result = self.todolist.print_todos() # copy TodoList content *before* executing command command = EditCommand([], self.todolist, self.out, self.error, None) command.execute() self.assertEqual(self.errors, "") self.assertEqual(self.todolist.print_todos(), result) mock_call.assert_called_once_with([editor, todotxt])
class PriorityCommandTest(CommandTest.CommandTest): def setUp(self): super(PriorityCommandTest, self).setUp() todos = [ "(A) Foo", "Bar", ] self.todolist = TodoList(todos) def test_set_prio1(self): command = PriorityCommand(["1", "B"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEquals(self.output, "Priority changed from A to B\n(B) Foo\n") self.assertEquals(self.errors, "") def test_set_prio2(self): command = PriorityCommand(["2", "Z"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEquals(self.output, "Priority set to Z.\n(Z) Bar\n") self.assertEquals(self.errors, "") def test_set_prio3(self): command = PriorityCommand(["Foo", "B"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEquals(self.output, "Priority changed from A to B\n(B) Foo\n") self.assertEquals(self.errors, "") def test_set_prio4(self): command = PriorityCommand(["1", "A"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEquals(self.output, "(A) Foo\n") self.assertEquals(self.errors, "") def test_invalid1(self): command = PriorityCommand(["99", "A"], 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.\n") def test_invalid2(self): command = PriorityCommand(["1", "ZZ"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEquals(self.errors, "Invalid priority given.\n") def test_invalid3(self): command = PriorityCommand(["A"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEquals(self.errors, command.usage() + "\n") def test_invalid4(self): command = PriorityCommand(["1"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEquals(self.errors, command.usage() + "\n") def test_empty(self): command = PriorityCommand([], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEquals(self.errors, command.usage() + "\n") def test_help(self): command = PriorityCommand(["help"], self.todolist, self.out, self.error) command.execute() self.assertEquals(self.output, "") self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n")
class DeleteCommandTest(CommandTest): def setUp(self): super().setUp() todos = [ "Foo id:1", "Bar p:1", "a @test with due:2015-06-03", "a @test with +project", ] self.todolist = TodoList(todos) def test_del1(self): command = DeleteCommand(["1"], self.todolist, self.out, self.error, _no_prompt) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.todo(1).source(), "Bar") self.assertEqual(self.output, "| 2| Bar p:1\nRemoved: Foo id:1\n") self.assertEqual(self.errors, "") def test_del1_regex(self): command = DeleteCommand(["Foo"], self.todolist, self.out, self.error, _no_prompt) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.todo(1).source(), "Bar") self.assertEqual(self.output, "| 2| Bar p:1\nRemoved: Foo id:1\n") self.assertEqual(self.errors, "") def test_del2(self): command = DeleteCommand(["1"], self.todolist, self.out, self.error, _yes_prompt) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.count(), 2) self.assertEqual(self.output, "| 2| Bar p:1\nRemoved: Bar\nRemoved: Foo\n") self.assertEqual(self.errors, "") def test_del3(self): command = DeleteCommand(["-f", "1"], self.todolist, self.out, self.error, _yes_prompt) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.count(), 3) # force won't delete subtasks self.assertEqual(self.output, "| 2| Bar p:1\nRemoved: Foo id:1\n") self.assertEqual(self.errors, "") def test_del4(self): command = DeleteCommand(["--force", "1"], self.todolist, self.out, self.error, _yes_prompt) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.count(), 3) # force won't delete subtasks self.assertEqual(self.output, "| 2| Bar p:1\nRemoved: Foo id:1\n") self.assertEqual(self.errors, "") def test_del5(self): command = DeleteCommand(["2"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.todo(1).source(), "Foo") self.assertEqual(self.output, "Removed: Bar p:1\nThe following todo item(s) became active:\n| 1| Foo\n") self.assertEqual(self.errors, "") def test_del7(self): command = DeleteCommand(["99"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number given.\n") def test_del8(self): command = DeleteCommand(["A"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number given.\n") def test_del9(self): """ Test deletion with textual IDs. """ config("test/data/todolist-uid.conf") command = DeleteCommand(["8to"], self.todolist, self.out, self.error) command.execute() result = "Foo\na @test with due:2015-06-03\na @test with +project" self.assertEqual(self.todolist.print_todos(), result) self.assertRaises(InvalidTodoException, self.todolist.todo, 'b0n') def test_multi_del1(self): """ Test deletion of multiple items. """ command = DeleteCommand(["1", "2"], self.todolist, self.out, self.error, _no_prompt) command.execute() result = "a @test with due:2015-06-03\na @test with +project" self.assertEqual(self.todolist.count(), 2) self.assertEqual(self.todolist.print_todos(), result) def test_multi_del2(self): """ Test deletion of multiple items. """ command = DeleteCommand(["1", "2"], self.todolist, self.out, self.error, _yes_prompt) command.execute() result = "a @test with due:2015-06-03\na @test with +project" self.assertEqual(self.todolist.count(), 2) self.assertEqual(self.todolist.print_todos(), result) def test_multi_del3(self): """ Fail if any of supplied todo numbers is invalid. """ command = DeleteCommand(["99", "2"], self.todolist, self.out, self.error, _yes_prompt) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number given: 99.\n") def test_multi_del4(self): """ Check output when all supplied todo numbers are invalid. """ command = DeleteCommand(["99", "A"], self.todolist, self.out, self.error, _yes_prompt) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number given: 99.\nInvalid todo number given: A.\n") def test_multi_del5(self): """ Throw an error with invalid argument containing special characters. """ command = DeleteCommand([u"Fo\u00d3B\u0105r", "Bar"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, u"Invalid todo number given: Fo\u00d3B\u0105r.\n") def test_expr_del1(self): command = DeleteCommand(["-e", "@test"], self.todolist, self.out, self.error, None) command.execute() result = "Removed: a @test with due:2015-06-03\nRemoved: a @test with +project\n" self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.count(), 2) self.assertEqual(self.output, result) self.assertEqual(self.errors, "") def test_expr_del2(self): command = DeleteCommand(["-e", "@test", "due:2015-06-03"], self.todolist, self.out, self.error, None) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "Removed: a @test with due:2015-06-03\n") self.assertEqual(self.errors, "") def test_expr_del3(self): command = DeleteCommand(["-e", "@test", "due:2015-06-03", "+project"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) def test_expr_del4(self): """ Remove only relevant todo items. """ command = DeleteCommand(["-e", ""], self.todolist, self.out, self.error, None) command.execute() result = "Foo" self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.count(), 1) self.assertEqual(self.todolist.print_todos(), result) def test_expr_del5(self): """ Force deleting unrelevant items with additional -x flag. """ command = DeleteCommand(["-xe", ""], self.todolist, self.out, self.error, _yes_prompt) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.count(), 0) def test_empty(self): command = DeleteCommand([], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, command.usage() + "\n") def test_help(self): command = DeleteCommand(["help"], self.todolist, self.out, self.error) command.execute() self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
class DeleteCommandTest(CommandTest.CommandTest): def setUp(self): super(DeleteCommandTest, self).setUp() todos = [ "Foo id:1", "Bar p:1", ] self.todolist = TodoList(todos) def test_del1(self): command = DeleteCommand(["1"], self.todolist, self.out, self.error, _no_prompt) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEquals(self.todolist.todo(1).source(), "Bar") self.assertEquals(self.output, "| 2| Bar p:1\nRemoved: Foo id:1\n") self.assertEquals(self.errors, "") def test_del1_regex(self): command = DeleteCommand(["Foo"], self.todolist, self.out, self.error, _no_prompt) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEquals(self.todolist.todo(1).source(), "Bar") self.assertEquals(self.output, "| 2| Bar p:1\nRemoved: Foo id:1\n") self.assertEquals(self.errors, "") def test_del2(self): command = DeleteCommand(["1"], self.todolist, self.out, self.error, _yes_prompt) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEquals(self.todolist.count(), 0) self.assertEquals(self.output, "| 2| Bar p:1\nRemoved: Bar\nRemoved: Foo\n") self.assertEquals(self.errors, "") def test_del3(self): command = DeleteCommand(["-f", "1"], self.todolist, self.out, self.error, _yes_prompt) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEquals(self.todolist.count(), 1) # force won't delete subtasks self.assertEquals(self.output, "| 2| Bar p:1\nRemoved: Foo id:1\n") self.assertEquals(self.errors, "") def test_del4(self): command = DeleteCommand(["--force", "1"], self.todolist, self.out, self.error, _yes_prompt) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEquals(self.todolist.count(), 1) # force won't delete subtasks self.assertEquals(self.output, "| 2| Bar p:1\nRemoved: Foo id:1\n") self.assertEquals(self.errors, "") def test_del5(self): command = DeleteCommand(["2"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEquals(self.todolist.todo(1).source(), "Foo") self.assertEquals( self.output, "Removed: Bar p:1\nThe following todo item(s) became active:\n| 1| Foo\n" ) self.assertEquals(self.errors, "") def test_del7(self): command = DeleteCommand(["99"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEquals(self.output, "") self.assertEquals(self.errors, "Invalid todo number given.\n") def test_del8(self): command = DeleteCommand(["A"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEquals(self.output, "") self.assertEquals(self.errors, "Invalid todo number given.\n") def test_del9(self): """ Test deletion with textual IDs. """ config("test/data/todolist-uid.conf") command = DeleteCommand(["b0n"], self.todolist, self.out, self.error) command.execute() self.assertEquals(str(self.todolist), "Foo") self.assertRaises(InvalidTodoException, self.todolist.todo, 'b0n') def test_multi_del1(self): """ Test deletion of multiple items. """ command = DeleteCommand(["1", "2"], self.todolist, self.out, self.error, _no_prompt) command.execute() self.assertEquals(self.todolist.count(), 0) def test_multi_del2(self): """ Test deletion of multiple items. """ command = DeleteCommand(["1", "2"], self.todolist, self.out, self.error, _yes_prompt) command.execute() self.assertEquals(self.todolist.count(), 0) def test_multi_del3(self): """ Test deletion of multiple items. """ command = DeleteCommand(["99", "2"], self.todolist, self.out, self.error, _yes_prompt) command.execute() self.assertEquals(self.todolist.count(), 1) def test_empty(self): command = DeleteCommand([], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEquals(self.errors, command.usage() + "\n") def test_help(self): command = DeleteCommand(["help"], self.todolist, self.out, self.error) command.execute() self.assertEquals(self.output, "") self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n")
class PriorityCommandTest(CommandTest): def setUp(self): super(PriorityCommandTest, self).setUp() todos = [ "(A) Foo", "Bar", "(B) a @test with due:2015-06-03", "a @test with +project p:1", "Baz id:1", ] self.todolist = TodoList(todos) def test_set_prio1(self): command = PriorityCommand(["1", "B"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "Priority changed from A to B\n| 1| (B) Foo\n") self.assertEqual(self.errors, "") def test_set_prio2(self): command = PriorityCommand(["2", "Z"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "Priority set to Z.\n| 2| (Z) Bar\n") self.assertEqual(self.errors, "") def test_set_prio3(self): command = PriorityCommand(["Foo", "B"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "Priority changed from A to B\n| 1| (B) Foo\n") self.assertEqual(self.errors, "") def test_set_prio4(self): command = PriorityCommand(["1", "A"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "| 1| (A) Foo\n") self.assertEqual(self.errors, "") def test_set_prio5(self): command = PriorityCommand(["Foo", "2", "C"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "Priority changed from A to C\n| 1| (C) Foo\nPriority set to C.\n| 2| (C) Bar\n") self.assertEqual(self.errors, "") def test_set_prio6(self): """ Allow priority to be set including parentheses. """ command = PriorityCommand(["Foo", "2", "(C)"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "Priority changed from A to C\n| 1| (C) Foo\nPriority set to C.\n| 2| (C) Bar\n") self.assertEqual(self.errors, "") def test_expr_prio1(self): command = PriorityCommand(["-e", "@test", "C"], self.todolist, self.out, self.error, None) command.execute() result = "Priority changed from B to C\n| 3| (C) a @test with due:2015-06-03\nPriority set to C.\n| 4| (C) a @test with +project p:1\n" self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, result) self.assertEqual(self.errors, "") def test_expr_prio2(self): command = PriorityCommand(["-e", "@test", "due:2015-06-03", "C"], self.todolist, self.out, self.error, None) command.execute() result = "Priority changed from B to C\n| 3| (C) a @test with due:2015-06-03\n" self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, result) self.assertEqual(self.errors, "") def test_expr_prio3(self): command = PriorityCommand(["-e", "@test", "due:2015-06-03", "+project", "C"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) def test_expr_prio4(self): """ Don't prioritize unrelevant todo items. """ command = PriorityCommand(["-e", "Baz", "C"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) def test_expr_prio5(self): """ Force prioritizing unrelevant items with additional -x flag. """ command = PriorityCommand(["-xe", "Baz", "D"], self.todolist, self.out, self.error, None) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "Priority set to D.\n| 5| (D) Baz id:1\n") self.assertEqual(self.errors, "") def test_invalid1(self): command = PriorityCommand(["99", "A"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, "Invalid todo number given.\n") def test_invalid2(self): command = PriorityCommand(["1", "99", "A"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, "Invalid todo number given: 99.\n") def test_invalid3(self): command = PriorityCommand(["98", "99", "A"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, "Invalid todo number given: 98.\nInvalid todo number given: 99.\n") def test_invalid4(self): command = PriorityCommand(["1", "ZZ"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, "Invalid priority given.\n") def test_invalid5(self): command = PriorityCommand(["A"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, command.usage() + "\n") def test_invalid6(self): command = PriorityCommand(["1"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, command.usage() + "\n") def test_invalid7(self): """ Throw an error with invalid argument containing special characters. """ command = PriorityCommand([u("Fo\u00d3B\u0105r"), "Bar", "C"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, u("Invalid todo number given: Fo\u00d3B\u0105r.\n")) def test_invalid8(self): """ Test that there's only one capital surrounded by non-word characters that makes up a priority. """ command = PriorityCommand(["2", "(Aa)"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid priority given.\n") def test_invalid9(self): """ Test that there's only one capital surrounded by non-word characters that makes up a priority. """ command = PriorityCommand(["2", "Aa"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid priority given.\n") def test_empty(self): command = PriorityCommand([], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, command.usage() + "\n") def test_help(self): command = PriorityCommand(["help"], self.todolist, self.out, self.error) command.execute() self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
class TagCommandTest(CommandTest): def setUp(self): super().setUp() todos = [ "Foo", "Bar due:2014-10-22", "Baz due:2014-10-20", "Fnord due:2014-10-20 due:2014-10-22", ] self.todolist = TodoList(todos) def test_add_tag1(self): command = TagCommand(["1", "due", "2014-10-22"], self.todolist, self.out, self.error) command.execute() self.assertEqual(self.todolist.todo(1).source(), "Foo due:2014-10-22") self.assertEqual(self.output, "| 1| Foo due:2014-10-22\n") self.assertEqual(self.errors, "") self.assertTrue(self.todolist.is_dirty()) def test_add_tag2(self): command = TagCommand(["Foo", "due", "2014-10-22"], self.todolist, self.out, self.error) command.execute() self.assertEqual(self.todolist.todo(1).source(), "Foo due:2014-10-22") self.assertEqual(self.output, "| 1| Foo due:2014-10-22\n") self.assertEqual(self.errors, "") self.assertTrue(self.todolist.is_dirty()) def test_add_tag3(self): command = TagCommand(["-a", "2", "due", "2014-10-19"], self.todolist, self.out, self.error) command.execute() self.assertEqual(self.todolist.todo(2).source(), "Bar due:2014-10-22 due:2014-10-19") self.assertEqual(self.output, "| 2| Bar due:2014-10-22 due:2014-10-19\n") self.assertEqual(self.errors, "") self.assertTrue(self.todolist.is_dirty()) def test_add_tag4(self): command = TagCommand(["Foox", "due", "2014-10-22"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, "Invalid todo number.\n") def test_force_add_tag01(self): '''Tries to different values to a tag for the same name 3 times.''' for letter in ['a', 'b', 'c']: command = TagCommand(['-a', '1', 'k', letter], self.todolist, self.out, self.error) command.execute() self.assertEqual(self.errors, "") self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.todo(1).source(), "Foo k:a k:b k:c") def test_set_tag04(self): command = TagCommand(["3", "due", "2014-10-20"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "| 3| Baz due:2014-10-20\n") self.assertEqual(self.errors, "") def test_set_tag05(self): command = TagCommand(["4", "due", "2014-10-20"], self.todolist, self.out, self.error, lambda t: "all") command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, " 1. 2014-10-20\n 2. 2014-10-22\n| 4| Fnord due:2014-10-20 due:2014-10-20\n") self.assertEqual(self.errors, "") def test_set_tag06(self): command = TagCommand(["4", "due", "2014-10-20"], self.todolist, self.out, self.error, lambda t: "1") command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, " 1. 2014-10-20\n 2. 2014-10-22\n| 4| Fnord due:2014-10-20 due:2014-10-22\n") self.assertEqual(self.errors, "") def test_set_tag07(self): command = TagCommand(["4", "due", "2014-10-20"], self.todolist, self.out, self.error, lambda t: "2") command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, " 1. 2014-10-20\n 2. 2014-10-22\n| 4| Fnord due:2014-10-20 due:2014-10-20\n") self.assertEqual(self.errors, "") def test_set_tag08(self): command = TagCommand(["4", "due", "2014-10-20"], self.todolist, self.out, self.error, lambda t: "") command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, " 1. 2014-10-20\n 2. 2014-10-22\n| 4| Fnord due:2014-10-20 due:2014-10-22\n") self.assertEqual(self.errors, "") def test_set_tag09(self): command = TagCommand(["4", "due", "2014-10-20"], self.todolist, self.out, self.error, lambda t: "99") command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, " 1. 2014-10-20\n 2. 2014-10-22\n| 4| Fnord due:2014-10-20 due:2014-10-22\n") self.assertEqual(self.errors, "") def test_set_tag10(self): command = TagCommand(["-f", "4", "due", "2014-10-20"], self.todolist, self.out, self.error, lambda t: "99") command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "| 4| Fnord due:2014-10-20 due:2014-10-20\n") self.assertEqual(self.errors, "") @freeze_time('2015, 11, 19') def test_set_tag11(self): command = TagCommand(["3", "due", "today"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "| 3| Baz due:2015-11-19\n") self.assertEqual(self.errors, "") def test_set_tag12(self): """ Do not convert relative dates for tags that were not configured as start/due date. """ command = TagCommand(["3", "foo", "today"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "| 3| Baz due:2014-10-20 foo:today\n") self.assertEqual(self.errors, "") def test_rm_tag01(self): command = TagCommand(["1", "due"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "| 1| Foo\n") self.assertEqual(self.errors, "") def test_rm_tag02(self): command = TagCommand(["2", "due"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "| 2| Bar\n") self.assertEqual(self.errors, "") def test_rm_tag03(self): command = TagCommand(["4", "due"], self.todolist, self.out, self.error, lambda t: "all") command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, " 1. 2014-10-20\n 2. 2014-10-22\n| 4| Fnord\n") self.assertEqual(self.errors, "") def test_rm_tag04(self): command = TagCommand(["4", "due"], self.todolist, self.out, self.error, lambda t: "1") command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, " 1. 2014-10-20\n 2. 2014-10-22\n| 4| Fnord due:2014-10-22\n") self.assertEqual(self.errors, "") def test_rm_tag06(self): command = TagCommand(["4", "due"], self.todolist, self.out, self.error, lambda t: "99") command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, " 1. 2014-10-20\n 2. 2014-10-22\n| 4| Fnord due:2014-10-20 due:2014-10-22\n") self.assertEqual(self.errors, "") def test_rm_tag07(self): command = TagCommand(["4", "due"], self.todolist, self.out, self.error, lambda t: "A") command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, " 1. 2014-10-20\n 2. 2014-10-22\n| 4| Fnord due:2014-10-20 due:2014-10-22\n") self.assertEqual(self.errors, "") def test_rm_tag08(self): command = TagCommand(["5", "due"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number.\n") def test_rm_tag09(self): command = TagCommand(["A", "due"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number.\n") def test_rm_tag10(self): command = TagCommand(["-f", "4", "due"], self.todolist, self.out, self.error, lambda t: "A") command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "| 4| Fnord\n") self.assertEqual(self.errors, "") def test_no_tag(self): command = TagCommand(["4"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n") def test_help(self): command = TagCommand(["help"], self.todolist, self.out, self.error) command.execute() self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
class PostponeCommandTest(CommandTest): def setUp(self): super(PostponeCommandTest, self).setUp() self.today = date.today() self.past = date.today() - timedelta(1) self.future = date.today() + timedelta(1) self.start = date.today() - timedelta(2) self.future_start = self.future - timedelta(2) todos = [ "Foo", "Bar due:{}".format(self.today.isoformat()), "Baz due:{} t:{}".format(self.today.isoformat(), self.start.isoformat()), "Past due:{}".format(self.past.isoformat()), "Future due:{} t:{}".format(self.future.isoformat(), self.future_start.isoformat()), "FutureStart t:{}".format(self.future.isoformat()) ] self.todolist = TodoList(todos) def test_postpone1(self): command = PostponeCommand(["1", "1w"], self.todolist, self.out, self.error) command.execute() due = self.today + timedelta(7) self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "| 1| Foo due:{}\n".format(due.isoformat())) self.assertEqual(self.errors, "") def test_postpone2(self): command = PostponeCommand(["2", "1w"], self.todolist, self.out, self.error) command.execute() due = self.today + timedelta(7) self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "| 2| Bar due:{}\n".format(due.isoformat())) self.assertEqual(self.errors, "") def test_postpone3(self): command = PostponeCommand(["-s", "2", "1w"], self.todolist, self.out, self.error) command.execute() due = self.today + timedelta(7) self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "| 2| Bar due:{}\n".format(due.isoformat())) self.assertEqual(self.errors, "") def test_postpone4(self): command = PostponeCommand(["3", "1w"], self.todolist, self.out, self.error) command.execute() due = self.today + timedelta(7) self.assertTrue(self.todolist.is_dirty()) self.assertEqual( self.output, "| 3| Baz due:{} t:{}\n".format(due.isoformat(), self.start.isoformat())) self.assertEqual(self.errors, "") def test_postpone5(self): command = PostponeCommand(["-s", "3", "1w"], self.todolist, self.out, self.error) command.execute() due = self.today + timedelta(7) start = self.start + timedelta(7) self.assertTrue(self.todolist.is_dirty()) # pylint: disable=E1103 self.assertEqual( self.output, "| 3| Baz due:{} t:{}\n".format(due.isoformat(), start.isoformat())) self.assertEqual(self.errors, "") def test_postpone6(self): command = PostponeCommand(["4", "1w"], self.todolist, self.out, self.error) command.execute() due = self.today + timedelta(7) self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "| 4| Past due:{}\n".format(due.isoformat())) self.assertEqual(self.errors, "") def test_postpone7(self): command = PostponeCommand(["5", "1w"], self.todolist, self.out, self.error) command.execute() due = self.future + timedelta(7) self.assertTrue(self.todolist.is_dirty()) # pylint: disable=E1103 self.assertEqual( self.output, "| 5| Future due:{} t:{}\n".format(due.isoformat(), self.future_start.isoformat())) self.assertEqual(self.errors, "") def test_postpone8(self): command = PostponeCommand(["-s", "5", "1w"], self.todolist, self.out, self.error) command.execute() due = self.future + timedelta(7) start = self.future_start + timedelta(7) self.assertTrue(self.todolist.is_dirty()) # pylint: disable=E1103 self.assertEqual( self.output, "| 5| Future due:{} t:{}\n".format(due.isoformat(), start.isoformat())) self.assertEqual(self.errors, "") def test_postpone9(self): command = PostponeCommand(["1", "foo"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid date pattern given.\n") def test_postpone10(self): command = PostponeCommand(["99", "foo"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number given.\n") def test_postpone11(self): command = PostponeCommand(["A", "foo"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number given.\n") def test_postpone12(self): command = PostponeCommand(["1"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n") def test_postpone13(self): command = PostponeCommand(["Foo", "1w"], self.todolist, self.out, self.error) command.execute() due = self.today + timedelta(7) self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "| 1| Foo due:{}\n".format(due.isoformat())) self.assertEqual(self.errors, "") def test_postpone14(self): command = PostponeCommand(["1", "2", "1w"], self.todolist, self.out, self.error) command.execute() due = self.today + timedelta(7) self.assertTrue(self.todolist.is_dirty()) self.assertEqual( self.output, "| 1| Foo due:{}\n| 2| Bar due:{}\n".format( due.isoformat(), due.isoformat())) self.assertEqual(self.errors, "") def test_postpone15(self): command = PostponeCommand(["Foo", "2", "1w"], self.todolist, self.out, self.error) command.execute() due = self.today + timedelta(7) self.assertTrue(self.todolist.is_dirty()) self.assertEqual( self.output, "| 1| Foo due:{}\n| 2| Bar due:{}\n".format( due.isoformat(), due.isoformat())) self.assertEqual(self.errors, "") def test_postpone16(self): command = PostponeCommand(["-s", "2", "3", "1w"], self.todolist, self.out, self.error) command.execute() due = self.today + timedelta(7) start = self.start + timedelta(7) self.assertTrue(self.todolist.is_dirty()) # pylint: disable=E1103 self.assertEqual( self.output, "| 2| Bar due:{}\n| 3| Baz due:{} t:{}\n".format( due.isoformat(), due.isoformat(), start.isoformat())) self.assertEqual(self.errors, "") def test_postpone17(self): command = PostponeCommand(["1", "2", "3"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid date pattern given.\n") def test_postpone18(self): command = PostponeCommand(["1", "99", "123", "1w"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual( self.errors, "Invalid todo number given: 99.\nInvalid todo number given: 123.\n" ) def test_postpone19(self): command = PostponeCommand(["Zoo", "99", "123", "1w"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual( self.errors, "Invalid todo number given: Zoo.\nInvalid todo number given: 99.\nInvalid todo number given: 123.\n" ) def test_postpone20(self): """ Throw an error with invalid argument containing special characters. """ command = PostponeCommand([u("Fo\u00d3B\u0105r"), "Bar", "1d"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, u("Invalid todo number given: Fo\u00d3B\u0105r.\n")) def test_expr_postpone1(self): command = PostponeCommand(["-e", "due:tod", "2w"], self.todolist, self.out, self.error, None) command.execute() due = self.today + timedelta(14) result = "| 2| Bar due:{d}\n| 3| Baz due:{d} t:{s}\n".format( d=due.isoformat(), s=self.start.isoformat()) self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, result) self.assertEqual(self.errors, "") def test_expr_postpone2(self): cmd_args = [ "-e", "t:{}".format(self.start.isoformat()), "due:tod", "1w" ] command = PostponeCommand(cmd_args, self.todolist, self.out, self.error, None) command.execute() due = self.today + timedelta(7) result = "| 3| Baz due:{} t:{}\n".format(due.isoformat(), self.start.isoformat()) self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, result) self.assertEqual(self.errors, "") def test_expr_postpone3(self): command = PostponeCommand(["-e", "@test", "due:tod", "+project", "C"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) def test_expr_postpone4(self): """ Don't postpone unrelevant todo items. """ command = PostponeCommand(["-e", "FutureStart", "1w"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) def test_expr_postpone5(self): """ Force postponing unrelevant items with additional -x flag. """ command = PostponeCommand(["-xe", "FutureStart", "1w"], self.todolist, self.out, self.error, None) command.execute() due = self.today + timedelta(7) result = "| 6| FutureStart t:{} due:{}\n".format( self.future.isoformat(), due.isoformat()) self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, result) self.assertEqual(self.errors, "") def test_help(self): command = PostponeCommand(["help"], self.todolist, self.out, self.error) command.execute() self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
class EditCommandTest(CommandTest): def setUp(self): super().setUp() todos = [ "Foo id:1", "Bar p:1 @test", "Baz @test", u"Fo\u00f3B\u0105\u017a", ] self.todolist = TodoList(todos) @mock.patch('topydo.commands.EditCommand._is_edited') @mock.patch('topydo.commands.EditCommand.EditCommand._todos_from_temp') @mock.patch('topydo.commands.EditCommand.EditCommand._open_in_editor') def test_edit01(self, mock_open_in_editor, mock_todos_from_temp, mock_is_edited): """ Preserve dependencies after editing. """ mock_open_in_editor.return_value = 0 mock_todos_from_temp.return_value = [Todo('Foo id:1')] mock_is_edited.return_value = True command = EditCommand(["1"], self.todolist, self.out, self.error, None) command.execute() self.assertEqual(self.errors, "") self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.print_todos(), u"Bar p:1 @test\nBaz @test\nFo\u00f3B\u0105\u017a\nFoo id:1") @mock.patch('topydo.commands.EditCommand._is_edited') @mock.patch('topydo.commands.EditCommand.EditCommand._todos_from_temp') @mock.patch('topydo.commands.EditCommand.EditCommand._open_in_editor') def test_edit02(self, mock_open_in_editor, mock_todos_from_temp, mock_is_edited): """ Edit some todo. """ mock_open_in_editor.return_value = 0 mock_todos_from_temp.return_value = [Todo('Lazy Cat')] mock_is_edited.return_value = True command = EditCommand(["Bar"], self.todolist, self.out, self.error, None) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.errors, "") self.assertEqual(self.todolist.print_todos(), u"Foo id:1\nBaz @test\nFo\u00f3B\u0105\u017a\nLazy Cat") def test_edit03(self): """ Throw an error after invalid todo number given as argument. """ command = EditCommand(["FooBar"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.errors, "Invalid todo number given.\n") def test_edit04(self): """ Throw an error with pointing invalid argument. """ command = EditCommand(["Bar", "5"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.errors, "Invalid todo number given: 5.\n") def test_edit05(self): """ Throw an error with invalid argument containing special characters. """ command = EditCommand([u"Fo\u00d3B\u0105r", "Bar"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.errors, u"Invalid todo number given: Fo\u00d3B\u0105r.\n") @mock.patch('topydo.commands.EditCommand._is_edited') @mock.patch('topydo.commands.EditCommand.EditCommand._todos_from_temp') @mock.patch('topydo.commands.EditCommand.EditCommand._open_in_editor') def test_edit06(self, mock_open_in_editor, mock_todos_from_temp, mock_is_edited): """ Edit todo with special characters. """ mock_open_in_editor.return_value = 0 mock_todos_from_temp.return_value = [Todo('Lazy Cat')] mock_is_edited.return_value = True command = EditCommand([u"Fo\u00f3B\u0105\u017a"], self.todolist, self.out, self.error, None) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.errors, "") self.assertEqual(self.todolist.print_todos(), u"Foo id:1\nBar p:1 @test\nBaz @test\nLazy Cat") @mock.patch('topydo.commands.EditCommand._is_edited') @mock.patch('topydo.commands.EditCommand.EditCommand._todos_from_temp') @mock.patch('topydo.commands.EditCommand.EditCommand._open_in_editor') def test_edit07(self, mock_open_in_editor, mock_todos_from_temp, mock_is_edited): """ Don't perform write if tempfile is unchanged """ mock_open_in_editor.return_value = 0 mock_todos_from_temp.return_value = [Todo('Only one line')] mock_is_edited.return_value = False command = EditCommand(["1", "Bar"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.errors, "Editing aborted. Nothing to do.\n") self.assertEqual(self.todolist.print_todos(), u"Foo id:1\nBar p:1 @test\nBaz @test\nFo\u00f3B\u0105\u017a") @mock.patch('topydo.commands.EditCommand._is_edited') @mock.patch('topydo.commands.EditCommand.EditCommand._todos_from_temp') @mock.patch('topydo.commands.EditCommand.EditCommand._open_in_editor') def test_edit_expr(self, mock_open_in_editor, mock_todos_from_temp, mock_is_edited): """ Edit todos matching expression. """ mock_open_in_editor.return_value = 0 mock_todos_from_temp.return_value = [Todo('Lazy Cat'), Todo('Lazy Dog')] mock_is_edited.return_value = True command = EditCommand(["-e", "@test"], self.todolist, self.out, self.error, None) command.execute() expected = u"| 3| Lazy Cat\n| 4| Lazy Dog\n" self.assertEqual(self.errors, "") self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, expected) self.assertEqual(self.todolist.print_todos(), u"Foo id:1\nFo\u00f3B\u0105\u017a\nLazy Cat\nLazy Dog") @mock.patch('topydo.commands.EditCommand.check_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(["-d"], self.todolist, self.out, self.error, None) command.execute() self.assertEqual(self.errors, "") mock_call.assert_called_once_with([editor, archive]) @mock.patch('topydo.commands.EditCommand.check_call') def test_edit_todotxt(self, mock_call): """ Edit todo file. """ mock_call.return_value = 0 editor = 'vi' os.environ['EDITOR'] = editor todotxt = config().todotxt() result = self.todolist.print_todos() # copy TodoList content *before* executing command command = EditCommand([], self.todolist, self.out, self.error, None) command.execute() self.assertEqual(self.errors, "") self.assertEqual(self.todolist.print_todos(), result) mock_call.assert_called_once_with([editor, todotxt]) def test_help(self): command = EditCommand(["help"], self.todolist, self.out, self.error, None) command.execute() self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
class PostponeCommandTest(CommandTest): def setUp(self): super(PostponeCommandTest, self).setUp() self.today = date.today() self.past = date.today() - timedelta(1) self.future = date.today() + timedelta(1) self.start = date.today() - timedelta(2) self.future_start = self.future - timedelta(2) todos = [ "Foo", "Bar due:{}".format(self.today.isoformat()), "Baz due:{} t:{}".format(self.today.isoformat(), self.start.isoformat()), "Past due:{}".format(self.past.isoformat()), "Future due:{} t:{}".format(self.future.isoformat(), self.future_start.isoformat()), "FutureStart t:{}".format(self.future.isoformat()) ] self.todolist = TodoList(todos) def test_postpone1(self): command = PostponeCommand(["1", "1w"], self.todolist, self.out, self.error) command.execute() due = self.today + timedelta(7) self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "| 1| Foo due:{}\n".format(due.isoformat())) self.assertEqual(self.errors, "") def test_postpone2(self): command = PostponeCommand(["2", "1w"], self.todolist, self.out, self.error) command.execute() due = self.today + timedelta(7) self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "| 2| Bar due:{}\n".format(due.isoformat())) self.assertEqual(self.errors, "") def test_postpone3(self): command = PostponeCommand(["-s", "2", "1w"], self.todolist, self.out, self.error) command.execute() due = self.today + timedelta(7) self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "| 2| Bar due:{}\n".format(due.isoformat())) self.assertEqual(self.errors, "") def test_postpone4(self): command = PostponeCommand(["3", "1w"], self.todolist, self.out, self.error) command.execute() due = self.today + timedelta(7) self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "| 3| Baz due:{} t:{}\n".format(due.isoformat(), self.start.isoformat())) self.assertEqual(self.errors, "") def test_postpone5(self): command = PostponeCommand(["-s", "3", "1w"], self.todolist, self.out, self.error) command.execute() due = self.today + timedelta(7) start = self.start + timedelta(7) self.assertTrue(self.todolist.is_dirty()) # pylint: disable=E1103 self.assertEqual(self.output, "| 3| Baz due:{} t:{}\n".format(due.isoformat(), start.isoformat())) self.assertEqual(self.errors, "") def test_postpone6(self): command = PostponeCommand(["4", "1w"], self.todolist, self.out, self.error) command.execute() due = self.today + timedelta(7) self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "| 4| Past due:{}\n".format(due.isoformat())) self.assertEqual(self.errors, "") def test_postpone7(self): command = PostponeCommand(["5", "1w"], self.todolist, self.out, self.error) command.execute() due = self.future + timedelta(7) self.assertTrue(self.todolist.is_dirty()) # pylint: disable=E1103 self.assertEqual(self.output, "| 5| Future due:{} t:{}\n".format(due.isoformat(), self.future_start.isoformat())) self.assertEqual(self.errors, "") def test_postpone8(self): command = PostponeCommand(["-s", "5", "1w"], self.todolist, self.out, self.error) command.execute() due = self.future + timedelta(7) start = self.future_start + timedelta(7) self.assertTrue(self.todolist.is_dirty()) # pylint: disable=E1103 self.assertEqual(self.output, "| 5| Future due:{} t:{}\n".format(due.isoformat(), start.isoformat())) self.assertEqual(self.errors, "") def test_postpone9(self): command = PostponeCommand(["1", "foo"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid date pattern given.\n") def test_postpone10(self): command = PostponeCommand(["99", "foo"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number given.\n") def test_postpone11(self): command = PostponeCommand(["A", "foo"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number given.\n") def test_postpone12(self): command = PostponeCommand(["1"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n") def test_postpone13(self): command = PostponeCommand(["Foo", "1w"], self.todolist, self.out, self.error) command.execute() due = self.today + timedelta(7) self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "| 1| Foo due:{}\n".format(due.isoformat())) self.assertEqual(self.errors, "") def test_postpone14(self): command = PostponeCommand(["1", "2", "1w"], self.todolist, self.out, self.error) command.execute() due = self.today + timedelta(7) self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "| 1| Foo due:{}\n| 2| Bar due:{}\n".format(due.isoformat(), due.isoformat())) self.assertEqual(self.errors, "") def test_postpone15(self): command = PostponeCommand(["Foo", "2", "1w"], self.todolist, self.out, self.error) command.execute() due = self.today + timedelta(7) self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "| 1| Foo due:{}\n| 2| Bar due:{}\n".format(due.isoformat(), due.isoformat())) self.assertEqual(self.errors, "") def test_postpone16(self): command = PostponeCommand(["-s", "2", "3", "1w"], self.todolist, self.out, self.error) command.execute() due = self.today + timedelta(7) start = self.start + timedelta(7) self.assertTrue(self.todolist.is_dirty()) # pylint: disable=E1103 self.assertEqual(self.output, "| 2| Bar due:{}\n| 3| Baz due:{} t:{}\n".format(due.isoformat(), due.isoformat(), start.isoformat())) self.assertEqual(self.errors, "") def test_postpone17(self): command = PostponeCommand(["1", "2", "3"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid date pattern given.\n") def test_postpone18(self): command = PostponeCommand(["1", "99", "123", "1w"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number given: 99.\nInvalid todo number given: 123.\n") def test_postpone19(self): command = PostponeCommand(["Zoo", "99", "123", "1w"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number given: Zoo.\nInvalid todo number given: 99.\nInvalid todo number given: 123.\n") def test_postpone20(self): """ Throw an error with invalid argument containing special characters. """ command = PostponeCommand([u("Fo\u00d3B\u0105r"), "Bar", "1d"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, u("Invalid todo number given: Fo\u00d3B\u0105r.\n")) def test_expr_postpone1(self): command = PostponeCommand(["-e", "due:tod", "2w"], self.todolist, self.out, self.error, None) command.execute() due = self.today + timedelta(14) result = "| 2| Bar due:{d}\n| 3| Baz due:{d} t:{s}\n".format(d=due.isoformat(), s=self.start.isoformat()) self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, result) self.assertEqual(self.errors, "") def test_expr_postpone2(self): cmd_args = ["-e", "t:{}".format(self.start.isoformat()), "due:tod", "1w"] command = PostponeCommand(cmd_args, self.todolist, self.out, self.error, None) command.execute() due = self.today + timedelta(7) result = "| 3| Baz due:{} t:{}\n".format(due.isoformat(), self.start.isoformat()) self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, result) self.assertEqual(self.errors, "") def test_expr_postpone3(self): command = PostponeCommand(["-e", "@test", "due:tod", "+project", "C"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) def test_expr_postpone4(self): """ Don't postpone unrelevant todo items. """ command = PostponeCommand(["-e", "FutureStart", "1w"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) def test_expr_postpone5(self): """ Force postponing unrelevant items with additional -x flag. """ command = PostponeCommand(["-xe", "FutureStart", "1w"], self.todolist, self.out, self.error, None) command.execute() due = self.today + timedelta(7) result = "| 6| FutureStart t:{} due:{}\n".format(self.future.isoformat(), due.isoformat()) self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, result) self.assertEqual(self.errors, "") def test_help(self): command = PostponeCommand(["help"], self.todolist, self.out, self.error) command.execute() self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
class DeleteCommandTest(CommandTest): def setUp(self): super(DeleteCommandTest, self).setUp() todos = [ "Foo id:1", "Bar p:1", "a @test with due:2015-06-03", "a @test with +project", ] self.todolist = TodoList(todos) def test_del1(self): command = DeleteCommand(["1"], self.todolist, self.out, self.error, _no_prompt) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.todo(1).source(), "Bar") self.assertEqual(self.output, "| 2| Bar p:1\nRemoved: Foo id:1\n") self.assertEqual(self.errors, "") def test_del1_regex(self): command = DeleteCommand(["Foo"], self.todolist, self.out, self.error, _no_prompt) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.todo(1).source(), "Bar") self.assertEqual(self.output, "| 2| Bar p:1\nRemoved: Foo id:1\n") self.assertEqual(self.errors, "") def test_del2(self): command = DeleteCommand(["1"], self.todolist, self.out, self.error, _yes_prompt) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.count(), 2) self.assertEqual(self.output, "| 2| Bar p:1\nRemoved: Bar\nRemoved: Foo\n") self.assertEqual(self.errors, "") def test_del3(self): command = DeleteCommand(["-f", "1"], self.todolist, self.out, self.error, _yes_prompt) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.count(), 3) # force won't delete subtasks self.assertEqual(self.output, "| 2| Bar p:1\nRemoved: Foo id:1\n") self.assertEqual(self.errors, "") def test_del4(self): command = DeleteCommand(["--force", "1"], self.todolist, self.out, self.error, _yes_prompt) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.count(), 3) # force won't delete subtasks self.assertEqual(self.output, "| 2| Bar p:1\nRemoved: Foo id:1\n") self.assertEqual(self.errors, "") def test_del5(self): command = DeleteCommand(["2"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.todo(1).source(), "Foo") self.assertEqual( self.output, "Removed: Bar p:1\nThe following todo item(s) became active:\n| 1| Foo\n" ) self.assertEqual(self.errors, "") def test_del7(self): command = DeleteCommand(["99"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number given.\n") def test_del8(self): command = DeleteCommand(["A"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number given.\n") def test_del9(self): """ Test deletion with textual IDs. """ config("test/data/todolist-uid.conf") command = DeleteCommand(["8to"], self.todolist, self.out, self.error) command.execute() result = "Foo\na @test with due:2015-06-03\na @test with +project" self.assertEqual(self.todolist.print_todos(), result) self.assertRaises(InvalidTodoException, self.todolist.todo, 'b0n') def test_multi_del1(self): """ Test deletion of multiple items. """ command = DeleteCommand(["1", "2"], self.todolist, self.out, self.error, _no_prompt) command.execute() result = "a @test with due:2015-06-03\na @test with +project" self.assertEqual(self.todolist.count(), 2) self.assertEqual(self.todolist.print_todos(), result) def test_multi_del2(self): """ Test deletion of multiple items. """ command = DeleteCommand(["1", "2"], self.todolist, self.out, self.error, _yes_prompt) command.execute() result = "a @test with due:2015-06-03\na @test with +project" self.assertEqual(self.todolist.count(), 2) self.assertEqual(self.todolist.print_todos(), result) def test_multi_del3(self): """ Fail if any of supplied todo numbers is invalid. """ command = DeleteCommand(["99", "2"], self.todolist, self.out, self.error, _yes_prompt) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number given: 99.\n") def test_multi_del4(self): """ Check output when all supplied todo numbers are invalid. """ command = DeleteCommand(["99", "A"], self.todolist, self.out, self.error, _yes_prompt) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual( self.errors, "Invalid todo number given: 99.\nInvalid todo number given: A.\n") def test_multi_del5(self): """ Throw an error with invalid argument containing special characters. """ command = DeleteCommand([u("Fo\u00d3B\u0105r"), "Bar"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, u("Invalid todo number given: Fo\u00d3B\u0105r.\n")) def test_expr_del1(self): command = DeleteCommand(["-e", "@test"], self.todolist, self.out, self.error, None) command.execute() result = "Removed: a @test with due:2015-06-03\nRemoved: a @test with +project\n" self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.count(), 2) self.assertEqual(self.output, result) self.assertEqual(self.errors, "") def test_expr_del2(self): command = DeleteCommand(["-e", "@test", "due:2015-06-03"], self.todolist, self.out, self.error, None) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "Removed: a @test with due:2015-06-03\n") self.assertEqual(self.errors, "") def test_expr_del3(self): command = DeleteCommand(["-e", "@test", "due:2015-06-03", "+project"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) def test_expr_del4(self): """ Remove only relevant todo items. """ command = DeleteCommand(["-e", ""], self.todolist, self.out, self.error, None) command.execute() result = "Foo" self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.count(), 1) self.assertEqual(self.todolist.print_todos(), result) def test_expr_del5(self): """ Force deleting unrelevant items with additional -x flag. """ command = DeleteCommand(["-xe", ""], self.todolist, self.out, self.error, _yes_prompt) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.count(), 0) def test_empty(self): command = DeleteCommand([], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, command.usage() + "\n") def test_help(self): command = DeleteCommand(["help"], self.todolist, self.out, self.error) command.execute() self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
class DoCommandTest(CommandTest): def setUp(self): super(DoCommandTest, self).setUp() todos = [ "Foo id:1", "Bar p:1", "Baz p:1", "Recurring! rec:1d", "x 2014-10-18 Already complete", "Inactive t:2030-12-31 id:2", "Subtodo of inactive p:2", "Strict due:2014-01-01 rec:1d", "Invalid rec:1", "a @test with due:2015-06-03", "a @test with +project", ] self.todolist = TodoList(todos) self.today = date.today() self.tomorrow = self.today + timedelta(1) self.yesterday = self.today - timedelta(1) self.yesterday = self.yesterday.isoformat() self.today = self.today.isoformat() self.tomorrow = self.tomorrow.isoformat() def test_do1(self): command = DoCommand(["3"], self.todolist, self.out, self.error, _no_prompt) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.todo(3).is_completed()) self.assertEqual(self.output, "Completed: x {} Baz p:1\n".format(self.today)) self.assertEqual(self.errors, "") def test_do_subtasks1(self): command = DoCommand(["1"], self.todolist, self.out, self.error, _yes_prompt) command.execute() result = "| 2| Bar p:1\n| 3| Baz p:1\nCompleted: x {today} Bar p:1\nCompleted: x {today} Baz p:1\nCompleted: x {today} Foo id:1\n".format( today=self.today) for number in [1, 2, 3]: self.assertTrue(self.todolist.todo(number).is_completed()) self.assertTrue(self.todolist.is_dirty()) self.assertFalse(self.todolist.todo(4).is_completed()) self.assertEqual(self.output, result) self.assertEqual(self.errors, "") def test_do_subtasks2(self): command = DoCommand(["1"], self.todolist, self.out, self.error, _no_prompt) command.execute() result = "| 2| Bar p:1\n| 3| Baz p:1\nCompleted: x {} Foo id:1\n".format( self.today) self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.todo(1).is_completed()) self.assertFalse(self.todolist.todo(2).is_completed()) self.assertFalse(self.todolist.todo(3).is_completed()) self.assertEqual(self.output, result) self.assertEqual(self.errors, "") def test_do_subtasks_force1(self): prompt_shown = False def prompt(p_prompt): global prompt_shown prompt_shown = True command = DoCommand(["-f", "1"], self.todolist, self.out, self.error, prompt) command.execute() self.assertFalse(prompt_shown) self.assertEqual(self.errors, "") self.assertFalse(self.todolist.todo(2).is_completed()) def test_do_subtasks_force2(self): prompt_shown = False def prompt(p_prompt): global prompt_shown prompt_shown = True command = DoCommand(["--force", "1"], self.todolist, self.out, self.error, prompt) command.execute() self.assertFalse(prompt_shown) self.assertEqual(self.errors, "") self.assertFalse(self.todolist.todo(2).is_completed()) def _recurrence_helper(self, p_flags): command = DoCommand(p_flags, self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.errors, "") self.assertEqual(self.todolist.count(), 12) def test_recurrence(self): self.assertFalse(self.todolist.todo(4).has_tag('due')) self._recurrence_helper(["4"]) self.assertTrue(self.todolist.todo(4).is_completed()) result = "| 12| {today} Recurring! rec:1d due:{tomorrow}\nCompleted: x {today} Recurring! rec:1d\n".format( today=self.today, tomorrow=self.tomorrow) self.assertEqual(self.output, result) todo = self.todolist.todo(10) self.assertFalse(todo.is_completed()) self.assertTrue(todo.has_tag('due')) def test_strict_recurrence1(self): self._recurrence_helper(["-s", "8"]) result = "| 12| {today} Strict due:2014-01-02 rec:1d\nCompleted: x {today} Strict due:2014-01-01 rec:1d\n".format( today=self.today) self.assertEqual(self.output, result) def test_strict_recurrence2(self): self._recurrence_helper(["--strict", "8"]) result = "| 12| {today} Strict due:2014-01-02 rec:1d\nCompleted: x {today} Strict due:2014-01-01 rec:1d\n".format( today=self.today) self.assertEqual(self.output, result) def test_invalid1(self): command = DoCommand(["99"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, "Invalid todo number given.\n") def test_invalid2(self): command = DoCommand(["AAA"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, "Invalid todo number given.\n") def test_invalid3(self): command = DoCommand(["01"], self.todolist, self.out, self.error, _yes_prompt) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, "Invalid todo number given.\n") def test_activated_todos1(self): command = DoCommand(["2"], self.todolist, self.out, self.error) command.execute() first_output = "Completed: x {} Bar p:1\n".format(self.today) self.assertEqual(self.output, first_output) self.assertEqual(self.errors, "") command = DoCommand(["3"], self.todolist, self.out, self.error) command.execute() self.assertEqual( self.output, first_output + "Completed: x {} Baz p:1\nThe following todo item(s) became active:\n| 1| Foo id:1\n" .format(self.today)) self.assertEqual(self.errors, "") def test_activated_todos2(self): command = DoCommand(["7"], self.todolist, self.out, self.error) command.execute() self.assertEqual( self.output, "Completed: x {} Subtodo of inactive p:2\n".format(self.today)) self.assertEqual(self.errors, "") def test_already_complete(self): command = DoCommand(["5"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual( self.todolist.todo(5).completion_date(), date(2014, 10, 18)) self.assertFalse(self.output) self.assertEqual(self.errors, "Todo has already been completed.\n") def test_do_regex1(self): command = DoCommand(["baz"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.todo(3).is_completed()) self.assertEqual(self.output, "Completed: x {} Baz p:1\n".format(self.today)) self.assertEqual(self.errors, "") def test_do_custom_date1(self): command = DoCommand(["-d", "2014-11-18", "3"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "Completed: x 2014-11-18 Baz p:1\n") self.assertEqual(self.errors, "") def test_do_custom_date2(self): command = DoCommand(["-d", "2014-11-18", "1"], self.todolist, self.out, self.error, _yes_prompt) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual( self.output, "| 2| Bar p:1\n| 3| Baz p:1\nCompleted: x 2014-11-18 Bar p:1\nCompleted: x 2014-11-18 Baz p:1\nCompleted: x 2014-11-18 Foo id:1\n" ) self.assertEqual(self.errors, "") def test_do_custom_date3(self): command = DoCommand(["--date=2014-11-18", "3"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "Completed: x 2014-11-18 Baz p:1\n") self.assertEqual(self.errors, "") def test_do_custom_date4(self): command = DoCommand(["-d", "foo", "3"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "Completed: x {} Baz p:1\n".format(self.today)) self.assertEqual(self.errors, "") def test_do_custom_date5(self): """ Make sure that the new recurrence date is correct when a custom date is given. """ command = DoCommand(["-d", self.yesterday, "4"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual( self.output, "| 12| {today} Recurring! rec:1d due:{today}\nCompleted: x {yesterday} Recurring! rec:1d\n" .format(today=self.today, yesterday=self.yesterday)) self.assertEqual(self.errors, "") def test_do_custom_date6(self): """ When a custom date is set, strict recurrence must still hold on to the due date as the offset. This todo item however, has no due date, then the completion date must be used as an offset. """ command = DoCommand(["-s", "-d", self.yesterday, "4"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual( self.output, "| 12| {today} Recurring! rec:1d due:{today}\nCompleted: x {yesterday} Recurring! rec:1d\n" .format(today=self.today, yesterday=self.yesterday)) self.assertEqual(self.errors, "") def test_do_custom_date7(self): """ When a custom date is set, strict recurrence must still hold on to the due date as the offset. """ command = DoCommand(["-s", "-d", self.yesterday, "8"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual( self.output, "| 12| {today} Strict due:2014-01-02 rec:1d\nCompleted: x {yesterday} Strict due:2014-01-01 rec:1d\n" .format(today=self.today, yesterday=self.yesterday)) self.assertEqual(self.errors, "") def test_multi_do1(self): command = DoCommand(["1", "3"], self.todolist, self.out, self.error, _yes_prompt) command.execute() self.assertTrue(self.todolist.todo(1).is_completed()) self.assertTrue(self.todolist.todo(2).is_completed()) self.assertTrue(self.todolist.todo(3).is_completed()) self.assertEqual( self.output, "| 2| Bar p:1\n| 3| Baz p:1\nCompleted: x {today} Bar p:1\nCompleted: x {today} Baz p:1\nCompleted: x {today} Foo id:1\n" .format(today=self.today)) def test_multi_do2(self): command = DoCommand(["1", "3"], self.todolist, self.out, self.error, _no_prompt) command.execute() self.assertTrue(self.todolist.todo(1).is_completed()) self.assertFalse(self.todolist.todo(2).is_completed()) self.assertTrue(self.todolist.todo(3).is_completed()) self.assertEqual( self.output, "| 2| Bar p:1\n| 3| Baz p:1\nCompleted: x {today} Foo id:1\nCompleted: x {today} Baz p:1\n" .format(today=self.today)) def test_multi_do3(self): command = DoCommand(["3", "3"], self.todolist, self.out, self.error, _no_prompt) command.execute() self.assertTrue(self.todolist.todo(3).is_completed()) self.assertEqual(self.output, "Completed: x {} Baz p:1\n".format(self.today)) def test_multi_do4(self): command = DoCommand(["99", "3"], self.todolist, self.out, self.error, _no_prompt) command.execute() self.assertFalse(self.todolist.todo(3).is_completed()) self.assertEqual(self.errors, "Invalid todo number given: 99.\n") def test_multi_do5(self): """ Check output when all supplied todo numbers are invalid. """ command = DoCommand(["99", "15"], self.todolist, self.out, self.error, _no_prompt) command.execute() self.assertEqual( self.errors, "Invalid todo number given: 99.\nInvalid todo number given: 15.\n") def test_multi_do6(self): """ Throw an error with invalid argument containing special characters. """ command = DoCommand([u("Fo\u00d3B\u0105r"), "Bar"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.errors, u("Invalid todo number given: Fo\u00d3B\u0105r.\n")) def test_expr_do1(self): command = DoCommand(["-e", "@test"], self.todolist, self.out, self.error, None) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual( self.output, "Completed: x {t} a @test with due:2015-06-03\nCompleted: x {t} a @test with +project\n" .format(t=self.today)) self.assertEqual(self.errors, "") def test_expr_do2(self): command = DoCommand(["-e", "@test", "due:2015-06-03"], self.todolist, self.out, self.error, None) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual( self.output, "Completed: x {} a @test with due:2015-06-03\n".format(self.today)) self.assertEqual(self.errors, "") def test_expr_do3(self): command = DoCommand(["-e", "@test", "due:2015-06-03", "+project"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) def test_expr_do4(self): """ Don't do anything with unrelevant todo items. """ command = DoCommand(["-e", "Foo"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) def test_expr_do5(self): """ Force marking unrelevant items as done with additional -x flag. """ command = DoCommand(["-xe", "Foo"], self.todolist, self.out, self.error, _yes_prompt) command.execute() result = "| 2| Bar p:1\n| 3| Baz p:1\nCompleted: x {t} Bar p:1\nCompleted: x {t} Baz p:1\nCompleted: x {t} Foo id:1\n".format( t=self.today) self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, result) self.assertEqual(self.errors, "") def test_invalid_recurrence(self): """ Show error message when an item has an invalid recurrence pattern. """ command = DoCommand(["9"], self.todolist, self.out, self.error, _no_prompt) command.execute() self.assertEqual(self.output, "Completed: x {} Invalid rec:1\n".format(self.today)) self.assertEqual( self.errors, "Warning: todo item has an invalid recurrence pattern.\n") def test_empty(self): command = DoCommand([], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, command.usage() + "\n") def test_help(self): command = DoCommand(["help"], self.todolist, self.out, self.error) command.execute() self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
class TodoListDependencyTester(TopydoTest): def setUp(self): super().setUp() self.todolist = TodoList([]) self.todolist.add("Foo id:1") self.todolist.add("Bar p:1") self.todolist.add("Baz p:1 id:2") self.todolist.add("Buzz p:2") self.todolist.add("Fnord") self.todolist.add("Something with +Project") self.todolist.add("Another one with +Project") self.todolist.add("Todo with +AnotherProject") self.todolist.add("Todo without children id:3") self.todolist.add("Orphan p:4") def test_check_dep(self): children = self.todolist.children(self.todolist.todo(1)) self.assertEqual(sorted([todo.source() for todo in children]), sorted(['Bar p:1', 'Baz p:1 id:2', 'Buzz p:2'])) children = self.todolist.children(self.todolist.todo(1), True) self.assertEqual(sorted([todo.source() for todo in children]), sorted(['Bar p:1', 'Baz p:1 id:2'])) children = self.todolist.children(self.todolist.todo(3)) self.assertEqual(sorted([todo.source() for todo in children]), ['Buzz p:2']) parents = self.todolist.parents(self.todolist.todo(4)) self.assertEqual(sorted([todo.source() for todo in parents]), sorted(['Foo id:1', 'Baz p:1 id:2'])) parents = self.todolist.parents(self.todolist.todo(4), True) self.assertEqual(sorted([todo.source() for todo in parents]), ['Baz p:1 id:2']) self.assertEqual(self.todolist.children(self.todolist.todo(2)), []) self.assertEqual(self.todolist.parents(self.todolist.todo(1)), []) def test_add_dep1(self): todo4 = self.todolist.todo(4) todo5 = self.todolist.todo(5) self.todolist.add_dependency(todo5, todo4) self.assertTrue(todo5.has_tag('id', '5')) self.assertTrue(todo4.has_tag('p', '5')) def test_add_dep2(self): """ Make sure that previous add_dependency invocation stored the edge_id properly. """ todo1 = self.todolist.todo(1) todo4 = self.todolist.todo(4) todo5 = self.todolist.todo(5) self.todolist.add_dependency(todo5, todo4) self.todolist.add_dependency(todo4, todo1) self.assertTrue(todo4.has_tag('id', '6')) self.assertTrue(todo1.has_tag('p', '6')) def test_add_dep3(self): """ Test that projects are not added double. """ todo6 = self.todolist.todo(6) todo7 = self.todolist.todo(7) projects = todo7.projects().copy() self.todolist.add_dependency(todo6, todo7) self.assertEqual(projects, todo7.projects()) def test_add_dep4(self): """ Test that a new project is added to the sub todo. """ config("test/data/config3") todo6 = self.todolist.todo(6) todo8 = self.todolist.todo(8) self.todolist.add_dependency(todo6, todo8) self.assertEqual(set(["Project", "AnotherProject"]), todo8.projects()) def test_remove_dep1(self): from_todo = self.todolist.todo(3) to_todo = self.todolist.todo(4) self.todolist.remove_dependency(from_todo, to_todo) self.assertFalse(from_todo.has_tag('id')) self.assertFalse(to_todo.has_tag('p')) self.assertFalse(self.todolist.todo_by_dep_id('2')) def test_remove_dep2(self): old = str(self.todolist) from_todo = self.todolist.todo(1) to_todo = self.todolist.todo(4) self.todolist.remove_dependency(from_todo, to_todo) self.assertEqual(str(self.todolist), old) self.assertTrue(self.todolist.todo_by_dep_id('1')) self.assertTrue(self.todolist.todo_by_dep_id('2')) self.assertTrue(self.todolist.todo_by_dep_id('3')) def test_remove_dep3(self): """ Try to remove non-existing dependency. """ old = str(self.todolist) from_todo = self.todolist.todo(4) to_todo = self.todolist.todo(1) self.todolist.remove_dependency(from_todo, to_todo) self.assertEqual(str(self.todolist), old) self.assertTrue(self.todolist.todo_by_dep_id('1')) self.assertTrue(self.todolist.todo_by_dep_id('2')) self.assertTrue(self.todolist.todo_by_dep_id('3')) def test_remove_todo_check_children(self): todo = self.todolist.todo(2) self.todolist.delete(todo) todo = self.todolist.todo(2) self.assertTrue(self.todolist.children(todo)) def test_remove_task(self): todo = self.todolist.todo(3) self.todolist.delete(todo) self.assertFalse(todo.has_tag('p', '2')) self.assertFalse(self.todolist.todo_by_dep_id('2')) todo = self.todolist.todo(1) children = self.todolist.children(todo) self.assertEqual([t.source() for t in children], ['Bar p:1']) def test_add_double_dep(self): todo1 = self.todolist.todo(1) todo2 = self.todolist.todo(2) self.todolist.add_dependency(todo1, todo2) self.assertEqual(todo1.source(), 'Foo id:1') self.assertEqual(todo2.source(), 'Bar p:1') def test_todo_by_dep_id(self): """ Tests that todos can be retrieved by their id tag. """ todolist = TodoList([]) todolist.add("(C) Foo id:1") self.assertTrue(todolist.todo_by_dep_id('1')) self.assertFalse(todolist.todo_by_dep_id('2')) def test_add_after_dependencies(self): """ Test that information is properly stored after dependency related information was retrieved from the todo list. """ todo = self.todolist.todo(1) self.todolist.parents(todo) self.todolist.add('New dependency id:99') self.todolist.add('Child p:99') self.assertTrue(self.todolist.dirty) self.assertTrue(self.todolist.todo_by_dep_id('99')) def test_delete01(self): """ Check that dependency tags are cleaned up. """ todo = self.todolist.todo(4) self.todolist.delete(todo, p_leave_tags=False) self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.todo(3).source(), "Baz p:1") def test_delete02(self): """ Check that dependency tags are left when requested. """ todo = self.todolist.todo(4) self.todolist.delete(todo, p_leave_tags=True) self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.todo(3).source(), "Baz p:1 id:2") def test_delete03(self): """ Check that dependency tags are left when requested. """ todo = self.todolist.todo(3) self.todolist.delete(todo, p_leave_tags=True) self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.todo(3).source(), "Buzz p:2")
class PriorityCommandTest(CommandTest): def setUp(self): super(PriorityCommandTest, self).setUp() todos = [ "(A) Foo", "Bar", "(B) a @test with due:2015-06-03", "a @test with +project p:1", "Baz id:1", ] self.todolist = TodoList(todos) def test_set_prio1(self): command = PriorityCommand(["1", "B"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "Priority changed from A to B\n| 1| (B) Foo\n") self.assertEqual(self.errors, "") def test_set_prio2(self): command = PriorityCommand(["2", "Z"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "Priority set to Z.\n| 2| (Z) Bar\n") self.assertEqual(self.errors, "") def test_set_prio3(self): command = PriorityCommand(["Foo", "B"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "Priority changed from A to B\n| 1| (B) Foo\n") self.assertEqual(self.errors, "") def test_set_prio4(self): command = PriorityCommand(["1", "A"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "| 1| (A) Foo\n") self.assertEqual(self.errors, "") def test_set_prio5(self): command = PriorityCommand(["Foo", "2", "C"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual( self.output, "Priority changed from A to C\n| 1| (C) Foo\nPriority set to C.\n| 2| (C) Bar\n" ) self.assertEqual(self.errors, "") def test_set_prio6(self): """ Allow priority to be set including parentheses. """ command = PriorityCommand(["Foo", "2", "(C)"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual( self.output, "Priority changed from A to C\n| 1| (C) Foo\nPriority set to C.\n| 2| (C) Bar\n" ) self.assertEqual(self.errors, "") def test_expr_prio1(self): command = PriorityCommand(["-e", "@test", "C"], self.todolist, self.out, self.error, None) command.execute() result = "Priority changed from B to C\n| 3| (C) a @test with due:2015-06-03\nPriority set to C.\n| 4| (C) a @test with +project p:1\n" self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, result) self.assertEqual(self.errors, "") def test_expr_prio2(self): command = PriorityCommand(["-e", "@test", "due:2015-06-03", "C"], self.todolist, self.out, self.error, None) command.execute() result = "Priority changed from B to C\n| 3| (C) a @test with due:2015-06-03\n" self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, result) self.assertEqual(self.errors, "") def test_expr_prio3(self): command = PriorityCommand( ["-e", "@test", "due:2015-06-03", "+project", "C"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) def test_expr_prio4(self): """ Don't prioritize unrelevant todo items. """ command = PriorityCommand(["-e", "Baz", "C"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) def test_expr_prio5(self): """ Force prioritizing unrelevant items with additional -x flag. """ command = PriorityCommand(["-xe", "Baz", "D"], self.todolist, self.out, self.error, None) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "Priority set to D.\n| 5| (D) Baz id:1\n") self.assertEqual(self.errors, "") def test_invalid1(self): command = PriorityCommand(["99", "A"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, "Invalid todo number given.\n") def test_invalid2(self): command = PriorityCommand(["1", "99", "A"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, "Invalid todo number given: 99.\n") def test_invalid3(self): command = PriorityCommand(["98", "99", "A"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual( self.errors, "Invalid todo number given: 98.\nInvalid todo number given: 99.\n") def test_invalid4(self): command = PriorityCommand(["1", "ZZ"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, "Invalid priority given.\n") def test_invalid5(self): command = PriorityCommand(["A"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, command.usage() + "\n") def test_invalid6(self): command = PriorityCommand(["1"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, command.usage() + "\n") def test_invalid7(self): """ Throw an error with invalid argument containing special characters. """ command = PriorityCommand([u("Fo\u00d3B\u0105r"), "Bar", "C"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, u("Invalid todo number given: Fo\u00d3B\u0105r.\n")) def test_invalid8(self): """ Test that there's only one capital surrounded by non-word characters that makes up a priority. """ command = PriorityCommand(["2", "(Aa)"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid priority given.\n") def test_invalid9(self): """ Test that there's only one capital surrounded by non-word characters that makes up a priority. """ command = PriorityCommand(["2", "Aa"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid priority given.\n") def test_empty(self): command = PriorityCommand([], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, command.usage() + "\n") def test_help(self): command = PriorityCommand(["help"], self.todolist, self.out, self.error) command.execute() self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
class TagCommandTest(CommandTest): def setUp(self): super(TagCommandTest, self).setUp() todos = [ "Foo", "Bar due:2014-10-22", "Baz due:2014-10-20", "Fnord due:2014-10-20 due:2014-10-22", ] self.todolist = TodoList(todos) def test_add_tag1(self): command = TagCommand(["1", "due", "2014-10-22"], self.todolist, self.out, self.error) command.execute() self.assertEqual(self.todolist.todo(1).source(), "Foo due:2014-10-22") self.assertEqual(self.output, "| 1| Foo due:2014-10-22\n") self.assertEqual(self.errors, "") self.assertTrue(self.todolist.is_dirty()) def test_add_tag2(self): command = TagCommand(["Foo", "due", "2014-10-22"], self.todolist, self.out, self.error) command.execute() self.assertEqual(self.todolist.todo(1).source(), "Foo due:2014-10-22") self.assertEqual(self.output, "| 1| Foo due:2014-10-22\n") self.assertEqual(self.errors, "") self.assertTrue(self.todolist.is_dirty()) def test_add_tag3(self): command = TagCommand(["-a", "2", "due", "2014-10-19"], self.todolist, self.out, self.error) command.execute() self.assertEqual(self.todolist.todo(2).source(), "Bar due:2014-10-22 due:2014-10-19") self.assertEqual(self.output, "| 2| Bar due:2014-10-22 due:2014-10-19\n") self.assertEqual(self.errors, "") self.assertTrue(self.todolist.is_dirty()) def test_add_tag4(self): command = TagCommand(["Foox", "due", "2014-10-22"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, "Invalid todo number.\n") def test_set_tag4(self): command = TagCommand(["3", "due", "2014-10-20"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "| 3| Baz due:2014-10-20\n") self.assertEqual(self.errors, "") def test_set_tag5(self): command = TagCommand(["4", "due", "2014-10-20"], self.todolist, self.out, self.error, lambda t: "all") command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, " 1. 2014-10-20\n 2. 2014-10-22\n| 4| Fnord due:2014-10-20 due:2014-10-20\n") self.assertEqual(self.errors, "") def test_set_tag6(self): command = TagCommand(["4", "due", "2014-10-20"], self.todolist, self.out, self.error, lambda t: "1") command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, " 1. 2014-10-20\n 2. 2014-10-22\n| 4| Fnord due:2014-10-20 due:2014-10-22\n") self.assertEqual(self.errors, "") def test_set_tag7(self): command = TagCommand(["4", "due", "2014-10-20"], self.todolist, self.out, self.error, lambda t: "2") command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, " 1. 2014-10-20\n 2. 2014-10-22\n| 4| Fnord due:2014-10-20 due:2014-10-20\n") self.assertEqual(self.errors, "") def test_set_tag8(self): command = TagCommand(["4", "due", "2014-10-20"], self.todolist, self.out, self.error, lambda t: "") command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, " 1. 2014-10-20\n 2. 2014-10-22\n| 4| Fnord due:2014-10-20 due:2014-10-22\n") self.assertEqual(self.errors, "") def test_set_tag9(self): command = TagCommand(["4", "due", "2014-10-20"], self.todolist, self.out, self.error, lambda t: "99") command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, " 1. 2014-10-20\n 2. 2014-10-22\n| 4| Fnord due:2014-10-20 due:2014-10-22\n") self.assertEqual(self.errors, "") def test_set_tag10(self): command = TagCommand(["-f", "4", "due", "2014-10-20"], self.todolist, self.out, self.error, lambda t: "99") command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "| 4| Fnord due:2014-10-20 due:2014-10-20\n") self.assertEqual(self.errors, "") def test_rm_tag1(self): command = TagCommand(["1", "due"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "| 1| Foo\n") self.assertEqual(self.errors, "") def test_rm_tag2(self): command = TagCommand(["2", "due"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "| 2| Bar\n") self.assertEqual(self.errors, "") def test_rm_tag3(self): command = TagCommand(["4", "due"], self.todolist, self.out, self.error, lambda t: "all") command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, " 1. 2014-10-20\n 2. 2014-10-22\n| 4| Fnord\n") self.assertEqual(self.errors, "") def test_rm_tag4(self): command = TagCommand(["4", "due"], self.todolist, self.out, self.error, lambda t: "1") command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, " 1. 2014-10-20\n 2. 2014-10-22\n| 4| Fnord due:2014-10-22\n") self.assertEqual(self.errors, "") def test_rm_tag6(self): command = TagCommand(["4", "due"], self.todolist, self.out, self.error, lambda t: "99") command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, " 1. 2014-10-20\n 2. 2014-10-22\n| 4| Fnord due:2014-10-20 due:2014-10-22\n") self.assertEqual(self.errors, "") def test_rm_tag7(self): command = TagCommand(["4", "due"], self.todolist, self.out, self.error, lambda t: "A") command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, " 1. 2014-10-20\n 2. 2014-10-22\n| 4| Fnord due:2014-10-20 due:2014-10-22\n") self.assertEqual(self.errors, "") def test_rm_tag8(self): command = TagCommand(["5", "due"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number.\n") def test_rm_tag9(self): command = TagCommand(["A", "due"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number.\n") def test_rm_tag10(self): command = TagCommand(["-f", "4", "due"], self.todolist, self.out, self.error, lambda t: "A") command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "| 4| Fnord\n") self.assertEqual(self.errors, "") def test_no_tag(self): command = TagCommand(["4"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n") def test_help(self): command = TagCommand(["help"], self.todolist, self.out, self.error) command.execute() self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
class DepriCommandTest(CommandTest): def setUp(self): super(DepriCommandTest, self).setUp() todos = [ "(A) Foo", "Bar", "(B) Baz", "(E) a @test with due:2015-06-03", "(Z) a @test with +project p:1", "(D) Bax id:1", ] self.todolist = TodoList(todos) def test_depri1(self): command = DepriCommand(["1"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.todo(1).priority(), None) self.assertEqual(self.output, "Priority removed.\n| 1| Foo\n") self.assertEqual(self.errors, "") def test_depri2(self): command = DepriCommand(["2"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.todolist.todo(2).priority(), None) self.assertEqual(self.output, "") self.assertEqual(self.errors, "") def test_depri3(self): command = DepriCommand(["Foo"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.todo(1).priority(), None) self.assertEqual(self.output, "Priority removed.\n| 1| Foo\n") self.assertEqual(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.assertEqual(self.todolist.todo(1).priority(), None) self.assertEqual(self.todolist.todo(3).priority(), None) self.assertEqual( self.output, "Priority removed.\n| 1| Foo\nPriority removed.\n| 3| Baz\n") self.assertEqual(self.errors, "") def test_expr_depri1(self): command = DepriCommand(["-e", "@test"], self.todolist, self.out, self.error, None) command.execute() result = "Priority removed.\n| 4| a @test with due:2015-06-03\nPriority removed.\n| 5| a @test with +project p:1\n" self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, result) self.assertEqual(self.errors, "") def test_expr_depri2(self): command = DepriCommand(["-e", "@test", "due:2015-06-03"], self.todolist, self.out, self.error, None) command.execute() result = "Priority removed.\n| 4| a @test with due:2015-06-03\n" self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, result) self.assertEqual(self.errors, "") def test_expr_depri3(self): command = DepriCommand(["-e", "@test", "due:2015-06-03", "+project"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) def test_expr_depri4(self): """ Don't remove priority from unrelevant todo items. """ command = DepriCommand(["-e", "Bax"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) def test_expr_depri5(self): """ Force unprioritizing unrelevant items with additional -x flag. """ command = DepriCommand(["-xe", "Bax"], self.todolist, self.out, self.error, None) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "Priority removed.\n| 6| Bax id:1\n") self.assertEqual(self.errors, "") def test_invalid1(self): command = DepriCommand(["99"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(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.assertEqual(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.assertEqual( self.errors, "Invalid todo number given: 99.\nInvalid todo number given: FooBar.\n" ) def test_invalid4(self): """ Throw an error with invalid argument containing special characters. """ command = DepriCommand([u("Fo\u00d3B\u0105r"), "Bar"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, u("Invalid todo number given: Fo\u00d3B\u0105r.\n")) def test_empty(self): command = DepriCommand([], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, command.usage() + "\n") def test_help(self): command = DepriCommand(["help"], self.todolist, self.out, self.error) command.execute() self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
class DepriCommandTest(CommandTest): def setUp(self): super().setUp() todos = [ "(A) Foo", "Bar", "(B) Baz", "(E) a @test with due:2015-06-03", "(Z) a @test with +project p:1", "(D) Bax id:1", ] self.todolist = TodoList(todos) def test_depri1(self): command = DepriCommand(["1"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.todo(1).priority(), None) self.assertEqual(self.output, "Priority removed.\n| 1| Foo\n") self.assertEqual(self.errors, "") def test_depri2(self): command = DepriCommand(["2"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.todolist.todo(2).priority(), None) self.assertEqual(self.output, "") self.assertEqual(self.errors, "") def test_depri3(self): command = DepriCommand(["Foo"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.todolist.todo(1).priority(), None) self.assertEqual(self.output, "Priority removed.\n| 1| Foo\n") self.assertEqual(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.assertEqual(self.todolist.todo(1).priority(), None) self.assertEqual(self.todolist.todo(3).priority(), None) self.assertEqual(self.output, "Priority removed.\n| 1| Foo\nPriority removed.\n| 3| Baz\n") self.assertEqual(self.errors, "") def test_expr_depri1(self): command = DepriCommand(["-e", "@test"], self.todolist, self.out, self.error, None) command.execute() result = "Priority removed.\n| 4| a @test with due:2015-06-03\nPriority removed.\n| 5| a @test with +project p:1\n" self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, result) self.assertEqual(self.errors, "") def test_expr_depri2(self): command = DepriCommand(["-e", "@test", "due:2015-06-03"], self.todolist, self.out, self.error, None) command.execute() result = "Priority removed.\n| 4| a @test with due:2015-06-03\n" self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, result) self.assertEqual(self.errors, "") def test_expr_depri3(self): command = DepriCommand(["-e", "@test", "due:2015-06-03", "+project"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) def test_expr_depri4(self): """ Don't remove priority from unrelevant todo items. """ command = DepriCommand(["-e", "Bax"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) def test_expr_depri5(self): """ Force unprioritizing unrelevant items with additional -x flag. """ command = DepriCommand(["-xe", "Bax"], self.todolist, self.out, self.error, None) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "Priority removed.\n| 6| Bax id:1\n") self.assertEqual(self.errors, "") def test_invalid1(self): command = DepriCommand(["99"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(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.assertEqual(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.assertEqual(self.errors, "Invalid todo number given: 99.\nInvalid todo number given: FooBar.\n") def test_invalid4(self): """ Throw an error with invalid argument containing special characters. """ command = DepriCommand([u"Fo\u00d3B\u0105r", "Bar"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, u"Invalid todo number given: Fo\u00d3B\u0105r.\n") def test_empty(self): command = DepriCommand([], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, command.usage() + "\n") def test_help(self): command = DepriCommand(["help"], self.todolist, self.out, self.error) command.execute() self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
class DoCommandTest(CommandTest): def setUp(self): super(DoCommandTest, self).setUp() todos = [ "Foo id:1", "Bar p:1", "Baz p:1", "Recurring! rec:1d", "x 2014-10-18 Already complete", "Inactive t:2030-12-31 id:2", "Subtodo of inactive p:2", "Strict due:2014-01-01 rec:1d", "Invalid rec:1", "a @test with due:2015-06-03", "a @test with +project", ] self.todolist = TodoList(todos) self.today = date.today() self.tomorrow = self.today + timedelta(1) self.yesterday = self.today - timedelta(1) self.yesterday = self.yesterday.isoformat() self.today = self.today.isoformat() self.tomorrow = self.tomorrow.isoformat() def test_do1(self): command = DoCommand(["3"], self.todolist, self.out, self.error, _no_prompt) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.todo(3).is_completed()) self.assertEqual(self.output, "Completed: x {} Baz p:1\n".format( self.today)) self.assertEqual(self.errors, "") def test_do_subtasks1(self): command = DoCommand(["1"], self.todolist, self.out, self.error, _yes_prompt) command.execute() result = "| 2| Bar p:1\n| 3| Baz p:1\nCompleted: x {today} Bar p:1\nCompleted: x {today} Baz p:1\nCompleted: x {today} Foo id:1\n".format(today=self.today) for number in [1, 2, 3]: self.assertTrue(self.todolist.todo(number).is_completed()) self.assertTrue(self.todolist.is_dirty()) self.assertFalse(self.todolist.todo(4).is_completed()) self.assertEqual(self.output, result) self.assertEqual(self.errors, "") def test_do_subtasks2(self): command = DoCommand(["1"], self.todolist, self.out, self.error, _no_prompt) command.execute() result = "| 2| Bar p:1\n| 3| Baz p:1\nCompleted: x {} Foo id:1\n".format(self.today) self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.todo(1).is_completed()) self.assertFalse(self.todolist.todo(2).is_completed()) self.assertFalse(self.todolist.todo(3).is_completed()) self.assertEqual(self.output, result) self.assertEqual(self.errors, "") def test_do_subtasks_force1(self): prompt_shown = False def prompt(p_prompt): global prompt_shown prompt_shown = True command = DoCommand(["-f", "1"], self.todolist, self.out, self.error, prompt) command.execute() self.assertFalse(prompt_shown) self.assertEqual(self.errors, "") self.assertFalse(self.todolist.todo(2).is_completed()) def test_do_subtasks_force2(self): prompt_shown = False def prompt(p_prompt): global prompt_shown prompt_shown = True command = DoCommand(["--force", "1"], self.todolist, self.out, self.error, prompt) command.execute() self.assertFalse(prompt_shown) self.assertEqual(self.errors, "") self.assertFalse(self.todolist.todo(2).is_completed()) def _recurrence_helper(self, p_flags): command = DoCommand(p_flags, self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.errors, "") self.assertEqual(self.todolist.count(), 12) def test_recurrence(self): self.assertFalse(self.todolist.todo(4).has_tag('due')) self._recurrence_helper(["4"]) self.assertTrue(self.todolist.todo(4).is_completed()) result = "| 12| {today} Recurring! rec:1d due:{tomorrow}\nCompleted: x {today} Recurring! rec:1d\n".format(today=self.today, tomorrow=self.tomorrow) self.assertEqual(self.output, result) todo = self.todolist.todo(10) self.assertFalse(todo.is_completed()) self.assertTrue(todo.has_tag('due')) def test_strict_recurrence1(self): self._recurrence_helper(["-s", "8"]) result = "| 12| {today} Strict due:2014-01-02 rec:1d\nCompleted: x {today} Strict due:2014-01-01 rec:1d\n".format(today=self.today) self.assertEqual(self.output, result) def test_strict_recurrence2(self): self._recurrence_helper(["--strict", "8"]) result = "| 12| {today} Strict due:2014-01-02 rec:1d\nCompleted: x {today} Strict due:2014-01-01 rec:1d\n".format(today=self.today) self.assertEqual(self.output, result) def test_invalid1(self): command = DoCommand(["99"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, "Invalid todo number given.\n") def test_invalid2(self): command = DoCommand(["AAA"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, "Invalid todo number given.\n") def test_invalid3(self): command = DoCommand(["01"], self.todolist, self.out, self.error, _yes_prompt) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, "Invalid todo number given.\n") def test_activated_todos1(self): command = DoCommand(["2"], self.todolist, self.out, self.error) command.execute() first_output = "Completed: x {} Bar p:1\n".format(self.today) self.assertEqual(self.output, first_output) self.assertEqual(self.errors, "") command = DoCommand(["3"], self.todolist, self.out, self.error) command.execute() self.assertEqual(self.output, first_output + "Completed: x {} Baz p:1\nThe following todo item(s) became active:\n| 1| Foo id:1\n".format(self.today)) self.assertEqual(self.errors, "") def test_activated_todos2(self): command = DoCommand(["7"], self.todolist, self.out, self.error) command.execute() self.assertEqual(self.output, "Completed: x {} Subtodo of inactive p:2\n".format(self.today)) self.assertEqual(self.errors, "") def test_already_complete(self): command = DoCommand(["5"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.todolist.todo(5).completion_date(), date(2014, 10, 18)) self.assertFalse(self.output) self.assertEqual(self.errors, "Todo has already been completed.\n") def test_do_regex1(self): command = DoCommand(["baz"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.todo(3).is_completed()) self.assertEqual(self.output, "Completed: x {} Baz p:1\n".format(self.today)) self.assertEqual(self.errors, "") def test_do_custom_date1(self): command = DoCommand(["-d", "2014-11-18", "3"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "Completed: x 2014-11-18 Baz p:1\n") self.assertEqual(self.errors, "") def test_do_custom_date2(self): command = DoCommand(["-d", "2014-11-18", "1"], self.todolist, self.out, self.error, _yes_prompt) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "| 2| Bar p:1\n| 3| Baz p:1\nCompleted: x 2014-11-18 Bar p:1\nCompleted: x 2014-11-18 Baz p:1\nCompleted: x 2014-11-18 Foo id:1\n") self.assertEqual(self.errors, "") def test_do_custom_date3(self): command = DoCommand(["--date=2014-11-18", "3"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "Completed: x 2014-11-18 Baz p:1\n") self.assertEqual(self.errors, "") def test_do_custom_date4(self): command = DoCommand(["-d", "foo", "3"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "Completed: x {} Baz p:1\n".format(self.today)) self.assertEqual(self.errors, "") def test_do_custom_date5(self): """ Make sure that the new recurrence date is correct when a custom date is given. """ command = DoCommand(["-d", self.yesterday, "4"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "| 12| {today} Recurring! rec:1d due:{today}\nCompleted: x {yesterday} Recurring! rec:1d\n".format(today=self.today, yesterday=self.yesterday)) self.assertEqual(self.errors, "") def test_do_custom_date6(self): """ When a custom date is set, strict recurrence must still hold on to the due date as the offset. This todo item however, has no due date, then the completion date must be used as an offset. """ command = DoCommand(["-s", "-d", self.yesterday, "4"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "| 12| {today} Recurring! rec:1d due:{today}\nCompleted: x {yesterday} Recurring! rec:1d\n".format(today=self.today, yesterday=self.yesterday)) self.assertEqual(self.errors, "") def test_do_custom_date7(self): """ When a custom date is set, strict recurrence must still hold on to the due date as the offset. """ command = DoCommand(["-s", "-d", self.yesterday, "8"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "| 12| {today} Strict due:2014-01-02 rec:1d\nCompleted: x {yesterday} Strict due:2014-01-01 rec:1d\n".format(today=self.today, yesterday=self.yesterday)) self.assertEqual(self.errors, "") def test_multi_do1(self): command = DoCommand(["1", "3"], self.todolist, self.out, self.error, _yes_prompt) command.execute() self.assertTrue(self.todolist.todo(1).is_completed()) self.assertTrue(self.todolist.todo(2).is_completed()) self.assertTrue(self.todolist.todo(3).is_completed()) self.assertEqual(self.output, "| 2| Bar p:1\n| 3| Baz p:1\nCompleted: x {today} Bar p:1\nCompleted: x {today} Baz p:1\nCompleted: x {today} Foo id:1\n".format(today=self.today)) def test_multi_do2(self): command = DoCommand(["1", "3"], self.todolist, self.out, self.error, _no_prompt) command.execute() self.assertTrue(self.todolist.todo(1).is_completed()) self.assertFalse(self.todolist.todo(2).is_completed()) self.assertTrue(self.todolist.todo(3).is_completed()) self.assertEqual(self.output, "| 2| Bar p:1\n| 3| Baz p:1\nCompleted: x {today} Foo id:1\nCompleted: x {today} Baz p:1\n".format(today=self.today)) def test_multi_do3(self): command = DoCommand(["3", "3"], self.todolist, self.out, self.error, _no_prompt) command.execute() self.assertTrue(self.todolist.todo(3).is_completed()) self.assertEqual(self.output, "Completed: x {} Baz p:1\n".format(self.today)) def test_multi_do4(self): command = DoCommand(["99", "3"], self.todolist, self.out, self.error, _no_prompt) command.execute() self.assertFalse(self.todolist.todo(3).is_completed()) self.assertEqual(self.errors, "Invalid todo number given: 99.\n") def test_multi_do5(self): """ Check output when all supplied todo numbers are invalid. """ command = DoCommand(["99", "15"], self.todolist, self.out, self.error, _no_prompt) command.execute() self.assertEqual(self.errors, "Invalid todo number given: 99.\nInvalid todo number given: 15.\n") def test_multi_do6(self): """ Throw an error with invalid argument containing special characters. """ command = DoCommand([u("Fo\u00d3B\u0105r"), "Bar"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.errors, u("Invalid todo number given: Fo\u00d3B\u0105r.\n")) def test_expr_do1(self): command = DoCommand(["-e", "@test"], self.todolist, self.out, self.error, None) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "Completed: x {t} a @test with due:2015-06-03\nCompleted: x {t} a @test with +project\n".format(t=self.today)) self.assertEqual(self.errors, "") def test_expr_do2(self): command = DoCommand(["-e", "@test", "due:2015-06-03"], self.todolist, self.out, self.error, None) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, "Completed: x {} a @test with due:2015-06-03\n".format(self.today)) self.assertEqual(self.errors, "") def test_expr_do3(self): command = DoCommand(["-e", "@test", "due:2015-06-03", "+project"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) def test_expr_do4(self): """ Don't do anything with unrelevant todo items. """ command = DoCommand(["-e", "Foo"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) def test_expr_do5(self): """ Force marking unrelevant items as done with additional -x flag. """ command = DoCommand(["-xe", "Foo"], self.todolist, self.out, self.error, _yes_prompt) command.execute() result = "| 2| Bar p:1\n| 3| Baz p:1\nCompleted: x {t} Bar p:1\nCompleted: x {t} Baz p:1\nCompleted: x {t} Foo id:1\n".format(t=self.today) self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.output, result) self.assertEqual(self.errors, "") def test_invalid_recurrence(self): """ Show error message when an item has an invalid recurrence pattern. """ command = DoCommand(["9"], self.todolist, self.out, self.error, _no_prompt) command.execute() self.assertEqual(self.output, "Completed: x {} Invalid rec:1\n".format(self.today)) self.assertEqual(self.errors, "Warning: todo item has an invalid recurrence pattern.\n") def test_empty(self): command = DoCommand([], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, command.usage() + "\n") def test_help(self): command = DoCommand(["help"], self.todolist, self.out, self.error) command.execute() self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
class DepCommandTest(CommandTest): def setUp(self): super().setUp() todos = [ "Foo id:1", "Bar p:1", "Baz p:1", "Fnord id:2", "Garbage dependency p:99", "Fart p:2", ] self.todolist = TodoList(todos) def test_add1(self): command = DepCommand(["add", "1", "to", "4"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.todo(4).has_tag('p', '1')) self.assertEqual(self.output, "") self.assertEqual(self.errors, "") def test_add2(self): command = DepCommand(["add", "1", "4"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.todo(4).has_tag('p', '1')) self.assertEqual(self.output, "") self.assertEqual(self.errors, "") def test_add3(self): command = DepCommand(["add", "99", "3"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number given.\n") def test_add4(self): command = DepCommand(["add", "A", "3"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number given.\n") def test_add5(self): command = DepCommand(["add", "1"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n") def test_add6(self): command = DepCommand(["add", "1", "after", "4"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.todo(4).has_tag('p', '1')) self.assertEqual(self.output, "") self.assertEqual(self.errors, "") def test_add7(self): command = DepCommand(["add", "1", "before", "4"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.todo(1).has_tag('p', '2')) self.assertEqual(self.output, "") self.assertEqual(self.errors, "") def test_add8(self): command = DepCommand(["add", "1", "partof", "4"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.todo(1).has_tag('p', '2')) self.assertEqual(self.output, "") self.assertEqual(self.errors, "") def test_add9(self): command = DepCommand(["add", "Foo", "to", "4"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.todo(4).has_tag('p', '1')) self.assertEqual(self.output, "") self.assertEqual(self.errors, "") def add_parentsof_helper(self, p_args): command = DepCommand(p_args, self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.todo(4).has_tag('p', '1')) self.assertEqual(self.output, "") self.assertEqual(self.errors, "") def test_add10(self): self.add_parentsof_helper(["add", "4", "parents-of", "2"]) def test_add11(self): self.add_parentsof_helper(["add", "4", "parent-of", "2"]) def test_add12(self): self.add_parentsof_helper(["add", "4", "parentsof", "2"]) def test_add13(self): self.add_parentsof_helper(["add", "4", "parentof", "2"]) def test_add14(self): command = DepCommand(["add", "4", "parents-of", "5"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "") def add_childrenof_helper(self, p_args): command = DepCommand(p_args, self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.todo(2).has_tag('p', '2')) self.assertTrue(self.todolist.todo(3).has_tag('p', '2')) self.assertEqual(self.output, "") self.assertEqual(self.errors, "") def test_add15(self): self.add_childrenof_helper(["add", "4", "children-of", "1"]) def test_add16(self): self.add_childrenof_helper(["add", "4", "child-of", "1"]) def test_add17(self): self.add_childrenof_helper(["add", "4", "childrenof", "1"]) def test_add18(self): self.add_childrenof_helper(["add", "4", "childof", "1"]) def test_add19(self): command = DepCommand(["add", "4", "children-of", "5"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "") def rm_helper(self, p_args): """ Helper function that checks the removal of the dependency from todo 1 to todo 3. """ command = DepCommand(p_args, self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.todo(1).has_tag('id', '1')) self.assertFalse(self.todolist.todo(3).has_tag('p', '1')) self.assertEqual(self.output, "") self.assertEqual(self.errors, "") def test_rm1(self): self.rm_helper(["rm", "1", "to", "3"]) def test_rm2(self): self.rm_helper(["rm", "1", "3"]) def test_del1(self): self.rm_helper(["del", "1", "to", "3"]) def test_del2(self): self.rm_helper(["del", "1", "3"]) def test_rm3(self): command = DepCommand(["rm", "99", "3"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number given.\n") def test_rm4(self): command = DepCommand(["rm", "A", "3"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number given.\n") def test_rm5(self): command = DepCommand(["rm", "1"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n") def test_ls1(self): command = DepCommand(["ls", "1", "to"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "| 2| Bar p:1\n| 3| Baz p:1\n") self.assertEqual(self.errors, "") def test_ls2(self): command = DepCommand(["ls", "99", "to"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number given.\n") def test_ls3(self): command = DepCommand(["ls", "to", "3"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "| 1| Foo id:1\n") self.assertEqual(self.errors, "") def test_ls4(self): command = DepCommand(["ls", "to", "99"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number given.\n") def test_ls5(self): command = DepCommand(["ls", "1"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n") def test_ls6(self): command = DepCommand(["ls"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, command.usage() + "\n") def test_ls7(self): command = DepCommand(["ls", "top", "99"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n") def gc_helper(self, p_subcommand): command = DepCommand([p_subcommand], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertFalse(self.errors) self.assertFalse(self.todolist.todo(5).has_tag('p', '99')) def test_clean(self): self.gc_helper("clean") def test_gc(self): self.gc_helper("gc") def test_invalid_subsubcommand(self): command = DepCommand(["foo"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.output) self.assertEqual(self.errors, command.usage() + "\n") self.assertFalse(self.todolist.is_dirty()) def test_no_subsubcommand(self): command = DepCommand([], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.output) self.assertEqual(self.errors, command.usage() + "\n") self.assertFalse(self.todolist.is_dirty()) def test_help(self): command = DepCommand(["help"], self.todolist, self.out, self.error) command.execute() self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
class DepCommandTest(CommandTest): def setUp(self): super(DepCommandTest, self).setUp() todos = [ "Foo id:1", "Bar p:1", "Baz p:1", "Fnord id:2", "Garbage dependency p:99", "Fart p:2", ] self.todolist = TodoList(todos) def test_add1(self): command = DepCommand(["add", "1", "to", "4"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.todo(4).has_tag('p', '1')) self.assertEqual(self.output, "") self.assertEqual(self.errors, "") def test_add2(self): command = DepCommand(["add", "1", "4"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.todo(4).has_tag('p', '1')) self.assertEqual(self.output, "") self.assertEqual(self.errors, "") def test_add3(self): command = DepCommand(["add", "99", "3"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number given.\n") def test_add4(self): command = DepCommand(["add", "A", "3"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number given.\n") def test_add5(self): command = DepCommand(["add", "1"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n") def test_add6(self): command = DepCommand(["add", "1", "after", "4"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.todo(4).has_tag('p', '1')) self.assertEqual(self.output, "") self.assertEqual(self.errors, "") def test_add7(self): command = DepCommand(["add", "1", "before", "4"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.todo(1).has_tag('p', '2')) self.assertEqual(self.output, "") self.assertEqual(self.errors, "") def test_add8(self): command = DepCommand(["add", "1", "partof", "4"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.todo(1).has_tag('p', '2')) self.assertEqual(self.output, "") self.assertEqual(self.errors, "") def test_add9(self): command = DepCommand(["add", "Foo", "to", "4"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.todo(4).has_tag('p', '1')) self.assertEqual(self.output, "") self.assertEqual(self.errors, "") def rm_helper(self, p_args): """ Helper function that checks the removal of the dependency from todo 1 to todo 3. """ command = DepCommand(p_args, self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.todo(1).has_tag('id', '1')) self.assertFalse(self.todolist.todo(3).has_tag('p', '1')) self.assertEqual(self.output, "") self.assertEqual(self.errors, "") def test_rm1(self): self.rm_helper(["rm", "1", "to", "3"]) def test_rm2(self): self.rm_helper(["rm", "1", "3"]) def test_del1(self): self.rm_helper(["del", "1", "to", "3"]) def test_del2(self): self.rm_helper(["del", "1", "3"]) def test_rm3(self): command = DepCommand(["rm", "99", "3"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number given.\n") def test_rm4(self): command = DepCommand(["rm", "A", "3"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number given.\n") def test_rm5(self): command = DepCommand(["rm", "1"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n") def test_ls1(self): command = DepCommand(["ls", "1", "to"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "| 2| Bar p:1\n| 3| Baz p:1\n") self.assertEqual(self.errors, "") def test_ls2(self): command = DepCommand(["ls", "99", "to"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number given.\n") def test_ls3(self): command = DepCommand(["ls", "to", "3"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "| 1| Foo id:1\n") self.assertEqual(self.errors, "") def test_ls4(self): command = DepCommand(["ls", "to", "99"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, "Invalid todo number given.\n") def test_ls5(self): command = DepCommand(["ls", "1"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n") def test_ls6(self): command = DepCommand(["ls"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEqual(self.errors, command.usage() + "\n") def test_ls7(self): command = DepCommand(["ls", "top", "99"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n") def gc_helper(self, p_subcommand): command = DepCommand([p_subcommand], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertFalse(self.errors) self.assertFalse(self.todolist.todo(5).has_tag('p', '99')) def test_clean(self): self.gc_helper("clean") def test_gc(self): self.gc_helper("gc") def test_invalid_subsubcommand(self): command = DepCommand(["foo"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.output) self.assertEqual(self.errors, command.usage() + "\n") self.assertFalse(self.todolist.is_dirty()) def test_no_subsubcommand(self): command = DepCommand([], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.output) self.assertEqual(self.errors, command.usage() + "\n") self.assertFalse(self.todolist.is_dirty()) def test_help(self): command = DepCommand(["help"], self.todolist, self.out, self.error) command.execute() self.assertEqual(self.output, "") self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
class EditCommandTest(CommandTest): def setUp(self): super(EditCommandTest, self).setUp() todos = [ "Foo id:1", "Bar p:1 @test", "Baz @test", u("Fo\u00f3B\u0105\u017a"), ] self.todolist = TodoList(todos) @mock.patch('topydo.commands.EditCommand.EditCommand._open_in_editor') def test_edit1(self, mock_open_in_editor): """ Preserve dependencies after editing. """ mock_open_in_editor.return_value = 0 command = EditCommand(["1"], self.todolist, self.out, self.error, None) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.errors, "") self.assertEqual( self.todolist.print_todos(), u("Bar p:1 @test\nBaz @test\nFo\u00f3B\u0105\u017a\nFoo id:1")) @mock.patch('topydo.commands.EditCommand.EditCommand._todos_from_temp') @mock.patch('topydo.commands.EditCommand.EditCommand._open_in_editor') def test_edit2(self, mock_open_in_editor, mock_todos_from_temp): """ Edit some todo. """ mock_open_in_editor.return_value = 0 mock_todos_from_temp.return_value = [Todo('Lazy Cat')] command = EditCommand(["Bar"], self.todolist, self.out, self.error, None) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.errors, "") self.assertEqual( self.todolist.print_todos(), u("Foo id:1\nBaz @test\nFo\u00f3B\u0105\u017a\nLazy Cat")) def test_edit3(self): """ Throw an error after invalid todo number given as argument. """ command = EditCommand(["FooBar"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.errors, "Invalid todo number given.\n") def test_edit4(self): """ Throw an error with pointing invalid argument. """ command = EditCommand(["Bar", "5"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.errors, "Invalid todo number given: 5.\n") @mock.patch('topydo.commands.EditCommand.EditCommand._todos_from_temp') @mock.patch('topydo.commands.EditCommand.EditCommand._open_in_editor') def test_edit5(self, mock_open_in_editor, mock_todos_from_temp): """ Don't let to delete todos acidentally while editing. """ mock_open_in_editor.return_value = 0 mock_todos_from_temp.return_value = [Todo('Only one line')] command = EditCommand(["1", "Bar"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual( self.errors, "Number of edited todos is not equal to number of supplied todo IDs.\n" ) self.assertEqual( self.todolist.print_todos(), u("Foo id:1\nBar p:1 @test\nBaz @test\nFo\u00f3B\u0105\u017a")) def test_edit6(self): """ Throw an error with invalid argument containing special characters. """ command = EditCommand([u("Fo\u00d3B\u0105r"), "Bar"], self.todolist, self.out, self.error, None) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.errors, u("Invalid todo number given: Fo\u00d3B\u0105r.\n")) @mock.patch('topydo.commands.EditCommand.EditCommand._todos_from_temp') @mock.patch('topydo.commands.EditCommand.EditCommand._open_in_editor') def test_edit7(self, mock_open_in_editor, mock_todos_from_temp): """ Edit todo with special characters. """ mock_open_in_editor.return_value = 0 mock_todos_from_temp.return_value = [Todo('Lazy Cat')] command = EditCommand([u("Fo\u00f3B\u0105\u017a")], self.todolist, self.out, self.error, None) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.errors, "") self.assertEqual(self.todolist.print_todos(), u("Foo id:1\nBar p:1 @test\nBaz @test\nLazy Cat")) @mock.patch('topydo.commands.EditCommand.EditCommand._todos_from_temp') @mock.patch('topydo.commands.EditCommand.EditCommand._open_in_editor') def test_edit_expr(self, mock_open_in_editor, mock_todos_from_temp): """ Edit todos matching expression. """ mock_open_in_editor.return_value = 0 mock_todos_from_temp.return_value = [ Todo('Lazy Cat'), Todo('Lazy Dog') ] command = EditCommand(["-e", "@test"], self.todolist, self.out, self.error, None) command.execute() expected = u("| 3| Lazy Cat\n| 4| Lazy Dog\n") self.assertTrue(self.todolist.is_dirty()) self.assertEqual(self.errors, "") self.assertEqual(self.output, expected) self.assertEqual( self.todolist.print_todos(), u("Foo id:1\nFo\u00f3B\u0105\u017a\nLazy Cat\nLazy Dog")) @mock.patch('topydo.commands.EditCommand.check_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(["-d"], self.todolist, self.out, self.error, None) command.execute() self.assertEqual(self.errors, "") mock_call.assert_called_once_with([editor, archive]) @mock.patch('topydo.commands.EditCommand.check_call') def test_edit_todotxt(self, mock_call): """ Edit todo file. """ mock_call.return_value = 0 editor = 'vi' os.environ['EDITOR'] = editor todotxt = config().todotxt() result = self.todolist.print_todos( ) # copy TodoList content *before* executing command command = EditCommand([], self.todolist, self.out, self.error, None) command.execute() self.assertEqual(self.errors, "") self.assertEqual(self.todolist.print_todos(), result) mock_call.assert_called_once_with([editor, todotxt])
class DoCommandTest(CommandTest.CommandTest): def setUp(self): super(DoCommandTest, self).setUp() todos = [ "Foo id:1", "Bar p:1", "Baz p:1", "Recurring! rec:1d", "x 2014-10-18 Already complete", "Inactive t:2030-12-31 id:2", "Subtodo of inactive p:2", "Strict due:2014-01-01 rec:1d", "Invalid rec:1", ] self.todolist = TodoList(todos) self.today = date.today() self.tomorrow = self.today + timedelta(1) self.yesterday = self.today - timedelta(1) self.yesterday = self.yesterday.isoformat() self.today = self.today.isoformat() self.tomorrow = self.tomorrow.isoformat() def test_do1(self): command = DoCommand(["3"], self.todolist, self.out, self.error, _no_prompt) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.todo(3).is_completed()) self.assertEquals(self.output, "Completed: x {} Baz p:1\n".format(self.today)) self.assertEquals(self.errors, "") def test_do_subtasks1(self): command = DoCommand(["1"], self.todolist, self.out, self.error, _yes_prompt) command.execute() result = "| 2| Bar p:1\n| 3| Baz p:1\nCompleted: x {today} Bar p:1\nCompleted: x {today} Baz p:1\nCompleted: x {today} Foo id:1\n".format( today=self.today) for number in [1, 2, 3]: self.assertTrue(self.todolist.todo(number).is_completed()) self.assertTrue(self.todolist.is_dirty()) self.assertFalse(self.todolist.todo(4).is_completed()) self.assertEquals(self.output, result) self.assertEquals(self.errors, "") def test_do_subtasks2(self): command = DoCommand(["1"], self.todolist, self.out, self.error, _no_prompt) command.execute() result = "| 2| Bar p:1\n| 3| Baz p:1\nCompleted: x {} Foo id:1\n".format( self.today) self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.todo(1).is_completed()) self.assertFalse(self.todolist.todo(2).is_completed()) self.assertFalse(self.todolist.todo(3).is_completed()) self.assertEquals(self.output, result) self.assertEquals(self.errors, "") def test_do_subtasks_force1(self): prompt_shown = False def prompt(p_prompt): global prompt_shown prompt_shown = True command = DoCommand(["-f", "1"], self.todolist, self.out, self.error, prompt) command.execute() self.assertFalse(prompt_shown) self.assertEquals(self.errors, "") self.assertFalse(self.todolist.todo(2).is_completed()) def test_do_subtasks_force2(self): prompt_shown = False def prompt(p_prompt): global prompt_shown prompt_shown = True command = DoCommand(["--force", "1"], self.todolist, self.out, self.error, prompt) command.execute() self.assertFalse(prompt_shown) self.assertEquals(self.errors, "") self.assertFalse(self.todolist.todo(2).is_completed()) def _recurrence_helper(self, p_flags): command = DoCommand(p_flags, self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEquals(self.errors, "") self.assertEquals(self.todolist.count(), 10) def test_recurrence(self): self.assertFalse(self.todolist.todo(4).has_tag('due')) self._recurrence_helper(["4"]) self.assertTrue(self.todolist.todo(4).is_completed()) result = "| 10| {today} Recurring! rec:1d due:{tomorrow}\nCompleted: x {today} Recurring! rec:1d\n".format( today=self.today, tomorrow=self.tomorrow) self.assertEquals(self.output, result) todo = self.todolist.todo(10) self.assertFalse(todo.is_completed()) self.assertTrue(todo.has_tag('due')) def test_strict_recurrence1(self): self._recurrence_helper(["-s", "8"]) result = "| 10| {today} Strict due:2014-01-02 rec:1d\nCompleted: x {today} Strict due:2014-01-01 rec:1d\n".format( today=self.today) self.assertEquals(self.output, result) def test_strict_recurrence2(self): self._recurrence_helper(["--strict", "8"]) result = "| 10| {today} Strict due:2014-01-02 rec:1d\nCompleted: x {today} Strict due:2014-01-01 rec:1d\n".format( today=self.today) self.assertEquals(self.output, result) def test_invalid1(self): command = DoCommand(["99"], 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.\n") def test_invalid2(self): command = DoCommand(["AAA"], 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.\n") def test_invalid3(self): command = DoCommand(["01"], self.todolist, self.out, self.error, _yes_prompt) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEquals(self.errors, "Invalid todo number given.\n") def test_activated_todos1(self): command = DoCommand(["2"], self.todolist, self.out, self.error) command.execute() first_output = "Completed: x {} Bar p:1\n".format(self.today) self.assertEquals(self.output, first_output) self.assertEquals(self.errors, "") command = DoCommand(["3"], self.todolist, self.out, self.error) command.execute() self.assertEquals( self.output, first_output + "Completed: x {} Baz p:1\nThe following todo item(s) became active:\n| 1| Foo id:1\n" .format(self.today)) self.assertEquals(self.errors, "") def test_activated_todos2(self): command = DoCommand(["7"], self.todolist, self.out, self.error) command.execute() self.assertEquals( self.output, "Completed: x {} Subtodo of inactive p:2\n".format(self.today)) self.assertEquals(self.errors, "") def test_already_complete(self): command = DoCommand(["5"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEquals( self.todolist.todo(5).completion_date(), date(2014, 10, 18)) self.assertFalse(self.output) self.assertEquals(self.errors, "Todo has already been completed.\n") def test_do_regex1(self): command = DoCommand(["baz"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.todo(3).is_completed()) self.assertEquals(self.output, "Completed: x {} Baz p:1\n".format(self.today)) self.assertEquals(self.errors, "") def test_do_custom_date1(self): command = DoCommand(["-d", "2014-11-18", "3"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEquals(self.output, "Completed: x 2014-11-18 Baz p:1\n") self.assertEquals(self.errors, "") def test_do_custom_date2(self): command = DoCommand(["-d", "2014-11-18", "1"], self.todolist, self.out, self.error, _yes_prompt) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEquals( self.output, "| 2| Bar p:1\n| 3| Baz p:1\nCompleted: x 2014-11-18 Bar p:1\nCompleted: x 2014-11-18 Baz p:1\nCompleted: x 2014-11-18 Foo id:1\n" ) self.assertEquals(self.errors, "") def test_do_custom_date3(self): command = DoCommand(["--date=2014-11-18", "3"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEquals(self.output, "Completed: x 2014-11-18 Baz p:1\n") self.assertEquals(self.errors, "") def test_do_custom_date4(self): command = DoCommand(["-d", "foo", "3"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEquals(self.output, "Completed: x {} Baz p:1\n".format(self.today)) self.assertEquals(self.errors, "") def test_do_custom_date5(self): """ Make sure that the new recurrence date is correct when a custom date is given. """ command = DoCommand(["-d", self.yesterday, "4"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEquals( self.output, "| 10| {today} Recurring! rec:1d due:{today}\nCompleted: x {yesterday} Recurring! rec:1d\n" .format(today=self.today, yesterday=self.yesterday)) self.assertEquals(self.errors, "") def test_do_custom_date6(self): """ When a custom date is set, strict recurrence must still hold on to the due date as the offset. This todo item however, has no due date, then the completion date must be used as an offset. """ command = DoCommand(["-s", "-d", self.yesterday, "4"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEquals( self.output, "| 10| {today} Recurring! rec:1d due:{today}\nCompleted: x {yesterday} Recurring! rec:1d\n" .format(today=self.today, yesterday=self.yesterday)) self.assertEquals(self.errors, "") def test_do_custom_date7(self): """ When a custom date is set, strict recurrence must still hold on to the due date as the offset. """ command = DoCommand(["-s", "-d", self.yesterday, "8"], self.todolist, self.out, self.error) command.execute() self.assertTrue(self.todolist.is_dirty()) self.assertEquals( self.output, "| 10| {today} Strict due:2014-01-02 rec:1d\nCompleted: x {yesterday} Strict due:2014-01-01 rec:1d\n" .format(today=self.today, yesterday=self.yesterday)) self.assertEquals(self.errors, "") def test_multi_do1(self): command = DoCommand(["1", "3"], self.todolist, self.out, self.error, _yes_prompt) command.execute() self.assertTrue(self.todolist.todo(1).is_completed()) self.assertTrue(self.todolist.todo(2).is_completed()) self.assertTrue(self.todolist.todo(3).is_completed()) self.assertEquals( self.output, "| 2| Bar p:1\n| 3| Baz p:1\nCompleted: x {today} Bar p:1\nCompleted: x {today} Baz p:1\nCompleted: x {today} Foo id:1\n" .format(today=self.today)) def test_multi_do2(self): command = DoCommand(["1", "3"], self.todolist, self.out, self.error, _no_prompt) command.execute() self.assertTrue(self.todolist.todo(1).is_completed()) self.assertFalse(self.todolist.todo(2).is_completed()) self.assertTrue(self.todolist.todo(3).is_completed()) self.assertEquals( self.output, "| 2| Bar p:1\n| 3| Baz p:1\nCompleted: x {today} Foo id:1\nCompleted: x {today} Baz p:1\n" .format(today=self.today)) def test_multi_do3(self): command = DoCommand(["3", "3"], self.todolist, self.out, self.error, _no_prompt) command.execute() self.assertTrue(self.todolist.todo(3).is_completed()) self.assertEquals(self.output, "Completed: x {} Baz p:1\n".format(self.today)) def test_multi_do4(self): command = DoCommand(["99", "3"], self.todolist, self.out, self.error, _no_prompt) command.execute() self.assertTrue(self.todolist.todo(3).is_completed()) self.assertEquals(self.output, "Completed: x {} Baz p:1\n".format(self.today)) self.assertEquals(self.errors, "Invalid todo number given.\n") def test_multi_do5(self): """ When a todo item was generated by a recurring todo item, make sure it cannot be completed in the same invocation. """ command = DoCommand(["4", "10"], self.todolist, self.out, self.error, _no_prompt) command.execute() self.assertTrue(self.todolist.todo(4).is_completed()) self.assertFalse(self.todolist.todo(10).is_completed()) def test_invalid_recurrence(self): """ Show error message when an item has an invalid recurrence pattern. """ command = DoCommand(["9"], self.todolist, self.out, self.error, _no_prompt) command.execute() self.assertEquals(self.output, "Completed: x {} Invalid rec:1\n".format(self.today)) self.assertEquals( self.errors, "Warning: todo item has an invalid recurrence pattern.\n") def test_empty(self): command = DoCommand([], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.output) self.assertEquals(self.errors, command.usage() + "\n") def test_help(self): command = DoCommand(["help"], self.todolist, self.out, self.error) command.execute() self.assertEquals(self.output, "") self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n")