ci: fix poetry

This commit is contained in:
long2ice
2023-02-15 10:45:19 +08:00
parent d04be274e9
commit 27acce3160
5 changed files with 14 additions and 7 deletions

View File

@@ -8,7 +8,7 @@ jobs:
- uses: actions/setup-python@v4 - uses: actions/setup-python@v4
with: with:
python-version: "3.x" python-version: "3.x"
- uses: abatilo/actions-poetry@v2.1.6 - uses: abatilo/actions-poetry@v2
- name: Config poetry - name: Config poetry
run: poetry config experimental.new-installer false run: poetry config experimental.new-installer false
- name: CI - name: CI

View File

@@ -42,14 +42,17 @@ async def get_date():
async def get_datetime(request: Request, response: Response): async def get_datetime(request: Request, response: Response):
return {"now": pendulum.now()} return {"now": pendulum.now()}
@cache(namespace="test") @cache(namespace="test")
async def func_kwargs(*unused_args, **kwargs): async def func_kwargs(*unused_args, **kwargs):
return kwargs return kwargs
@app.get("/kwargs") @app.get("/kwargs")
async def get_kwargs(name: str): async def get_kwargs(name: str):
return await func_kwargs(name, name=name) return await func_kwargs(name, name=name)
@app.get("/sync-me") @app.get("/sync-me")
@cache(namespace="test") @cache(namespace="test")
def sync_me(): def sync_me():

View File

@@ -13,7 +13,7 @@ class RedisBackend(Backend):
async def get_with_ttl(self, key: str) -> Tuple[int, str]: async def get_with_ttl(self, key: str) -> Tuple[int, str]:
async with self.redis.pipeline(transaction=not self.is_cluster) as pipe: async with self.redis.pipeline(transaction=not self.is_cluster) as pipe:
return await (pipe.ttl(key).get(key).execute()) return await pipe.ttl(key).get(key).execute()
async def get(self, key: str) -> Optional[str]: async def get(self, key: str) -> Optional[str]:
return await self.redis.get(key) return await self.redis.get(key)

View File

@@ -136,7 +136,9 @@ def cache(
try: try:
ttl, ret = await backend.get_with_ttl(cache_key) ttl, ret = await backend.get_with_ttl(cache_key)
except Exception: except Exception:
logger.warning(f"Error retrieving cache key '{cache_key}' from backend:", exc_info=True) logger.warning(
f"Error retrieving cache key '{cache_key}' from backend:", exc_info=True
)
ttl, ret = 0, None ttl, ret = 0, None
if not request: if not request:
if ret is not None: if ret is not None:
@@ -145,7 +147,9 @@ def cache(
try: try:
await backend.set(cache_key, coder.encode(ret), expire) await backend.set(cache_key, coder.encode(ret), expire)
except Exception: except Exception:
logger.warning(f"Error setting cache key '{cache_key}' in backend:", exc_info=True) logger.warning(
f"Error setting cache key '{cache_key}' in backend:", exc_info=True
)
return ret return ret
if request.method != "GET": if request.method != "GET":

View File

@@ -37,7 +37,6 @@ def test_datetime() -> None:
def test_date() -> None: def test_date() -> None:
"""Test path function without request or response arguments.""" """Test path function without request or response arguments."""
with TestClient(app) as client: with TestClient(app) as client:
response = client.get("/date") response = client.get("/date")
assert pendulum.parse(response.json()) == pendulum.today() assert pendulum.parse(response.json()) == pendulum.today()
@@ -68,8 +67,9 @@ def test_cache_response_obj() -> None:
assert get_cache_response.headers.get("cache-control") assert get_cache_response.headers.get("cache-control")
assert get_cache_response.headers.get("etag") assert get_cache_response.headers.get("etag")
def test_kwargs() -> None: def test_kwargs() -> None:
with TestClient(app) as client: with TestClient(app) as client:
name = "Jon" name = "Jon"
response = client.get("/kwargs", params = {"name": name}) response = client.get("/kwargs", params={"name": name})
assert response.json() == {"name": name} assert response.json() == {"name": name}