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


Python Weave.add_lines方法代码示例

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


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

示例1: runTest

# 需要导入模块: from bzrlib.weave import Weave [as 别名]
# 或者: from bzrlib.weave.Weave import add_lines [as 别名]
    def runTest(self):
        k = Weave()

        base_text = ['one', 'two', 'three', 'four']

        k.add_lines('text0', [], base_text)
        
        texts = [['one', 'two', 'three'],
                 ['two', 'three', 'four'],
                 ['one', 'four'],
                 ['one', 'two', 'three', 'four'],
                 ]

        i = 1
        for t in texts:
            ver = k.add_lines('text%d' % i,
                        ['text0'], t)
            i += 1

        self.log('final weave:')
        self.log('k._weave=' + pformat(k._weave))

        for i in range(len(texts)):
            self.assertEqual(k.get_lines(i+1),
                             texts[i])
开发者ID:c0ns0le,项目名称:cygwin,代码行数:27,代码来源:test_weave.py

示例2: test_written_detection

# 需要导入模块: from bzrlib.weave import Weave [as 别名]
# 或者: from bzrlib.weave.Weave import add_lines [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

示例3: test_multi_line_merge

# 需要导入模块: from bzrlib.weave import Weave [as 别名]
# 或者: from bzrlib.weave.Weave import add_lines [as 别名]
    def test_multi_line_merge(self):
        rawtexts = [
            """A Book of Verses underneath the Bough,
            A Jug of Wine, a Loaf of Bread, -- and Thou
            Beside me singing in the Wilderness --
            Oh, Wilderness were Paradise enow!""",
            
            """A Book of Verses underneath the Bough,
            A Jug of Wine, a Loaf of Bread, -- and Thou
            Beside me singing in the Wilderness --
            Oh, Wilderness were Paradise now!""",

            """A Book of poems underneath the tree,
            A Jug of Wine, a Loaf of Bread,
            and Thou
            Beside me singing in the Wilderness --
            Oh, Wilderness were Paradise now!

            -- O. Khayyam""",

            """A Book of Verses underneath the Bough,
            A Jug of Wine, a Loaf of Bread,
            and Thou
            Beside me singing in the Wilderness --
            Oh, Wilderness were Paradise now!""",
            ]
        texts = [[l.strip() for l in t.split('\n')] for t in rawtexts]

        k = Weave()
        parents = set()
        i = 0
        for t in texts:
            ver = k.add_lines('text%d' % i,
                        list(parents), t)
            parents.add('text%d' % i)
            i += 1

        self.log("k._weave=" + pformat(k._weave))

        for i, t in enumerate(texts):
            self.assertEqual(k.get_lines(i), t)

        self.check_read_write(k)
开发者ID:c0ns0le,项目名称:cygwin,代码行数:45,代码来源:test_weave.py

示例4: test_allow_reserved_true

# 需要导入模块: from bzrlib.weave import Weave [as 别名]
# 或者: from bzrlib.weave.Weave import add_lines [as 别名]
 def test_allow_reserved_true(self):
     w = Weave('name', allow_reserved=True)
     w.add_lines('name:', [], TEXT_1)
     self.assertEqual(TEXT_1, w.get_lines('name:'))
开发者ID:c0ns0le,项目名称:cygwin,代码行数:6,代码来源:test_weave.py

示例5: test_allow_reserved_false

# 需要导入模块: from bzrlib.weave import Weave [as 别名]
# 或者: from bzrlib.weave.Weave import add_lines [as 别名]
 def test_allow_reserved_false(self):
     w = Weave('name', allow_reserved=False)
     # Add lines is checked at the WeaveFile level, not at the Weave level
     w.add_lines('name:', [], TEXT_1)
     # But get_lines is checked at this level
     self.assertRaises(errors.ReservedId, w.get_lines, 'name:')
开发者ID:c0ns0le,项目名称:cygwin,代码行数:8,代码来源:test_weave.py

示例6: test_duplicate_add

# 需要导入模块: from bzrlib.weave import Weave [as 别名]
# 或者: from bzrlib.weave.Weave import add_lines [as 别名]
 def test_duplicate_add(self):
     k = Weave()
     idx = k.add_lines('text0', [], TEXT_0)
     idx2 = k.add_lines('text0', [], TEXT_0)
     self.assertEqual(idx, idx2)
开发者ID:c0ns0le,项目名称:cygwin,代码行数:7,代码来源:test_weave.py


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