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


Python ProtocolGraphWalker.read_proto_line方法代码示例

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


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

示例1: ProtocolGraphWalkerTestCase

# 需要导入模块: from dulwich.server import ProtocolGraphWalker [as 别名]
# 或者: from dulwich.server.ProtocolGraphWalker import read_proto_line [as 别名]
class ProtocolGraphWalkerTestCase(TestCase):

    def setUp(self):
        # Create the following commit tree:
        #   3---5
        #  /
        # 1---2---4
        self._objects = {
            ONE: TestCommit(ONE, [], 111),
            TWO: TestCommit(TWO, [ONE], 222),
            THREE: TestCommit(THREE, [ONE], 333),
            FOUR: TestCommit(FOUR, [TWO], 444),
            FIVE: TestCommit(FIVE, [THREE], 555),
            }

        self._walker = ProtocolGraphWalker(
            TestUploadPackHandler(self._objects, TestProto()),
            self._objects, None)

    def test_is_satisfied_no_haves(self):
        self.assertFalse(self._walker._is_satisfied([], ONE, 0))
        self.assertFalse(self._walker._is_satisfied([], TWO, 0))
        self.assertFalse(self._walker._is_satisfied([], THREE, 0))

    def test_is_satisfied_have_root(self):
        self.assertTrue(self._walker._is_satisfied([ONE], ONE, 0))
        self.assertTrue(self._walker._is_satisfied([ONE], TWO, 0))
        self.assertTrue(self._walker._is_satisfied([ONE], THREE, 0))

    def test_is_satisfied_have_branch(self):
        self.assertTrue(self._walker._is_satisfied([TWO], TWO, 0))
        # wrong branch
        self.assertFalse(self._walker._is_satisfied([TWO], THREE, 0))

    def test_all_wants_satisfied(self):
        self._walker.set_wants([FOUR, FIVE])
        # trivial case: wants == haves
        self.assertTrue(self._walker.all_wants_satisfied([FOUR, FIVE]))
        # cases that require walking the commit tree
        self.assertTrue(self._walker.all_wants_satisfied([ONE]))
        self.assertFalse(self._walker.all_wants_satisfied([TWO]))
        self.assertFalse(self._walker.all_wants_satisfied([THREE]))
        self.assertTrue(self._walker.all_wants_satisfied([TWO, THREE]))

    def test_read_proto_line(self):
        self._walker.proto.set_output([
            'want %s' % ONE,
            'want %s' % TWO,
            'have %s' % THREE,
            'foo %s' % FOUR,
            'bar',
            'done',
            ])
        self.assertEquals(('want', ONE), self._walker.read_proto_line())
        self.assertEquals(('want', TWO), self._walker.read_proto_line())
        self.assertEquals(('have', THREE), self._walker.read_proto_line())
        self.assertRaises(GitProtocolError, self._walker.read_proto_line)
        self.assertRaises(GitProtocolError, self._walker.read_proto_line)
        self.assertEquals(('done', None), self._walker.read_proto_line())
        self.assertEquals((None, None), self._walker.read_proto_line())

    def test_determine_wants(self):
        self.assertRaises(GitProtocolError, self._walker.determine_wants, {})

        self._walker.proto.set_output([
            'want %s multi_ack' % ONE,
            'want %s' % TWO,
            ])
        heads = {'ref1': ONE, 'ref2': TWO, 'ref3': THREE}
        self._walker.get_peeled = heads.get
        self.assertEquals([ONE, TWO], self._walker.determine_wants(heads))

        self._walker.proto.set_output(['want %s multi_ack' % FOUR])
        self.assertRaises(GitProtocolError, self._walker.determine_wants, heads)

        self._walker.proto.set_output([])
        self.assertEquals([], self._walker.determine_wants(heads))

        self._walker.proto.set_output(['want %s multi_ack' % ONE, 'foo'])
        self.assertRaises(GitProtocolError, self._walker.determine_wants, heads)

        self._walker.proto.set_output(['want %s multi_ack' % FOUR])
        self.assertRaises(GitProtocolError, self._walker.determine_wants, heads)

    def test_determine_wants_advertisement(self):
        self._walker.proto.set_output([])
        # advertise branch tips plus tag
        heads = {'ref4': FOUR, 'ref5': FIVE, 'tag6': SIX}
        peeled = {'ref4': FOUR, 'ref5': FIVE, 'tag6': FIVE}
        self._walker.get_peeled = peeled.get
        self._walker.determine_wants(heads)
        lines = []
        while True:
            line = self._walker.proto.get_received_line()
            if line == 'None':
                break
            # strip capabilities list if present
            if '\x00' in line:
                line = line[:line.index('\x00')]
            lines.append(line.rstrip())
#.........这里部分代码省略.........
开发者ID:tmc,项目名称:dulwich,代码行数:103,代码来源:test_server.py

示例2: ProtocolGraphWalkerTestCase

# 需要导入模块: from dulwich.server import ProtocolGraphWalker [as 别名]
# 或者: from dulwich.server.ProtocolGraphWalker import read_proto_line [as 别名]
class ProtocolGraphWalkerTestCase(TestCase):
    def setUp(self):
        # Create the following commit tree:
        #   3---5
        #  /
        # 1---2---4
        self._objects = {
            ONE: TestCommit(ONE, [], 111),
            TWO: TestCommit(TWO, [ONE], 222),
            THREE: TestCommit(THREE, [ONE], 333),
            FOUR: TestCommit(FOUR, [TWO], 444),
            FIVE: TestCommit(FIVE, [THREE], 555),
            }
        self._walker = ProtocolGraphWalker(
            TestHandler(self._objects, TestProto()))

    def test_is_satisfied_no_haves(self):
        self.assertFalse(self._walker._is_satisfied([], ONE, 0))
        self.assertFalse(self._walker._is_satisfied([], TWO, 0))
        self.assertFalse(self._walker._is_satisfied([], THREE, 0))

    def test_is_satisfied_have_root(self):
        self.assertTrue(self._walker._is_satisfied([ONE], ONE, 0))
        self.assertTrue(self._walker._is_satisfied([ONE], TWO, 0))
        self.assertTrue(self._walker._is_satisfied([ONE], THREE, 0))

    def test_is_satisfied_have_branch(self):
        self.assertTrue(self._walker._is_satisfied([TWO], TWO, 0))
        # wrong branch
        self.assertFalse(self._walker._is_satisfied([TWO], THREE, 0))

    def test_all_wants_satisfied(self):
        self._walker.set_wants([FOUR, FIVE])
        # trivial case: wants == haves
        self.assertTrue(self._walker.all_wants_satisfied([FOUR, FIVE]))
        # cases that require walking the commit tree
        self.assertTrue(self._walker.all_wants_satisfied([ONE]))
        self.assertFalse(self._walker.all_wants_satisfied([TWO]))
        self.assertFalse(self._walker.all_wants_satisfied([THREE]))
        self.assertTrue(self._walker.all_wants_satisfied([TWO, THREE]))

    def test_read_proto_line(self):
        self._walker.proto.set_output([
            'want %s' % ONE,
            'want %s' % TWO,
            'have %s' % THREE,
            'foo %s' % FOUR,
            'bar',
            'done',
            ])
        self.assertEquals(('want', ONE), self._walker.read_proto_line())
        self.assertEquals(('want', TWO), self._walker.read_proto_line())
        self.assertEquals(('have', THREE), self._walker.read_proto_line())
        self.assertRaises(GitProtocolError, self._walker.read_proto_line)
        self.assertRaises(GitProtocolError, self._walker.read_proto_line)
        self.assertEquals(('done', None), self._walker.read_proto_line())
        self.assertEquals((None, None), self._walker.read_proto_line())

    def test_determine_wants(self):
        self.assertRaises(GitProtocolError, self._walker.determine_wants, {})

        self._walker.proto.set_output([
            'want %s multi_ack' % ONE,
            'want %s' % TWO,
            ])
        heads = {'ref1': ONE, 'ref2': TWO, 'ref3': THREE}
        self.assertEquals([ONE, TWO], self._walker.determine_wants(heads))

        self._walker.proto.set_output(['want %s multi_ack' % FOUR])
        self.assertRaises(GitProtocolError, self._walker.determine_wants, heads)

        self._walker.proto.set_output([])
        self.assertEquals([], self._walker.determine_wants(heads))

        self._walker.proto.set_output(['want %s multi_ack' % ONE, 'foo'])
        self.assertRaises(GitProtocolError, self._walker.determine_wants, heads)

        self._walker.proto.set_output(['want %s multi_ack' % FOUR])
        self.assertRaises(GitProtocolError, self._walker.determine_wants, heads)
开发者ID:abderrahim,项目名称:dulwich,代码行数:81,代码来源:test_server.py


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