File size: 1,402 Bytes
f3d078e
313814b
bf48682
81fa68b
 
f3d078e
b8804a6
dc4f25f
f3d078e
313814b
23a3cae
 
313814b
 
 
dc4f25f
313814b
 
 
81fa68b
 
04d664a
23a3cae
81fa68b
bf48682
 
81fa68b
5aa421e
 
f3d078e
 
bf48682
 
f3d078e
 
 
b8804a6
 
 
a5d2e48
 
23a3cae
a5d2e48
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from collections.abc import AsyncGenerator, Generator
import logging
import os

from fastapi.testclient import TestClient
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"]


def pytest_configure() -> None:
    for logger_name in disable_loggers:
        logger = logging.getLogger(logger_name)
        logger.disabled = True


# NOTE: not being used. Keeping just in case
@pytest.fixture
def client() -> Generator[TestClient, None, None]:
    os.environ["WHISPER__MODEL"] = "Systran/faster-whisper-tiny.en"
    with TestClient(create_app()) as client:
        yield client


@pytest_asyncio.fixture()
async def aclient() -> AsyncGenerator[AsyncClient, None]:
    os.environ["WHISPER__MODEL"] = "Systran/faster-whisper-tiny.en"
    async with AsyncClient(transport=ASGITransport(app=create_app()), base_url="http://test") as aclient:
        yield aclient


@pytest_asyncio.fixture()
def openai_client(aclient: AsyncClient) -> AsyncOpenAI:
    return AsyncOpenAI(api_key="cant-be-empty", http_client=aclient)


@pytest.fixture
def actual_openai_client() -> AsyncOpenAI:
    return AsyncOpenAI(
        base_url="https://api.openai.com/v1"
    )  # `base_url` is provided in case `OPENAI_API_BASE_URL` is set to a different value