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

整理: 巨大なバイナリファイルがあってもsnapshotが良い感じに取れるように #1050

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 8 additions & 19 deletions test/e2e/test_speakers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
TODO: 話者と歌手の両ドメイン共通のドメイン用語を定め、このテストファイル名を変更する。
"""

from test.utility import hash_long_string

from fastapi.testclient import TestClient
from pydantic import parse_obj_as
from syrupy import filters
from syrupy.assertion import SnapshotAssertion

from voicevox_engine.metas.Metas import Speaker
Expand All @@ -23,15 +24,9 @@ def test_話者の情報を取得できる(client: TestClient, snapshot_json: Sn
response = client.get(
"/speaker_info", params={"speaker_uuid": speaker.speaker_uuid}
)
assert (
snapshot_json(
name=speaker.speaker_uuid,
exclude=filters.props(
"portrait", "icon", "voice_samples"
), # バイナリファイル系は除外 FIXME: 除外せずにハッシュ化する
)
== response.json()
)
assert snapshot_json(
name=speaker.speaker_uuid,
) == hash_long_string(response.json())


def test_歌手一覧が取得できる(client: TestClient, snapshot_json: SnapshotAssertion) -> None:
Expand All @@ -46,12 +41,6 @@ def test_歌手の情報を取得できる(client: TestClient, snapshot_json: Sn
response = client.get(
"/singer_info", params={"speaker_uuid": singer.speaker_uuid}
)
assert (
snapshot_json(
name=singer.speaker_uuid,
exclude=filters.props(
"portrait", "icon", "voice_samples"
), # バイナリファイル系は除外 FIXME: 除外せずにハッシュ化する
)
== response.json()
)
assert snapshot_json(
name=singer.speaker_uuid,
) == hash_long_string(response.json())
17 changes: 17 additions & 0 deletions test/utility.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import hashlib
import json
from typing import Any

Expand All @@ -19,3 +20,19 @@ def round_floats(value: Any, round_value: int) -> Any:
def pydantic_to_native_type(value: Any) -> Any:
"""pydanticの型をnativeな型に変換する"""
return json.loads(json.dumps(value, default=pydantic_encoder))


def hash_long_string(value: Any) -> Any:
"""文字数が1000文字を超えるものはハッシュ化する"""

def to_hash(value: str) -> str:
return "MD5:" + hashlib.md5(value.encode()).hexdigest()

if isinstance(value, str):
return value if len(value) <= 1000 else to_hash(value)
elif isinstance(value, list):
return [hash_long_string(v) for v in value]
elif isinstance(value, dict):
return {k: hash_long_string(v) for k, v in value.items()}
else:
return value
Loading