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


Python mocks.ServiceMock类代码示例

本文整理汇总了Python中cocaine.testing.mocks.ServiceMock的典型用法代码示例。如果您正苦于以下问题:Python ServiceMock类的具体用法?Python ServiceMock怎么用?Python ServiceMock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_SingleChunk_SingleThen

 def test_SingleChunk_SingleThen(self):
     expected = [lambda r: self.assertEqual(1, r.get()), lambda r: self.assertRaises(ChokeEvent, r.get)]
     check = checker(expected, self)
     f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop).execute()
     f.then(check)
     self.wait()
     self.assertTrue(len(expected) == 0)
开发者ID:nexusriot,项目名称:cocaine-framework-python,代码行数:7,代码来源:test_api.py

示例2: test_GetMultipleChunks

 def test_GetMultipleChunks(self):
     f = ServiceMock(chunks=[1, 2, 3], T=self.T, ioLoop=self.io_loop).execute()
     r1 = f.get()
     r2 = f.get()
     r3 = f.get()
     self.assertEqual(1, r1)
     self.assertEqual(2, r2)
     self.assertEqual(3, r3)
开发者ID:nexusriot,项目名称:cocaine-framework-python,代码行数:8,代码来源:test_api.py

示例3: test_GetSingleChunkMultipleTimesAfterWaiting

 def test_GetSingleChunkMultipleTimesAfterWaiting(self):
     s = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop)
     f1 = s.execute()
     f1.wait()
     f1.get()
     f2 = s.execute()
     f2.wait()
     r2 = f2.get()
     self.assertEqual(1, r2)
开发者ID:nexusriot,项目名称:cocaine-framework-python,代码行数:9,代码来源:test_api.py

示例4: test_SingleChunk_MultipleThen_ErrorMiddleman

    def test_SingleChunk_MultipleThen_ErrorMiddleman(self):
        expected = [lambda r: self.assertRaises(ValueError, r.get), lambda r: self.assertRaises(ValueError, r.get)]
        check = checker(expected, self)

        def middleMan(result):
            raise ValueError("Middleman")

        f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop).execute()
        f.then(middleMan).then(check)
        self.wait()
        self.assertTrue(len(expected) == 0)
开发者ID:nexusriot,项目名称:cocaine-framework-python,代码行数:11,代码来源:test_api.py

示例5: test_SingleChunk_MultipleThen_Middleman

    def test_SingleChunk_MultipleThen_Middleman(self):
        expected = [lambda r: self.assertEqual(2, r.get())]
        check = checker(expected, self)

        def middleMan(result):
            return result.get() + 1

        f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop).execute()
        f.then(middleMan).then(check)
        self.wait(timeout=0.5)
        self.assertTrue(len(expected) == 0)
开发者ID:nexusriot,项目名称:cocaine-framework-python,代码行数:11,代码来源:test_api.py

示例6: test_GetMultipleMixChunksWithComplexChain

 def test_GetMultipleMixChunksWithComplexChain(self):
     def middleMan(result):
         r = result.get()
         if r == 2:
             raise Exception('=(')
         yield r
     f = ServiceMock(chunks=[1, 2, 3], T=self.T, ioLoop=self.io_loop).execute()
     f.then(middleMan)
     self.assertEqual(1, f.get())
     self.assertRaises(Exception, f.get)
     self.assertEqual(3, f.get())
开发者ID:devlato,项目名称:cocaine-framework-python,代码行数:11,代码来源:test_api.py

示例7: test_SingleChunk_MultipleThen

    def test_SingleChunk_MultipleThen(self):
        expected = [lambda r: self.assertEqual(2, r.get()), lambda r: self.assertRaises(ChokeEvent, r.get)]
        check = checker(expected, self)
        f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop).execute()

        def firstStep(futureResult):
            r = futureResult.get()
            return r * 2

        f.then(firstStep).then(check)
        self.wait()
        self.assertTrue(len(expected) == 0)
开发者ID:nexusriot,项目名称:cocaine-framework-python,代码行数:12,代码来源:test_api.py

示例8: test_SingleChunk_SingleThen_YieldMiddleman

    def test_SingleChunk_SingleThen_YieldMiddleman(self):
        expected = [lambda r: self.assertEqual(3, r.get()), lambda r: self.assertRaises(ChokeEvent, r.get)]
        check = checker(expected, self)

        def middleMan(result):
            result.get()
            yield "String that won't be seen by anyone"
            yield 3

        f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop).execute()
        f.then(middleMan).then(check)
        self.wait()
        self.assertTrue(len(expected) == 0)
开发者ID:nexusriot,项目名称:cocaine-framework-python,代码行数:13,代码来源:test_api.py

示例9: test_GetMultipleChunksMultipleTimes

    def test_GetMultipleChunksMultipleTimes(self):
        s = ServiceMock(chunks=[1, 2, 3], T=self.T, ioLoop=self.io_loop)
        f1 = s.execute()
        f1.get()
        f1.get()
        f1.get()

        f2 = s.execute()
        r21 = f2.get()
        r22 = f2.get()
        r23 = f2.get()
        self.assertEqual(1, r21)
        self.assertEqual(2, r22)
        self.assertEqual(3, r23)
开发者ID:nexusriot,项目名称:cocaine-framework-python,代码行数:14,代码来源:test_api.py

示例10: test_SingleChunk_SingleThen_YieldAsyncDoubleMiddlemanWithLessChunks

    def test_SingleChunk_SingleThen_YieldAsyncDoubleMiddlemanWithLessChunks(self):
        expected = [lambda r: self.assertEqual([4, 5, 6], r.get()), lambda r: self.assertRaises(ChokeEvent, r.get)]
        check = checker(expected, self)

        def middleMan(result):
            result.get()
            s1 = yield ServiceMock(chunks=[4, 5], T=self.T, ioLoop=self.io_loop, interval=0.002).execute()
            s2 = yield
            s3 = yield ServiceMock(chunks=[6], T=self.T, ioLoop=self.io_loop, interval=0.001).execute()
            yield [s1, s2, s3]

        f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop, interval=0.01).execute()
        f.then(middleMan).then(check)
        self.wait()
        self.assertTrue(len(expected) == 0)
开发者ID:nexusriot,项目名称:cocaine-framework-python,代码行数:15,代码来源:test_api.py

示例11: test_SingleChunk_MultipleChainItems_MixedProcessing2

    def test_SingleChunk_MultipleChainItems_MixedProcessing2(self):
        expected = [lambda r: self.assertEqual(6, r.get()), lambda r: self.assertRaises(ChokeEvent, r.get)]
        check = checker(expected, self)

        def firstStep(result):
            yield result.get() * 3

        def secondStep(result):
            r = result.get()
            return r * 2

        f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop).execute()
        f.then(firstStep).then(secondStep).then(check)
        self.wait()
        self.assertTrue(len(expected) == 0)
开发者ID:nexusriot,项目名称:cocaine-framework-python,代码行数:15,代码来源:test_api.py

示例12: test_YieldAsyncMiddlemanExtraChunkResultsInChokeEvent

    def test_YieldAsyncMiddlemanExtraChunkResultsInChokeEvent(self):
        expected = [lambda r: self.assertRaises(ChokeEvent, r.get), lambda r: self.assertRaises(ChokeEvent, r.get)]
        check = checker(expected, self)

        def middleMan(result):
            result.get()
            s1 = yield ServiceMock(chunks=[4, 5], T=self.T, ioLoop=self.io_loop, interval=0.001).execute()
            s2 = yield
            # This one will lead to the ChokeEvent
            s3 = yield
            yield [s1, s2, s3]

        f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop, interval=0.01).execute()
        f.then(middleMan).then(check)
        self.wait()
        self.assertTrue(len(expected) == 0)
开发者ID:nexusriot,项目名称:cocaine-framework-python,代码行数:16,代码来源:test_api.py

示例13: test_SingleChunk_MultipleChainItems_OnlyCoroutinesProcessing

    def test_SingleChunk_MultipleChainItems_OnlyCoroutinesProcessing(self):
        expected = [lambda r: self.assertEqual(4, r.get()), lambda r: self.assertRaises(ChokeEvent, r.get)]
        check = checker(expected, self)

        def firstStep(result):
            r = result.get()
            yield "String that won't be seen by anyone"
            yield r * 2

        def secondStep(result):
            yield result.get() * 2

        f = ServiceMock(chunks=[1], T=self.T, ioLoop=self.io_loop).execute()
        f.then(firstStep).then(secondStep).then(check)
        self.wait()
        self.assertTrue(len(expected) == 0)
开发者ID:nexusriot,项目名称:cocaine-framework-python,代码行数:16,代码来源:test_api.py

示例14: test_MultipleChunk_SingleThen_YieldMiddleman

    def test_MultipleChunk_SingleThen_YieldMiddleman(self):
        expected = [
            lambda r: self.assertEqual(3, r.get()),
            lambda r: self.assertEqual(6, r.get()),
            lambda r: self.assertEqual(9, r.get()),
            lambda r: self.assertRaises(ChokeEvent, r.get),
        ]
        check = checker(expected, self)

        def middleMan(result):
            r = result.get()
            yield 'This string won\'t be seen by anyone'
            yield r * 3
        f = ServiceMock(chunks=[1, 2, 3], T=self.T, ioLoop=self.io_loop).execute()
        f.then(middleMan).then(check)
        self.wait()
        self.assertTrue(len(expected) == 0)
开发者ID:devlato,项目名称:cocaine-framework-python,代码行数:17,代码来源:test_api.py

示例15: test_MultipleChunk_SingleThen_YieldErrorMiddleman

    def test_MultipleChunk_SingleThen_YieldErrorMiddleman(self):
        expected = [
            lambda r: self.assertEqual(1, r.get()),
            lambda r: self.assertRaises(Exception, r.get),
            lambda r: self.assertEqual(3, r.get()),
            lambda r: self.assertRaises(ChokeEvent, r.get),
        ]
        check = checker(expected, self)

        def middleMan(result):
            r = result.get()
            if r == 2:
                raise Exception('=(')
            yield r
        f = ServiceMock(chunks=[1, 2, 3], T=self.T, ioLoop=self.io_loop).execute()
        f.then(middleMan).then(check)
        self.wait()
        self.assertTrue(len(expected) == 0)
开发者ID:devlato,项目名称:cocaine-framework-python,代码行数:18,代码来源:test_api.py


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