async def test_register_service(): pipeline = Pipeline("test_name") service = ServiceForTests(pipeline) pipeline._register_service(service) assert pipeline._services == {service.id: service} assert pipeline._depends_on == {service.id: {}}
async def test_service_raise_exception_with_allow_failure(): pipeline = Pipeline("test", config={"serviceraise": {"allow_failure": True}}) service = ServiceRaise(pipeline) pipeline._register_service(service) await pipeline.run() assert service.is_finished assert service.status == ServiceStatus.FAILED assert service.result is None
async def test_register_service_with_depends_on(): pipeline = Pipeline("test_name") first_service = ServiceForTests(pipeline) pipeline._register_service(first_service) second_service = ServiceForTests(pipeline) pipeline._register_service(second_service, depends_on={ServiceForTests: "sha1"}) assert pipeline._services == {first_service.id: first_service, second_service.id: second_service} assert pipeline._depends_on == {first_service.id: {}, second_service.id: {first_service: ["sha1"]}} assert list(pipeline.services) == [first_service, second_service]
async def test_service_with_timeout(): pipeline = Pipeline("test", config={"servicewithtimeout": {"timeout": 0.1}}) service = ServiceWithTimeout(pipeline) pipeline._register_service(service) with pytest.raises(asyncio.TimeoutError): await pipeline.run() assert service.is_finished assert service.status == ServiceStatus.FAILED assert service.result is None
async def test_service_raise_exception(): pipeline = Pipeline("test") service = ServiceRaise(pipeline) pipeline._register_service(service) with pytest.raises(ZeroDivisionError): await pipeline.run() assert service.is_finished assert service.status == ServiceStatus.FAILED assert service.result is None
async def test_service_return_result(): config = { "servicefortests": { "__kwargs": { "this": "is", "awesome": "result" } } } pipeline = Pipeline("test", config=config) service = ServiceForTests(pipeline) pipeline._register_service(service) await pipeline.run() assert service.is_finished assert service.status == ServiceStatus.DONE assert service.result == {"this": "is", "awesome": "result"}
async def test_pipeline_build_service_kwargs_with_dependence(): class ServiceForTests1(ServiceForTests): ... class ServiceForTests2(ServiceForTests): ... config = { "servicefortests1": { "__kwargs": { "a": 23, "b": 42 } } } pipeline = Pipeline("test", config=config) service = ServiceForTests(pipeline) service.result = { "a": 48, "b.c.d.e": "bad key", "e": "fake", "b": { "e": "fake", "c": { "e": "fake", "d": { "e": 1516, "j": 12 } }} } pipeline._register_service(service) service1 = ServiceForTests1(pipeline) pipeline._register_service(service1, depends_on={ServiceForTests: ["a", "b.c.d.e"]}) kwargs = pipeline.build_service_kwargs(service1, 1) assert kwargs == {"a": 23, "b": 42, "__service_number": 1, "servicefortests.a": 48, "servicefortests.b.c.d.e": 1516} service3 = ServiceForTests2(pipeline) pipeline._register_service(service3, depends_on={ServiceForTests: "bad_key"}) with pytest.raises(AioFlowKeyError): pipeline.build_service_kwargs(service3, 2)