From 1a02399d7d303dba0f3690df153fee69ede5b9c9 Mon Sep 17 00:00:00 2001 From: Fedir Zadniprovskyi Date: Mon, 30 Sep 2024 08:55:38 -0700 Subject: [PATCH] chore: auto-fix ruff errors --- tests/api_model_test.py | 6 +++--- tests/api_timestamp_granularities_test.py | 7 ++++--- tests/conftest.py | 7 ++++--- tests/openai_timestamp_granularities_test.py | 11 ++++++----- tests/sse_test.py | 19 ++++++++++--------- 5 files changed, 27 insertions(+), 23 deletions(-) diff --git a/tests/api_model_test.py b/tests/api_model_test.py index c66659dd..08c74350 100644 --- a/tests/api_model_test.py +++ b/tests/api_model_test.py @@ -7,19 +7,19 @@ MIN_EXPECTED_NUMBER_OF_MODELS = 70 # At the time of the test creation there are 89 models -@pytest.mark.asyncio() +@pytest.mark.asyncio async def test_list_models(openai_client: AsyncOpenAI) -> None: models = (await openai_client.models.list()).data assert len(models) > MIN_EXPECTED_NUMBER_OF_MODELS -@pytest.mark.asyncio() +@pytest.mark.asyncio async def test_model_exists(openai_client: AsyncOpenAI) -> None: model = await openai_client.models.retrieve(MODEL_THAT_EXISTS) assert model.id == MODEL_THAT_EXISTS -@pytest.mark.asyncio() +@pytest.mark.asyncio async def test_model_does_not_exist(openai_client: AsyncOpenAI) -> None: with pytest.raises(openai.NotFoundError): await openai_client.models.retrieve(MODEL_THAT_DOES_NOT_EXIST) diff --git a/tests/api_timestamp_granularities_test.py b/tests/api_timestamp_granularities_test.py index fbf49e03..c855329b 100644 --- a/tests/api_timestamp_granularities_test.py +++ b/tests/api_timestamp_granularities_test.py @@ -2,12 +2,13 @@ from pathlib import Path -from faster_whisper_server.api_models import TIMESTAMP_GRANULARITIES_COMBINATIONS, TimestampGranularities from openai import AsyncOpenAI import pytest +from faster_whisper_server.api_models import TIMESTAMP_GRANULARITIES_COMBINATIONS, TimestampGranularities + -@pytest.mark.asyncio() +@pytest.mark.asyncio @pytest.mark.parametrize("timestamp_granularities", TIMESTAMP_GRANULARITIES_COMBINATIONS) async def test_api_json_response_format_and_timestamp_granularities_combinations( openai_client: AsyncOpenAI, @@ -20,7 +21,7 @@ async def test_api_json_response_format_and_timestamp_granularities_combinations ) -@pytest.mark.asyncio() +@pytest.mark.asyncio @pytest.mark.parametrize("timestamp_granularities", TIMESTAMP_GRANULARITIES_COMBINATIONS) async def test_api_verbose_json_response_format_and_timestamp_granularities_combinations( openai_client: AsyncOpenAI, diff --git a/tests/conftest.py b/tests/conftest.py index 36be228b..279390ce 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,12 +3,13 @@ import os from fastapi.testclient import TestClient -from faster_whisper_server.main import create_app from httpx import ASGITransport, AsyncClient from openai import AsyncOpenAI import pytest import pytest_asyncio +from faster_whisper_server.main import create_app + disable_loggers = ["multipart.multipart", "faster_whisper"] @@ -19,7 +20,7 @@ def pytest_configure() -> None: # NOTE: not being used. Keeping just in case -@pytest.fixture() +@pytest.fixture def client() -> Generator[TestClient, None, None]: os.environ["WHISPER__MODEL"] = "Systran/faster-whisper-tiny.en" with TestClient(create_app()) as client: @@ -38,7 +39,7 @@ def openai_client(aclient: AsyncClient) -> AsyncOpenAI: return AsyncOpenAI(api_key="cant-be-empty", http_client=aclient) -@pytest.fixture() +@pytest.fixture def actual_openai_client() -> AsyncOpenAI: return AsyncOpenAI( base_url="https://api.openai.com/v1" diff --git a/tests/openai_timestamp_granularities_test.py b/tests/openai_timestamp_granularities_test.py index 38c2e1b3..727db5d4 100644 --- a/tests/openai_timestamp_granularities_test.py +++ b/tests/openai_timestamp_granularities_test.py @@ -2,13 +2,14 @@ from pathlib import Path -from faster_whisper_server.api_models import TIMESTAMP_GRANULARITIES_COMBINATIONS, TimestampGranularities from openai import AsyncOpenAI, BadRequestError import pytest +from faster_whisper_server.api_models import TIMESTAMP_GRANULARITIES_COMBINATIONS, TimestampGranularities + -@pytest.mark.asyncio() -@pytest.mark.requires_openai() +@pytest.mark.asyncio +@pytest.mark.requires_openai @pytest.mark.parametrize("timestamp_granularities", TIMESTAMP_GRANULARITIES_COMBINATIONS) async def test_openai_json_response_format_and_timestamp_granularities_combinations( actual_openai_client: AsyncOpenAI, @@ -29,8 +30,8 @@ async def test_openai_json_response_format_and_timestamp_granularities_combinati ) -@pytest.mark.asyncio() -@pytest.mark.requires_openai() +@pytest.mark.asyncio +@pytest.mark.requires_openai @pytest.mark.parametrize("timestamp_granularities", TIMESTAMP_GRANULARITIES_COMBINATIONS) async def test_openai_verbose_json_response_format_and_timestamp_granularities_combinations( actual_openai_client: AsyncOpenAI, diff --git a/tests/sse_test.py b/tests/sse_test.py index ad03638d..c6d9704e 100644 --- a/tests/sse_test.py +++ b/tests/sse_test.py @@ -2,10 +2,6 @@ from pathlib import Path import anyio -from faster_whisper_server.api_models import ( - CreateTranscriptionResponseJson, - CreateTranscriptionResponseVerboseJson, -) from httpx import AsyncClient from httpx_sse import aconnect_sse import pytest @@ -13,6 +9,11 @@ import webvtt import webvtt.vtt +from faster_whisper_server.api_models import ( + CreateTranscriptionResponseJson, + CreateTranscriptionResponseVerboseJson, +) + FILE_PATHS = ["audio.wav"] # HACK ENDPOINTS = [ "/v1/audio/transcriptions", @@ -23,7 +24,7 @@ parameters = [(file_path, endpoint) for endpoint in ENDPOINTS for file_path in FILE_PATHS] -@pytest.mark.asyncio() +@pytest.mark.asyncio @pytest.mark.parametrize(("file_path", "endpoint"), parameters) async def test_streaming_transcription_text(aclient: AsyncClient, file_path: str, endpoint: str) -> None: extension = Path(file_path).suffix[1:] @@ -39,7 +40,7 @@ async def test_streaming_transcription_text(aclient: AsyncClient, file_path: str assert len(event.data) > 1 # HACK: 1 because of the space character that's always prepended -@pytest.mark.asyncio() +@pytest.mark.asyncio @pytest.mark.parametrize(("file_path", "endpoint"), parameters) async def test_streaming_transcription_json(aclient: AsyncClient, file_path: str, endpoint: str) -> None: extension = Path(file_path).suffix[1:] @@ -54,7 +55,7 @@ async def test_streaming_transcription_json(aclient: AsyncClient, file_path: str CreateTranscriptionResponseJson(**json.loads(event.data)) -@pytest.mark.asyncio() +@pytest.mark.asyncio @pytest.mark.parametrize(("file_path", "endpoint"), parameters) async def test_streaming_transcription_verbose_json(aclient: AsyncClient, file_path: str, endpoint: str) -> None: extension = Path(file_path).suffix[1:] @@ -69,7 +70,7 @@ async def test_streaming_transcription_verbose_json(aclient: AsyncClient, file_p CreateTranscriptionResponseVerboseJson(**json.loads(event.data)) -@pytest.mark.asyncio() +@pytest.mark.asyncio async def test_transcription_vtt(aclient: AsyncClient) -> None: async with await anyio.open_file("audio.wav", "rb") as f: data = await f.read() @@ -87,7 +88,7 @@ async def test_transcription_vtt(aclient: AsyncClient) -> None: webvtt.from_string(text) -@pytest.mark.asyncio() +@pytest.mark.asyncio async def test_transcription_srt(aclient: AsyncClient) -> None: async with await anyio.open_file("audio.wav", "rb") as f: data = await f.read()