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


Python Changeset.add_op方法代码示例

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


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

示例1: test_si_sd

# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import add_op [as 别名]
    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
开发者ID:citizencurator,项目名称:majormajor,代码行数:34,代码来源:test_string_transformations.py

示例2: test_sd_si

# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import add_op [as 别名]
    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"
开发者ID:citizencurator,项目名称:majormajor,代码行数:33,代码来源:test_string_transformations.py

示例3: build_branch

# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import add_op [as 别名]
    def build_branch(self):
        doc = self.doc
        # pick a random changeset to start building off of
        parent = random.choice(doc.get_ordered_changesets())
        branch_length = random.choice(xrange(4, 15))
        for x in xrange(branch_length):
            # revert document to when it went as far as parent
            doc.rebuild_historical_document([parent])
            cs = Changeset(doc.get_id(), str(self.user_vector), [parent])
            op = self.build_random_insert_or_delete()
            cs.add_op(op)
            doc.receive_changeset(cs)
            parent = cs
            if len(self.remaining_chars) == 0:
                break
        # Pull back in all changesets
        doc.pull_from_pending_list()

        # create a new changeset which just ties that branch back to the other
        # dependencies
        deps = doc.get_dependencies()
        deps.remove(parent)
        # chose another dep, if able
        if len(deps) != 0:
            dep = random.choice(deps)
            deps = [parent, dep]
            cs = Changeset(doc.get_id(), str(self.user_vector), deps)
            self.user_vector += 1
            op = self.build_random_insert_or_delete()
            cs.add_op(op)
            doc.receive_changeset(cs)
开发者ID:citizencurator,项目名称:majormajor,代码行数:33,代码来源:test_strings_in_complex_branches.py

示例4: test_oi_od

# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import add_op [as 别名]
    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 = []
开发者ID:citizencurator,项目名称:majormajor,代码行数:61,代码来源:test_object_transformations.py

示例5: test_ai_ai

# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import add_op [as 别名]
    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)
开发者ID:ritchiewilson,项目名称:majormajor,代码行数:60,代码来源:test_array_transformations.py

示例6: test_sd_sd

# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import add_op [as 别名]
    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
开发者ID:citizencurator,项目名称:majormajor,代码行数:59,代码来源:test_string_transformations.py

示例7: test_od_od

# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import add_op [as 别名]
    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 = []
开发者ID:citizencurator,项目名称:majormajor,代码行数:58,代码来源:test_object_transformations.py

示例8: test_od_oi

# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import add_op [as 别名]
    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 = []
开发者ID:citizencurator,项目名称:majormajor,代码行数:55,代码来源:test_object_transformations.py

示例9: test_oi_oi

# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import add_op [as 别名]
    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 = []
开发者ID:citizencurator,项目名称:majormajor,代码行数:51,代码来源:test_object_transformations.py

示例10: build_changesets_from_tuples

# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import add_op [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
开发者ID:citizencurator,项目名称:majormajor,代码行数:18,代码来源:test_utils.py

示例11: test_sequence_of_set_ops

# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import add_op [as 别名]
    def test_sequence_of_set_ops(self):
        op1 = Op("set", ["k", 3, "j"], val="ABC")
        cs1 = Changeset("doc_id", "author", [])
        cs1.add_op(op1)

        op2 = Op("set", ["k", 3, "j"], val="XYZ")
        op2.ot(cs1)
        assert op2.is_noop() == True
        assert op1.is_noop() == False

        cs2 = Changeset("doc_id", "author", [cs1])
        cs2.add_op(op2)

        op3 = Op("set", ["k", 3, "j"], val="XYZ")
        op3.ot(cs2)
        assert op2.is_noop() == True
        assert op3.is_noop() == False
开发者ID:ritchiewilson,项目名称:majormajor,代码行数:19,代码来源:test_op_set.py

示例12: test_set_root_after

# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import add_op [as 别名]
    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
开发者ID:ritchiewilson,项目名称:majormajor,代码行数:20,代码来源:test_op_set.py

示例13: test_set_root_preceding

# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import add_op [as 别名]
    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
开发者ID:ritchiewilson,项目名称:majormajor,代码行数:20,代码来源:test_op_set.py

示例14: test_complex_path

# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import add_op [as 别名]
    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
开发者ID:ritchiewilson,项目名称:majormajor,代码行数:21,代码来源:test_op_set.py

示例15: test_si_si

# 需要导入模块: from majormajor.changeset import Changeset [as 别名]
# 或者: from majormajor.changeset.Changeset import add_op [as 别名]
    def test_si_si(self):
        op1 = Op('si', [], offset=3, val="ABC")
        cs1 = Changeset('doc_id', 'author', [])
        cs1.add_op(op1)

        # op2 happens at a lower offset, so should not be affected
        op2 = Op('si', [], offset=2, val="XYZ")
        op2.ot(cs1)
        assert op2.t_offset == 2
        op1.remove_old_hazards(purge=True)

        # op3 happens at an equal offset, so should be pushed forward
        op2 = Op('si', [], offset=3, val="XYZ")
        op2.ot(cs1)
        assert op2.t_offset == 6
        op1.remove_old_hazards(purge=True)

        # op4 happens at a later offset, so should be pushed forward
        op2 = Op('si', [], offset=5, val="XYZ")
        op2.ot(cs1)
        assert op2.t_offset == 8
开发者ID:citizencurator,项目名称:majormajor,代码行数:23,代码来源:test_string_transformations.py


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