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

整理: CoreMockMockCoreWrapper で置き換え #1434

Merged
merged 6 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
19 changes: 18 additions & 1 deletion poetry.lock

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

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ flake8 = "^7.0.0"
isort = "^5.13.0"
mypy = "^1.10.0"
pytest = "^8.2.0"
pytest-mock = "^3.14.0"
coveralls = "^3.2.0"
poetry = "1.8.2"
poetry-plugin-export = "^1.8.0"
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pygments==2.18.0 ; python_version >= "3.11" and python_version < "3.12"
pyopenjtalk @ git+https://github.com/VOICEVOX/pyopenjtalk@b35fc89fe42948a28e33aed886ea145a51113f88 ; python_version >= "3.11" and python_version < "3.12"
pyproject-hooks==1.1.0 ; python_version >= "3.11" and python_version < "3.12"
pysen==0.11.0 ; python_version >= "3.11" and python_version < "3.12"
pytest-mock==3.14.0 ; python_version >= "3.11" and python_version < "3.12"
pytest==8.2.0 ; python_version >= "3.11" and python_version < "3.12"
python-multipart==0.0.9 ; python_version >= "3.11" and python_version < "3.12"
pywin32-ctypes==0.2.2 ; python_version >= "3.11" and python_version < "3.12" and sys_platform == "win32"
Expand Down
97 changes: 11 additions & 86 deletions test/unit/tts_pipeline/test_tts_engine.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import json
"""TTSEngine のテスト"""

from test.utility import pydantic_to_native_type, round_floats, summarize_big_ndarray
from unittest.mock import Mock

import numpy as np
import pytest
from numpy.typing import NDArray
from pytest_mock import MockerFixture
from syrupy.assertion import SnapshotAssertion

from voicevox_engine.dev.core.mock import MockCoreWrapper
Expand All @@ -29,81 +29,6 @@
from .tts_utils import gen_mora


def yukarin_s_mock(
length: int, phoneme_list: NDArray[np.int64], style_id: NDArray[np.int64]
) -> NDArray[np.float32]:
result = []
# mockとしての適当な処理、特に意味はない
for i in range(length):
result.append(round((phoneme_list[i] * 0.0625 + style_id).item(), 2))
return np.array(result, dtype=np.float32)


def yukarin_sa_mock(
length: int,
vowel_phoneme_list: NDArray[np.int64],
consonant_phoneme_list: NDArray[np.int64],
start_accent_list: NDArray[np.int64],
end_accent_list: NDArray[np.int64],
start_accent_phrase_list: NDArray[np.int64],
end_accent_phrase_list: NDArray[np.int64],
style_id: NDArray[np.int64],
) -> NDArray[np.float32]:
result = []
# mockとしての適当な処理、特に意味はない
for i in range(length):
result.append(
round(
(
(
vowel_phoneme_list[0][i]
+ consonant_phoneme_list[0][i]
+ start_accent_list[0][i]
+ end_accent_list[0][i]
+ start_accent_phrase_list[0][i]
+ end_accent_phrase_list[0][i]
)
* 0.0625
+ style_id
).item(),
2,
)
)
return np.array(result, dtype=np.float32)[np.newaxis]


def decode_mock(
length: int,
phoneme_size: int,
f0: NDArray[np.float32],
phoneme: NDArray[np.float32],
style_id: NDArray[np.int64],
) -> NDArray[np.float32]:
result = []
# mockとしての適当な処理、特に意味はない
for i in range(length):
result += [
(f0[i, 0] * (np.where(phoneme[i] == 1)[0] / phoneme_size) + style_id)
] * 256
return np.array(result, dtype=np.float32)


class MockCore:
default_sampling_rate = 24000
yukarin_s_forward = Mock(side_effect=yukarin_s_mock)
yukarin_sa_forward = Mock(side_effect=yukarin_sa_mock)
decode_forward = Mock(side_effect=decode_mock)

def metas(self) -> str:
return ""

def supported_devices(self) -> str:
return json.dumps({"cpu": True, "cuda": False, "dml": False})

def is_model_loaded(self, style_id: str) -> bool:
return True


def test_to_flatten_phonemes() -> None:
"""Test `to_flatten_phonemes`."""
# Inputs
Expand Down Expand Up @@ -191,10 +116,10 @@ def test_to_flatten_moras() -> None:
)


def test_update_length() -> None:
core = MockCore()
_yukarin_s_mock = core.yukarin_s_forward
tts_engine = TTSEngine(core=core) # type: ignore[arg-type]
def test_update_length(mocker: MockerFixture) -> None:
core = MockCoreWrapper()
_yukarin_s_mock = mocker.spy(core, "yukarin_s_forward")
tts_engine = TTSEngine(core=core)
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
# Inputs
hello_hiho = _gen_hello_hiho_accent_phrases()
# Indirect Outputs(yukarin_sに渡される値)
Expand All @@ -219,10 +144,10 @@ def test_update_length() -> None:
)


def test_update_pitch() -> None:
core = MockCore()
_yukarin_sa_mock = core.yukarin_sa_forward
tts_engine = TTSEngine(core=core) # type: ignore[arg-type]
def test_update_pitch(mocker: MockerFixture) -> None:
core = MockCoreWrapper()
_yukarin_sa_mock = mocker.spy(core, "yukarin_sa_forward")
tts_engine = TTSEngine(core=core)

# 空のリストでエラーを吐かないか
# Inputs
Expand Down
Loading