Skip to content

Commit

Permalink
chore: auto-fix ruff errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedir Zadniprovskyi authored and fedirz committed Sep 30, 2024
1 parent 7f36990 commit 1a02399
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 23 deletions.
6 changes: 3 additions & 3 deletions tests/api_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 4 additions & 3 deletions tests/api_timestamp_granularities_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]


Expand All @@ -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:
Expand All @@ -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"
Expand Down
11 changes: 6 additions & 5 deletions tests/openai_timestamp_granularities_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
19 changes: 10 additions & 9 deletions tests/sse_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
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
import srt
import webvtt
import webvtt.vtt

from faster_whisper_server.api_models import (
CreateTranscriptionResponseJson,
CreateTranscriptionResponseVerboseJson,
)

FILE_PATHS = ["audio.wav"] # HACK
ENDPOINTS = [
"/v1/audio/transcriptions",
Expand All @@ -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:]
Expand All @@ -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:]
Expand All @@ -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:]
Expand All @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 1a02399

Please sign in to comment.