Ejemplo n.º 1
0
 def test_two_tasks(self):
     task1 = 'do something +project1 @context1'
     task2 = '(A) do something else +project1 @context2'
     self.file.tasks.extend([Task(task1), Task(task2)])
     self.saveAndReload()
     self.assertEqual(self.file.tasks[0].text, task2)
     self.assertEqual(self.file.tasks[1].text, task1)
Ejemplo n.º 2
0
 def test_get_all_projects_incl_completed(self):
     self.file.tasks.extend([
         Task('x task with +project1'),
         Task('task with +project2'),
         Task('task with +project1 and +project2'),
         Task('x task with +project1 and +project2 and +project3')
     ])
     self.saveAndReload()
     self.assertEqual(self.file.getAllProjects(True), {
         'project1': 1,
         'project2': 2,
         'project3': 0
     })
Ejemplo n.º 3
0
 def test_get_all_incl_completed_contexts(self):
     self.file.tasks.extend([
         Task('x task with @context1'),
         Task('task with @context2'),
         Task('task with @context1 and @context2'),
         Task('x task with @context1 and @context2 and @context3')
     ])
     self.saveAndReload()
     self.assertEqual(self.file.getAllContexts(True), {
         'context1': 1,
         'context2': 2,
         'context3': 0
     })
Ejemplo n.º 4
0
 def test_five_tasks(self):
     task1 = Task('do something +project1 @context1')
     task2 = Task('(A) do something else +project1 @context2')
     task3 = Task('do something else +project1 @context2')
     task4 = Task('something else +project1 @context2')
     task5 = Task('abc +project1 @context2')
     self.file.tasks.extend([task1, task2, task3, task4, task5])
     self.saveAndReload()
     self.assertEqual(self.file.tasks[0].text, task2.text)
     self.assertEqual(self.file.tasks[1].text, task5.text)
     self.assertEqual(self.file.tasks[2].text, task1.text)
     self.assertEqual(self.file.tasks[3].text, task3.text)
     self.assertEqual(self.file.tasks[4].text, task4.text)
Ejemplo n.º 5
0
 def test_get_all_projects(self):
     self.file.tasks.extend([
         Task('x task with +project1'),
         Task('task with +project2'),
         Task('task with +project1 and +project2'),
         Task('task with +project1 and +project2 and +project3')
     ])
     self.saveAndReload()
     self.assertEqual(self.file.getAllProjects(), {
         'project1': 2,
         'project2': 3,
         'project3': 1
     })
Ejemplo n.º 6
0
 def _createTasksFromLines(self, lines):
     self.tasks = []
     for line in lines:
         task_text = line.strip()
         if task_text:
             task = Task(task_text)
             self.tasks.append(task)
Ejemplo n.º 7
0
    def test_completion(self):
        task = Task('(B) something +project1 @context1 pri:C')
        self.assertEqual(task.contexts, ['context1'])
        self.assertEqual(task.projects, ['project1'])
        self.assertFalse(task.is_complete)
        self.assertEqual(task.priority, 'B')
        self.assertEqual(len(task.keywords), 1)

        task.setCompleted()
        self.assertTrue(task.is_complete)
        self.assertEqual(task.completion_date, date.today())
        self.assertTrue(task.text.startswith("x "))

        task.setPending()
        self.assertFalse(task.is_complete)
        self.assertFalse(task.completion_date)
Ejemplo n.º 8
0
 def test_future(self):
     task = Task('(D) do something +project1 t:2030-10-06')
     self.assertEqual(task.contexts, [])
     self.assertEqual(task.projects, ['project1'])
     self.assertFalse(task.is_complete)
     self.assertTrue(task.priority)
     self.assertTrue(task.is_future)
Ejemplo n.º 9
0
    def test_get_all_due_ranges(self):
        today = date.today().strftime('%Y-%m-%d')
        yesterday = (date.today() - timedelta(days=1)).strftime('%Y-%m-%d')

        self.file.tasks.extend([
            Task('x due:' + today + ' completed task of today'),
            Task('due:' + today + ' first task of today'),
            Task('due:' + today + ' second task of today'),
            Task('due:' + yesterday + ' task of yesterday'),
        ])
        self.saveAndReload()
        self.assertEqual(self.file.getAllDueRanges()[0], {
            'Today': 2,
            'This week': 2,
            'This month': 2,
            'Overdue': 1
        })
        self.assertIsInstance(self.file.getAllDueRanges()[1], dict)
Ejemplo n.º 10
0
 def test_single_task(self):
     text = 'due:1999-10-10 do something +project1 @context1'
     self.file.tasks.append(Task(text))
     self.saveAndReload()
     self.assertEqual(self.file.tasks[0].text, text)
     self.assertEqual(self.file.tasks[0].contexts, ['context1'])
     self.assertEqual(self.file.tasks[0].projects, ['project1'])
     self.assertFalse(self.file.tasks[0].is_complete)
     self.assertFalse(self.file.tasks[0].priority)
     self.assertEqual(self.file.tasks[0].due, date(1999, 10, 10))
Ejemplo n.º 11
0
 def test_custom_keywords(self):
     task = Task(
         '(B) do something +project1 mykey:myval titi:toto @context1 rest + of line pri:C'
     )
     self.assertEqual(task.contexts, ['context1'])
     self.assertEqual(task.projects, ['project1'])
     self.assertFalse(task.is_complete)
     self.assertEqual(task.priority, 'B')
     self.assertEqual(len(task.keywords), 3)
     self.assertIn("titi", task.keywords)
     self.assertEqual(task.keywords['pri'], "C")
Ejemplo n.º 12
0
    def test_basic(self):
        task = Task('do something')
        self.assertEqual(task.text, 'do something')
        self.assertEqual(len(task.contexts), 0)
        self.assertFalse(len(task.projects), 0)
        self.assertFalse(task.is_complete)
        self.assertFalse(task.priority)

        task = Task('do something @context1 @context2')
        self.assertEqual(task.contexts, ['context1', 'context2'])
        self.assertEqual(task.projects, [])
        self.assertFalse(task.is_complete)
        self.assertFalse(task.priority)

        task = Task('do something +project1 +project2')
        self.assertEqual(task.contexts, [])
        self.assertEqual(task.projects, ['project1', 'project2'])
        self.assertFalse(task.is_complete)
        self.assertFalse(task.priority)

        task = Task(
            '(E) do something +project1 @context1 +project2 rest of line @context2'
        )
        self.assertEqual(task.contexts, ['context1', 'context2'])
        self.assertEqual(task.projects, ['project1', 'project2'])
        self.assertFalse(task.is_complete)
        self.assertTrue(task.priority)
        self.assertEqual(
            task.text,
            '(E) do something +project1 @context1 +project2 rest of line @context2'
        )

        # task with + alone and complete
        task = Task(
            'x 2016-01-23 do something +project1 @context1 +project2 rest + of line @context2'
        )
        self.assertEqual(task.contexts, ['context1', 'context2'])
        self.assertEqual(task.projects, ['project1', 'project2'])
        self.assertTrue(task.is_complete)
        self.assertFalse(task.priority)
        self.assertEqual(task.completion_date, date(2016, 1, 23))
Ejemplo n.º 13
0
 def test_task_ordering(self):
     task1 = Task('x task1')
     task2 = Task('task2')
     task3 = Task('abc task2')
     task4 = Task('(D) task2')
     task5 = Task('(C) b task')
     task6 = Task('(C) a task')
     task7 = Task('(B) task2')
     task8 = Task('(A) task2')
     self.assertTrue(task2 < task3)
     self.assertTrue(
         task1 < task2 < task3 < task4 < task5 < task6 < task7 < task8)
     l = [task1, task2, task3, task4, task5, task6, task7, task8]
     l2 = [task2, task3, task1, task4, task5, task6, task7, task8]
     self.assertFalse(l == l2)
     l2.sort()
     self.assertTrue(l == l2)
Ejemplo n.º 14
0
    def test_completion(self):
        task = Task('(B) something +project1 @context1 pri:C')
        self.assertEqual(task.contexts, ['context1'])
        self.assertEqual(task.projects, ['project1'])
        self.assertFalse(task.is_complete)
        self.assertEqual(task.priority, 'B')
        self.assertEqual(len(task.keywords), 1)

        task.setCompleted()
        self.assertTrue(task.is_complete)
        self.assertEqual(task.completion_date, date.today())
        self.assertTrue(task.text.startswith("x "))

        task.setPending()
        self.assertFalse(task.is_complete)
        self.assertFalse(task.completion_date)
Ejemplo n.º 15
0
 def test_creation_date(self):
     task = Task(
         '(B) 2016-03-15 do something +project1 mykey:myval titi:toto @context1 rest + of line pri:C'
     )
     self.assertTrue(task.creation_date)
     self.assertEqual(task.creation_date, date(2016, 3, 15))
     task = Task('2016-03-15 do something')
     self.assertTrue(task.creation_date)
     self.assertEqual(task.creation_date, date(2016, 3, 15))
     task = Task('do something')
     self.assertFalse(task.creation_date)
     task = Task('(A) do something')
     self.assertFalse(task.creation_date)
     task = Task('x 2017-08-12 2016-03-15 do something')
     self.assertTrue(task.creation_date)
     self.assertEqual(task.creation_date, date(2016, 3, 15))
     task = Task('x 2017-08-12 do something')
     self.assertFalse(task.creation_date)
Ejemplo n.º 16
0
    def test_priority(self):
        self.assertEqual(Task("task").priority, "")
        self.assertEqual(Task("(a) task").priority, "")
        self.assertEqual(Task("x (a) task").priority, "")
        self.assertEqual(Task("x 2016-03-12 task").priority, "")
        self.assertEqual(Task("(A) task").priority, "A")
        t = Task("(A) task")
        self.assertEqual(t.priority, "A")
        t.increasePriority()
        self.assertEqual(t.priority, "A")
        t.decreasePriority()
        self.assertEqual(t.priority, "B")
        t.decreasePriority()
        t.decreasePriority()
        self.assertEqual(t.priority, "D")
        self.assertEqual(t.text, "(D) task")
        t.decreasePriority()
        self.assertEqual(t.priority, "")
        self.assertEqual(t.text, "task")

        t.increasePriority()
        t.increasePriority()
        self.assertEqual(t.priority, "C")
        for i in range(20):
            t.increasePriority()
        self.assertEqual(t.priority, "A")
        for i in range(20):
            t.decreasePriority()
        self.assertEqual(t.priority, "")

        # this task i wrongly formated, x should be followed by adate
        # self.assertEqual(Task("x (A) task").priority, Priority("A"))

        # A task with a priority lower than our default minimal priority
        t = Task("(M) task")
        t.increasePriority()
        self.assertEqual(t.priority, "L")
        t.decreasePriority()
        self.assertEqual(t.priority, "")
Ejemplo n.º 17
0
 def test_priority_comparison(self):
     # this tests are a bit broken now that priority is only a character
     self.assertEqual(Task('task1').priority, Task('task2').priority)
     self.assertEqual(
         Task('(A) task1').priority,
         Task('(A) task2').priority)
     self.assertNotEqual(Task('(A) task').priority, Task('task').priority)
     self.assertLess(Task('(A) task').priority, Task('(B) task').priority)
     self.assertGreater(
         Task('(B) task').priority,
         Task('(A) task').priority)
     self.assertNotEqual(
         Task('(A) task1').priority,
         Task('(AA) task2').priority)
     self.assertEqual(
         Task('(1) task1').priority,
         Task('(1) task2').priority)
Ejemplo n.º 18
0
 def test_recurring_task_wrong_interval(self):
     task = Task('(B) do something rec:2g')
     self.assertIsNone(task.recursion)
Ejemplo n.º 19
0
 def test_recurring_task_wrong_increment(self):
     task = Task('(B) do something rec:0d')
     self.assertIsNone(task.recursion)
Ejemplo n.º 20
0
 def test_recurring_task_wrong_keyword(self):
     task = Task('(B) do something rect:5d')
     self.assertIsNone(task.recursion)
Ejemplo n.º 21
0
 def test_recurring_task_input_months(self):
     task = Task('(C) do something due:2016-09-05 rec:3m')
     self.assertIsNotNone(task.recursion)
     self.assertTrue(task.recursion.mode == recursiveMode.completitionDate)
     self.assertTrue(task.recursion.increment == str(3))
     self.assertTrue(task.recursion.interval == 'm')
Ejemplo n.º 22
0
 def test_recurring_task_input_years(self):
     task = Task('(C) do something due:2016-09-05 rec:+1y')
     self.assertIsNotNone(task.recursion)
     self.assertTrue(task.recursion.mode == recursiveMode.originalDueDate)
     self.assertTrue(task.recursion.increment == str(1))
     self.assertTrue(task.recursion.interval == 'y')
Ejemplo n.º 23
0
    def test_comparisons_comparison(self):
        self.assertEqual(Task('task'), Task('task'))
        self.assertEqual(Task('(A) task'), Task('(A) task'))

        # self.assertLess(Task('task1'), Task('task2'))
        self.assertLess(Task('x task'), Task('task'))
        self.assertGreater(Task('(A) task'), Task('(B) task'))
        self.assertGreater(Task('(A) task'), Task('task'))
        self.assertGreater(Task('(A) task'), Task('x (A) task'))

        # self.assertGreater(Task('task2'), Task('task1'))
        self.assertLess(Task('x task'), Task('task'))
        self.assertLess(Task('(B) task'), Task('(A) task'))
        self.assertLess(Task('task'), Task('(A) task'))
        self.assertLess(Task('x (A) task'), Task('(A) task'))
Ejemplo n.º 24
0
    def test_priority(self):
        self.assertEqual(Task("task").priority, "")
        self.assertEqual(Task("(a) task").priority, "")
        self.assertEqual(Task("x (a) task").priority, "")
        self.assertEqual(Task("x 2016-03-12 task").priority, "")
        self.assertEqual(Task("(A) task").priority, "A")
        t = Task("(A) task")
        self.assertEqual(t.priority, "A")
        t.increasePriority()
        self.assertEqual(t.priority, "A")
        t.decreasePriority()
        self.assertEqual(t.priority, "B")
        t.decreasePriority()
        t.decreasePriority()
        self.assertEqual(t.priority, "D")
        self.assertEqual(t.text, "(D) task")
        t.decreasePriority()
        self.assertEqual(t.priority, "")
        self.assertEqual(t.text, "task")

        t.increasePriority()
        t.increasePriority()
        self.assertEqual(t.priority, "C")
        for i in range(20):
            t.increasePriority()
        self.assertEqual(t.priority, "A")
        for i in range(20):
            t.decreasePriority()
        self.assertEqual(t.priority, "")

        # this task i wrongly formated, x should be followed by adate
        # self.assertEqual(Task("x (A) task").priority, Priority("A"))

        # A task with a priority lower than our default minimal priority
        t = Task("(M) task")
        t.increasePriority()
        self.assertEqual(t.priority, "L")
        t.decreasePriority()
        self.assertEqual(t.priority, "")
Ejemplo n.º 25
0
 def test_completeness_comparison(self):
     self.assertEqual(Task('task1').is_complete, Task('task2').is_complete)
     self.assertEqual(
         Task('x task1').is_complete,
         Task('x task2').is_complete)
     self.assertNotEqual(
         Task('task').is_complete,
         Task('x task').is_complete)
     self.assertNotEqual(
         Task('x task').is_complete,
         Task('task').is_complete)
     self.assertGreater(Task('task'), Task('x task'))
     self.assertLess(Task('x task'), Task('task'))