本文整理汇总了Python中majormajor.changeset.Changeset.set_id方法的典型用法代码示例。如果您正苦于以下问题:Python Changeset.set_id方法的具体用法?Python Changeset.set_id怎么用?Python Changeset.set_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类majormajor.changeset.Changeset
的用法示例。
在下文中一共展示了Changeset.set_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_has_needed_dependencies
# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import set_id [as 别名]
def test_has_needed_dependencies(self):
doc = self.doc0
cs1 = Changeset(doc.get_id(), 'user', [doc.get_root_changeset()])
assert doc.has_needed_dependencies(cs1)
cs2 = Changeset(doc.get_id(), 'user', [cs1])
assert not doc.has_needed_dependencies(cs2)
doc.receive_changeset(cs1)
assert doc.has_needed_dependencies(cs2)
cs3 = Changeset(doc.get_id(), 'user', [cs1, cs2])
assert not doc.has_needed_dependencies(cs3)
doc.receive_changeset(cs2)
assert doc.has_needed_dependencies(cs3)
cs4 = Changeset(doc.get_id(), 'user', [cs3, "555"])
assert not doc.has_needed_dependencies(cs4)
doc.receive_changeset(cs3)
assert not doc.has_needed_dependencies(cs4)
cs5 = Changeset(doc.get_id(), 'user', [cs1])
cs5.set_id("555")
doc.receive_changeset(cs5)
cs4.relink_changesets(doc.all_known_changesets)
assert cs5 in cs4.get_parents()
assert cs4.has_full_dependency_info()
assert doc.has_needed_dependencies(cs4)
示例2: test_delete_overlaping_ranges_revered
# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import set_id [as 别名]
def test_delete_overlaping_ranges_revered(self):
"""
Same opperations as previous test, but order of branches is reversed
(B now before A)
"""
s = '0123456789'
doc = Document(snapshot=s)
doc.HAS_EVENT_LOOP = False
root = doc.get_root_changeset()
# construct branch A, which deletes all but the first three
# and last three characters.
A0 = Changeset(doc.get_id(), 'u1', [root])
A0.add_op(Op('sd', [], offset=4, val=2))
A0.set_id('1A')
doc.receive_changeset(A0)
A1 = Changeset(doc.get_id(), 'u1', [A0])
A1.add_op(Op('sd', [], offset=3, val=2))
doc.receive_changeset(A1)
A2 = Changeset(doc.get_id(), 'u1', [A1])
A2.add_op(Op('sd', [], offset=2, val=2))
doc.receive_changeset(A2)
assert doc.get_snapshot() == '0189'
# Branch B has common parent with A. It deletes all but '89'
# User saw '0123456789' and deleted '3456'
B0 = Changeset(doc.get_id(), 'u2', [root])
opB0 = Op('sd', [], offset=3, val=4)
B0.add_op(opB0)
B0.set_id('0B')
doc.receive_changeset(B0)
a_index = doc.get_ordered_changesets().index(A0)
b_index = doc.get_ordered_changesets().index(B0)
assert a_index > b_index
assert doc.get_snapshot() == '0189'
# User saw '012789' and deleted '27'
B1 = Changeset(doc.get_id(), 'u2', [B0])
opB1 = Op('sd', [], offset=2, val=2)
B1.add_op(opB1)
B1.set_id('B1')
doc.receive_changeset(B1)
assert doc.get_snapshot() == '0189'
# Delete Range not known by branch A
B2 = Changeset(doc.get_id(), 'u2', [B1])
opB2 = Op('sd', [], offset=1, val=2)
B2.add_op(opB2)
B2.set_id('B2')
doc.receive_changeset(B2)
assert doc.get_snapshot() == '09'
# combine these braches again
C = Changeset(doc.get_id(), 'u2', [A2, B2])
C.add_op(Op('si', [], offset=1, val='12345678'))
doc.receive_changeset(C)
assert doc.get_snapshot() == '0123456789'
示例3: build_changesets_from_tuples
# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import set_id [as 别名]
def build_changesets_from_tuples(css_data, doc):
"""
When testing its easiest to write the desired changesets as tuples, then
this will convert that list of tuples into a list of changesets for the
desired doc.
"""
css = []
for cs_data in css_data:
action, offset, val, deps, _id = cs_data
deps = [doc.get_root_changeset() if dep == 'root' else dep
for dep in deps]
cs = Changeset(doc.get_id(), 'u1', deps)
cs.add_op(Op(action, [], offset=offset, val=val))
cs.set_id(_id)
css.append(cs)
return css
示例4: test_two_deletes_in_first_branch_reverse
# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import set_id [as 别名]
def test_two_deletes_in_first_branch_reverse(self):
"""
Same opperations as previous test, but order of branches is reversed
(B now before A)
"""
s = 'ab123cd456gh789ik'
doc = Document(snapshot=s)
doc.HAS_EVENT_LOOP = False
root = doc.get_root_changeset()
A0 = Changeset(doc.get_id(), 'u1', [root])
A0.add_op(Op('sd', [], offset=7, val=2))
A0.set_id('1A')
doc.receive_changeset(A0)
A1 = Changeset(doc.get_id(), 'u1', [A0])
A1.add_op(Op('sd', [], offset=10, val=3))
doc.receive_changeset(A1)
A2 = Changeset(doc.get_id(), 'u1', [A1])
A2.add_op(Op('si', [], offset=7, val='ef'))
doc.receive_changeset(A2)
assert doc.get_snapshot() == 'ab123cdef6ghik'
# Branch B has common parent with A. First it deletes a
# partialy overlaping range in A
B0 = Changeset(doc.get_id(), 'u2', [root])
opB0 = Op('sd', [], offset=8, val=2)
B0.add_op(opB0)
B0.set_id('0B')
doc.receive_changeset(B0)
a_index = doc.get_ordered_changesets().index(A0)
b_index = doc.get_ordered_changesets().index(B0)
assert a_index > b_index
assert doc.get_snapshot() == 'ab123cdefghik'
# Delete range partially overlaping range in A
B1 = Changeset(doc.get_id(), 'u2', [B0])
opB1 = Op('sd', [], offset=10, val=2)
B1.add_op(opB1)
B1.set_id('B1')
doc.receive_changeset(B1)
assert doc.get_snapshot() == 'ab123cdefghik'
# Delete Range unaffected by branch A
B2 = Changeset(doc.get_id(), 'u2', [B1])
opB2 = Op('sd', [], offset=2, val=3)
B2.add_op(opB2)
B2.set_id('B2')
doc.receive_changeset(B2)
assert doc.get_snapshot() == 'abcdefghik'
# combine these braches again
C = Changeset(doc.get_id(), 'u2', [A2, B2])
C.add_op(Op('si', [], offset=9, val='j'))
doc.receive_changeset(C)
assert doc.get_snapshot() == 'abcdefghijk'
示例5: test_two_deletes_in_first_branch
# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import set_id [as 别名]
def test_two_deletes_in_first_branch(self):
""" 01234567890123456 (helpful index of characters in doc)"""
s = 'ab123cd456gh789ik'
doc = Document(snapshot=s)
doc.HAS_EVENT_LOOP = False
root = doc.get_root_changeset()
# construct branch A, which has two string deletes, then
# adds text
A0 = Changeset(doc.get_id(), 'u1', [root])
A0.add_op(Op('sd', [], offset=7, val=2))
A0.set_id('A')
doc.receive_changeset(A0)
A1 = Changeset(doc.get_id(), 'u1', [A0])
A1.add_op(Op('sd', [], offset=10, val=3))
doc.receive_changeset(A1)
A2 = Changeset(doc.get_id(), 'u1', [A1])
A2.add_op(Op('si', [], offset=7, val='ef'))
doc.receive_changeset(A2)
assert doc.get_snapshot() == 'ab123cdef6ghik'
# Branch B has common parent with A. First it deletes a
# partialy overlaping range in A
B0 = Changeset(doc.get_id(), 'u2', [root])
opB0 = Op('sd', [], offset=8, val=2)
B0.add_op(opB0)
B0.set_id('B')
doc.receive_changeset(B0)
a_index = doc.get_ordered_changesets().index(A0)
b_index = doc.get_ordered_changesets().index(B0)
assert a_index < b_index
assert doc.get_snapshot() == 'ab123cdefghik'
# Delete range partially overlaping range in A
B1 = Changeset(doc.get_id(), 'u2', [B0])
opB1 = Op('sd', [], offset=10, val=2)
B1.add_op(opB1)
B1.set_id('B1')
doc.receive_changeset(B1)
assert doc.get_snapshot() == 'ab123cdefghik'
# Delete Range unaffected by branch A
B2 = Changeset(doc.get_id(), 'u2', [B1])
opB2 = Op('sd', [], offset=2, val=3)
B2.add_op(opB2)
B2.set_id('B2')
doc.receive_changeset(B2)
assert doc.get_snapshot() == 'abcdefghik'
# combine these braches again
C = Changeset(doc.get_id(), 'u2', [A2, B2])
C.add_op(Op('si', [], offset=9, val='j'))
doc.receive_changeset(C)
assert doc.get_snapshot() == 'abcdefghijk'
示例6: test_multiple_dependencies
# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import set_id [as 别名]
def test_multiple_dependencies(self):
"""
-- B ---- E
/ /
root -- A -- D
\ /
-- C --
"""
doc = Document(snapshot='')
doc.HAS_EVENT_LOOP = False
root = doc.get_root_changeset()
B = Changeset(doc.get_id(), "user0", [root])
B.set_id('b')
doc.receive_changeset(B)
A = Changeset(doc.get_id(), "user1", [root])
A.set_id('a')
doc.receive_changeset(A)
assert A.get_unaccounted_changesets() == []
assert B.get_unaccounted_changesets() == [A]
C = Changeset(doc.get_id(), "user2", [root])
C.set_id('c')
doc.receive_changeset(C)
assert A.get_unaccounted_changesets() == []
assert B.get_unaccounted_changesets() == [A]
assert C.get_unaccounted_changesets() == [A,B]
# test_multiple_dependencies_common_base
D = Changeset(doc.get_id(), "user0", [C,A])
D.set_id('d')
doc.receive_changeset(D)
assert A.get_unaccounted_changesets() == []
assert B.get_unaccounted_changesets() == [A]
assert C.get_unaccounted_changesets() == [A,B]
assert D.get_unaccounted_changesets() == [B]
E = Changeset(doc.get_id(), 'user1', [B, D])
E.set_id('e')
doc.receive_changeset(E)
assert A.get_unaccounted_changesets() == []
assert B.get_unaccounted_changesets() == [A]
assert C.get_unaccounted_changesets() == [A,B]
assert D.get_unaccounted_changesets() == [B]
assert E.get_unaccounted_changesets() == []
示例7: test_one_delete_in_first_branch
# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import set_id [as 别名]
def test_one_delete_in_first_branch(self):
"""
There is one delete in the first branch, multiple in branch B, then
each has more string inserts.
"""
doc = Document(snapshot='123abcde789')
doc.HAS_EVENT_LOOP = False
root = doc.get_root_changeset()
# construct branch A, which begins with a string delete, then
# adds text
A0 = Changeset(doc.get_id(), 'u1', [root])
A0.add_op(Op('sd', [], offset=3, val=5))
A0.set_id('A')
doc.receive_changeset(A0)
A1 = Changeset(doc.get_id(), 'u1', [A0])
A1.add_op(Op('si', [], offset=3, val='456'))
doc.receive_changeset(A1)
assert doc.get_snapshot() == '123456789'
# Branch B has common parent with A. B has three deletes, some of which
# overlap the delete in branch A
B0 = Changeset(doc.get_id(), 'u2', [root])
opB0 = Op('sd', [], offset=4, val=2)
B0.add_op(opB0)
B0.set_id('B')
doc.receive_changeset(B0)
a_index = doc.get_ordered_changesets().index(A0)
b_index = doc.get_ordered_changesets().index(B0)
assert a_index < b_index
assert doc.get_snapshot() == '123456789'
# Partially overlaping delete
B1 = Changeset(doc.get_id(), 'u2', [B0])
opB1 = Op('sd', [], offset=6, val=2)
B1.add_op(opB1)
B1.set_id('B1')
doc.receive_changeset(B1)
assert doc.get_snapshot() == '1234569'
# Delete Range unaffected by branch A
B2 = Changeset(doc.get_id(), 'u2', [B1])
opB2 = Op('sd', [], offset=1, val=1)
B2.add_op(opB2)
B2.set_id('B2')
doc.receive_changeset(B2)
assert doc.get_snapshot() == '134569'
# combine these braches again
C = Changeset(doc.get_id(), 'u2', [A1, B2])
C.add_op(Op('si', [], offset=1, val='2'))
C.add_op(Op('si', [], offset=6, val='78'))
doc.receive_changeset(C)
assert doc.get_snapshot() == '123456789'
示例8: test_multiple_dependencies
# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import set_id [as 别名]
def test_multiple_dependencies(self):
"""
-- B ---- E
/ /
root -- A -- D
\ /
-- C --
"""
doc = Document(snapshot='')
doc.HAS_EVENT_LOOP = False
root = doc.get_root_changeset()
B = Changeset(doc.get_id(), "user0", [root])
B.set_id('b')
doc.receive_changeset(B)
A = Changeset(doc.get_id(), "user1", [root])
A.set_id('a')
doc.receive_changeset(A)
assert set(doc.get_dependencies()) == set([B,A])
assert doc.get_ordered_changesets() == [root, A, B]
C = Changeset(doc.get_id(), "user2", [root])
C.set_id('c')
doc.receive_changeset(C)
assert set(doc.get_dependencies()) == set([B,A,C])
assert doc.get_ordered_changesets() == [root, A, B, C]
assert doc.get_ordered_changesets() == doc.tree_to_list()
# test_multiple_dependencies_common_base
D = Changeset(doc.get_id(), "user0", [C,A])
D.set_id('d')
doc.receive_changeset(D)
assert set(doc.get_dependencies()) == set([B,D])
assert doc.get_ordered_changesets() == [root, A, B, C, D]
assert doc.get_ordered_changesets() == doc.tree_to_list()
E = Changeset(doc.get_id(), 'user1', [B, D])
E.set_id('e')
doc.receive_changeset(E)
assert doc.get_dependencies() == [E]
assert doc.get_ordered_changesets() == [root, A, B, C, D, E]
assert doc.get_ordered_changesets() == doc.tree_to_list()
示例9: xtest_relink_dependency
# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import set_id [as 别名]
def xtest_relink_dependency(self):
dep = Changeset('doc_id', 'user_id', [])
dep.set_id('defined_id')
# a cs with no dependencies should never relink
assert not self.cs0.relink_changesets(dep)
# cs does not need given dep
cs1 = Changeset('doc_id', 'user_id', [self.cs0])
assert not cs1.relink_changesets(dep)
assert cs1.get_dependencies() == [self.cs0]
# cs already has given dep info
cs2 = Changeset('doc_id', 'user_id', [self.cs0, dep])
assert not cs2.relink_changesets(dep)
assert cs2.get_dependencies() == [self.cs0, dep]
# cs needed and relinked given dep
cs3 = Changeset('doc_id', 'user_id', [self.cs0, 'defined_id'])
assert cs3.relink_changesets(dep)
assert cs3.get_dependencies() == [self.cs0, dep]
示例10: test_one_delete_in_first_branch_reversed
# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import set_id [as 别名]
def test_one_delete_in_first_branch_reversed(self):
"""
Same opperations as previous test, but order of branches is reversed
(B now before A)
"""
doc = Document(snapshot='123abcde789')
doc.HAS_EVENT_LOOP = False
root = doc.get_root_changeset()
A0 = Changeset(doc.get_id(), 'u1', [root])
A0.add_op(Op('sd', [], offset=3, val=5))
A0.set_id('1A')
doc.receive_changeset(A0)
A1 = Changeset(doc.get_id(), 'u1', [A0])
A1.add_op(Op('si', [], offset=3, val='456'))
doc.receive_changeset(A1)
B0 = Changeset(doc.get_id(), 'u2', [root])
opB0 = Op('sd', [], offset=4, val=2)
B0.add_op(opB0)
B0.set_id('0B')
doc.receive_changeset(B0)
a_index = doc.get_ordered_changesets().index(A0)
b_index = doc.get_ordered_changesets().index(B0)
assert a_index > b_index
assert doc.get_snapshot() == '123456789'
B1 = Changeset(doc.get_id(), 'u2', [B0])
opB1 = Op('sd', [], offset=6, val=2)
B1.add_op(opB1)
B1.set_id('B1')
doc.receive_changeset(B1)
assert doc.get_snapshot() == '1234569'
B2 = Changeset(doc.get_id(), 'u2', [B1])
opB2 = Op('sd', [], offset=1, val=1)
B2.add_op(opB2)
B2.set_id('B2')
doc.receive_changeset(B2)
assert doc.get_snapshot() == '134569'
# combine these braches again
C = Changeset(doc.get_id(), 'u2', [A1, B2])
C.add_op(Op('si', [], offset=1, val='2'))
C.add_op(Op('si', [], offset=6, val='78'))
doc.receive_changeset(C)
assert doc.get_snapshot() == '123456789'
示例11: test_delete_in_second_branch
# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import set_id [as 别名]
def test_delete_in_second_branch(self):
"""
"""
doc = Document(snapshot='abcdefghij')
doc.HAS_EVENT_LOOP = False
root = doc.get_root_changeset()
# construct branch A, which begins with a string delete
A0 = Changeset(doc.get_id(), 'u1', [root])
A0.add_op(Op('sd', [], offset=5, val=5))
A0.set_id('2A')
doc.receive_changeset(A0)
assert doc.get_snapshot() == 'abcde'
# Branch B has common parent with A. It inserts strings at the end
# which should not be deleted.
B0 = Changeset(doc.get_id(), 'u2', [root])
for i in xrange(10):
op = Op('si', [], offset=10 + i, val=str(i))
B0.add_op(op)
B0.set_id('1B')
doc.receive_changeset(B0)
assert doc.get_snapshot() == 'abcde0123456789'
示例12: test_consecutive_inserts
# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import set_id [as 别名]
def test_consecutive_inserts(self):
doc = self.doc1
root = self.root1
# Branch A
A0 = Changeset(doc.get_id(), 'u1', [root])
vA0 = ['1', '2']
A0.add_op(Op('ai', [], offset=2, val=vA0))
A0.set_id('A')
doc.receive_changeset(A0)
A1 = Changeset(doc.get_id(), 'u1', [A0])
vA1 = ['3', '4']
A1.add_op(Op('ai', [], offset=4, val=vA1))
doc.receive_changeset(A1)
A2 = Changeset(doc.get_id(), 'u1', [A1])
vA2 = ['8', '9']
A2.add_op(Op('ai', [], offset=9, val=vA2))
doc.receive_changeset(A2)
A3 = Changeset(doc.get_id(), 'u1', [A2])
vA3 = ['0']
A3.add_op(Op('ai', [], offset=11, val=vA3))
doc.receive_changeset(A3)
result = ['ABCD',
'EFGH',
'1', '2', '3', '4',
'IJKL',
'MNOP',
'QRST',
'8', '9', '0',
'UVWX',
'YZ']
assert doc.get_snapshot() == result
# Now B has a series of inserts
B0 = Changeset(doc.get_id(), 'u1', [root])
vB0 = ['1b', '2b']
B0.add_op(Op('ai', [], offset=1, val=vB0))
B0.set_id('B')
doc.receive_changeset(B0)
result = ['ABCD',
'1b', '2b',
'EFGH',
'1', '2', '3', '4',
'IJKL',
'MNOP',
'QRST',
'8', '9', '0',
'UVWX',
'YZ']
assert doc.get_snapshot() == result
B1 = Changeset(doc.get_id(), 'u1', [B0])
vB1 = ['3b', '4b']
B1.add_op(Op('ai', [], offset=5, val=vB1))
doc.receive_changeset(B1)
result = ['ABCD',
'1b', '2b',
'EFGH',
'1', '2', '3', '4',
'IJKL',
'3b', '4b',
'MNOP',
'QRST',
'8', '9', '0',
'UVWX',
'YZ']
assert doc.get_snapshot() == result
B2 = Changeset(doc.get_id(), 'u1', [B1])
vB2 = ['8b', '9b', '0b']
B2.add_op(Op('ai', [], offset=7, val=vB2))
doc.receive_changeset(B2)
result = ['ABCD',
'1b', '2b',
'EFGH',
'1', '2', '3', '4',
'IJKL',
'3b', '4b', '8b', '9b', '0b',
'MNOP',
'QRST',
'8', '9', '0',
'UVWX',
'YZ']
assert doc.get_snapshot() == result
B3 = Changeset(doc.get_id(), 'u1', [B2])
vB3 = ['BBBB']
B3.add_op(Op('ai', [], offset=12, val=vB3))
doc.receive_changeset(B3)
result = ['ABCD',
'1b', '2b',
'EFGH',
'1', '2', '3', '4',
'IJKL',
'3b', '4b', '8b', '9b', '0b',
'MNOP',
'QRST',
#.........这里部分代码省略.........
示例13: test_consecutive_inserts_reversed
# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import set_id [as 别名]
def test_consecutive_inserts_reversed(self):
"""
Same as the previous test except branch B gets applied before branch A.
"""
doc = self.doc1
root = self.root1
# Branch A
A0 = Changeset(doc.get_id(), 'u1', [root])
vA0 = ['1', '2']
A0.add_op(Op('ai', [], offset=2, val=vA0))
A0.set_id('1A')
doc.receive_changeset(A0)
A1 = Changeset(doc.get_id(), 'u1', [A0])
vA1 = ['3', '4']
A1.add_op(Op('ai', [], offset=4, val=vA1))
doc.receive_changeset(A1)
A2 = Changeset(doc.get_id(), 'u1', [A1])
vA2 = ['8', '9']
A2.add_op(Op('ai', [], offset=9, val=vA2))
doc.receive_changeset(A2)
A3 = Changeset(doc.get_id(), 'u1', [A2])
vA3 = ['0']
A3.add_op(Op('ai', [], offset=11, val=vA3))
doc.receive_changeset(A3)
result = ['ABCD',
'EFGH',
'1', '2', '3', '4',
'IJKL',
'MNOP',
'QRST',
'8', '9', '0',
'UVWX',
'YZ']
assert doc.get_snapshot() == result
# Now B has a series of inserts
B0 = Changeset(doc.get_id(), 'u1', [root])
vB0 = ['1b', '2b']
B0.add_op(Op('ai', [], offset=1, val=vB0))
B0.set_id('0B')
doc.receive_changeset(B0)
a_index = doc.get_ordered_changesets().index(A0)
b_index = doc.get_ordered_changesets().index(B0)
assert a_index > b_index
result = ['ABCD',
'1b', '2b',
'EFGH',
'1', '2', '3', '4',
'IJKL',
'MNOP',
'QRST',
'8', '9', '0',
'UVWX',
'YZ']
assert doc.get_snapshot() == result
B1 = Changeset(doc.get_id(), 'u1', [B0])
vB1 = ['3b', '4b']
B1.add_op(Op('ai', [], offset=5, val=vB1))
doc.receive_changeset(B1)
result = ['ABCD',
'1b', '2b',
'EFGH',
'1', '2', '3', '4',
'IJKL',
'3b', '4b',
'MNOP',
'QRST',
'8', '9', '0',
'UVWX',
'YZ']
assert doc.get_snapshot() == result
B2 = Changeset(doc.get_id(), 'u1', [B1])
vB2 = ['8b', '9b', '0b']
B2.add_op(Op('ai', [], offset=7, val=vB2))
doc.receive_changeset(B2)
result = ['ABCD',
'1b', '2b',
'EFGH',
'1', '2', '3', '4',
'IJKL',
'3b', '4b', '8b', '9b', '0b',
'MNOP',
'QRST',
'8', '9', '0',
'UVWX',
'YZ']
assert doc.get_snapshot() == result
B3 = Changeset(doc.get_id(), 'u1', [B2])
vB3 = ['BBBB']
B3.add_op(Op('ai', [], offset=12, val=vB3))
doc.receive_changeset(B3)
result = ['ABCD',
'1b', '2b',
#.........这里部分代码省略.........
示例14: setup_method
# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import set_id [as 别名]
def setup_method(self, method):
s1 = ['ABCD',
'EFGH',
'IJKL',
'MNOP',
'QRST',
'UVWX',
'YZ']
doc = Document(snapshot=s1)
doc.HAS_EVENT_LOOP = False
self.doc = doc
self.root = self.doc.get_root_changeset()
# establish the reusable changesets
# Branch A inserts two new array elements, and add text to those two.
# It also inserts text into three existing elements, before any array
# insert, in the middle, and after the last array insert.
A0 = Changeset(doc.get_id(), 'u1', [self.root])
vA0 = ['02', '4']
A0.add_op(Op('ai', [], offset=2, val=vA0))
A0.set_id('A')
self.A0 = A0
A1 = Changeset(doc.get_id(), 'u1', [A0])
vA1 = ['5', '89']
A1.add_op(Op('ai', [], offset=6, val=vA1))
self.A1 = A1
A2 = Changeset(doc.get_id(), 'u1', [A1])
A2.add_op(Op('si', [2], offset=1, val='1'))
A2.add_op(Op('si', [3], offset=0, val='3'))
self.A2 = A2
A3 = Changeset(doc.get_id(), 'u1', [self.A2])
A3.add_op(Op('si', [6], offset=1, val='67'))
self.A3 = A3
A4 = Changeset(doc.get_id(), 'u1', [A3])
A4.add_op(Op('si', [0], offset=0, val='a'))
A4.add_op(Op('si', [4], offset=0, val='b'))
self.A4 = A4
A5 = Changeset(doc.get_id(), 'u1', [A4])
A5.add_op(Op('si', [9], offset=0, val='c'))
self.A5 = A5
# Branch B performs similar actions to branch A.
B0 = Changeset(doc.get_id(), 'u2', [self.root])
vB0a, vB0b = ['lm', 'ipsm'], ['or', 't']
opB0a = Op('ai', [], offset=2, val=vB0a)
B0.add_op(opB0a)
opB0b = Op('ai', [], offset=6, val=vB0b)
B0.add_op(opB0b)
B0.set_id('B')
self.B0 = B0
# Now B inserts strings into the elements it created
B1 = Changeset(doc.get_id(), 'u2', [B0])
B1.add_op(Op('si', [2], offset=1, val='ore'))
B1.add_op(Op('si', [3], offset=3, val='u'))
B1.add_op(Op('si', [6], offset=0, val='dol'))
B1.add_op(Op('si', [7], offset=0, val='si'))
B1.set_id('B1')
self.B1 = B1
# B inserts strings into each original element, including elements A
# had edited
B2 = Changeset(doc.get_id(), 'u2', [B1])
B2.add_op(Op('si', [0], offset=0, val='t'))
B2.add_op(Op('si', [1], offset=0, val='u'))
B2.add_op(Op('si', [4], offset=0, val='v'))
B2.add_op(Op('si', [5], offset=0, val='w'))
B2.add_op(Op('si', [8], offset=0, val='x'))
B2.add_op(Op('si', [9], offset=0, val='y'))
B2.add_op(Op('si', [10], offset=0, val='z'))
B2.set_id('B2')
self.B2 = B2
示例15: test_one_delete_in_first_branch_reversed
# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import set_id [as 别名]
def test_one_delete_in_first_branch_reversed(self):
"""
Same test as above, except branch B gets applied before branch A.
"""
doc = self.doc1
root = self.root1
# construct branch A, which begins with a string delete, then
# adds text
A0 = Changeset(doc.get_id(), 'u1', [root])
A0.add_op(Op('ad', [], offset=3, val=2))
A0.set_id('1A')
doc.receive_changeset(A0)
A1 = Changeset(doc.get_id(), 'u1', [A0])
v1 = ['0123', '4567']
A1.add_op(Op('ai', [], offset=3, val=v1))
doc.receive_changeset(A1)
result = ['ABCD',
'EFGH',
'IJKL',
'0123',
'4567',
'UVWX',
'YZ']
assert doc.get_snapshot() == result
# Branch B has common parent with A. B has three deletes, some of which
# overlap the delete in branch A
B0 = Changeset(doc.get_id(), 'u2', [root])
opB0 = Op('ad', [], offset=2, val=2)
B0.add_op(opB0)
B0.set_id('0B')
doc.receive_changeset(B0)
a_index = doc.get_ordered_changesets().index(A0)
b_index = doc.get_ordered_changesets().index(B0)
assert a_index > b_index
result = ['ABCD',
'EFGH',
'0123',
'4567',
'UVWX',
'YZ']
assert doc.get_snapshot() == result
# Partially overlaping delete
B1 = Changeset(doc.get_id(), 'u2', [B0])
opB1 = Op('ad', [], offset=2, val=1)
B1.add_op(opB1)
B1.set_id('B1')
doc.receive_changeset(B1)
result = ['ABCD',
'EFGH',
'0123',
'4567',
'UVWX',
'YZ']
assert doc.get_snapshot() == result
# Delete Range unaffected by branch A
B2 = Changeset(doc.get_id(), 'u2', [B1])
opB2 = Op('ad', [], offset=1, val=1)
B2.add_op(opB2)
B2.set_id('B2')
doc.receive_changeset(B2)
result = ['ABCD',
'0123',
'4567',
'UVWX',
'YZ']
assert doc.get_snapshot() == result
B3 = Changeset(doc.get_id(), 'u2', [B2])
vB3 = ['BBBBB', 'CCCCC']
opB3 = Op('ai', [], offset=1, val=vB3)
B3.add_op(opB3)
B3.set_id('B3')
doc.receive_changeset(B3)
result = ['ABCD',
'BBBBB',
'CCCCC',
'0123',
'4567',
'UVWX',
'YZ']
assert doc.get_snapshot() == result
B4 = Changeset(doc.get_id(), 'u2', [B3])
vB4 = ['DDDDD', 'EEEEE']
opB4 = Op('ai', [], offset=3, val=vB4)
B4.add_op(opB4)
B4.set_id('B4')
doc.receive_changeset(B4)
result = ['ABCD',
'BBBBB',
'CCCCC',
'DDDDD',
'EEEEE',
'0123',
'4567',
#.........这里部分代码省略.........