Skip to content

Commit

Permalink
test(server): convert bash test to python
Browse files Browse the repository at this point in the history
  • Loading branch information
eginhard committed Jan 10, 2025
1 parent 38fda7f commit 81b6340
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 23 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ test_xtts:

test_aux: ## run aux tests.
coverage run -m pytest -x -v --durations=0 tests/aux_tests
./run_bash_tests.sh

test_zoo: ## run zoo tests.
coverage run -m pytest -x -v --durations=0 tests/zoo_tests/test_models.py
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ exclude = [
"/.readthedocs.yml",
"/Makefile",
"/dockerfiles",
"/run_bash_tests.sh",
"/scripts",
"/tests",
]
Expand Down
6 changes: 0 additions & 6 deletions run_bash_tests.sh

This file was deleted.

47 changes: 47 additions & 0 deletions tests/aux_tests/test_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import os
import signal
import socket
import subprocess
import time
import wave

import pytest
import requests

PORT = 5003


def wait_for_server(host, port, timeout=30):
start_time = time.time()
while time.time() - start_time < timeout:
try:
with socket.create_connection((host, port), timeout=2):
return True
except (OSError, ConnectionRefusedError):
time.sleep(1)
raise TimeoutError(f"Server at {host}:{port} did not start within {timeout} seconds.")


@pytest.fixture(scope="module", autouse=True)
def start_flask_server():
server_process = subprocess.Popen(
["python", "-m", "TTS.server.server", "--port", str(PORT)],
)
wait_for_server("localhost", PORT)
yield
os.kill(server_process.pid, signal.SIGTERM)
server_process.wait()


def test_flask_server(tmp_path):
url = f"http://localhost:{PORT}/api/tts?text=synthesis%20schmynthesis"
response = requests.get(url)
assert response.status_code == 200, f"Request failed with status code {response.status_code}"

wav_path = tmp_path / "output.wav"
with wav_path.open("wb") as f:
f.write(response.content)

with wave.open(str(wav_path), "rb") as wav_file:
num_frames = wav_file.getnframes()
assert num_frames > 0, "WAV file contains no frames."
15 changes: 0 additions & 15 deletions tests/bash_tests/test_demo_server.sh

This file was deleted.

0 comments on commit 81b6340

Please sign in to comment.