当前位置: 首页>>代码示例>>Python>>正文


Python TodoList.print_todos方法代码示例

本文整理汇总了Python中topydo.lib.TodoList.TodoList.print_todos方法的典型用法代码示例。如果您正苦于以下问题:Python TodoList.print_todos方法的具体用法?Python TodoList.print_todos怎么用?Python TodoList.print_todos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在topydo.lib.TodoList.TodoList的用法示例。


在下文中一共展示了TodoList.print_todos方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_archive

# 需要导入模块: from topydo.lib.TodoList import TodoList [as 别名]
# 或者: from topydo.lib.TodoList.TodoList import print_todos [as 别名]
    def test_archive(self):
        todolist = 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.assertEqual(todolist.print_todos(), "x Not complete\n(C) Active")
        self.assertEqual(archive.print_todos(), "x 2014-10-19 Complete\nx 2014-10-20 Another one complete")
开发者ID:netimen,项目名称:topydo,代码行数:13,代码来源:ArchiveCommandTest.py

示例2: RevertCommandTest

# 需要导入模块: from topydo.lib.TodoList import TodoList [as 别名]
# 或者: from topydo.lib.TodoList.TodoList import print_todos [as 别名]
class RevertCommandTest(CommandTest):
    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([])

    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")

    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")

    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()))

    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)
#.........这里部分代码省略.........
开发者ID:rcraggs,项目名称:topydo,代码行数:103,代码来源:test_revert_command.py

示例3: DeleteCommandTest

# 需要导入模块: from topydo.lib.TodoList import TodoList [as 别名]
# 或者: from topydo.lib.TodoList.TodoList import print_todos [as 别名]
class DeleteCommandTest(CommandTest):
    def setUp(self):
        super().setUp()
        todos = [
            "Foo id:1",
            "Bar p:1",
            "a @test with due:2015-06-03",
            "a @test with +project",
        ]

        self.todolist = TodoList(todos)

    def test_del1(self):
        command = DeleteCommand(["1"], self.todolist, self.out, self.error,
                                _no_prompt)
        command.execute()

        self.assertTrue(self.todolist.is_dirty())
        self.assertEqual(self.todolist.todo(1).source(), "Bar")
        self.assertEqual(self.output, "|  2| Bar p:1\nRemoved: Foo id:1\n")
        self.assertEqual(self.errors, "")

    def test_del1_regex(self):
        command = DeleteCommand(["Foo"], self.todolist, self.out, self.error,
                                _no_prompt)
        command.execute()

        self.assertTrue(self.todolist.is_dirty())
        self.assertEqual(self.todolist.todo(1).source(), "Bar")
        self.assertEqual(self.output, "|  2| Bar p:1\nRemoved: Foo id:1\n")
        self.assertEqual(self.errors, "")

    def test_del2(self):
        command = DeleteCommand(["1"], self.todolist, self.out, self.error,
                                _yes_prompt)
        command.execute()

        self.assertTrue(self.todolist.is_dirty())
        self.assertEqual(self.todolist.count(), 2)
        self.assertEqual(self.output,
                         "|  2| Bar p:1\nRemoved: Bar\nRemoved: Foo\n")
        self.assertEqual(self.errors, "")

    def test_del3(self):
        command = DeleteCommand(["-f", "1"], self.todolist, self.out,
                                self.error, _yes_prompt)
        command.execute()

        self.assertTrue(self.todolist.is_dirty())
        self.assertEqual(self.todolist.count(), 3)  # force won't delete subtasks
        self.assertEqual(self.output, "|  2| Bar p:1\nRemoved: Foo id:1\n")
        self.assertEqual(self.errors, "")

    def test_del4(self):
        command = DeleteCommand(["--force", "1"], self.todolist, self.out,
                                self.error, _yes_prompt)
        command.execute()

        self.assertTrue(self.todolist.is_dirty())
        self.assertEqual(self.todolist.count(), 3)  # force won't delete subtasks
        self.assertEqual(self.output, "|  2| Bar p:1\nRemoved: Foo id:1\n")
        self.assertEqual(self.errors, "")

    def test_del5(self):
        command = DeleteCommand(["2"], self.todolist, self.out, self.error)
        command.execute()

        self.assertTrue(self.todolist.is_dirty())
        self.assertEqual(self.todolist.todo(1).source(), "Foo")
        self.assertEqual(self.output, "Removed: Bar p:1\nThe following todo item(s) became active:\n|  1| Foo\n")
        self.assertEqual(self.errors, "")

    def test_del7(self):
        command = DeleteCommand(["99"], self.todolist, self.out, self.error)
        command.execute()

        self.assertFalse(self.todolist.is_dirty())
        self.assertEqual(self.output, "")
        self.assertEqual(self.errors, "Invalid todo number given.\n")

    def test_del8(self):
        command = DeleteCommand(["A"], self.todolist, self.out, self.error)
        command.execute()

        self.assertFalse(self.todolist.is_dirty())
        self.assertEqual(self.output, "")
        self.assertEqual(self.errors, "Invalid todo number given.\n")

    def test_del9(self):
        """ Test deletion with textual IDs. """
        config("test/data/todolist-uid.conf")

        command = DeleteCommand(["8to"], self.todolist, self.out, self.error)
        command.execute()

        result = "Foo\na @test with due:2015-06-03\na @test with +project"

        self.assertEqual(self.todolist.print_todos(), result)
        self.assertRaises(InvalidTodoException, self.todolist.todo, 'b0n')

#.........这里部分代码省略.........
开发者ID:rameshg87,项目名称:topydo,代码行数:103,代码来源:test_delete_command.py

示例4: EditCommandTest

# 需要导入模块: from topydo.lib.TodoList import TodoList [as 别名]
# 或者: from topydo.lib.TodoList.TodoList import print_todos [as 别名]
class EditCommandTest(CommandTest):
    def setUp(self):
        super().setUp()
        todos = [
            "Foo id:1",
            "Bar p:1 @test",
            "Baz @test",
            u"Fo\u00f3B\u0105\u017a",
        ]

        self.todolist = TodoList(todos)

    @mock.patch('topydo.commands.EditCommand._is_edited')
    @mock.patch('topydo.commands.EditCommand.EditCommand._todos_from_temp')
    @mock.patch('topydo.commands.EditCommand.EditCommand._open_in_editor')
    def test_edit01(self, mock_open_in_editor, mock_todos_from_temp, mock_is_edited):
        """ Preserve dependencies after editing. """
        mock_open_in_editor.return_value = 0
        mock_todos_from_temp.return_value = [Todo('Foo id:1')]
        mock_is_edited.return_value = True

        command = EditCommand(["1"], self.todolist, self.out, self.error, None)
        command.execute()

        self.assertEqual(self.errors, "")
        self.assertTrue(self.todolist.dirty)
        self.assertEqual(self.todolist.print_todos(), u"Bar p:1 @test\nBaz @test\nFo\u00f3B\u0105\u017a\nFoo id:1")

    @mock.patch('topydo.commands.EditCommand._is_edited')
    @mock.patch('topydo.commands.EditCommand.EditCommand._todos_from_temp')
    @mock.patch('topydo.commands.EditCommand.EditCommand._open_in_editor')
    def test_edit02(self, mock_open_in_editor, mock_todos_from_temp, mock_is_edited):
        """ Edit some todo. """
        mock_open_in_editor.return_value = 0
        mock_todos_from_temp.return_value = [Todo('Lazy Cat')]
        mock_is_edited.return_value = True

        command = EditCommand(["Bar"], self.todolist, self.out, self.error,
                              None)
        command.execute()

        self.assertTrue(self.todolist.dirty)
        self.assertEqual(self.errors, "")
        self.assertEqual(self.todolist.print_todos(), u"Foo id:1\nBaz @test\nFo\u00f3B\u0105\u017a\nLazy Cat")

    def test_edit03(self):
        """ Throw an error after invalid todo number given as argument. """
        command = EditCommand(["FooBar"], self.todolist, self.out, self.error,
                              None)
        command.execute()

        self.assertFalse(self.todolist.dirty)
        self.assertEqual(self.errors, "Invalid todo number given.\n")

    def test_edit04(self):
        """ Throw an error with pointing invalid argument. """
        command = EditCommand(["Bar", "5"], self.todolist, self.out,
                              self.error, None)
        command.execute()

        self.assertFalse(self.todolist.dirty)
        self.assertEqual(self.errors, "Invalid todo number given: 5.\n")

    def test_edit05(self):
        """
        Throw an error with invalid argument containing special characters.
        """
        command = EditCommand([u"Fo\u00d3B\u0105r", "Bar"], self.todolist,
                              self.out, self.error, None)
        command.execute()

        self.assertFalse(self.todolist.dirty)
        self.assertEqual(self.errors,
                         u"Invalid todo number given: Fo\u00d3B\u0105r.\n")

    @mock.patch('topydo.commands.EditCommand._is_edited')
    @mock.patch('topydo.commands.EditCommand.EditCommand._todos_from_temp')
    @mock.patch('topydo.commands.EditCommand.EditCommand._open_in_editor')
    def test_edit06(self, mock_open_in_editor, mock_todos_from_temp, mock_is_edited):
        """ Edit todo with special characters. """
        mock_open_in_editor.return_value = 0
        mock_todos_from_temp.return_value = [Todo('Lazy Cat')]
        mock_is_edited.return_value = True

        command = EditCommand([u"Fo\u00f3B\u0105\u017a"], self.todolist,
                              self.out, self.error, None)
        command.execute()

        self.assertTrue(self.todolist.dirty)
        self.assertEqual(self.errors, "")
        self.assertEqual(self.todolist.print_todos(),
                         u"Foo id:1\nBar p:1 @test\nBaz @test\nLazy Cat")

    @mock.patch('topydo.commands.EditCommand._is_edited')
    @mock.patch('topydo.commands.EditCommand.EditCommand._todos_from_temp')
    @mock.patch('topydo.commands.EditCommand.EditCommand._open_in_editor')
    def test_edit07(self, mock_open_in_editor, mock_todos_from_temp, mock_is_edited):
        """ Don't perform write if tempfile is unchanged """
        mock_open_in_editor.return_value = 0
        mock_todos_from_temp.return_value = [Todo('Only one line')]
#.........这里部分代码省略.........
开发者ID:bram85,项目名称:topydo,代码行数:103,代码来源:test_edit_command.py

示例5: EditCommandTest

# 需要导入模块: from topydo.lib.TodoList import TodoList [as 别名]
# 或者: from topydo.lib.TodoList.TodoList import print_todos [as 别名]
class EditCommandTest(CommandTest):
    def setUp(self):
        super(EditCommandTest, self).setUp()
        todos = ["Foo id:1", "Bar p:1 @test", "Baz @test", u("Fo\u00f3B\u0105\u017a")]

        self.todolist = TodoList(todos)

    @mock.patch("topydo.commands.EditCommand.EditCommand._open_in_editor")
    def test_edit1(self, mock_open_in_editor):
        """ Preserve dependencies after editing. """
        mock_open_in_editor.return_value = 0

        command = EditCommand(["1"], self.todolist, self.out, self.error, None)
        command.execute()

        self.assertTrue(self.todolist.is_dirty())
        self.assertEqual(self.errors, "")
        self.assertEqual(self.todolist.print_todos(), u("Bar p:1 @test\nBaz @test\nFo\u00f3B\u0105\u017a\nFoo id:1"))

    @mock.patch("topydo.commands.EditCommand.EditCommand._todos_from_temp")
    @mock.patch("topydo.commands.EditCommand.EditCommand._open_in_editor")
    def test_edit2(self, mock_open_in_editor, mock_todos_from_temp):
        """ Edit some todo. """
        mock_open_in_editor.return_value = 0
        mock_todos_from_temp.return_value = [Todo("Lazy Cat")]

        command = EditCommand(["Bar"], self.todolist, self.out, self.error, None)
        command.execute()

        self.assertTrue(self.todolist.is_dirty())
        self.assertEqual(self.errors, "")
        self.assertEqual(self.todolist.print_todos(), u("Foo id:1\nBaz @test\nFo\u00f3B\u0105\u017a\nLazy Cat"))

    def test_edit3(self):
        """ Throw an error after invalid todo number given as argument. """
        command = EditCommand(["FooBar"], self.todolist, self.out, self.error, None)
        command.execute()

        self.assertFalse(self.todolist.is_dirty())
        self.assertEqual(self.errors, "Invalid todo number given.\n")

    def test_edit4(self):
        """ Throw an error with pointing invalid argument. """
        command = EditCommand(["Bar", "5"], self.todolist, self.out, self.error, None)
        command.execute()

        self.assertFalse(self.todolist.is_dirty())
        self.assertEqual(self.errors, "Invalid todo number given: 5.\n")

    @mock.patch("topydo.commands.EditCommand.EditCommand._todos_from_temp")
    @mock.patch("topydo.commands.EditCommand.EditCommand._open_in_editor")
    def test_edit5(self, mock_open_in_editor, mock_todos_from_temp):
        """ Don't let to delete todos acidentally while editing. """
        mock_open_in_editor.return_value = 0
        mock_todos_from_temp.return_value = [Todo("Only one line")]

        command = EditCommand(["1", "Bar"], self.todolist, self.out, self.error, None)
        command.execute()

        self.assertFalse(self.todolist.is_dirty())
        self.assertEqual(self.errors, "Number of edited todos is not equal to number of supplied todo IDs.\n")
        self.assertEqual(self.todolist.print_todos(), u("Foo id:1\nBar p:1 @test\nBaz @test\nFo\u00f3B\u0105\u017a"))

    def test_edit6(self):
        """ Throw an error with invalid argument containing special characters. """
        command = EditCommand([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"))

    @mock.patch("topydo.commands.EditCommand.EditCommand._todos_from_temp")
    @mock.patch("topydo.commands.EditCommand.EditCommand._open_in_editor")
    def test_edit7(self, mock_open_in_editor, mock_todos_from_temp):
        """ Edit todo with special characters. """
        mock_open_in_editor.return_value = 0
        mock_todos_from_temp.return_value = [Todo("Lazy Cat")]

        command = EditCommand([u("Fo\u00f3B\u0105\u017a")], self.todolist, self.out, self.error, None)
        command.execute()

        self.assertTrue(self.todolist.is_dirty())
        self.assertEqual(self.errors, "")
        self.assertEqual(self.todolist.print_todos(), u("Foo id:1\nBar p:1 @test\nBaz @test\nLazy Cat"))

    @mock.patch("topydo.commands.EditCommand.EditCommand._todos_from_temp")
    @mock.patch("topydo.commands.EditCommand.EditCommand._open_in_editor")
    def test_edit_expr(self, mock_open_in_editor, mock_todos_from_temp):
        """ Edit todos matching expression. """
        mock_open_in_editor.return_value = 0
        mock_todos_from_temp.return_value = [Todo("Lazy Cat"), Todo("Lazy Dog")]

        command = EditCommand(["-e", "@test"], self.todolist, self.out, self.error, None)
        command.execute()

        expected = u("|  3| Lazy Cat\n|  4| Lazy Dog\n")

        self.assertTrue(self.todolist.is_dirty())
        self.assertEqual(self.errors, "")
        self.assertEqual(self.output, expected)
#.........这里部分代码省略.........
开发者ID:netimen,项目名称:topydo,代码行数:103,代码来源:EditCommandTest.py


注:本文中的topydo.lib.TodoList.TodoList.print_todos方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。