Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

整理: e2e single API テスト vol 8 #1166

Merged
merged 13 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions test/e2e/single_api/__snapshots__/test_frame_synthesis.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# serializer version: 1
# name: test_post_frame_synthesis_200
'MD5:ee67a7e22f9e6c2ec519796610a2ed21'
# ---
4 changes: 4 additions & 0 deletions test/e2e/single_api/__snapshots__/test_synthesis.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# serializer version: 1
# name: test_post_synthesis_200
'MD5:c337b99b27bc5bc461faa58df029b302'
# ---
4 changes: 2 additions & 2 deletions test/e2e/single_api/test_audio_query.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
AudioQuery APIのテスト
/audio_query API のテスト
"""

from test.utility import round_floats
Expand All @@ -8,7 +8,7 @@
from syrupy.assertion import SnapshotAssertion


def test_speakerを指定して音声合成クエリが取得できる(
def test_post_audio_query_200(
client: TestClient, snapshot_json: SnapshotAssertion
) -> None:
response = client.post("/audio_query", params={"text": "テストです", "speaker": 0})
Expand Down
17 changes: 16 additions & 1 deletion test/e2e/single_api/test_frame_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
/frame_synthesis API のテスト
"""

import io
from test.utility import hash_long_string, round_floats

import soundfile as sf
from fastapi.testclient import TestClient
from syrupy.assertion import SnapshotAssertion


def test_post_frame_synthesis_200(client: TestClient) -> None:
def test_post_frame_synthesis_200(
client: TestClient, snapshot: SnapshotAssertion
) -> None:
query = {
"f0": [
0.0,
Expand Down Expand Up @@ -81,3 +88,11 @@ def test_post_frame_synthesis_200(client: TestClient) -> None:
}
response = client.post("/frame_synthesis", params={"speaker": 0}, json=query)
assert response.status_code == 200

# FileResponse 内の .wav から抽出された音声波形が一致する
assert response.headers["content-type"] == "audio/wav"
wave = sf.read(io.BytesIO(response.read()))[0].tolist()
# NOTE: Linux-Windows 数値精度問題に対するワークアラウンド
tarepan marked this conversation as resolved.
Show resolved Hide resolved
wave = round_floats(wave, 2)
wave_str = " ".join(map(lambda point: str(point), wave))
Copy link
Member

@Hiroshiba Hiroshiba Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

たしかnumpy辺りはtobufferみたいなのでバイナリにできるので、それ渡すhash_long_bytesみたいなのをいつか作っても良いかもですね。
ちょっと正確でちょっと早そうでちょっと意図が明確、くらいの気持ちですが

Copy link
Contributor Author

@tarepan tarepan Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

numpy辺りはtobufferみたいなのでバイナリにできるので、それ渡すhash_long_bytesみたいなのをいつか作っても良い

round_floats() の入力が ndarray でなく float であり、現時点でこの実装をするのは難しそうです。
round_floats() 変更は本 PR で触っていない複数のファイル編集を要するため、別のリファクタリング PR で将来的に対処するのが review 上好ましいと考えます。

「本 PR では対処無し」の方針で問題ないでしょうか?

assert snapshot == hash_long_string(wave_str)
14 changes: 14 additions & 0 deletions test/e2e/single_api/test_multi_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,17 @@ def test_post_multi_synthesis_200(client: TestClient) -> None:
]
response = client.post("/multi_synthesis", params={"speaker": 0}, json=queries)
assert response.status_code == 200

# FIXME: ZIP ファイル内の .wav に Linux-Windows 数値精度問題があるため、スナップショットテストには解凍が必要
tarepan marked this conversation as resolved.
Show resolved Hide resolved
assert response.headers["content-type"] == "application/zip"
# import io
# from test.utility import hash_long_string, round_floats
# import soundfile as sf
# from syrupy.assertion import SnapshotAssertion
# FileResponse 内の zip ファイルに圧縮された .wav から抽出された音声波形が一致する
# # zip 解凍
# waves = concatenate_func(map(lambda path: sf.read(path)[0].tolist(), wave_paths))
# # NOTE: Linux-Windows 数値精度問題に対するワークアラウンド
# waves = round_floats(waves, 2)
# waves_str = " ".join(map(lambda point: str(point), waves))
# assert snapshot == hash_long_string(waves_str)
14 changes: 13 additions & 1 deletion test/e2e/single_api/test_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
/synthesis API のテスト
"""

import io
from test.e2e.single_api.utils import gen_mora
from test.utility import hash_long_string, round_floats

import soundfile as sf
from fastapi.testclient import TestClient
from syrupy.assertion import SnapshotAssertion


def test_post_synthesis_200(client: TestClient) -> None:
def test_post_synthesis_200(client: TestClient, snapshot: SnapshotAssertion) -> None:
query = {
"accent_phrases": [
{
Expand All @@ -33,3 +37,11 @@ def test_post_synthesis_200(client: TestClient) -> None:
}
response = client.post("/synthesis", params={"speaker": 0}, json=query)
assert response.status_code == 200

# FileResponse 内の .wav から抽出された音声波形が一致する
assert response.headers["content-type"] == "audio/wav"
wave = sf.read(io.BytesIO(response.read()))[0].tolist()
# NOTE: Linux-Windows 数値精度問題に対するワークアラウンド
tarepan marked this conversation as resolved.
Show resolved Hide resolved
wave = round_floats(wave, 2)
wave_str = " ".join(map(lambda point: str(point), wave))
assert snapshot == hash_long_string(wave_str)
13 changes: 13 additions & 0 deletions test/e2e/single_api/test_synthesis_morphing.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,16 @@ def test_post_synthesis_morphing_200(client: TestClient) -> None:
json=queries,
)
assert response.status_code == 200

# FIXME: Linux-MacOS 数値精度問題によりスナップショットテストがコケる
tarepan marked this conversation as resolved.
Show resolved Hide resolved
# import io
# from test.utility import hash_long_string, round_floats
# import soundfile as sf
# from syrupy.assertion import SnapshotAssertion
# # FileResponse 内の .wav から抽出された音声波形が一致する
# assert response.headers["content-type"] == "audio/wav"
# wave = sf.read(io.BytesIO(response.read()))[0].tolist()
# # NOTE: Linux-Windows 数値精度問題に対するワークアラウンド
# wave = round_floats(wave, 2)
# wave_str = " ".join(map(lambda point: str(point), wave))
# assert snapshot == hash_long_string(wave_str)
Loading