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


Python Weave.get_text方法代码示例

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


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

示例1: test_written_detection

# 需要导入模块: from bzrlib.weave import Weave [as 别名]
# 或者: from bzrlib.weave.Weave import get_text [as 别名]
    def test_written_detection(self):
        # Test detection of weave file corruption.
        #
        # Make sure that we can detect if a weave file has
        # been corrupted. This doesn't test all forms of corruption,
        # but it at least helps verify the data you get, is what you want.
        from cStringIO import StringIO

        w = Weave()
        w.add_lines('v1', [], ['hello\n'])
        w.add_lines('v2', ['v1'], ['hello\n', 'there\n'])

        tmpf = StringIO()
        write_weave(w, tmpf)

        # Because we are corrupting, we need to make sure we have the exact text
        self.assertEquals('# bzr weave file v5\n'
                          'i\n1 f572d396fae9206628714fb2ce00f72e94f2258f\nn v1\n\n'
                          'i 0\n1 90f265c6e75f1c8f9ab76dcf85528352c5f215ef\nn v2\n\n'
                          'w\n{ 0\n. hello\n}\n{ 1\n. there\n}\nW\n',
                          tmpf.getvalue())

        # Change a single letter
        tmpf = StringIO('# bzr weave file v5\n'
                        'i\n1 f572d396fae9206628714fb2ce00f72e94f2258f\nn v1\n\n'
                        'i 0\n1 90f265c6e75f1c8f9ab76dcf85528352c5f215ef\nn v2\n\n'
                        'w\n{ 0\n. hello\n}\n{ 1\n. There\n}\nW\n')

        w = read_weave(tmpf)

        self.assertEqual('hello\n', w.get_text('v1'))
        self.assertRaises(errors.WeaveInvalidChecksum, w.get_text, 'v2')
        self.assertRaises(errors.WeaveInvalidChecksum, w.get_lines, 'v2')
        self.assertRaises(errors.WeaveInvalidChecksum, w.check)

        # Change the sha checksum
        tmpf = StringIO('# bzr weave file v5\n'
                        'i\n1 f572d396fae9206628714fb2ce00f72e94f2258f\nn v1\n\n'
                        'i 0\n1 f0f265c6e75f1c8f9ab76dcf85528352c5f215ef\nn v2\n\n'
                        'w\n{ 0\n. hello\n}\n{ 1\n. there\n}\nW\n')

        w = read_weave(tmpf)

        self.assertEqual('hello\n', w.get_text('v1'))
        self.assertRaises(errors.WeaveInvalidChecksum, w.get_text, 'v2')
        self.assertRaises(errors.WeaveInvalidChecksum, w.get_lines, 'v2')
        self.assertRaises(errors.WeaveInvalidChecksum, w.check)
开发者ID:c0ns0le,项目名称:cygwin,代码行数:49,代码来源:test_weave.py


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