Skip to content

Commit

Permalink
整理: e2e 合成系 single API テスト (#1086)
Browse files Browse the repository at this point in the history
* refactor: TTS系 single_api テスト追加

* fix: モーラ生成 util と lint

* fix: lint

* fix: path

* fix: lint

* fix: テストスキップ形式
  • Loading branch information
tarepan authored Feb 29, 2024
1 parent 5339685 commit 341809b
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/e2e/single_api/test_accent_phrases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""
/accent_phrases API のテスト
"""

from fastapi.testclient import TestClient


def test_post_accent_phrases_200(client: TestClient) -> None:
response = client.post(
"/accent_phrases", params={"text": "テストです", "speaker": 0}
)
assert response.status_code == 200
21 changes: 21 additions & 0 deletions test/e2e/single_api/test_audio_query_from_preset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
/audio_query_from_preset API のテスト
"""

import pytest
from fastapi.testclient import TestClient


@pytest.mark.skip(reason="200の前提として別APIを要するプリセット登録が必要だから")
def test_post_audio_query_from_preset_200(client: TestClient) -> None:
response = client.post(
"/audio_query_from_preset", params={"text": "テストです", "preset_id": 0}
)
assert response.status_code == 200


def test_post_audio_query_from_preset_422(client: TestClient) -> None:
response = client.post(
"/audio_query_from_preset", params={"text": "テストです", "preset_id": 404}
)
assert response.status_code == 422
24 changes: 24 additions & 0 deletions test/e2e/single_api/test_mora_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
/mora_data API のテスト
"""

from test.e2e.single_api.utils import gen_mora

from fastapi.testclient import TestClient


def test_post_mora_data_200(client: TestClient) -> None:
accent_phrases = [
{
"moras": [
gen_mora("テ", "t", 2.3, "e", 0.8, 3.3),
gen_mora("ス", "s", 2.1, "U", 0.3, 0.0),
gen_mora("ト", "t", 2.3, "o", 1.8, 4.1),
],
"accent": 1,
"pause_mora": None,
"is_interrogative": False,
}
]
response = client.post("/mora_data", params={"speaker": 0}, json=accent_phrases)
assert response.status_code == 200
24 changes: 24 additions & 0 deletions test/e2e/single_api/test_mora_length.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
/mora_length API のテスト
"""

from test.e2e.single_api.utils import gen_mora

from fastapi.testclient import TestClient


def test_post_mora_length_200(client: TestClient) -> None:
accent_phrases = [
{
"moras": [
gen_mora("テ", "t", 2.3, "e", 0.8, 3.3),
gen_mora("ス", "s", 2.1, "U", 0.3, 0.0),
gen_mora("ト", "t", 2.3, "o", 1.8, 4.1),
],
"accent": 1,
"pause_mora": None,
"is_interrogative": False,
}
]
response = client.post("/mora_length", params={"speaker": 0}, json=accent_phrases)
assert response.status_code == 200
24 changes: 24 additions & 0 deletions test/e2e/single_api/test_mora_pitch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
/mora_pitch API のテスト
"""

from test.e2e.single_api.utils import gen_mora

from fastapi.testclient import TestClient


def test_post_mora_pitch_200(client: TestClient) -> None:
accent_phrases = [
{
"moras": [
gen_mora("テ", "t", 2.3, "e", 0.8, 3.3),
gen_mora("ス", "s", 2.1, "U", 0.3, 0.0),
gen_mora("ト", "t", 2.3, "o", 1.8, 4.1),
],
"accent": 1,
"pause_mora": None,
"is_interrogative": False,
}
]
response = client.post("/mora_pitch", params={"speaker": 0}, json=accent_phrases)
assert response.status_code == 200
35 changes: 35 additions & 0 deletions test/e2e/single_api/test_synthesis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
/synthesis API のテスト
"""

from test.e2e.single_api.utils import gen_mora

from fastapi.testclient import TestClient


def test_post_synthesis_200(client: TestClient) -> None:
query = {
"accent_phrases": [
{
"moras": [
gen_mora("テ", "t", 2.3, "e", 0.8, 3.3),
gen_mora("ス", "s", 2.1, "U", 0.3, 0.0),
gen_mora("ト", "t", 2.3, "o", 1.8, 4.1),
],
"accent": 1,
"pause_mora": None,
"is_interrogative": False,
}
],
"speedScale": 1.0,
"pitchScale": 1.0,
"intonationScale": 1.0,
"volumeScale": 1.0,
"prePhonemeLength": 0.1,
"postPhonemeLength": 0.1,
"outputSamplingRate": 24000,
"outputStereo": False,
"kana": "テ'_スト",
}
response = client.post("/synthesis", params={"speaker": 0}, json=query)
assert response.status_code == 200
28 changes: 28 additions & 0 deletions test/e2e/single_api/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from typing import TypedDict


class MoraForTest(TypedDict):
text: str
consonant: str
consonant_length: float
vowel: str
vowel_length: float
pitch: float


def gen_mora(
text: str,
consonant: str,
consonant_length: float,
vowel: str,
vowel_length: float,
pitch: float,
) -> MoraForTest:
return {
"text": text,
"consonant": consonant,
"consonant_length": consonant_length,
"vowel": vowel,
"vowel_length": vowel_length,
"pitch": pitch,
}

0 comments on commit 341809b

Please sign in to comment.