本文整理汇总了Python中majormajor.changeset.Changeset类的典型用法代码示例。如果您正苦于以下问题:Python Changeset类的具体用法?Python Changeset怎么用?Python Changeset使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Changeset类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sd_si
def test_sd_si(self):
op1 = Op('sd', [], offset=3, val=3)
cs1 = Changeset('doc_id', 'author', [])
cs1.add_op(op1)
# delete range has greater index than this insert. Do nothing
op2 = Op('si', [], offset=2, val="ABC")
op2.ot(cs1)
assert op2.t_offset == 2
assert op2.t_val == "ABC"
op1.remove_old_hazards(purge=True)
# edge case. avoid deleting
op3 = Op('si', [], offset=3, val="ABC")
op3.ot(cs1)
assert op3.t_offset == 3
assert op3.t_val == "ABC"
op1.remove_old_hazards(purge=True)
# text was put into delete range, so get rid of it.
op4 = Op('si', [], offset=4, val="ABC")
op4.ot(cs1)
assert op4.t_offset == 3
assert op4.t_val == ""
op1.remove_old_hazards(purge=True)
# text is at edge after delete range
op5 = Op('si', [], offset=6, val="ABC")
op5.ot(cs1)
assert op5.t_offset == 3
assert op5.t_val == "ABC"
示例2: test_si_sd
def test_si_sd(self):
op1 = Op('si', [], offset=3, val="ABC")
cs1 = Changeset('doc_id', 'author', [])
cs1.add_op(op1)
# insertion was at a later index than this delete. No change
op2 = Op('sd', [], offset=0, val=3)
op2.ot(cs1)
assert op2.t_offset == 0
assert op2.t_val == 3
op1.remove_old_hazards(purge=True)
# this deletion should expand to delete inserted text as well.
op3 = Op('sd', [], offset=2, val=2)
op3.ot(cs1)
assert op3.t_offset == 2
assert op3.t_val == 5
op1.remove_old_hazards(purge=True)
# edge case, don't delete text if don't have have to. Shift
# delete range.
op4 = Op('sd', [], offset=3, val=2)
op4.ot(cs1)
assert op4.t_offset == 6
assert op4.t_val == 2
op1.remove_old_hazards(purge=True)
# insertion was at lower index. shift delete range forward.
op5 = Op('sd', [], offset=4, val=2)
op5.ot(cs1)
assert op5.t_offset == 7
assert op5.t_val == 2
示例3: test_oi_od
def test_oi_od(self):
"""
A past opperation is an object insert which gets applied to these
object deletes.
"""
array_path = ['a', 'b', 3, 4]
op1 = Op('oi', array_path, offset='X', val=['X', 'Y'])
cs1 = Changeset('doc_id', 'author', [])
cs1.add_op(op1)
# op2 happens at a different path, so should not be affected
op2 = Op('od', ['a', 'b', 3, 5], offset='R')
op2.ot(cs1)
assert op2.t_path == ['a', 'b', 3, 5]
assert op2.t_offset == 'R'
assert not op2.is_noop()
op1.hazards = []
# op3 deletes a key were unknown op had inserted one. Could not have
# intended to delete what it did not know, so noop
op3 = Op('od', array_path, offset='X')
op3.ot(cs1)
assert op3.t_path == array_path
assert op3.t_offset == 'X'
assert op3.is_noop()
op1.hazards = []
# same as above, but well within the inserted value
op4_path = array_path + ['X']
op4 = Op('od', op4_path, offset='Y')
op4.ot(cs1)
assert op4.t_path == array_path + ['X']
assert op4.t_offset == 'Y'
assert op4.is_noop()
op1.hazards = []
# op5 is at same path, differant offset. No change
op5 = Op('od', array_path, offset='R')
op5.ot(cs1)
assert op5.t_path == array_path
assert op5.t_offset == 'R'
assert not op5.is_noop()
op1.hazards = []
# op6 is at shorter path. No change
op6 = Op('od', ['a'], offset='c')
op6.ot(cs1)
assert op6.t_path == ['a']
assert op6.t_offset == 'c'
assert not op6.is_noop()
op1.hazards = []
# op7 deletes whatever was previously changed
op7 = Op('od', ['a'], offset='b')
op7.ot(cs1)
assert op7.t_path == ['a']
assert op7.t_offset == 'b'
assert not op7.is_noop()
op1.hazards = []
示例4: test_ai_ai
def test_ai_ai(self):
"""
A past opperations is an array insert which gets applied to this op.
"""
array_path = ["a", "b", 3, 4]
op1 = Op("ai", array_path, offset=3, val=["X", "Y"])
cs1 = Changeset("doc_id", "author", [])
cs1.add_op(op1)
# op2 happens at a different path, so should not be affected
op2 = Op("ai", ["a", "b", 3, 5], offset=2, val=["XYZ"])
op2.ot(cs1)
assert op2.t_path == ["a", "b", 3, 5]
op1.remove_old_hazards(purge=True)
# op3 happens at same path, but lower offset, no change
op3 = Op("ai", array_path, offset=2, val=["XYZ"])
op3.ot(cs1)
assert op3.t_path == array_path
assert op3.t_offset == 2
op1.remove_old_hazards(purge=True)
# op4 is at same path with offset to get pushed forward (edge case)
op4 = Op("ai", array_path, offset=3, val=["XYZ"])
op4.ot(cs1)
assert op4.t_path == array_path
assert op4.t_offset == 5
op1.remove_old_hazards(purge=True)
# op5 is at same path with offset to get pushed forward (not edge case)
op5 = Op("ai", array_path, offset=8, val=["XYZ"])
op5.ot(cs1)
assert op5.t_path == array_path
assert op5.t_offset == 10
op1.remove_old_hazards(purge=True)
# op6 path is in an array element being pushed forward (edge case)
op6_path = array_path + [3, 9, "c"]
op6 = Op("ai", op6_path, offset=8, val=["XYZ"])
op6.ot(cs1)
assert op6.t_path == array_path + [5, 9, "c"]
assert op6.t_offset == 8
op1.remove_old_hazards(purge=True)
# op7 path is in an array element being pushed forward (not edge case)
op7_path = array_path + [5, 9, "c"]
op7 = Op("ai", op7_path, offset=8, val=["XYZ"])
op7.ot(cs1)
assert op7.t_path == array_path + [7, 9, "c"]
op1.remove_old_hazards(purge=True)
# op8 path is shorter then array's path, so no change
op8_path = ["a", "b", 3]
op8 = Op("ai", op8_path, offset=8, val=["XYZ"])
op8.ot(cs1)
assert op8.t_path == op8_path
assert op8.t_offset == 8
op1.remove_old_hazards(purge=True)
示例5: test_sd_sd
def test_sd_sd(self):
op1 = Op('sd', [], offset=3, val=3)
cs1 = Changeset('doc_id', 'author', [])
cs1.add_op(op1)
# op1 deletes a range after op2, so should not affect it
# |-- op1 --|
# |-- op2 --|
op2 = Op('sd', [], offset=1, val=2)
op2.ot(cs1)
assert op2.t_offset == 1
assert op2.t_val == 2
op1.remove_old_hazards(purge=True)
# The end of op3 overlaps the start of op 1
# |-- op1 --|
# |-- op3 --|
op3 = Op('sd', [], offset=2, val=2)
op3.ot(cs1)
assert op3.t_offset == 2
assert op3.t_val == 1
op1.remove_old_hazards(purge=True)
# op1 range is encompased by op 4 range
# |-- op1 --|
# |---- op4 ----|
op4 = Op('sd', [], offset=2, val=6)
op4.ot(cs1)
assert op4.t_offset == 2
assert op4.t_val == 3
op1.remove_old_hazards(purge=True)
# op5 range is encompased by op1 range
# |---- op1 ----|
# |-- op5 --|
op5 = Op('sd', [], offset=4, val=1)
op5.ot(cs1)
assert op5.t_offset == 3
assert op5.t_val == 0
op1.remove_old_hazards(purge=True)
# start of op6 range overlaps end of op1 range
# |-- op1 --|
# |-- op6 --|
op6 = Op('sd', [], offset=5, val=3)
op6.ot(cs1)
assert op6.t_offset == 3
assert op6.t_val == 2
op1.remove_old_hazards(purge=True)
# start of op7 range is after start of op1 range
# |-- op1 --|
# |-- op7 --|
op7 = Op('sd', [], offset=8, val=3)
op7.ot(cs1)
assert op7.t_offset == 5
assert op7.t_val == 3
示例6: test_od_od
def test_od_od(self):
"""
A past opperation is an object delete which gets applied to these
object deletes.
"""
array_path = ['a', 'b', 3, 4]
op1 = Op('od', array_path, offset='X')
cs1 = Changeset('doc_id', 'author', [])
cs1.add_op(op1)
# op2 happens at a different path, so should not be affected
op2 = Op('od', ['a', 'b', 3, 5], offset='Y')
op2.ot(cs1)
assert op2.t_path == ['a', 'b', 3, 5]
assert op2.t_offset == 'Y'
assert not op2.is_noop()
op1.hazards = []
# op3 happens at same path but different offset
op3 = Op('od', array_path, offset='R')
op3.ot(cs1)
assert op3.t_path == array_path
assert op3.t_offset == 'R'
assert not op3.is_noop()
op1.hazards = []
# op4 tries to delete the same key as op1
op4 = Op('od', array_path, offset='X')
op4.ot(cs1)
assert op4.is_noop()
op1.hazards = []
# op5 tries to delete something within what was already deleted
op5_path = array_path + ['X']
op5 = Op('od', op5_path, offset='R')
op5.ot(cs1)
assert op5.is_noop()
op1.hazards = []
# op6 is at a shorter, different path. No change
op6_path = ['a']
op6 = Op('od', op6_path, offset='c')
op6.ot(cs1)
assert op6.t_path == ['a']
assert op6.t_offset == 'c'
assert not op6.is_noop()
op1.hazards = []
# op9 is at shorter, same path. No change
op9_path = ['a']
op9 = Op('od', op9_path, offset='b')
op9.ot(cs1)
assert op9.t_path == op9_path
assert op9.t_offset == 'b'
assert not op9.is_noop()
op1.hazards = []
示例7: test_linear
def test_linear(self):
doc = Document(snapshot='')
doc.HAS_EVENT_LOOP = False
root = doc.get_root_changeset()
cs0 = Changeset(doc.get_id(), "dummyuser", [root])
doc.add_to_known_changesets(cs0)
doc.insert_changeset_into_ordered_list(cs0)
doc.update_unaccounted_changesets(cs0)
assert root.get_unaccounted_changesets() == []
assert cs0.get_unaccounted_changesets() == []
cs1 = Changeset(doc.get_id(), "user1", [cs0])
doc.add_to_known_changesets(cs1)
doc.insert_changeset_into_ordered_list(cs1)
doc.update_unaccounted_changesets(cs1)
assert root.get_unaccounted_changesets() == []
assert cs0.get_unaccounted_changesets() == []
assert cs1.get_unaccounted_changesets() == []
cs2 = Changeset(doc.get_id(), "user1", [cs1])
doc.add_to_known_changesets(cs2)
doc.insert_changeset_into_ordered_list(cs2)
doc.update_unaccounted_changesets(cs2)
assert root.get_unaccounted_changesets() == []
assert cs0.get_unaccounted_changesets() == []
assert cs1.get_unaccounted_changesets() == []
assert cs2.get_unaccounted_changesets() == []
示例8: test_get_dependency_ids
def test_get_dependency_ids(self):
cs0 = Changeset('doc_id', 'user_id', [])
assert cs0.get_dependency_ids() == []
cs1 = Changeset('doc_id', 'user_id', ['randomid'])
assert cs1.get_dependency_ids() == ['randomid']
cs2 = Changeset('doc_id', 'user_id', [cs1])
assert cs2.get_dependency_ids() == [cs1.get_id()]
cs3 = Changeset('doc_id', 'user_id', [cs2, 'otherrandomid'])
assert cs3.get_dependency_ids() == [cs2.get_id(), 'otherrandomid']
示例9: test_od_oi
def test_od_oi(self):
"""
A past opperations is an object delete which gets applied to this
object insert.
"""
array_path = ['a', 'b', 3, 4]
op1 = Op('od', array_path, offset='X')
cs1 = Changeset('doc_id', 'author', [])
cs1.add_op(op1)
# op2 happens at a different path, so should not be affected
op2 = Op('oi', ['a', 'b', 3, 5], offset='Y', val=['XYZ'])
op2.ot(cs1)
assert op2.t_path == ['a', 'b', 3, 5]
assert op2.t_offset == 'Y'
assert op2.t_val == ['XYZ']
assert not op2.is_noop()
op1.hazards = []
# op3 happens at path, but differant offset, no change
op3 = Op('oi', array_path, offset='W', val=['XYZ'])
op3.ot(cs1)
assert op3.t_path == array_path
assert op3.t_offset == 'W'
assert not op3.is_noop()
op1.hazards = []
# op4 happens within deletion
op4_path = array_path + ['X']
op4 = Op('oi', op4_path, offset='R', val=['XYZ'])
op4.ot(cs1)
assert op4.is_noop()
op1.hazards = []
# op5 inserts right where there was a deletion. Some previous conflict,
# so noop
op5 = Op('oi', array_path, offset='X', val='XYZ')
op5.ot(cs1)
assert op5.t_path == array_path
assert op5.t_offset == 'X'
assert op5.t_val == 'XYZ'
assert op5.is_noop()
op1.hazards = []
# op6 is at a partial path along deletion, no change
op6_path = ['a']
op6 = Op('oi', op6_path, offset='c', val=['XYZ'])
op6.ot(cs1)
assert op6.t_path == ['a']
assert op6.t_offset == 'c'
assert op6.t_val == ['XYZ']
assert not op6.is_noop()
op1.hazards = []
示例10: test_has_needed_dependencies
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)
示例11: test_oi_oi
def test_oi_oi(self):
"""
A past opperation is an Object insert which gets applied to this object
insert. The only opportunity for conflict is if the later insert
happens along a path that is no longer valid.
"""
array_path = ['a', 'b', 3, 4]
op1 = Op('oi', array_path, offset='X', val=['Y', 'Z'])
cs1 = Changeset('doc_id', 'author', [])
cs1.add_op(op1)
# op2 happens at a different path, so should not be affected
op2 = Op('oi', ['a', 'b', 3, 5], offset='c', val=["XYZ"])
op2.ot(cs1)
assert op2.t_path == ['a', 'b', 3, 5]
op1.hazards = []
# op3 happens along path, so it will just overwrite past data
op3 = Op('oi', ['a'], offset='b', val="XYZ")
op3.ot(cs1)
assert op3.t_path == ['a']
assert op3.t_offset == 'b'
assert op3.t_val == 'XYZ'
op1.hazards = []
# op4 is at same path, different offset, so no conflict
op4 = Op('oi', array_path, offset='W', val="WWW")
op4.ot(cs1)
assert op4.t_path == array_path
assert op4.t_offset == 'W'
assert op4.t_val == 'WWW'
assert not op4.is_noop()
op1.hazards = []
# op5 is at same path and offset, so previous op takes precedence
op5 = Op('oi', array_path, offset='X', val=["XXX"])
op5.ot(cs1)
assert op5.t_path == array_path
assert op5.t_offset == 'X'
assert op5.t_val == ['XXX']
assert op5.is_noop()
op1.hazards = []
# op6 path is deep within a previous object insert
op6_path = array_path + ['X', 9, 'c']
op6 = Op('oi', op6_path, offset=8, val=["XYZ"])
op6.ot(cs1)
assert op6.is_noop()
op1.hazards = []
示例12: build_changesets_from_tuples
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
示例13: test_set_root_preceding
def test_set_root_preceding(self):
"""
A preceding operation did a set at the root. Any following
operations should be transformed to a noop.
"""
op1 = Op("set", [], val="ABC")
cs1 = Changeset("doc_id", "author", [])
cs1.add_op(op1)
# op2 happens at root so should be affected
op2 = Op("si", [], offset=2, val="XYZ")
op2.ot(cs1)
assert op2.is_noop() == True
# op3 happens not at root. still should be affected
op3 = Op("si", ["k", 3, "j"], offset=3, val="XYZ")
op3.ot(cs1)
assert op3.is_noop() == True
示例14: test_set_root_after
def test_set_root_after(self):
"""
The set root occurs after other unknown operations. They should
have no effect.
"""
op1 = Op("si", [], offset=0, val="ABC")
cs1 = Changeset("doc_id", "author", [])
cs1.add_op(op1)
op2 = Op("set", [], val="XYZ")
op2.ot(cs1)
assert op2.is_noop() == False
assert op1.is_noop() == False
# op3 happens not at root. still should be affected
op3 = Op("set", ["k", 3, "j"], offset=3, val="XYZ")
op3.ot(cs1)
assert op3.is_noop() == False
示例15: test_complex_path
def test_complex_path(self):
op1 = Op("set", ["k", 3, "j"], val="ABC")
cs1 = Changeset("doc_id", "author", [])
cs1.add_op(op1)
op2 = Op("si", [], val="XYZ")
op2.ot(cs1)
assert op2.is_noop() == False
assert op1.is_noop() == False
op3 = Op("si", ["k", 3, "j"], offset=3, val="XYZ")
op3.ot(cs1)
assert op3.is_noop() == True
assert op1.is_noop() == False
op4 = Op("si", ["k", 3, "j", "h"], offset=3, val="XYZ")
op4.ot(cs1)
assert op4.is_noop() == True
assert op1.is_noop() == False