Skip to content

Commit

Permalink
remove litestar dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkkul committed Dec 4, 2024
1 parent 938bbf4 commit a1113bc
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 65 deletions.
128 changes: 64 additions & 64 deletions journey_tests/test_litestar.py
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
from contextlib import asynccontextmanager

from litestar import Litestar, get
from litestar.datastructures import State
from litestar.testing import TestClient

from journey_tests.journeys import AsyncJourneys, SyncJourneys


class MyState(State):
sync: SyncJourneys
async_: AsyncJourneys


@asynccontextmanager
async def lifespan(app: Litestar):
sync = SyncJourneys.use()
async_ = await AsyncJourneys.use()
app.state.sync = sync
app.state.async_ = async_
try:
yield
finally:
sync.close()
await async_.close()


@get("/sync-in-sync", sync_to_thread=True)
def sync_in_sync(state: MyState) -> dict:
return state.sync.simple()


@get("/sync-in-async", sync_to_thread=True)
async def sync_in_async(state: MyState) -> dict:
return state.sync.simple()


@get("/async-in-async")
async def async_in_async(state: MyState) -> dict:
return await state.async_.simple()


app = Litestar(route_handlers=[sync_in_sync, sync_in_async, async_in_async], lifespan=[lifespan])


def test_sync_in_sync() -> None:
with TestClient(app=app) as client:
res = client.get("/sync-in-sync")
assert res.status_code == 200
assert len(res.json()) == 100


def test_sync_in_async() -> None:
with TestClient(app=app) as client:
res = client.get("/sync-in-async")
assert res.status_code == 200
assert len(res.json()) == 100


def test_async_in_async() -> None:
with TestClient(app=app) as client:
res = client.get("/async-in-async")
assert res.status_code == 200
assert len(res.json()) == 100
# litestart not yet supported by 3.13
# from contextlib import asynccontextmanager
#
# from litestar import Litestar, get
# from litestar.datastructures import State
# from litestar.testing import TestClient
#
# from journey_tests.journeys import AsyncJourneys, SyncJourneys
#
# class MyState(State):
# sync: SyncJourneys
# async_: AsyncJourneys
#
#
# @asynccontextmanager
# async def lifespan(app: Litestar):
# sync = SyncJourneys.use()
# async_ = await AsyncJourneys.use()
# app.state.sync = sync
# app.state.async_ = async_
# try:
# yield
# finally:
# sync.close()
# await async_.close()
#
#
# @get("/sync-in-sync", sync_to_thread=True)
# def sync_in_sync(state: MyState) -> dict:
# return state.sync.simple()
#
#
# @get("/sync-in-async", sync_to_thread=True)
# async def sync_in_async(state: MyState) -> dict:
# return state.sync.simple()
#
#
# @get("/async-in-async")
# async def async_in_async(state: MyState) -> dict:
# return await state.async_.simple()
#
#
# app = Litestar(route_handlers=[sync_in_sync, sync_in_async, async_in_async], lifespan=[lifespan])
#
#
# def test_sync_in_sync() -> None:
# with TestClient(app=app) as client:
# res = client.get("/sync-in-sync")
# assert res.status_code == 200
# assert len(res.json()) == 100
#
#
# def test_sync_in_async() -> None:
# with TestClient(app=app) as client:
# res = client.get("/sync-in-async")
# assert res.status_code == 200
# assert len(res.json()) == 100
#
#
# def test_async_in_async() -> None:
# with TestClient(app=app) as client:
# res = client.get("/async-in-async")
# assert res.status_code == 200
# assert len(res.json()) == 100
2 changes: 1 addition & 1 deletion requirements-devel.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ polars>=0.20.26,<1.10.0

fastapi>=0.111.0,<1.0.0
flask[async]>=2.0.0,<3.0.0
litestar>=2.13.0,<3.0.0
# litestar>=2.13.0,<3.0.0 does not support python 3.13 yet - reenable when it does

mypy==1.13.0
mypy-extensions==1.0.0
Expand Down

0 comments on commit a1113bc

Please sign in to comment.