Example #1
0
    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")
Example #2
0
    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")
Example #3
0
    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")
Example #4
0
    def test_revert01(self):
        backup = ChangeSet(p_label=['do 1'])
        backup.add_todolist(self.todolist)
        backup.add_archive(self.archive)
        backup.timestamp = '1'
        command = DoCommand(["1"], self.todolist, self.out, self.error, None)
        command.execute()
        archive_command = ArchiveCommand(self.todolist, self.archive)
        archive_command.execute()
        self.archive_file.write(self.archive.print_todos())
        backup.save(self.todolist)

        self.assertEqual(self.archive.print_todos(),
                         "x {} Foo".format(self.today))
        self.assertEqual(self.todolist.print_todos(), "Bar\nBaz")

        revert_command = RevertCommand([], self.todolist, self.out, self.error,
                                       None)
        revert_command.execute()

        result = TodoList(self.archive_file.read()).print_todos()

        self.assertEqual(self.errors, "")
        self.assertTrue(self.output.endswith("Successfully reverted: do 1\n"))
        self.assertEqual(result, "")
        self.assertEqual(self.todolist.print_todos(), "Foo\nBar\nBaz")
Example #5
0
    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)
Example #6
0
    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")
Example #7
0
    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")
Example #8
0
    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)
Example #9
0
    def test_activated_todos2(self):
        command = DoCommand(["7"], self.todolist, self.out, self.error)
        command.execute()
        command.execute_post_archive_actions()

        self.assertEqual(self.output, "Completed: x {} Subtodo of inactive p:2\n".format(self.today))
        self.assertEqual(self.errors, "")
Example #10
0
    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")
Example #11
0
    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())
Example #12
0
    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, "")
Example #13
0
    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, "")
Example #14
0
    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, "")
Example #15
0
    def test_invalid2(self):
        command = DoCommand(["AAA"], self.todolist, self.out, self.error)
        command.execute()

        self.assertFalse(self.todolist.dirty)
        self.assertFalse(self.output)
        self.assertEqual(self.errors, "Invalid todo number given.\n")
Example #16
0
    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"))
Example #17
0
    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")
Example #18
0
    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")
Example #19
0
    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.dirty)
Example #20
0
    def test_expr_do3(self):
        command = DoCommand(["-e", "@test", "due:2015-06-03", "+project"],
                            self.todolist, self.out, self.error, None)
        command.execute()
        command.execute_post_archive_actions()

        self.assertFalse(self.todolist.dirty)
Example #21
0
    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, "")
Example #22
0
    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")
Example #23
0
    def test_invalid1(self):
        command = DoCommand(["99"], self.todolist, self.out, self.error)
        command.execute()
        command.execute_post_archive_actions()

        self.assertFalse(self.todolist.dirty)
        self.assertFalse(self.output)
        self.assertEqual(self.errors, "Invalid todo number given.\n")
Example #24
0
    def _recurrence_helper(self, p_flags):
        command = DoCommand(p_flags, self.todolist, self.out, self.error)
        command.execute()
        command.execute_post_archive_actions()

        self.assertTrue(self.todolist.dirty)
        self.assertEqual(self.errors, "")
        self.assertEqual(self.todolist.count(), 12)
Example #25
0
    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))
Example #26
0
    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, "")
Example #27
0
    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")
Example #28
0
    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))
Example #29
0
    def test_expr_do1(self):
        command = DoCommand(["-e", "@test"], self.todolist, self.out,
                            self.error, None)
        command.execute()

        self.assertTrue(self.todolist.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, "")
Example #30
0
    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, "")
Example #31
0
    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, "")
Example #32
0
    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"))
Example #33
0
    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, "")
Example #34
0
    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, "")
Example #35
0
    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")
Example #36
0
    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))
Example #37
0
    def test_do_custom_date1(self):
        command = DoCommand(["-d", "2014-11-18", "3"], self.todolist, self.out,
                            self.error)
        command.execute()
        command.execute_post_archive_actions()

        self.assertTrue(self.todolist.dirty)
        self.assertEqual(self.output, "Completed: x 2014-11-18 Baz p:1\n")
        self.assertEqual(self.errors, "")
Example #38
0
    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, "")
Example #39
0
    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, "")
Example #40
0
    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, "")
Example #41
0
    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, "")
Example #42
0
    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, "")
Example #43
0
    def test_do1(self):
        command = DoCommand(["3"], self.todolist, self.out, self.error,
                            _no_prompt)
        command.execute()
        command.execute_post_archive_actions()

        self.assertTrue(self.todolist.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, "")
Example #44
0
    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")
Example #45
0
    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")
Example #46
0
    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, "")
Example #47
0
    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, "")
Example #48
0
    def test_do_custom_date8(self):
        """
        Convert relative completion dates to an absolute date (yesterday).
        """
        command = DoCommand(["-d", "yesterday", "3"], self.todolist, self.out,
                            self.error)
        command.execute()
        command.execute_post_archive_actions()

        self.assertTrue(self.todolist.dirty)
        self.assertEqual(self.output, "Completed: x {} Baz p:1\n".format(self.yesterday))
        self.assertEqual(self.errors, "")
Example #49
0
    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))
Example #50
0
    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, "")
Example #51
0
    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())
Example #52
0
    def test_help(self):
        command = DoCommand(["help"], self.todolist, self.out, self.error)
        command.execute()
        command.execute_post_archive_actions()

        self.assertEqual(self.output, "")
        self.assertEqual(self.errors,
                         command.usage() + "\n\n" + command.help() + "\n")
Example #53
0
    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, "")
Example #54
0
    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, "")
Example #55
0
    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, "")
Example #56
0
    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, "")
Example #57
0
    def test_empty(self):
        command = DoCommand([], self.todolist, self.out, self.error)
        command.execute()
        command.execute_post_archive_actions()

        self.assertFalse(self.todolist.dirty)
        self.assertFalse(self.output)
        self.assertEqual(self.errors, command.usage() + "\n")
Example #58
0
    def test_expr_do3(self):
        command = DoCommand(["-e", "@test", "due:2015-06-03", "+project"],
                            self.todolist, self.out, self.error, None)
        command.execute()
        command.execute_post_archive_actions()

        self.assertFalse(self.todolist.dirty)
Example #59
0
    def test_invalid2(self):
        command = DoCommand(["AAA"], self.todolist, self.out, self.error)
        command.execute()
        command.execute_post_archive_actions()

        self.assertFalse(self.todolist.dirty)
        self.assertFalse(self.output)
        self.assertEqual(self.errors, "Invalid todo number given.\n")
Example #60
0
    def _recurrence_helper(self, p_flags):
        command = DoCommand(p_flags, self.todolist, self.out, self.error)
        command.execute()
        command.execute_post_archive_actions()

        self.assertTrue(self.todolist.dirty)
        self.assertEqual(self.errors, "")
        self.assertEqual(self.todolist.count(), 12)