コード例 #1
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")
コード例 #2
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")
コード例 #3
0
ファイル: test_revert_command.py プロジェクト: rcraggs/topydo
    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
ファイル: test_revert_command.py プロジェクト: wzel/topydo
    def test_revert03(self):
        """ Test behavior when no backup is found """
        command = RevertCommand([], self.todolist, self.out, self.error)
        command.execute()

        self.assertEqual(
            self.errors,
            "No backup was found for the current state of {}\n".format(
                config().todotxt()))
コード例 #5
0
ファイル: test_revert_command.py プロジェクト: wzel/topydo
 def test_revert_invalid(self):
     """ Test invalid input for revert. """
     command_executer(RevertCommand, ["foo"], self.todolist, None, self.out,
                      self.error, None)
     command_executer(RevertCommand, ["ls", "foo"], self.todolist, None,
                      self.out, self.error, None)
     command_executer(RevertCommand, ["1", "foo"], self.todolist, None,
                      self.out, self.error, None)
     usage_text = RevertCommand([], self.todolist).usage() + '\n'
     self.assertEqual(self.errors, usage_text * 3)
コード例 #6
0
ファイル: test_revert_command.py プロジェクト: wzel/topydo
    def test_help(self):
        command = RevertCommand(["help"], self.todolist, self.out, self.error)
        command.execute()

        self.assertEqual(self.output, "")
        self.assertEqual(self.errors,
                         command.usage() + "\n\n" + command.help() + "\n")
コード例 #7
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")
コード例 #8
0
ファイル: test_revert_command.py プロジェクト: rcraggs/topydo
    def test_revert_name(self):
        name = RevertCommand.name()

        self.assertEqual(name, 'revert')
コード例 #9
0
ファイル: test_revert_command.py プロジェクト: rcraggs/topydo
    def test_revert05(self):
        """ Test for possible backup collisions """
        backup = ChangeSet(self.todolist, self.archive, ['add One'])
        backup.timestamp = '1'
        command1 = AddCommand(["One"], self.todolist, self.out, self.error, None)
        command1.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Two'])
        backup.timestamp = '2'
        command2 = AddCommand(["Two"], self.todolist, self.out, self.error, None)
        command2.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Three'])
        backup.timestamp = '3'
        command3 = AddCommand(["Three"], self.todolist, self.out, self.error, None)
        command3.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['delete Three'])
        backup.timestamp = '4'
        command4 = DeleteCommand(["Three"], self.todolist, self.out, self.error, None)
        command4.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Four'])
        backup.timestamp = '5'
        command4 = AddCommand(["Four"], self.todolist, self.out, self.error, None)
        command4.execute()
        backup.save(self.todolist)

        revert_command = RevertCommand([], self.todolist, self.out, self.error, None)
        revert_command.execute()
        self.assertEqual(self.errors, "")
        self.assertTrue(self.output.endswith("Successfully reverted: add Four\n"))
        self.assertEqual(self.todolist.print_todos(), "Foo\nBar\nBaz\n{t} One\n{t} Two".format(t=self.today))

        revert_command = RevertCommand([], self.todolist, self.out, self.error, None)
        revert_command.execute()
        self.assertEqual(self.errors, "")
        self.assertTrue(self.output.endswith("Successfully reverted: delete Three\n"))
        self.assertEqual(self.todolist.print_todos(), "Foo\nBar\nBaz\n{t} One\n{t} Two\n{t} Three".format(t=self.today))

        revert_command = RevertCommand([], self.todolist, self.out, self.error, None)
        revert_command.execute()
        self.assertEqual(self.errors, "")
        self.assertTrue(self.output.endswith("Successfully reverted: add Three\n"))
        self.assertEqual(self.todolist.print_todos(), "Foo\nBar\nBaz\n{t} One\n{t} Two".format(t=self.today))

        revert_command = RevertCommand([], self.todolist, self.out, self.error, None)
        revert_command.execute()
        self.assertEqual(self.errors, "")
        self.assertTrue(self.output.endswith("Successfully reverted: add Two\n"))
        self.assertEqual(self.todolist.print_todos(), "Foo\nBar\nBaz\n{t} One".format(t=self.today))

        revert_command = RevertCommand([], self.todolist, self.out, self.error, None)
        revert_command.execute()
        self.assertEqual(self.errors, "")
        self.assertTrue(self.output.endswith("Successfully reverted: add One\n"))
        self.assertEqual(self.todolist.print_todos(), "Foo\nBar\nBaz")
コード例 #10
0
ファイル: test_revert_command.py プロジェクト: rcraggs/topydo
    def test_revert04(self):
        """ Test trimming of the backup_file """
        backup = ChangeSet(self.todolist, self.archive, ['add One'])
        backup.timestamp = '1'
        command1 = AddCommand(["One"], self.todolist, self.out, self.error, None)
        command1.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Two'])
        backup.timestamp = '2'
        command2 = AddCommand(["Two"], self.todolist, self.out, self.error, None)
        command2.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Three'])
        backup.timestamp = '3'
        command3 = AddCommand(["Three"], self.todolist, self.out, self.error, None)
        command3.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Four'])
        backup.timestamp = '4'
        command4 = AddCommand(["Four"], self.todolist, self.out, self.error, None)
        command4.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Five'])
        backup.timestamp = '5'
        command5 = AddCommand(["Five"], self.todolist, self.out, self.error, None)
        command5.execute()
        backup.save(self.todolist)

        result = len(ChangeSet().backup_dict.keys())
        self.assertEqual(result, 6)

        backup = ChangeSet(self.todolist, self.archive, ['add Six'])
        backup.timestamp = '6'
        command6 = AddCommand(["Six"], self.todolist, self.out, self.error, None)
        command6.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Seven'])
        backup.timestamp = '7'
        command7 = AddCommand(["Seven"], self.todolist, self.out, self.error, None)
        command7.execute()
        backup.save(self.todolist)

        result = len(ChangeSet().backup_dict.keys())
        self.assertEqual(result, 6)

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

        backup = ChangeSet()
        changesets = list(backup.backup_dict.keys())
        changesets.remove('index')
        index_timestamps = [change[0] for change in backup._get_index()]
        result = list(set(index_timestamps) - set(changesets))

        self.assertEqual(len(changesets), 4)
        self.assertEqual(result, [])
        self.assertEqual(self.errors, "")
        self.assertTrue(self.output.endswith("Successfully reverted: add Seven\n"))
コード例 #11
0
ファイル: test_revert_command.py プロジェクト: rcraggs/topydo
    def test_revert03(self):
        """ Test behavior when no backup is found """
        command = RevertCommand([], self.todolist, self.out, self.error)
        command.execute()

        self.assertEqual(self.errors, "No backup was found for the current state of {}\n".format(config().todotxt()))
コード例 #12
0
    def test_revert05(self):
        """ Test for possible backup collisions """
        backup = ChangeSet(self.todolist, self.archive, ['add One'])
        backup.timestamp = '1'
        command1 = AddCommand(["One"], self.todolist, self.out, self.error,
                              None)
        command1.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Two'])
        backup.timestamp = '2'
        command2 = AddCommand(["Two"], self.todolist, self.out, self.error,
                              None)
        command2.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Three'])
        backup.timestamp = '3'
        command3 = AddCommand(["Three"], self.todolist, self.out, self.error,
                              None)
        command3.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['delete Three'])
        backup.timestamp = '4'
        command4 = DeleteCommand(["Three"], self.todolist, self.out,
                                 self.error, None)
        command4.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Four'])
        backup.timestamp = '5'
        command4 = AddCommand(["Four"], self.todolist, self.out, self.error,
                              None)
        command4.execute()
        backup.save(self.todolist)

        revert_command = RevertCommand([], self.todolist, self.out, self.error,
                                       None)
        revert_command.execute()
        self.assertEqual(self.errors, "")
        self.assertTrue(
            self.output.endswith("Successfully reverted: add Four\n"))
        self.assertEqual(
            self.todolist.print_todos(),
            "Foo\nBar\nBaz\n{t} One\n{t} Two".format(t=self.today))

        revert_command = RevertCommand([], self.todolist, self.out, self.error,
                                       None)
        revert_command.execute()
        self.assertEqual(self.errors, "")
        self.assertTrue(
            self.output.endswith("Successfully reverted: delete Three\n"))
        self.assertEqual(
            self.todolist.print_todos(),
            "Foo\nBar\nBaz\n{t} One\n{t} Two\n{t} Three".format(t=self.today))

        revert_command = RevertCommand([], self.todolist, self.out, self.error,
                                       None)
        revert_command.execute()
        self.assertEqual(self.errors, "")
        self.assertTrue(
            self.output.endswith("Successfully reverted: add Three\n"))
        self.assertEqual(
            self.todolist.print_todos(),
            "Foo\nBar\nBaz\n{t} One\n{t} Two".format(t=self.today))

        revert_command = RevertCommand([], self.todolist, self.out, self.error,
                                       None)
        revert_command.execute()
        self.assertEqual(self.errors, "")
        self.assertTrue(
            self.output.endswith("Successfully reverted: add Two\n"))
        self.assertEqual(self.todolist.print_todos(),
                         "Foo\nBar\nBaz\n{t} One".format(t=self.today))

        revert_command = RevertCommand([], self.todolist, self.out, self.error,
                                       None)
        revert_command.execute()
        self.assertEqual(self.errors, "")
        self.assertTrue(
            self.output.endswith("Successfully reverted: add One\n"))
        self.assertEqual(self.todolist.print_todos(), "Foo\nBar\nBaz")
コード例 #13
0
ファイル: test_revert_command.py プロジェクト: wzel/topydo
    def test_revert05(self):
        """ Test for possible backup collisions """
        backup = BackupSimulator(self.todolist, self.archive, '1', ['add One'])
        command_executer(AddCommand, ["One"], self.todolist, None, self.out,
                         self.error, None)
        backup.save(self.todolist)

        backup = BackupSimulator(self.todolist, self.archive, '2', ['add Two'])
        command_executer(AddCommand, ["Two"], self.todolist, None, self.out,
                         self.error, None)
        backup.save(self.todolist)

        backup = BackupSimulator(self.todolist, self.archive, '3',
                                 ['add Three'])
        command_executer(AddCommand, ["Three"], self.todolist, None, self.out,
                         self.error, None)
        backup.save(self.todolist)

        backup = BackupSimulator(self.todolist, self.archive, '4',
                                 ['delete Three'])
        command_executer(DeleteCommand, ["Three"], self.todolist, None,
                         self.out, self.error, None)
        backup.save(self.todolist)

        backup = BackupSimulator(self.todolist, self.archive, '5',
                                 ['add Four'])
        command_executer(AddCommand, ["Four"], self.todolist, None, self.out,
                         self.error, None)
        backup.save(self.todolist)

        revert_command = RevertCommand([], self.todolist, self.out, self.error,
                                       None)
        revert_command.execute()
        self.assertEqual(self.errors, "")
        self.assertTrue(
            self.output.endswith("Reverted to state before: add Four\n"))
        self.assertEqual(
            self.todolist.print_todos(),
            "Foo\nBar\nBaz\n{t} One\n{t} Two".format(t=self.today))

        revert_command = RevertCommand([], self.todolist, self.out, self.error,
                                       None)
        revert_command.execute()
        self.assertEqual(self.errors, "")
        self.assertTrue(
            self.output.endswith("Reverted to state before: delete Three\n"))
        self.assertEqual(
            self.todolist.print_todos(),
            "Foo\nBar\nBaz\n{t} One\n{t} Two\n{t} Three".format(t=self.today))

        revert_command = RevertCommand([], self.todolist, self.out, self.error,
                                       None)
        revert_command.execute()
        self.assertEqual(self.errors, "")
        self.assertTrue(
            self.output.endswith("Reverted to state before: add Three\n"))
        self.assertEqual(
            self.todolist.print_todos(),
            "Foo\nBar\nBaz\n{t} One\n{t} Two".format(t=self.today))

        revert_command = RevertCommand([], self.todolist, self.out, self.error,
                                       None)
        revert_command.execute()
        self.assertEqual(self.errors, "")
        self.assertTrue(
            self.output.endswith("Reverted to state before: add Two\n"))
        self.assertEqual(self.todolist.print_todos(),
                         "Foo\nBar\nBaz\n{t} One".format(t=self.today))

        revert_command = RevertCommand([], self.todolist, self.out, self.error,
                                       None)
        revert_command.execute()
        self.assertEqual(self.errors, "")
        self.assertTrue(
            self.output.endswith("Reverted to state before: add One\n"))
        self.assertEqual(self.todolist.print_todos(), "Foo\nBar\nBaz")
コード例 #14
0
ファイル: test_revert_command.py プロジェクト: wzel/topydo
    def test_revert04(self, mock_archive):
        """ Test trimming of the backup_file """
        mock_archive.return_value = ''  # test for empty archive setting
        backup = BackupSimulator(self.todolist, self.archive, '1', ['add One'])
        command_executer(AddCommand, ["One"], self.todolist, None, self.out,
                         self.error, None)
        backup.save(self.todolist)

        backup = BackupSimulator(self.todolist, self.archive, '2', ['add Two'])
        command_executer(AddCommand, ["Two"], self.todolist, None, self.out,
                         self.error, None)
        backup.save(self.todolist)

        backup = BackupSimulator(self.todolist, self.archive, '3',
                                 ['add Three'])
        command_executer(AddCommand, ["Three"], self.todolist, None, self.out,
                         self.error, None)
        backup.save(self.todolist)

        backup = BackupSimulator(self.todolist, self.archive, '4',
                                 ['add Four'])
        command_executer(AddCommand, ["Four"], self.todolist, None, self.out,
                         self.error, None)
        backup.save(self.todolist)

        backup = BackupSimulator(self.todolist, self.archive, '5',
                                 ['add Five'])
        command_executer(AddCommand, ["Five"], self.todolist, None, self.out,
                         self.error, None)
        backup.save(self.todolist)

        result = len(ChangeSet().backup_dict.keys())
        self.assertEqual(result, 6)

        backup = BackupSimulator(self.todolist, self.archive, '6', ['add Six'])
        command_executer(AddCommand, ["Six"], self.todolist, None, self.out,
                         self.error, None)
        backup.save(self.todolist)

        backup = BackupSimulator(self.todolist, self.archive, '7',
                                 ['add Seven'])
        command_executer(AddCommand, ["Seven"], self.todolist, None, self.out,
                         self.error, None)
        backup.save(self.todolist)

        result = len(ChangeSet().backup_dict.keys())
        self.assertEqual(result, 6)

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

        backup = ChangeSet()
        changesets = list(backup.backup_dict.keys())
        changesets.remove('index')
        index_timestamps = [change[0] for change in backup._get_index()]
        result = list(set(index_timestamps) - set(changesets))

        self.assertEqual(len(changesets), 4)
        self.assertEqual(result, [])
        self.assertEqual(self.errors, "")
        self.assertTrue(
            self.output.endswith("Reverted to state before: add Seven\n"))
コード例 #15
0
ファイル: test_revert_command.py プロジェクト: rcraggs/topydo
    def test_help(self):
        command = RevertCommand(["help"], self.todolist, self.out, self.error)
        command.execute()

        self.assertEqual(self.output, "")
        self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
コード例 #16
0
ファイル: test_revert_command.py プロジェクト: wzel/topydo
    def test_revert_name(self):
        name = RevertCommand.name()

        self.assertEqual(name, 'revert')
コード例 #17
0
    def test_revert04(self):
        """ Test trimming of the backup_file """
        backup = ChangeSet(self.todolist, self.archive, ['add One'])
        backup.timestamp = '1'
        command1 = AddCommand(["One"], self.todolist, self.out, self.error,
                              None)
        command1.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Two'])
        backup.timestamp = '2'
        command2 = AddCommand(["Two"], self.todolist, self.out, self.error,
                              None)
        command2.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Three'])
        backup.timestamp = '3'
        command3 = AddCommand(["Three"], self.todolist, self.out, self.error,
                              None)
        command3.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Four'])
        backup.timestamp = '4'
        command4 = AddCommand(["Four"], self.todolist, self.out, self.error,
                              None)
        command4.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Five'])
        backup.timestamp = '5'
        command5 = AddCommand(["Five"], self.todolist, self.out, self.error,
                              None)
        command5.execute()
        backup.save(self.todolist)

        result = len(ChangeSet().backup_dict.keys())
        self.assertEqual(result, 6)

        backup = ChangeSet(self.todolist, self.archive, ['add Six'])
        backup.timestamp = '6'
        command6 = AddCommand(["Six"], self.todolist, self.out, self.error,
                              None)
        command6.execute()
        backup.save(self.todolist)

        backup = ChangeSet(self.todolist, self.archive, ['add Seven'])
        backup.timestamp = '7'
        command7 = AddCommand(["Seven"], self.todolist, self.out, self.error,
                              None)
        command7.execute()
        backup.save(self.todolist)

        result = len(ChangeSet().backup_dict.keys())
        self.assertEqual(result, 6)

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

        backup = ChangeSet()
        changesets = list(backup.backup_dict.keys())
        changesets.remove('index')
        index_timestamps = [change[0] for change in backup._get_index()]
        result = list(set(index_timestamps) - set(changesets))

        self.assertEqual(len(changesets), 4)
        self.assertEqual(result, [])
        self.assertEqual(self.errors, "")
        self.assertTrue(
            self.output.endswith("Successfully reverted: add Seven\n"))