Skip to content

Commit

Permalink
Fix lifespan tests (#913)
Browse files Browse the repository at this point in the history
  • Loading branch information
florimondmanca committed Dec 26, 2020
1 parent 49c0a55 commit f8dd9fb
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions tests/test_lifespan.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,34 +155,41 @@ async def test():
assert "Application startup failed. Exiting." in error_messages.pop(0)


@pytest.mark.parametrize("mode", ("auto", "on"))
def test_lifespan_scope_asgi3app(mode):
def test_lifespan_scope_asgi3app():
async def asgi3app(scope, receive, send):
assert scope == {"version": "3.0", "spec_version": "2.0"}
assert scope == {
"type": "lifespan",
"asgi": {"version": "3.0", "spec_version": "2.0"},
}

async def test():
config = Config(app=asgi3app, lifespan=mode)
config = Config(app=asgi3app, lifespan="on")
lifespan = LifespanOn(config)

await lifespan.startup()
assert not lifespan.startup_failed
assert not lifespan.error_occured
assert not lifespan.should_exit
await lifespan.shutdown()

loop = asyncio.new_event_loop()
loop.run_until_complete(test())


@pytest.mark.parametrize("mode", ("auto", "on"))
def test_lifespan_scope_asgi2app(mode):
def test_lifespan_scope_asgi2app():
def asgi2app(scope):
assert scope == {"version": "2.0", "spec_version": "2.0"}
assert scope == {
"type": "lifespan",
"asgi": {"version": "2.0", "spec_version": "2.0"},
}

async def asgi(receive, send):
pass

return asgi

async def test():
config = Config(app=asgi2app, lifespan=mode)
config = Config(app=asgi2app, lifespan="on")
lifespan = LifespanOn(config)

await lifespan.startup()
Expand Down

0 comments on commit f8dd9fb

Please sign in to comment.