Exemple #1
0
 def test_priority_at_least(self):
     """Test that the task has a minimum priority."""
     self.assertTrue(todotxt.Task("(A) Task").priority_at_least("A"))
     self.assertTrue(todotxt.Task("(A) Task").priority_at_least("B"))
     self.assertFalse(todotxt.Task("(B) Task").priority_at_least("A"))
     self.assertTrue(todotxt.Task("(Z) Task").priority_at_least("Z"))
     self.assertFalse(todotxt.Task("Task").priority_at_least("Z"))
 def test_due_dates(self):
     """Test that a task with an earlier due date takes precedence."""
     no_due_date = todotxt.Task("Task 1")
     earlier_task = todotxt.Task("Task 2 due:2018-02-02")
     later_task = todotxt.Task("Task 3 due:2019-01-01")
     self.assertEqual([earlier_task, later_task, no_due_date],
                      pick_action.next_actions([no_due_date, later_task, earlier_task], self.namespace))
 def test_project(self):
     """Test that the next action can be limited to a specific project."""
     task1 = todotxt.Task("Todo 1 +ProjectX")
     task2 = todotxt.Task("(B) Todo 2 +ProjectX")
     task3 = todotxt.Task("(A) Todo 3 +ProjectY")
     self.namespace.projects = {"ProjectX"}
     self.assertEqual([task2, task1], pick_action.next_actions([task1, task2, task3], self.namespace))
 def test_contexts(self):
     """Test that the next action can be limited to a set of contexts."""
     task1 = todotxt.Task("Todo 1 @work @computer")
     task2 = todotxt.Task("(B) Todo 2 @work @computer")
     task3 = todotxt.Task("(A) Todo 3 @home @computer")
     self.namespace.contexts = {"work", "computer"}
     self.assertEqual([task2, task1], pick_action.next_actions([task1, task2, task3], self.namespace))
 def test_creation_dates(self):
     """Test that a task with an older creation date takes precedence."""
     no_creation_date = todotxt.Task("Task 1")
     newer_task = todotxt.Task("2018-02-02 Task 2")
     older_task = todotxt.Task("2017-01-01 Task 3")
     self.assertEqual([older_task, newer_task, no_creation_date],
                      pick_action.next_actions([no_creation_date, newer_task, older_task], self.namespace))
 def setUp(self):
     """Set up tasks."""
     super().setUp()
     self.no_duedate = todotxt.Task("Task")
     self.future_duedate = todotxt.Task("Task due:9999-01-01")
     self.overdue = todotxt.Task("Task due:2000-01-01")
     self.tasks = [self.no_duedate, self.future_duedate, self.overdue]
 def test_priority_and_creation_date(self):
     """Test that priority takes precedence over creation date."""
     priority = todotxt.Task("(C) Task 1")
     newer_task = todotxt.Task("2018-02-02 Task 2")
     older_task = todotxt.Task("2017-01-01 Task 3")
     self.assertEqual([priority, older_task, newer_task],
                      pick_action.next_actions([priority, newer_task, older_task], self.namespace))
 def test_priority(self):
     """Test that tasks without priority are filtered."""
     no_priority = todotxt.Task("Task")
     high_priority = todotxt.Task("(A) Task")
     low_priority = todotxt.Task("(Z) Task")
     self.namespace.priority = "K"
     self.assertEqual(
         [high_priority], pick_action.next_actions([no_priority, low_priority, high_priority], self.namespace))
Exemple #9
0
 def test_is_future_task(self):
     """Test that a task with a creation date in the future is a future task."""
     self.assertTrue(
         todotxt.Task(
             "9999-01-01 Prepare for five-digit years").is_future())
     self.assertFalse(
         todotxt.Task(
             f"{datetime.date.today().isoformat()} Todo").is_future())
Exemple #10
0
 def test_single_digits(self):
     """Test a creation date with single digits for day and/or month."""
     self.assertEqual(datetime.date(2018, 12, 3),
                      todotxt.Task("(B) 2018-12-3 Todo").creation_date())
     self.assertEqual(datetime.date(2018, 1, 13),
                      todotxt.Task("(B) 2018-1-13 Todo").creation_date())
     self.assertEqual(datetime.date(2018, 1, 1),
                      todotxt.Task("(B) 2018-1-1 Todo").creation_date())
Exemple #11
0
 def test_priority(self, argument):
     """Test that the priority arguments are rendered correctly."""
     self.assertEqual(
         "A C",
         render_arguments(
             argument,
             todotxt.Tasks([todotxt.Task("(A) A"),
                            todotxt.Task("(C) C")])))
 def test_priority_of_blocked_task(self):
     """Test that a task that blocks a task with a higher priority takes precendence."""
     high_prio_but_blocked = todotxt.Task("(A) Task id:1")
     blocking_task = todotxt.Task("Blocking before:1")
     second_prio = todotxt.Task("(B) Task")
     high_prio_but_blocked.set_is_blocked()
     blocking_task.add_blocked_task(high_prio_but_blocked)
     tasks = todotxt.Tasks([second_prio, blocking_task])
     self.assertEqual([blocking_task, second_prio], pick_action.next_actions(tasks, self.namespace))
Exemple #13
0
 def test_blocked_recursive(self):
     """Test that the blocked tasks are rendered, recursively."""
     self.namespace.blocked = True
     lather = todotxt.Task("Lather before:rinse")
     rinse = todotxt.Task("Rinse id:rinse before:repeat")
     lather.add_blocked_task(rinse)
     rinse.add_blocked_task(self.repeat)
     self.assertEqual(
         f"Lather before:rinse\nblocks:\n- Rinse id:rinse before:repeat\n  blocks:\n  - {self.repeat.text}",
         render_next_action([lather], [], self.namespace))
Exemple #14
0
    def test_blocking(self):
        """Test the due date of a task without its own due date.

        Test that the due date of a task without its own due date equals the due date of the task it is blocking.
        """
        after = todotxt.Task("After id:after due:2018-01-01")
        before = todotxt.Task("Before before:after")
        after.set_is_blocked()
        before.add_blocked_task(after)
        self.assertEqual(datetime.date(2018, 1, 1), before.due_date())
Exemple #15
0
 def test_blocked_multiple(self):
     """Test that multiple blocked tasks are rendered."""
     self.namespace.blocked = True
     lather = todotxt.Task("Rinse before:repeat before:rinse")
     rinse = todotxt.Task("Rinse id:rinse")
     lather.add_blocked_task(self.repeat)
     lather.add_blocked_task(rinse)
     self.assertEqual(
         f"Rinse before:repeat before:rinse\nblocks:\n- {self.repeat.text}\n- Rinse id:rinse",
         render_next_action([lather], [], self.namespace))
 def test_due_date_of_blocked_task(self):
     """Test that a task that blocks a task with an earlier due date takes precendence."""
     tasks = todotxt.Tasks()
     due_first_but_blocked = todotxt.Task("Task id:1 due:2018-01-01")
     blocking_task = todotxt.Task("Blocking before:1")
     due_second = todotxt.Task("Task due:2018-02-01")
     due_first_but_blocked.set_is_blocked()
     blocking_task.add_blocked_task(due_first_but_blocked)
     tasks.extend([blocking_task, due_second])
     self.assertEqual([blocking_task, due_second], pick_action.next_actions(tasks, self.namespace))
Exemple #17
0
    def test_blocking(self):
        """Test the priority of a task without its own priority.

        Test that the priority of a task without its own priority equals the priority of the task it is
        blocking.
        """
        after = todotxt.Task("(A) After id:1")
        before = todotxt.Task("Before before:1")
        after.set_is_blocked()
        before.add_blocked_task(after)
        self.assertEqual("A", before.priority())
Exemple #18
0
 def setUp(self):
     """Set up the namespace with default arguments for all unit tests."""
     super().setUp()
     self.line_number1 = 42
     self.filename2 = "work.txt"
     self.call_mom = todotxt.Task("Call mom",
                                  filename=self.filename1,
                                  line_number=self.line_number1)
     self.paint_house = todotxt.Task(
         "(A) Paint house @home +HomeImprovement due:2018-10-10",
         filename=self.filename2)
     self.fix_lamp = todotxt.Task(
         "(A) Fix lamp @home +HomeImprovement due:2018-10-10",
         filename=self.filename2)
Exemple #19
0
    def test_blocking_multiple(self):
        """Test the priority of a task without its own priority.

        Test that the priority of a task without its own priority equals the highest priority of the tasks it is
        blocking.
        """
        after1 = todotxt.Task("(A) After id:1")
        after2 = todotxt.Task("(B) After after:before")
        before = todotxt.Task("Before before:1 id:before")
        before.add_blocked_task(after1)
        before.add_blocked_task(after2)
        after1.set_is_blocked()
        after2.set_is_blocked()
        self.assertEqual("A", before.priority())
Exemple #20
0
 def test_is_due(self):
     """Test the is_due method."""
     self.assertTrue(
         todotxt.Task("due:2019-01-01").is_due(datetime.date.today()))
     self.assertTrue(
         todotxt.Task("due:2019-01-01").is_due(datetime.date(2019, 1, 1)))
     self.assertTrue(
         todotxt.Task("9999-01-01 due:2018-01-01").is_due(
             datetime.date(2018, 1, 1)))
     self.assertFalse(
         todotxt.Task("due:2018-01-01").is_due(datetime.date(2017, 12, 31)))
     self.assertFalse(
         todotxt.Task("Without due date").is_due(datetime.date(
             2017, 12, 31)))
Exemple #21
0
    def test_blocking_multiple(self):
        """Test the due date of a task without its own due date.

        Test that the due date of a task without its own due date equals the earliest due date of the tasks it is
        blocking.
        """
        after1 = todotxt.Task("After id:after due:2018-10-01")
        after2 = todotxt.Task("After after:before due:2018-01-01")
        before = todotxt.Task("Before before:after id:before")
        after1.set_is_blocked()
        after2.set_is_blocked()
        before.add_blocked_task(after1)
        before.add_blocked_task(after2)
        self.assertEqual(datetime.date(2018, 1, 1), before.due_date())
Exemple #22
0
 def test_multiple_urls(self):
     """Test that a task with multiple URLs returns the URLs."""
     task = todotxt.Task(
         "Search for things using https://www.google.com and https://duckduckgo.com"
     )
     self.assertEqual(["https://www.google.com", "https://duckduckgo.com"],
                      task.urls())
Exemple #23
0
 def test_brackets(self, brackets):
     """Test that a bracketed project is considered a project."""
     opening, closing = brackets[0], brackets[1]
     self.assertEqual(
         {"GarageSale"},
         todotxt.Task(
             f"Organize {opening}+GarageSale{closing} @home").projects())
Exemple #24
0
 def test_blocked(self):
     """Test that the blocked task is rendered."""
     self.namespace.blocked = True
     rinse = todotxt.Task("Rinse before:repeat")
     rinse.add_blocked_task(self.repeat)
     self.assertEqual(f"Rinse before:repeat\nblocks:\n- {self.repeat.text}",
                      render_next_action([rinse], [], self.namespace))
Exemple #25
0
 def test_reference_multiple(self):
     """Test that the source filename is added if reference is multiple and there are multiple todo.txt files."""
     self.namespace.file.append("work.txt")
     self.assertEqual(
         f"{self.call_mom.text} [{self.filename1}]\nProposal [{self.filename2}]",
         render_next_action(
             [self.call_mom,
              todotxt.Task("Proposal", self.filename2)], [],
             self.namespace))
Exemple #26
0
 def setUp(self):
     """Set up the namespace with default arguments for all unit tests."""
     self.namespace = argparse.Namespace()
     self.namespace.line_number = False
     self.namespace.reference = "multiple"
     self.filename = "todo.txt"
     self.line_number = 42
     self.namespace.file = [self.filename]
     self.task = todotxt.Task("Todo", self.filename, self.line_number)
Exemple #27
0
 def test_reference_never(self):
     """Test that the source filename is not added if reference is never."""
     self.namespace.reference = "never"
     self.namespace.file.append(self.filename2)
     self.assertEqual(
         f"{self.call_mom.text}\nProposal",
         render_next_action(
             [self.call_mom,
              todotxt.Task("Proposal", self.filename2)], [],
             self.namespace))
 def test_excluded_context(self):
     """Test that contexts can be excluded."""
     task = todotxt.Task("(A) Todo @computer")
     self.namespace.excluded_contexts = {"computer"}
     self.assertEqual([], pick_action.next_actions([task], self.namespace))
 def test_projects(self):
     """Test that a task with more projects takes precedence over a task with less projects."""
     task1 = todotxt.Task("Task 1 +Project")
     task2 = todotxt.Task("Task 2 +Project1 +Project2")
     self.assertEqual([task2, task1], pick_action.next_actions([task1, task2], self.namespace))
 def test_project(self):
     """Test that a task with a project takes precedence over a task without a project."""
     task1 = todotxt.Task("Task 1 without project")
     task2 = todotxt.Task("Task 2 +Project")
     self.assertEqual([task2, task1], pick_action.next_actions([task1, task2], self.namespace))