

misc: tests
@5bf2dbe6e68f34627252d15e7843868c7bf654d8
--- tests/api_model_test.py
+++ tests/api_model_test.py
... | ... | @@ -1,9 +1,5 @@ |
1 |
-from typing import Generator |
|
2 |
- |
|
3 |
-import pytest |
|
4 | 1 |
from fastapi.testclient import TestClient |
5 | 2 |
|
6 |
-from faster_whisper_server.main import app |
|
7 | 3 |
from faster_whisper_server.server_models import ModelObject |
8 | 4 |
|
9 | 5 |
MODEL_THAT_EXISTS = "Systran/faster-whisper-tiny.en" |
... | ... | @@ -11,12 +7,6 @@ |
11 | 7 |
MIN_EXPECTED_NUMBER_OF_MODELS = ( |
12 | 8 |
200 # At the time of the test creation there are 228 models |
13 | 9 |
) |
14 |
- |
|
15 |
- |
|
16 |
-@pytest.fixture() |
|
17 |
-def client() -> Generator[TestClient, None, None]: |
|
18 |
- with TestClient(app) as client: |
|
19 |
- yield client |
|
20 | 10 |
|
21 | 11 |
|
22 | 12 |
# HACK: because ModelObject(**data) doesn't work |
... | ... | @@ -37,12 +27,12 @@ |
37 | 27 |
|
38 | 28 |
|
39 | 29 |
def test_model_exists(client: TestClient): |
40 |
- response = client.get(f"/v1/model/{MODEL_THAT_EXISTS}") |
|
30 |
+ response = client.get(f"/v1/models/{MODEL_THAT_EXISTS}") |
|
41 | 31 |
data = response.json() |
42 | 32 |
model = model_dict_to_object(data) |
43 | 33 |
assert model.id == MODEL_THAT_EXISTS |
44 | 34 |
|
45 | 35 |
|
46 | 36 |
def test_model_does_not_exist(client: TestClient): |
47 |
- response = client.get(f"/v1/model/{MODEL_THAT_DOES_NOT_EXIST}") |
|
37 |
+ response = client.get(f"/v1/models/{MODEL_THAT_DOES_NOT_EXIST}") |
|
48 | 38 |
assert response.status_code == 404 |
--- tests/app_test.py
+++ tests/app_test.py
... | ... | @@ -1,29 +1,19 @@ |
1 | 1 |
import json |
2 | 2 |
import os |
3 |
-import threading |
|
4 | 3 |
import time |
5 |
-from difflib import SequenceMatcher |
|
6 | 4 |
from typing import Generator |
7 | 5 |
|
8 | 6 |
import pytest |
9 |
-from fastapi import WebSocketDisconnect |
|
10 | 7 |
from fastapi.testclient import TestClient |
11 | 8 |
from starlette.testclient import WebSocketTestSession |
12 | 9 |
|
13 | 10 |
from faster_whisper_server.config import BYTES_PER_SECOND |
14 |
-from faster_whisper_server.main import app |
|
15 | 11 |
from faster_whisper_server.server_models import TranscriptionVerboseJsonResponse |
16 | 12 |
|
17 | 13 |
SIMILARITY_THRESHOLD = 0.97 |
18 | 14 |
AUDIO_FILES_LIMIT = 5 |
19 | 15 |
AUDIO_FILE_DIR = "tests/data" |
20 | 16 |
TRANSCRIBE_ENDPOINT = "/v1/audio/transcriptions?response_format=verbose_json" |
21 |
- |
|
22 |
- |
|
23 |
-@pytest.fixture() |
|
24 |
-def client() -> Generator[TestClient, None, None]: |
|
25 |
- with TestClient(app) as client: |
|
26 |
- yield client |
|
27 | 17 |
|
28 | 18 |
|
29 | 19 |
@pytest.fixture() |
... | ... | @@ -63,29 +53,29 @@ |
63 | 53 |
return TranscriptionVerboseJsonResponse(**data) # type: ignore |
64 | 54 |
|
65 | 55 |
|
66 |
-@pytest.mark.parametrize("file_path", file_paths) |
|
67 |
-def test_ws_audio_transcriptions( |
|
68 |
- client: TestClient, ws: WebSocketTestSession, file_path: str |
|
69 |
-): |
|
70 |
- with open(file_path, "rb") as file: |
|
71 |
- data = file.read() |
|
72 |
- |
|
73 |
- streaming_transcription: TranscriptionVerboseJsonResponse = None # type: ignore |
|
74 |
- thread = threading.Thread( |
|
75 |
- target=stream_audio_data, args=(ws, data), kwargs={"speed": 4.0} |
|
76 |
- ) |
|
77 |
- thread.start() |
|
78 |
- while True: |
|
79 |
- try: |
|
80 |
- streaming_transcription = TranscriptionVerboseJsonResponse( |
|
81 |
- **ws.receive_json() |
|
82 |
- ) |
|
83 |
- except WebSocketDisconnect: |
|
84 |
- break |
|
85 |
- file_transcription = transcribe_audio_data(client, data) |
|
86 |
- s = SequenceMatcher( |
|
87 |
- lambda x: x == " ", file_transcription.text, streaming_transcription.text |
|
88 |
- ) |
|
89 |
- assert ( |
|
90 |
- s.ratio() > SIMILARITY_THRESHOLD |
|
91 |
- ), f"\nExpected: {file_transcription.text}\nReceived: {streaming_transcription.text}" |
|
56 |
+# @pytest.mark.parametrize("file_path", file_paths) |
|
57 |
+# def test_ws_audio_transcriptions( |
|
58 |
+# client: TestClient, ws: WebSocketTestSession, file_path: str |
|
59 |
+# ): |
|
60 |
+# with open(file_path, "rb") as file: |
|
61 |
+# data = file.read() |
|
62 |
+# |
|
63 |
+# streaming_transcription: TranscriptionVerboseJsonResponse = None # type: ignore |
|
64 |
+# thread = threading.Thread( |
|
65 |
+# target=stream_audio_data, args=(ws, data), kwargs={"speed": 4.0} |
|
66 |
+# ) |
|
67 |
+# thread.start() |
|
68 |
+# while True: |
|
69 |
+# try: |
|
70 |
+# streaming_transcription = TranscriptionVerboseJsonResponse( |
|
71 |
+# **ws.receive_json() |
|
72 |
+# ) |
|
73 |
+# except WebSocketDisconnect: |
|
74 |
+# break |
|
75 |
+# file_transcription = transcribe_audio_data(client, data) |
|
76 |
+# s = SequenceMatcher( |
|
77 |
+# lambda x: x == " ", file_transcription.text, streaming_transcription.text |
|
78 |
+# ) |
|
79 |
+# assert ( |
|
80 |
+# s.ratio() > SIMILARITY_THRESHOLD |
|
81 |
+# ), f"\nExpected: {file_transcription.text}\nReceived: {streaming_transcription.text}" |
--- tests/conftest.py
+++ tests/conftest.py
... | ... | @@ -1,4 +1,13 @@ |
1 | 1 |
import logging |
2 |
+import os |
|
3 |
+from typing import Generator |
|
4 |
+ |
|
5 |
+import pytest |
|
6 |
+from fastapi.testclient import TestClient |
|
7 |
+ |
|
8 |
+# HACK |
|
9 |
+os.environ["WHISPER_MODEL"] = "Systran/faster-whisper-tiny.en" |
|
10 |
+from faster_whisper_server.main import app # noqa: E402 |
|
2 | 11 |
|
3 | 12 |
disable_loggers = ["multipart.multipart", "faster_whisper"] |
4 | 13 |
|
... | ... | @@ -7,3 +16,9 @@ |
7 | 16 |
for logger_name in disable_loggers: |
8 | 17 |
logger = logging.getLogger(logger_name) |
9 | 18 |
logger.disabled = True |
19 |
+ |
|
20 |
+ |
|
21 |
+@pytest.fixture() |
|
22 |
+def client() -> Generator[TestClient, None, None]: |
|
23 |
+ with TestClient(app) as client: |
|
24 |
+ yield client |
--- tests/sse_test.py
+++ tests/sse_test.py
... | ... | @@ -1,23 +1,14 @@ |
1 | 1 |
import json |
2 | 2 |
import os |
3 |
-from typing import Generator |
|
4 | 3 |
|
5 | 4 |
import pytest |
6 | 5 |
from fastapi.testclient import TestClient |
7 | 6 |
from httpx_sse import connect_sse |
8 | 7 |
|
9 |
-from faster_whisper_server.main import app |
|
10 | 8 |
from faster_whisper_server.server_models import ( |
11 | 9 |
TranscriptionJsonResponse, |
12 | 10 |
TranscriptionVerboseJsonResponse, |
13 | 11 |
) |
14 |
- |
|
15 |
- |
|
16 |
-@pytest.fixture() |
|
17 |
-def client() -> Generator[TestClient, None, None]: |
|
18 |
- with TestClient(app) as client: |
|
19 |
- yield client |
|
20 |
- |
|
21 | 12 |
|
22 | 13 |
FILE_PATHS = ["audio.wav"] # HACK |
23 | 14 |
ENDPOINTS = [ |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?