本文整理汇总了Python中bzrlib.weave.Weave类的典型用法代码示例。如果您正苦于以下问题:Python Weave类的具体用法?Python Weave怎么用?Python Weave使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Weave类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: runTest
def runTest(self):
k = Weave()
k._parents = [frozenset(),
]
k._weave = ['bad line',
('{', 0),
'foo {',
('{', 1),
' added in version 1',
('{', 2),
' added in v2',
('}', 2),
' also from v1',
('}', 1),
'}',
('}', 0)]
################################### SKIPPED
# Weave.get doesn't trap this anymore
return
self.assertRaises(WeaveFormatError,
k.get,
0)
示例2: setUp
def setUp(self):
super(JoinWeavesTests, self).setUp()
self.weave1 = Weave()
self.lines1 = ['hello\n']
self.lines3 = ['hello\n', 'cruel\n', 'world\n']
self.weave1.add_lines('v1', [], self.lines1)
self.weave1.add_lines('v2', ['v1'], ['hello\n', 'world\n'])
self.weave1.add_lines('v3', ['v2'], self.lines3)
示例3: test_multi_line_merge
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)
示例4: JoinWeavesTests
class JoinWeavesTests(TestBase):
def setUp(self):
super(JoinWeavesTests, self).setUp()
self.weave1 = Weave()
self.lines1 = ['hello\n']
self.lines3 = ['hello\n', 'cruel\n', 'world\n']
self.weave1.add_lines('v1', [], self.lines1)
self.weave1.add_lines('v2', ['v1'], ['hello\n', 'world\n'])
self.weave1.add_lines('v3', ['v2'], self.lines3)
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)
示例5: test_compatible_parents
def test_compatible_parents(self):
w1 = Weave('a')
my_parents = set([1, 2, 3])
# subsets are ok
self.assertTrue(w1._compatible_parents(my_parents, set([3])))
# same sets
self.assertTrue(w1._compatible_parents(my_parents, set(my_parents)))
# same empty corner case
self.assertTrue(w1._compatible_parents(set(), set()))
# other cannot contain stuff my_parents does not
self.assertFalse(w1._compatible_parents(set(), set([1])))
self.assertFalse(w1._compatible_parents(my_parents, set([1, 2, 3, 4])))
self.assertFalse(w1._compatible_parents(my_parents, set([4])))
示例6: _extract
def _extract(self, versions):
self._extract_count += 1
return Weave._extract(self, versions)
示例7: __init__
def __init__(self, weave_name=None):
self._extract_count = 0
Weave.__init__(self, weave_name=weave_name)
示例8: test_allow_reserved_true
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:'))
示例9: test_allow_reserved_false
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:')
示例10: test_duplicate_add
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)