Ejemplo n.º 1
0
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 = TodoListBase(lines)

    def test_contexts(self):
        self.assertEqual(set(["Context1", "Context2"]), self.todolist.contexts())
        self.assertFalse(self.todolist.is_dirty())

    def test_projects(self):
        self.assertEqual(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.assertEqual(self.todolist.todo(count + 1).source(), text)
        self.assertEqual(set(["Project1", "Project2", "Project3"]), self.todolist.projects())
        self.assertEqual(set(["Context1", "Context2", "Context3"]), self.todolist.contexts())
        self.assertEqual(self.todolist.number(todo), 6)
        self.assertTrue(self.todolist.is_dirty())

    def test_add2(self):
        text = str(self.todolist)
        self.todolist.add("")
        self.assertEqual(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.assertEqual(str(self.todolist), text)

    def test_add5(self):
        text = str(self.todolist)
        self.todolist.add("\n")
        self.assertEqual(str(self.todolist), text)

    def test_delete1(self):
        count = self.todolist.count()
        todo = self.todolist.todo(2)
        self.todolist.delete(todo)

        self.assertEqual(self.todolist.todo(2).source(), "(C) Baz @Context1 +Project1 key:value")
        self.assertEqual(self.todolist.count(), count - 1)
        self.assertTrue(self.todolist.is_dirty())
        self.assertRaises(InvalidTodoException, self.todolist.number, todo)

    def test_delete2(self):
        """ Try to remove a todo item that does not exist. """
        count = self.todolist.count()

        todo = Todo("Not in the list")
        self.todolist.delete(todo)

        self.assertEqual(self.todolist.count(), count)
        self.assertFalse(self.todolist.is_dirty())

    def test_append1(self):
        todo = self.todolist.todo(3)
        self.todolist.append(todo, "@Context3")

        self.assertEqual(todo.source(), "(C) Baz @Context1 +Project1 key:value @Context3")
        self.assertEqual(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.assertEqual(todo.text(), text)
        self.assertEqual(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.assertEqual(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_count(self):
        """ Test that empty lines are not counted. """
        self.assertEqual(self.todolist.count(), 5)

    def test_todo_number1(self):
        todo = Todo("No number")
        self.todolist.add_todo(todo)

        todo = self.todolist.todo(6)
        self.assertIsInstance(todo, Todo)
        self.assertEqual(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.assertEqual(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.assertEqual(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.assertEqual(todo.source(), "(D) Bar @Context1 +Project2")

    def test_uid1(self):
        config("test/data/todolist-uid.conf")

        self.assertEqual(self.todolist.todo("t5c").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("t5c")
        self.todolist.set_priority(todo, "B")
        self.assertEqual(self.todolist.todo("t5c").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("t5c")
        self.todolist.append(todo, "A")

        self.assertNotEqual(self.todolist.number(todo), "t5c")
Ejemplo n.º 2
0
class TodoListTester(TopydoTest):
    def setUp(self):
        super().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 = TodoListBase(lines)

    def test_contexts(self):
        self.assertEqual(set(['Context1', 'Context2']),
                         self.todolist.contexts())
        self.assertFalse(self.todolist.dirty)

    def test_projects(self):
        self.assertEqual(set(['Project1', 'Project2']),
                         self.todolist.projects())
        self.assertFalse(self.todolist.dirty)

    def test_add1(self):
        text = "(C) Adding a new task @Context3 +Project3"
        count = self.todolist.count()
        todo = self.todolist.add(text)

        self.assertEqual(self.todolist.todo(count+1).source(), text)
        self.assertEqual(set(['Project1', 'Project2', 'Project3']),
                         self.todolist.projects())
        self.assertEqual(set(['Context1', 'Context2', 'Context3']),
                         self.todolist.contexts())
        self.assertEqual(self.todolist.number(todo), 6)
        self.assertTrue(self.todolist.dirty)

    def test_add2(self):
        text = str(self.todolist)
        self.todolist.add('')
        self.assertEqual(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.assertEqual(str(self.todolist), text)

    def test_add5(self):
        text = str(self.todolist)
        self.todolist.add("\n")
        self.assertEqual(str(self.todolist), text)

    def test_delete1(self):
        count = self.todolist.count()
        todo = self.todolist.todo(2)
        self.todolist.delete(todo)

        self.assertEqual(self.todolist.todo(2).source(),
                         "(C) Baz @Context1 +Project1 key:value")
        self.assertEqual(self.todolist.count(), count - 1)
        self.assertTrue(self.todolist.dirty)
        self.assertRaises(InvalidTodoException, self.todolist.number, todo)

    def test_delete2(self):
        """ Try to remove a todo item that does not exist. """
        count = self.todolist.count()

        todo = Todo('Not in the list')
        self.todolist.delete(todo)

        self.assertEqual(self.todolist.count(), count)
        self.assertFalse(self.todolist.dirty)

    def test_append1(self):
        todo = self.todolist.todo(3)
        self.todolist.append(todo, "@Context3")

        self.assertEqual(todo.source(),
                         "(C) Baz @Context1 +Project1 key:value @Context3")
        self.assertEqual(set(['Context1', 'Context2', 'Context3']),
                         self.todolist.contexts())
        self.assertTrue(self.todolist.dirty)

    def test_append2(self):
        todo = self.todolist.todo(3)
        text = todo.text()
        self.todolist.append(todo, "foo:bar")

        self.assertEqual(todo.text(), text)
        self.assertEqual(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.assertEqual(todo.text(), text)

    def test_todo(self):
        count = self.todolist.count()

        self.assertRaises(InvalidTodoException, self.todolist.todo,
                          count + 100)
        self.assertFalse(self.todolist.dirty)

    def test_count(self):
        """ Test that empty lines are not counted. """
        self.assertEqual(self.todolist.count(), 5)

    def test_todo_number1(self):
        todo = Todo("No number")
        self.todolist.add_todo(todo)

        todo = self.todolist.todo(6)
        self.assertIsInstance(todo, Todo)
        self.assertEqual(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.dirty)

    def test_todo_priority1(self):
        todo = self.todolist.todo(1)
        self.todolist.set_priority(todo, 'F')

        self.assertEqual(self.todolist.todo(1).priority(), 'F')
        self.assertTrue(self.todolist.dirty)

    def test_todo_priority2(self):
        todo = self.todolist.todo(1)
        self.todolist.set_priority(todo, 'C')

        self.assertFalse(self.todolist.dirty)

    def test_erase(self):
        self.todolist.erase()

        self.assertEqual(self.todolist.count(), 0)
        self.assertTrue(self.todolist.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.assertEqual(todo.source(), "(D) Bar @Context1 +Project2")

    def test_uid1(self):
        config("test/data/todolist-uid.conf")

        self.assertEqual(self.todolist.todo('t5c').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('t5c')
        self.todolist.set_priority(todo, 'B')
        self.assertEqual(self.todolist.todo('t5c').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_uid4(self):
        """
        Handle UIDs properly when line numbers are configured.
        """
        config(p_overrides={('topydo', 'identifiers'): 'linenumber'})
        self.assertRaises(InvalidTodoException, self.todolist.todo, '11a')

    def test_uid5(self):
        """ Handle bogus UIDs """
        todo = Todo('invalid')
        self.assertRaises(InvalidTodoException, self.todolist.uid, todo)

    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('t5c')
        self.todolist.append(todo, "A")

        self.assertNotEqual(self.todolist.number(todo), 't5c')

    def test_iteration(self):
        """ Confirms that the iternation method is working. """
        results = ["(C) Foo @Context2 Not@Context +Project1 Not+Project",
                   "(D) Bar @Context1 +Project2",
                   "(C) Baz @Context1 +Project1 key:value",
                   "(C) Drink beer @ home",
                   "(C) 13 + 29 = 42"]

        i = 0
        for todo in self.todolist:
            self.assertEqual(todo.src, results[i])
            i += 1

    def test_ids_linenumber(self):
        """ Confirms the ids method lists all todo IDs as line-numbers. """
        config(p_overrides={('topydo', 'identifiers'): 'linenumber'})
        results = {'1', '2', '3', '4', '5'}

        self.assertEqual(results, self.todolist.ids())

    def test_ids_uids(self):
        """ Confirms the ids method lists all todo IDs as text uids. """
        config("test/data/todolist-uid.conf")
        results = {'n8m', 'mfg', 'z63', 't5c', 'wa5'}

        self.assertEqual(results, self.todolist.ids())
Ejemplo n.º 3
0
class TodoListTester(TopydoTest):
    def setUp(self):
        super().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 = TodoListBase(lines)

    def test_contexts(self):
        self.assertEqual(set(['Context1', 'Context2']),
                         self.todolist.contexts())
        self.assertFalse(self.todolist.is_dirty())

    def test_projects(self):
        self.assertEqual(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.assertEqual(self.todolist.todo(count+1).source(), text)
        self.assertEqual(set(['Project1', 'Project2', 'Project3']),
                         self.todolist.projects())
        self.assertEqual(set(['Context1', 'Context2', 'Context3']),
                         self.todolist.contexts())
        self.assertEqual(self.todolist.number(todo), 6)
        self.assertTrue(self.todolist.is_dirty())

    def test_add2(self):
        text = str(self.todolist)
        self.todolist.add('')
        self.assertEqual(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.assertEqual(str(self.todolist), text)

    def test_add5(self):
        text = str(self.todolist)
        self.todolist.add("\n")
        self.assertEqual(str(self.todolist), text)

    def test_delete1(self):
        count = self.todolist.count()
        todo = self.todolist.todo(2)
        self.todolist.delete(todo)

        self.assertEqual(self.todolist.todo(2).source(),
                         "(C) Baz @Context1 +Project1 key:value")
        self.assertEqual(self.todolist.count(), count - 1)
        self.assertTrue(self.todolist.is_dirty())
        self.assertRaises(InvalidTodoException, self.todolist.number, todo)

    def test_delete2(self):
        """ Try to remove a todo item that does not exist. """
        count = self.todolist.count()

        todo = Todo('Not in the list')
        self.todolist.delete(todo)

        self.assertEqual(self.todolist.count(), count)
        self.assertFalse(self.todolist.is_dirty())

    def test_append1(self):
        todo = self.todolist.todo(3)
        self.todolist.append(todo, "@Context3")

        self.assertEqual(todo.source(),
                         "(C) Baz @Context1 +Project1 key:value @Context3")
        self.assertEqual(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.assertEqual(todo.text(), text)
        self.assertEqual(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.assertEqual(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_count(self):
        """ Test that empty lines are not counted. """
        self.assertEqual(self.todolist.count(), 5)

    def test_todo_number1(self):
        todo = Todo("No number")
        self.todolist.add_todo(todo)

        todo = self.todolist.todo(6)
        self.assertIsInstance(todo, Todo)
        self.assertEqual(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.assertEqual(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.assertEqual(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.assertEqual(todo.source(), "(D) Bar @Context1 +Project2")

    def test_uid1(self):
        config("test/data/todolist-uid.conf")

        self.assertEqual(self.todolist.todo('t5c').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('t5c')
        self.todolist.set_priority(todo, 'B')
        self.assertEqual(self.todolist.todo('t5c').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_uid4(self):
        """
        Handle UIDs properly when line numbers are configured.
        """
        config(p_overrides={('topydo', 'identifiers'): 'linenumber'})
        self.assertRaises(InvalidTodoException, self.todolist.todo, '11a')

    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('t5c')
        self.todolist.append(todo, "A")

        self.assertNotEqual(self.todolist.number(todo), 't5c')

    def test_iteration(self):
        """ Confirms that the iternation method is working. """
        results = ["(C) Foo @Context2 Not@Context +Project1 Not+Project",
                   "(D) Bar @Context1 +Project2",
                   "(C) Baz @Context1 +Project1 key:value",
                   "(C) Drink beer @ home",
                   "(C) 13 + 29 = 42"]

        i = 0
        for todo in self.todolist:
            self.assertEqual(todo.src, results[i])
            i += 1
Ejemplo n.º 4
0
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 = TodoListBase(lines)

    def test_contexts(self):
        self.assertEqual(set(['Context1', 'Context2']), \
            self.todolist.contexts())
        self.assertFalse(self.todolist.is_dirty())

    def test_projects(self):
        self.assertEqual(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.assertEqual(self.todolist.todo(count+1).source(), text)
        self.assertEqual(set(['Project1', 'Project2', 'Project3']), \
            self.todolist.projects())
        self.assertEqual(set(['Context1', 'Context2', 'Context3']), \
            self.todolist.contexts())
        self.assertEqual(self.todolist.number(todo), 6)
        self.assertTrue(self.todolist.is_dirty())

    def test_add2(self):
        text = str(self.todolist)
        self.todolist.add('')
        self.assertEqual(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.assertEqual(str(self.todolist), text)

    def test_add5(self):
        text = str(self.todolist)
        self.todolist.add("\n")
        self.assertEqual(str(self.todolist), text)

    def test_delete1(self):
        count = self.todolist.count()
        todo = self.todolist.todo(2)
        self.todolist.delete(todo)

        self.assertEqual(self.todolist.todo(2).source(), \
            "(C) Baz @Context1 +Project1 key:value")
        self.assertEqual(self.todolist.count(), count - 1)
        self.assertTrue(self.todolist.is_dirty())
        self.assertRaises(InvalidTodoException, self.todolist.number, todo)

    def test_delete2(self):
        """ Try to remove a todo item that does not exist. """
        count = self.todolist.count()

        todo = Todo('Not in the list')
        self.todolist.delete(todo)

        self.assertEqual(self.todolist.count(), count)
        self.assertFalse(self.todolist.is_dirty())

    def test_append1(self):
        todo = self.todolist.todo(3)
        self.todolist.append(todo, "@Context3")

        self.assertEqual(todo.source(), \
            "(C) Baz @Context1 +Project1 key:value @Context3")
        self.assertEqual(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.assertEqual(todo.text(), text)
        self.assertEqual(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.assertEqual(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_count(self):
        """ Test that empty lines are not counted. """
        self.assertEqual(self.todolist.count(), 5)

    def test_todo_number1(self):
        todo = Todo("No number")
        self.todolist.add_todo(todo)

        todo = self.todolist.todo(6)
        self.assertIsInstance(todo, Todo)
        self.assertEqual(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.assertEqual(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.assertEqual(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.assertEqual(todo.source(), "(D) Bar @Context1 +Project2")

    def test_uid1(self):
        config("test/data/todolist-uid.conf")

        self.assertEqual(self.todolist.todo('t5c').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('t5c')
        self.todolist.set_priority(todo, 'B')
        self.assertEqual(self.todolist.todo('t5c').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('t5c')
        self.todolist.append(todo, "A")

        self.assertNotEqual(self.todolist.number(todo), 't5c')