From 5540576dabca25e7ae2cf140a0dce4ba53bc74e8 Mon Sep 17 00:00:00 2001 From: tarepan Date: Fri, 24 May 2024 08:31:45 +0900 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86:=20mock=20TTS=20engine=20?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=20pytest=20=E5=8C=96=20(#1?= =?UTF-8?q?274)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: mock TTS engine テストを pytest 化 * fix: 型間違いと lint を修正 --- test/test_mock_tts_engine.py | 104 +++++++++++++++++------------------ 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/test/test_mock_tts_engine.py b/test/test_mock_tts_engine.py index eaeda7990..8c5fb5d67 100644 --- a/test/test_mock_tts_engine.py +++ b/test/test_mock_tts_engine.py @@ -1,5 +1,3 @@ -from unittest import TestCase - from voicevox_engine.dev.tts_engine.mock import MockTTSEngine from voicevox_engine.metas.Metas import StyleId from voicevox_engine.model import AccentPhrase, AudioQuery, Mora @@ -18,57 +16,59 @@ def _gen_mora(text: str, consonant: str | None, vowel: str) -> Mora: ) -class TestMockTTSEngine(TestCase): - def setUp(self) -> None: - super().setUp() +def _gen_accent_phrases() -> list[AccentPhrase]: + return [ + AccentPhrase( + moras=[ + _gen_mora("コ", "k", "o"), + _gen_mora("ン", None, "N"), + _gen_mora("ニ", "n", "i"), + _gen_mora("チ", "ch", "i"), + _gen_mora("ワ", "w", "a"), + ], + accent=5, + pause_mora=_gen_mora("、", None, "pau"), + ), + AccentPhrase( + moras=[ + _gen_mora("ヒ", "h", "i"), + _gen_mora("ホ", "h", "o"), + _gen_mora("デ", "d", "e"), + _gen_mora("ス", "s", "U"), + ], + accent=1, + pause_mora=None, + ), + ] + - self.accent_phrases_hello_hiho = [ - AccentPhrase( - moras=[ - _gen_mora("コ", "k", "o"), - _gen_mora("ン", None, "N"), - _gen_mora("ニ", "n", "i"), - _gen_mora("チ", "ch", "i"), - _gen_mora("ワ", "w", "a"), - ], - accent=5, - pause_mora=_gen_mora("、", None, "pau"), - ), - AccentPhrase( - moras=[ - _gen_mora("ヒ", "h", "i"), - _gen_mora("ホ", "h", "o"), - _gen_mora("デ", "d", "e"), - _gen_mora("ス", "s", "U"), - ], - accent=1, - pause_mora=None, - ), - ] - self.engine = MockTTSEngine() +def test_update_length() -> None: + """`.update_length()` がエラー無く生成をおこなう""" + engine = MockTTSEngine() + engine.update_length(_gen_accent_phrases(), StyleId(0)) - def test_update_length(self) -> None: - """`.update_length()` がエラー無く生成をおこなう""" - self.engine.update_length(self.accent_phrases_hello_hiho, StyleId(0)) - def test_update_pitch(self) -> None: - """`.update_pitch()` がエラー無く生成をおこなう""" - self.engine.update_pitch(self.accent_phrases_hello_hiho, StyleId(0)) +def test_update_pitch() -> None: + """`.update_pitch()` がエラー無く生成をおこなう""" + engine = MockTTSEngine() + engine.update_pitch(_gen_accent_phrases(), StyleId(0)) - def test_synthesize_wave(self) -> None: - """`.synthesize_wave()` がエラー無く生成をおこなう""" - self.engine.synthesize_wave( - AudioQuery( - accent_phrases=self.accent_phrases_hello_hiho, - speedScale=1, - pitchScale=0, - intonationScale=1, - volumeScale=1, - prePhonemeLength=0.1, - postPhonemeLength=0.1, - outputSamplingRate=24000, - outputStereo=False, - kana=create_kana(self.accent_phrases_hello_hiho), - ), - StyleId(0), - ) + +def test_synthesize_wave() -> None: + """`.synthesize_wave()` がエラー無く生成をおこなう""" + engine = MockTTSEngine() + engine.synthesize_wave( + AudioQuery( + accent_phrases=_gen_accent_phrases(), + speedScale=1, + pitchScale=0, + intonationScale=1, + volumeScale=1, + prePhonemeLength=0.1, + postPhonemeLength=0.1, + outputSamplingRate=24000, + outputStereo=False, + kana=create_kana(_gen_accent_phrases()), + ), + StyleId(0), + )