本文整理汇总了Python中cocaine.testing.mocks.ServiceMock.then方法的典型用法代码示例。如果您正苦于以下问题:Python ServiceMock.then方法的具体用法?Python ServiceMock.then怎么用?Python ServiceMock.then使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cocaine.testing.mocks.ServiceMock
的用法示例。
在下文中一共展示了ServiceMock.then方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_SingleChunk_SingleThen
# 需要导入模块: from cocaine.testing.mocks import ServiceMock [as 别名]
# 或者: from cocaine.testing.mocks.ServiceMock import then [as 别名]
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)
示例2: test_SingleChunk_MultipleThen_ErrorMiddleman
# 需要导入模块: from cocaine.testing.mocks import ServiceMock [as 别名]
# 或者: from cocaine.testing.mocks.ServiceMock import then [as 别名]
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)
示例3: test_GetMultipleMixChunksWithComplexChain
# 需要导入模块: from cocaine.testing.mocks import ServiceMock [as 别名]
# 或者: from cocaine.testing.mocks.ServiceMock import then [as 别名]
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())
示例4: test_SingleChunk_MultipleThen_Middleman
# 需要导入模块: from cocaine.testing.mocks import ServiceMock [as 别名]
# 或者: from cocaine.testing.mocks.ServiceMock import then [as 别名]
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)
示例5: test_SingleChunk_MultipleThen
# 需要导入模块: from cocaine.testing.mocks import ServiceMock [as 别名]
# 或者: from cocaine.testing.mocks.ServiceMock import then [as 别名]
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)
示例6: test_SingleChunk_SingleThen_YieldMiddleman
# 需要导入模块: from cocaine.testing.mocks import ServiceMock [as 别名]
# 或者: from cocaine.testing.mocks.ServiceMock import then [as 别名]
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)
示例7: test_SingleChunk_SingleThen_YieldAsyncDoubleMiddlemanWithLessChunks
# 需要导入模块: from cocaine.testing.mocks import ServiceMock [as 别名]
# 或者: from cocaine.testing.mocks.ServiceMock import then [as 别名]
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)
示例8: test_SingleChunk_MultipleChainItems_MixedProcessing2
# 需要导入模块: from cocaine.testing.mocks import ServiceMock [as 别名]
# 或者: from cocaine.testing.mocks.ServiceMock import then [as 别名]
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)
示例9: test_YieldAsyncMiddlemanExtraChunkResultsInChokeEvent
# 需要导入模块: from cocaine.testing.mocks import ServiceMock [as 别名]
# 或者: from cocaine.testing.mocks.ServiceMock import then [as 别名]
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)
示例10: test_SingleChunk_MultipleChainItems_OnlyCoroutinesProcessing
# 需要导入模块: from cocaine.testing.mocks import ServiceMock [as 别名]
# 或者: from cocaine.testing.mocks.ServiceMock import then [as 别名]
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)
示例11: test_MultipleChunk_SingleThen_YieldMiddleman
# 需要导入模块: from cocaine.testing.mocks import ServiceMock [as 别名]
# 或者: from cocaine.testing.mocks.ServiceMock import then [as 别名]
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)
示例12: test_MultipleChunk_SingleThen_YieldErrorMiddleman
# 需要导入模块: from cocaine.testing.mocks import ServiceMock [as 别名]
# 或者: from cocaine.testing.mocks.ServiceMock import then [as 别名]
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)
示例13: test_MultipleChunk_SingleThen_YieldAsyncMiddleman
# 需要导入模块: from cocaine.testing.mocks import ServiceMock [as 别名]
# 或者: from cocaine.testing.mocks.ServiceMock import then [as 别名]
def test_MultipleChunk_SingleThen_YieldAsyncMiddleman(self):
expected = [
lambda r: self.assertEqual([1, 2], r.get()),
lambda r: self.assertEqual([2, 3], r.get()),
lambda r: self.assertEqual([3, 4], r.get()),
lambda r: self.assertRaises(ChokeEvent, r.get),
]
check = checker(expected, self)
def middleMan(result):
r = result.get()
s1 = yield ServiceMock(chunks=[r, r + 1], T=self.T, ioLoop=self.io_loop, interval=0.001).execute()
s2 = yield
yield [s1, s2]
f = ServiceMock(chunks=[1, 2, 3], T=self.T, ioLoop=self.io_loop, interval=0.01).execute()
f.then(middleMan).then(check)
self.wait()
self.assertTrue(len(expected) == 0)
示例14: test_MultipleChunks_MultipleThen_ErrorMiddleman
# 需要导入模块: from cocaine.testing.mocks import ServiceMock [as 别名]
# 或者: from cocaine.testing.mocks.ServiceMock import then [as 别名]
def test_MultipleChunks_MultipleThen_ErrorMiddleman(self):
expected = [
lambda r: self.assertEqual(2, r.get()),
lambda r: self.assertRaises(ValueError, r.get),
lambda r: self.assertEqual(6, r.get()),
lambda r: self.assertRaises(ChokeEvent, r.get),
]
check = checker(expected, self)
def middleMan(result):
if result.get() == 2:
raise ValueError('Middleman')
else:
return result.get() * 2
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)
示例15: test_MultipleChunk_MultipleThen_SyncTransformation
# 需要导入模块: from cocaine.testing.mocks import ServiceMock [as 别名]
# 或者: from cocaine.testing.mocks.ServiceMock import then [as 别名]
def test_MultipleChunk_MultipleThen_SyncTransformation(self):
expected = [
lambda r: self.assertEqual({"app": "info"}, r.get()),
lambda r: self.assertRaises(ChokeEvent, r.get),
]
check = checker(expected, self)
def firstStep(result):
r = result.get()
return {"app": r}
def secondStep(result):
r = result.get()
return r
s = ServiceMock(chunks=["info"], T=self.T, ioLoop=self.io_loop).execute()
s.then(firstStep).then(secondStep).then(check)
self.wait()
self.assertTrue(len(expected) == 0)