From 0389ee7c9662e8733e236d9dd5b3e05ad6e5bf89 Mon Sep 17 00:00:00 2001 From: Waket Zheng Date: Thu, 11 Apr 2024 17:15:59 +0800 Subject: [PATCH] fix ci error with Python<3.11 --- .github/workflows/ci.yml | 4 ++-- poetry.lock | 2 +- pyproject.toml | 1 + tests/favicon_online_cdn/test_race_favicon.py | 13 +++++++++++-- tests/http_race/test_http_race.py | 8 +++++++- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8285593..bbe54a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,12 +36,12 @@ jobs: - name: Install requirements run: | poetry install - poetry run pip install isort black ruff mypy bandit coveralls + poetry run pip install coveralls - name: Check code style and Type Hint run: | poetry run isort --check-only --src=fastapi_cdn_host . poetry run black --check --fast . - poetry run ruff . + poetry run ruff check . poetry run mypy . poetry run bandit -r fastapi_cdn_host - name: test diff --git a/poetry.lock b/poetry.lock index ce67671..aca3d77 100644 --- a/poetry.lock +++ b/poetry.lock @@ -905,4 +905,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "441b8dddbb0ea86cec543022224889b1964f2e951a84a509ded0b2c2341773d2" +content-hash = "637e6d7963718e840c5fd82933271a9b17e1ee8eab0f46a9171c341b83d2f03b" diff --git a/pyproject.toml b/pyproject.toml index 52f1aa8..5285b1b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,6 +20,7 @@ black = "*" ruff = "*" mypy = "*" pytest = "*" +coverage = "*" bandit = "^1.7.8" starlette = "*" pydantic = "*" diff --git a/tests/favicon_online_cdn/test_race_favicon.py b/tests/favicon_online_cdn/test_race_favicon.py index ec81117..20d0be9 100644 --- a/tests/favicon_online_cdn/test_race_favicon.py +++ b/tests/favicon_online_cdn/test_race_favicon.py @@ -1,11 +1,17 @@ # mypy: no-disallow-untyped-decorators import pytest -from asyncur import timeit from httpx import ASGITransport, AsyncClient from main import app from fastapi_cdn_host.client import CdnHostBuilder, CdnHostEnum, HttpSpider +try: + from asyncur import timeit +except ImportError: + + def timeit(f): # type:ignore + return f + @pytest.fixture(scope="module") def anyio_backend(): @@ -22,7 +28,10 @@ async def client(): @pytest.mark.anyio async def test_docs(client: AsyncClient): # nosec - urls = await timeit(CdnHostBuilder.sniff_the_fastest)() + if timeit is None: + urls = await CdnHostBuilder.sniff_the_fastest() + else: + urls = await timeit(CdnHostBuilder.sniff_the_fastest)() response = await client.get("/docs") text = response.text assert response.status_code == 200, text diff --git a/tests/http_race/test_http_race.py b/tests/http_race/test_http_race.py index cffd6c9..fe2549e 100644 --- a/tests/http_race/test_http_race.py +++ b/tests/http_race/test_http_race.py @@ -2,13 +2,19 @@ import time import pytest -from asyncur import timeit from httpx import AsyncClient from main import app from utils import TestClient, UvicornServer from fastapi_cdn_host.client import HttpSpider +try: + from asyncur import timeit +except ImportError: + + def timeit(f): # type:ignore + return f + @pytest.fixture(scope="module") def anyio_backend():