コード例 #1
0
ファイル: test_revert_command.py プロジェクト: wzel/topydo
    def setUp(self):
        super().setUp()
        todos = [
            "Foo",
            "Bar",
            "Baz",
        ]

        self.todolist = TodoList(todos)
        self.today = date.today()

        self.tmp_name = str(uuid4().hex.upper()[0:6])

        archive_filename = tempfile.gettempdir(
        ) + os.sep + self.tmp_name + '_archive'
        todo_filename = tempfile.gettempdir(
        ) + os.sep + self.tmp_name + '_todo'

        config(
            p_overrides={
                ('topydo', 'archive_filename'): archive_filename,
                ('topydo', 'filename'): todo_filename,
                ('topydo', 'backup_count'): '5'
            })

        self.archive_file = TodoFile(archive_filename)
        self.archive = TodoList([])
コード例 #2
0
ファイル: test_revert_command.py プロジェクト: wzel/topydo
    def test_revert02(self):
        backup = BackupSimulator(self.todolist, self.archive, '1', ['do 1'])
        command_executer(DoCommand, ["1"], self.todolist, self.archive,
                         self.out, self.error, None)
        self.archive_file.write(self.archive.print_todos())
        backup.save(self.todolist)

        # Use add_todolist and add_archive to also cover them
        backup = ChangeSet(p_label=['do Bar'])
        backup.add_todolist(self.todolist)
        backup.add_archive(self.archive)
        backup.timestamp = '2'
        command_executer(DoCommand, ["Bar"], self.todolist, self.archive,
                         self.out, self.error, None)
        self.archive_file.write(self.archive.print_todos())
        backup.save(self.todolist)

        self.assertEqual(self.archive.print_todos(),
                         "x {t} Foo\nx {t} Bar".format(t=self.today))
        self.assertEqual(self.todolist.print_todos(), "Baz")

        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("Reverted to state before: do Bar\n"))
        self.assertEqual(result, "x {} Foo".format(self.today))
        self.assertEqual(self.todolist.print_todos(), "Bar\nBaz")
コード例 #3
0
    def test_revert02(self):
        backup = ChangeSet(self.todolist, self.archive, ['do 1'])
        backup.timestamp = '1'
        command1 = DoCommand(["1"], self.todolist, self.out, self.error, None)
        command1.execute()
        archive_command1 = ArchiveCommand(self.todolist, self.archive)
        archive_command1.execute()
        self.archive_file.write(self.archive.print_todos())
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['do Bar'])
        backup.timestamp = '2'
        command2 = DoCommand(["Bar"], self.todolist, self.out, self.error,
                             None)
        command2.execute()
        archive_command2 = ArchiveCommand(self.todolist, self.archive)
        archive_command2.execute()
        self.archive_file.write(self.archive.print_todos())
        backup.save(self.todolist)

        self.assertEqual(self.archive.print_todos(),
                         "x {t} Foo\nx {t} Bar".format(t=self.today))
        self.assertEqual(self.todolist.print_todos(), "Baz")

        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 Bar\n"))
        self.assertEqual(result, "x {} Foo".format(self.today))
        self.assertEqual(self.todolist.print_todos(), "Bar\nBaz")
コード例 #4
0
    def read_backup(self, p_todolist=None, p_timestamp=None):
        """
        Retrieves a backup for p_timestamp or p_todolist (if p_timestamp is not
        specified) from backup file and sets timestamp, todolist, archive and
        label attributes to appropriate data from it.
        """
        if not p_timestamp:
            change_hash = hash_todolist(p_todolist)
            index = self._get_index()
            self.timestamp = index[[change[1]
                                    for change in index].index(change_hash)][0]
        else:
            self.timestamp = p_timestamp

        d = self.backup_dict[self.timestamp]

        self.todolist = TodoList(d[0])
        self.archive = TodoList(d[1])
        self.label = d[2]
コード例 #5
0
    def test_archive(self):
        todolist = TestFacilities.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.assertEquals(str(todolist), "x Not complete\n(C) Active")
        self.assertEquals(
            str(archive),
            "x 2014-10-19 Complete\nx 2014-10-20 Another one complete")
コード例 #6
0
ファイル: test_revert_command.py プロジェクト: wzel/topydo
    def test_revert01(self):
        backup = BackupSimulator(self.todolist, self.archive, '1', ['do 1'])
        command_executer(DoCommand, ["1"], self.todolist, self.archive,
                         self.out, self.error, None)
        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("Reverted to state before: do 1\n"))
        self.assertEqual(result, "")
        self.assertEqual(self.todolist.print_todos(), "Foo\nBar\nBaz")
コード例 #7
0
    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()