當前位置: 首頁>>代碼示例>>Python>>正文


Python Changeset.get_ops方法代碼示例

本文整理匯總了Python中majormajor.changeset.Changeset.get_ops方法的典型用法代碼示例。如果您正苦於以下問題:Python Changeset.get_ops方法的具體用法?Python Changeset.get_ops怎麽用?Python Changeset.get_ops使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在majormajor.changeset.Changeset的用法示例。


在下文中一共展示了Changeset.get_ops方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: setup_method

# 需要導入模塊: from majormajor.changeset import Changeset [as 別名]
# 或者: from majormajor.changeset.Changeset import get_ops [as 別名]
class TestChangesetHelpers:

    def setup_method(self, method):
        self.cs0 = Changeset('doc_id', 'user_id', [])
        
    def test_is_empty(self):
        cs = Changeset('doc_id', 'user_id', [])
        assert cs.is_empty()

        cs.add_op(Op('set',[],val=''))
        assert not cs.is_empty()

    def test_has_full_dependency_info(self):
        # should always pass when it has no dependencies
        cs0 = Changeset('doc_id', 'user_id', [])
        assert cs0.has_full_dependency_info()

        cs1 = Changeset('doc_id', 'user_id', ['randomid'])
        assert not cs1.has_full_dependency_info()

        cs2 = Changeset('doc_id', 'user_id', [cs1])
        assert cs2.has_full_dependency_info()

        cs3 = Changeset('doc_id', 'user_id', [cs2, 'otherrandomid'])
        assert not cs3.has_full_dependency_info()

        cs4 = Changeset('doc_id', 'user_id', [cs1])
        cs5 = Changeset('doc_id', 'user_id', [cs4, cs3])
        assert cs5.has_full_dependency_info()

        cs6 = Changeset('doc_id', 'user_id', [cs5, 'otherid'])
        assert not cs6.has_full_dependency_info()

    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']

    def test_set_id(self):
        cs0 = Changeset('doc_id', 'user_id', [])
        assert cs0.set_id('randomid')
        assert cs0.get_id() == 'randomid'

    def test_add_op(self):
        op = Op('set', [],val='')
        assert self.cs0.add_op(op)
        assert self.cs0.get_ops() == [op]

        # cannot add same op twice
        with pytest.raises(Exception):
            self.cs0.add_op(op)
            
        # add a differant op and it goes through
        op2 = Op('set', [],val='')
        assert self.cs0.add_op(op2)
        assert self.cs0.get_ops() == [op, op2]

        # once id is set, cannot add more ops
        self.cs0.get_id()
        op3 = Op('set', [],val='')
        with pytest.raises(Exception):
            self.cs0.add_op(op3)

    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]

    def test_has_ancestor(self):

        """
        Some complex tree.
        
               C -- G -- H -------- K
              /         /            \
#.........這裏部分代碼省略.........
開發者ID:citizencurator,項目名稱:majormajor,代碼行數:103,代碼來源:test_changeset_helpers.py


注:本文中的majormajor.changeset.Changeset.get_ops方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。