diff --git a/run.py b/run.py index ab4a0d09f..92a70d0ce 100644 --- a/run.py +++ b/run.py @@ -13,7 +13,7 @@ from io import BytesIO, TextIOWrapper from pathlib import Path from tempfile import NamedTemporaryFile, TemporaryFile -from typing import Annotated, Literal, Optional +from typing import Annotated, Any, Literal, Optional import soundfile import uvicorn @@ -211,7 +211,7 @@ async def block_origin_middleware( ) # 許可されていないAPIを無効化する - def check_disabled_mutable_api(): + def check_disabled_mutable_api() -> None: if disable_mutable_api: raise HTTPException( status_code=403, @@ -249,7 +249,7 @@ def check_disabled_mutable_api(): # _ = loop.create_task(cancellable_engine.catch_disconnection()) @app.on_event("startup") - def apply_user_dict(): + def apply_user_dict() -> None: update_dict() def get_engine(core_version: Optional[str]) -> TTSEngine: @@ -1389,7 +1389,7 @@ def setting_post( # BaseLibraryInfo/VvlibManifestモデルはAPIとして表には出ないが、エディタ側で利用したいので、手動で追加する # ref: https://fastapi.tiangolo.com/advanced/extending-openapi/#modify-the-openapi-schema - def custom_openapi(): + def custom_openapi() -> Any: if app.openapi_schema: return app.openapi_schema openapi_schema = get_openapi( diff --git a/test/e2e/conftest.py b/test/e2e/conftest.py index df5bb1744..61e6b9315 100644 --- a/test/e2e/conftest.py +++ b/test/e2e/conftest.py @@ -1,4 +1,5 @@ from pathlib import Path +from typing import Any import pytest from fastapi import FastAPI @@ -13,7 +14,7 @@ @pytest.fixture(scope="session") -def app_params(): +def app_params() -> dict[str, Any]: cores = initialize_cores(use_gpu=False, enable_mock=True) tts_engines = make_tts_engines_from_cores(cores) latest_core_version = get_latest_core_version(versions=list(tts_engines.keys())) diff --git a/test/preset/test_preset.py b/test/preset/test_preset.py index 1cd871a93..4a3b61609 100644 --- a/test/preset/test_preset.py +++ b/test/preset/test_preset.py @@ -15,52 +15,52 @@ class TestPresetManager(TestCase): - def setUp(self): + def setUp(self) -> None: self.tmp_dir = TemporaryDirectory() self.tmp_dir_path = Path(self.tmp_dir.name) - def tearDown(self): + def tearDown(self) -> None: self.tmp_dir.cleanup() - def test_validation(self): + def test_validation(self) -> None: preset_manager = PresetManager(preset_path=presets_test_1_yaml_path) presets = preset_manager.load_presets() self.assertFalse(presets is None) - def test_validation_same(self): + def test_validation_same(self) -> None: preset_manager = PresetManager(preset_path=presets_test_1_yaml_path) presets = preset_manager.load_presets() presets2 = preset_manager.load_presets() self.assertFalse(presets is None) self.assertEqual(presets, presets2) - def test_validation_2(self): + def test_validation_2(self) -> None: preset_manager = PresetManager(preset_path=presets_test_2_yaml_path) with self.assertRaises( PresetError, msg="プリセットの設定ファイルにミスがあります" ): preset_manager.load_presets() - def test_preset_id(self): + def test_preset_id(self) -> None: preset_manager = PresetManager(preset_path=presets_test_3_yaml_path) with self.assertRaises(PresetError, msg="プリセットのidに重複があります"): preset_manager.load_presets() - def test_empty_file(self): + def test_empty_file(self) -> None: preset_manager = PresetManager(preset_path=presets_test_4_yaml_path) with self.assertRaises( PresetError, msg="プリセットの設定ファイルが空の内容です" ): preset_manager.load_presets() - def test_not_exist_file(self): + def test_not_exist_file(self) -> None: preset_manager = PresetManager(preset_path=Path("test/presets-dummy.yaml")) with self.assertRaises( PresetError, msg="プリセットの設定ファイルが見つかりません" ): preset_manager.load_presets() - def test_add_preset(self): + def test_add_preset(self) -> None: temp_path = self.tmp_dir_path / "presets-test-temp.yaml" copyfile(presets_test_1_yaml_path, temp_path) preset_manager = PresetManager(preset_path=temp_path) @@ -86,7 +86,7 @@ def test_add_preset(self): self.assertEqual(_preset, preset) remove(temp_path) - def test_add_preset_load_failure(self): + def test_add_preset_load_failure(self) -> None: preset_manager = PresetManager(preset_path=presets_test_2_yaml_path) with self.assertRaises( PresetError, msg="プリセットの設定ファイルにミスがあります" @@ -108,7 +108,7 @@ def test_add_preset_load_failure(self): ) ) - def test_add_preset_conflict_id(self): + def test_add_preset_conflict_id(self) -> None: temp_path = self.tmp_dir_path / "presets-test-temp.yaml" copyfile(presets_test_1_yaml_path, temp_path) preset_manager = PresetManager(preset_path=temp_path) @@ -134,7 +134,7 @@ def test_add_preset_conflict_id(self): self.assertEqual(_preset, preset) remove(temp_path) - def test_add_preset_conflict_id2(self): + def test_add_preset_conflict_id2(self) -> None: temp_path = self.tmp_dir_path / "presets-test-temp.yaml" copyfile(presets_test_1_yaml_path, temp_path) preset_manager = PresetManager(preset_path=temp_path) @@ -160,7 +160,7 @@ def test_add_preset_conflict_id2(self): self.assertEqual(_preset, preset) remove(temp_path) - def test_add_preset_write_failure(self): + def test_add_preset_write_failure(self) -> None: temp_path = self.tmp_dir_path / "presets-test-temp.yaml" copyfile(presets_test_1_yaml_path, temp_path) preset_manager = PresetManager(preset_path=temp_path) @@ -188,7 +188,7 @@ def test_add_preset_write_failure(self): self.assertEqual(len(preset_manager.presets), 2) remove(temp_path) - def test_update_preset(self): + def test_update_preset(self) -> None: temp_path = self.tmp_dir_path / "presets-test-temp.yaml" copyfile(presets_test_1_yaml_path, temp_path) preset_manager = PresetManager(preset_path=temp_path) @@ -214,7 +214,7 @@ def test_update_preset(self): self.assertEqual(_preset, preset) remove(temp_path) - def test_update_preset_load_failure(self): + def test_update_preset_load_failure(self) -> None: preset_manager = PresetManager(preset_path=presets_test_2_yaml_path) with self.assertRaises( PresetError, msg="プリセットの設定ファイルにミスがあります" @@ -236,7 +236,7 @@ def test_update_preset_load_failure(self): ) ) - def test_update_preset_not_found(self): + def test_update_preset_not_found(self) -> None: temp_path = self.tmp_dir_path / "presets-test-temp.yaml" copyfile(presets_test_1_yaml_path, temp_path) preset_manager = PresetManager(preset_path=temp_path) @@ -259,7 +259,7 @@ def test_update_preset_not_found(self): self.assertEqual(len(preset_manager.presets), 2) remove(temp_path) - def test_update_preset_write_failure(self): + def test_update_preset_write_failure(self) -> None: temp_path = self.tmp_dir_path / "presets-test-temp.yaml" copyfile(presets_test_1_yaml_path, temp_path) preset_manager = PresetManager(preset_path=temp_path) @@ -288,7 +288,7 @@ def test_update_preset_write_failure(self): self.assertEqual(preset_manager.presets[0].name, "test") remove(temp_path) - def test_delete_preset(self): + def test_delete_preset(self) -> None: temp_path = self.tmp_dir_path / "presets-test-temp.yaml" copyfile(presets_test_1_yaml_path, temp_path) preset_manager = PresetManager(preset_path=temp_path) @@ -297,14 +297,14 @@ def test_delete_preset(self): self.assertEqual(len(preset_manager.presets), 1) remove(temp_path) - def test_delete_preset_load_failure(self): + def test_delete_preset_load_failure(self) -> None: preset_manager = PresetManager(preset_path=presets_test_2_yaml_path) with self.assertRaises( PresetError, msg="プリセットの設定ファイルにミスがあります" ): preset_manager.delete_preset(10) - def test_delete_preset_not_found(self): + def test_delete_preset_not_found(self) -> None: temp_path = self.tmp_dir_path / "presets-test-temp.yaml" copyfile(presets_test_1_yaml_path, temp_path) preset_manager = PresetManager(preset_path=temp_path) @@ -313,7 +313,7 @@ def test_delete_preset_not_found(self): self.assertEqual(len(preset_manager.presets), 2) remove(temp_path) - def test_delete_preset_write_failure(self): + def test_delete_preset_write_failure(self) -> None: temp_path = self.tmp_dir_path / "presets-test-temp.yaml" copyfile(presets_test_1_yaml_path, temp_path) preset_manager = PresetManager(preset_path=temp_path) diff --git a/test/setting/test_setting.py b/test/setting/test_setting.py index 468e76b11..6b4d63d4c 100644 --- a/test/setting/test_setting.py +++ b/test/setting/test_setting.py @@ -7,11 +7,11 @@ class TestSettingLoader(TestCase): - def setUp(self): + def setUp(self) -> None: self.tmp_dir = TemporaryDirectory() self.tmp_dir_path = Path(self.tmp_dir.name) - def test_loading_1(self): + def test_loading_1(self) -> None: setting_loader = SettingHandler(Path("not_exist.yaml")) settings = setting_loader.load() @@ -20,7 +20,7 @@ def test_loading_1(self): {"allow_origin": None, "cors_policy_mode": CorsPolicyMode.localapps}, ) - def test_loading_2(self): + def test_loading_2(self) -> None: setting_loader = SettingHandler( setting_file_path=Path("test/setting/setting-test-load-1.yaml") ) @@ -31,7 +31,7 @@ def test_loading_2(self): {"allow_origin": None, "cors_policy_mode": CorsPolicyMode.localapps}, ) - def test_loading_3(self): + def test_loading_3(self) -> None: setting_loader = SettingHandler( setting_file_path=Path("test/setting/setting-test-load-2.yaml") ) @@ -42,7 +42,7 @@ def test_loading_3(self): {"allow_origin": None, "cors_policy_mode": "all"}, ) - def test_loading_4(self): + def test_loading_4(self) -> None: setting_loader = SettingHandler( setting_file_path=Path("test/setting/setting-test-load-3.yaml") ) @@ -56,7 +56,7 @@ def test_loading_4(self): }, ) - def test_dump(self): + def test_dump(self) -> None: setting_loader = SettingHandler( setting_file_path=Path(self.tmp_dir_path / "setting-test-dump.yaml") ) @@ -69,5 +69,5 @@ def test_dump(self): {"allow_origin": None, "cors_policy_mode": CorsPolicyMode.localapps}, ) - def tearDown(self): + def tearDown(self) -> None: self.tmp_dir.cleanup() diff --git a/test/test_connect_base64_waves.py b/test/test_connect_base64_waves.py index 96cf92d1b..2bdc54abb 100644 --- a/test/test_connect_base64_waves.py +++ b/test/test_connect_base64_waves.py @@ -55,7 +55,7 @@ def generate_sine_wave_base64(seconds: float, samplerate: int, frequency: float) class TestConnectBase64Waves(TestCase): - def test_connect(self): + def test_connect(self) -> None: samplerate = 1000 wave = generate_sine_wave_ndarray( seconds=2, samplerate=samplerate, frequency=10 @@ -70,10 +70,10 @@ def test_connect(self): self.assertTrue((wave_x2_ref == wave_x2).all()) - def test_no_wave_error(self): + def test_no_wave_error(self) -> None: self.assertRaises(ConnectBase64WavesException, connect_base64_waves, waves=[]) - def test_invalid_base64_error(self): + def test_invalid_base64_error(self) -> None: wave_1000hz = generate_sine_wave_base64( seconds=2, samplerate=1000, frequency=10 ) @@ -87,7 +87,7 @@ def test_invalid_base64_error(self): ], ) - def test_invalid_wave_file_error(self): + def test_invalid_wave_file_error(self) -> None: wave_1000hz = generate_sine_wave_bytes(seconds=2, samplerate=1000, frequency=10) wave_1000hz_broken_bytes = wave_1000hz[1:] # remove head 1 byte wave_1000hz_broken = encode_base64(wave_1000hz_broken_bytes) @@ -100,7 +100,7 @@ def test_invalid_wave_file_error(self): ], ) - def test_different_frequency(self): + def test_different_frequency(self) -> None: wave_24000hz = generate_sine_wave_ndarray( seconds=1, samplerate=24000, frequency=10 ) @@ -118,7 +118,7 @@ def test_different_frequency(self): self.assertEqual(wave_x2_ref.shape, wave_x2.shape) numpy.testing.assert_array_almost_equal(wave_x2_ref, wave_x2) - def test_different_channels(self): + def test_different_channels(self) -> None: wave_1000hz = generate_sine_wave_ndarray( seconds=2, samplerate=1000, frequency=10 ) diff --git a/test/test_core_version_utility.py b/test/test_core_version_utility.py index 7ac191011..bff4b19a2 100644 --- a/test/test_core_version_utility.py +++ b/test/test_core_version_utility.py @@ -7,7 +7,7 @@ class TestCoreVersion(TestCase): - def test_parse_core_version(self): + def test_parse_core_version(self) -> None: parse_core_version("0.0.0") parse_core_version("0.1.0") parse_core_version("0.10.0") @@ -16,7 +16,7 @@ def test_parse_core_version(self): parse_core_version("0.14.0-preview.1") parse_core_version("0.14.0-preview.10") - def test_get_latest_core_version(self): + def test_get_latest_core_version(self) -> None: self.assertEqual( get_latest_core_version( versions=[ diff --git a/test/test_library_manager.py b/test/test_library_manager.py index 521311694..020a5111e 100644 --- a/test/test_library_manager.py +++ b/test/test_library_manager.py @@ -16,7 +16,7 @@ class TestLibraryManager(TestCase): - def setUp(self): + def setUp(self) -> None: super().setUp() self.tmp_dir = TemporaryDirectory() self.tmp_dir_path = Path(self.tmp_dir.name) @@ -39,7 +39,7 @@ def setUp(self): zf.writestr(vvlib_manifest_name, json.dumps(self.vvlib_manifest)) self.library_file = open(self.library_filename, "br") - def tearDown(self): + def tearDown(self) -> None: self.tmp_dir.cleanup() self.library_file.close() self.library_filename.unlink() @@ -58,7 +58,7 @@ def create_vvlib_manifest(self, **kwargs): vvlib_manifest = copy.deepcopy(self.vvlib_manifest) return {**vvlib_manifest, **kwargs} - def test_installed_libraries(self): + def test_installed_libraries(self) -> None: self.assertEqual(self.library_manger.installed_libraries(), {}) self.library_manger.install_library( @@ -73,7 +73,7 @@ def test_installed_libraries(self): self.library_manger.uninstall_library(self.library_uuid) self.assertEqual(self.library_manger.installed_libraries(), {}) - def test_install_library(self): + def test_install_library(self) -> None: # エンジンが把握していないライブラリのテスト invalid_uuid = "52398bd5-3cc3-406c-a159-dfec5ace4bab" with self.assertRaises(HTTPException) as e: @@ -193,7 +193,7 @@ def test_install_library(self): os.remove(invalid_vvlib_name) - def test_uninstall_library(self): + def test_uninstall_library(self) -> None: # TODO: アンインストール出来ないライブラリをテストできるようにしたい with self.assertRaises(HTTPException) as e: self.library_manger.uninstall_library(self.library_uuid) diff --git a/test/test_metas_store.py b/test/test_metas_store.py index cf354928a..42d8cf35d 100644 --- a/test/test_metas_store.py +++ b/test/test_metas_store.py @@ -30,7 +30,7 @@ def _equal_speakers(a: list[Speaker], b: list[Speaker]) -> bool: class TestMetasStore(TestCase): - def test_filter_speakers_and_styles_with_speaker(self): + def test_filter_speakers_and_styles_with_speaker(self) -> None: # Inputs speaker_talk_only = _gen_speaker(["talk"]) speaker_singing_teacher_only = _gen_speaker(["singing_teacher"]) @@ -63,7 +63,7 @@ def test_filter_speakers_and_styles_with_speaker(self): for style in speaker.styles: self.assertEqual(style.type, "talk") - def test_filter_speakers_and_styles_with_singer(self): + def test_filter_speakers_and_styles_with_singer(self) -> None: # Inputs speaker_talk_only = _gen_speaker(["talk"]) speaker_singing_teacher_only = _gen_speaker(["singing_teacher"]) diff --git a/test/test_mock_tts_engine.py b/test/test_mock_tts_engine.py index ef6bea1d5..eaeda7990 100644 --- a/test/test_mock_tts_engine.py +++ b/test/test_mock_tts_engine.py @@ -19,7 +19,7 @@ def _gen_mora(text: str, consonant: str | None, vowel: str) -> Mora: class TestMockTTSEngine(TestCase): - def setUp(self): + def setUp(self) -> None: super().setUp() self.accent_phrases_hello_hiho = [ @@ -47,15 +47,15 @@ def setUp(self): ] self.engine = MockTTSEngine() - def test_update_length(self): + def test_update_length(self) -> None: """`.update_length()` がエラー無く生成をおこなう""" self.engine.update_length(self.accent_phrases_hello_hiho, StyleId(0)) - def test_update_pitch(self): + def test_update_pitch(self) -> None: """`.update_pitch()` がエラー無く生成をおこなう""" self.engine.update_pitch(self.accent_phrases_hello_hiho, StyleId(0)) - def test_synthesize_wave(self): + def test_synthesize_wave(self) -> None: """`.synthesize_wave()` がエラー無く生成をおこなう""" self.engine.synthesize_wave( AudioQuery( diff --git a/test/tts_pipeline/test_kana_converter.py b/test/tts_pipeline/test_kana_converter.py index f5e20ff39..f16f87be2 100644 --- a/test/tts_pipeline/test_kana_converter.py +++ b/test/tts_pipeline/test_kana_converter.py @@ -11,7 +11,7 @@ def parse_kana(text: str) -> list[AccentPhrase]: class TestParseKana(TestCase): - def test_phrase_length(self): + def test_phrase_length(self) -> None: self.assertEqual(len(parse_kana("ア'/ア'")), 2) self.assertEqual(len(parse_kana("ア'、ア'")), 2) self.assertEqual(len(parse_kana("ア'/ア'/ア'/ア'/ア'")), 5) @@ -20,7 +20,7 @@ def test_phrase_length(self): self.assertEqual(len(parse_kana("ギェ'")), 1) self.assertEqual(len(parse_kana("ギェ'、ギェ'/ギェ'")), 3) - def test_accent(self): + def test_accent(self) -> None: self.assertEqual(parse_kana("シャ'シシュシェショ")[0].accent, 1) self.assertEqual(parse_kana("シャ'_シシュシェショ")[0].accent, 1) self.assertEqual(parse_kana("シャシ'シュシェショ")[0].accent, 2) @@ -30,7 +30,7 @@ def test_accent(self): self.assertEqual(parse_kana("シャシシュシェショ'")[0].accent, 5) self.assertEqual(parse_kana("シャ_シシュシェショ'")[0].accent, 5) - def test_mora_length(self): + def test_mora_length(self) -> None: self.assertEqual(len(parse_kana("シャ'シシュシェショ")[0].moras), 5) self.assertEqual(len(parse_kana("シャ'_シシュシェショ")[0].moras), 5) self.assertEqual(len(parse_kana("シャシ'シュシェショ")[0].moras), 5) @@ -38,17 +38,17 @@ def test_mora_length(self): self.assertEqual(len(parse_kana("シャシシュシェショ'")[0].moras), 5) self.assertEqual(len(parse_kana("シャ_シシュシェショ'")[0].moras), 5) - def test_pause(self): + def test_pause(self) -> None: self.assertIsNone(parse_kana("ア'/ア'")[0].pause_mora) self.assertIsNone(parse_kana("ア'/ア'")[1].pause_mora) self.assertIsNotNone(parse_kana("ア'、ア'")[0].pause_mora) self.assertIsNone(parse_kana("ア'、ア'")[1].pause_mora) - def test_unvoice(self): + def test_unvoice(self) -> None: self.assertEqual(parse_kana("ス'")[0].moras[0].vowel, "u") self.assertEqual(parse_kana("_ス'")[0].moras[0].vowel, "U") - def test_roundtrip(self): + def test_roundtrip(self) -> None: for text in [ "コンニチワ'", "ワタシワ'/シャチョオデ'_ス", @@ -65,8 +65,8 @@ def _accent_phrase_marks_base( accent_phrases = kana_converter.parse_kana(text) self.assertEqual(expected_accent_phrases, accent_phrases) - def test_accent_phrase_marks(self): - def a_slash_a_accent_phrases(): + def test_accent_phrase_marks(self) -> None: + def a_slash_a_accent_phrases() -> list[AccentPhrase]: return [ AccentPhrase( moras=[ @@ -104,7 +104,7 @@ def a_slash_a_accent_phrases(): expected_accent_phrases=expected_accent_phrases, ) - def a_jp_comma_a_accent_phrases(): + def a_jp_comma_a_accent_phrases() -> list[AccentPhrase]: return [ AccentPhrase( moras=[ @@ -149,7 +149,7 @@ def a_jp_comma_a_accent_phrases(): expected_accent_phrases=expected_accent_phrases, ) - def a_slash_a_slash_a_slash_a_slash_a_accent_phrases(): + def a_slash_a_slash_a_slash_a_slash_a_accent_phrases() -> list[AccentPhrase]: return [ AccentPhrase( moras=[ @@ -229,7 +229,7 @@ def a_slash_a_slash_a_slash_a_slash_a_accent_phrases(): expected_accent_phrases=expected_accent_phrases, ) - def su_accent_phrases(): + def su_accent_phrases() -> list[AccentPhrase]: return [ AccentPhrase( moras=[ @@ -253,7 +253,7 @@ def su_accent_phrases(): expected_accent_phrases=expected_accent_phrases, ) - def under_score_su_accent_phrases(): + def under_score_su_accent_phrases() -> list[AccentPhrase]: return [ AccentPhrase( moras=[ @@ -277,7 +277,7 @@ def under_score_su_accent_phrases(): expected_accent_phrases=expected_accent_phrases, ) - def gye_accent_phrases(): + def gye_accent_phrases() -> list[AccentPhrase]: return [ AccentPhrase( moras=[ @@ -301,7 +301,7 @@ def gye_accent_phrases(): expected_accent_phrases=expected_accent_phrases, ) - def gye_gye_gye_accent_phrases(): + def gye_gye_gye_accent_phrases() -> list[AccentPhrase]: return [ AccentPhrase( moras=[ @@ -360,8 +360,8 @@ def gye_gye_gye_accent_phrases(): expected_accent_phrases=expected_accent_phrases, ) - def test_interrogative_accent_phrase_marks(self): - def a_question_mark_accent_phrases(): + def test_interrogative_accent_phrase_marks(self) -> None: + def a_question_mark_accent_phrases() -> list[AccentPhrase]: return [ AccentPhrase( moras=[ @@ -386,7 +386,7 @@ def a_question_mark_accent_phrases(): expected_accent_phrases=expected_accent_phrases, ) - def gye_gye_gye_question_mark_accent_phrases(): + def gye_gye_gye_question_mark_accent_phrases() -> list[AccentPhrase]: return [ AccentPhrase( moras=[ @@ -446,7 +446,9 @@ def gye_gye_gye_question_mark_accent_phrases(): expected_accent_phrases=expected_accent_phrases, ) - def a_pause_a_question_pause_a_question_a_question_mark_accent_phrases(): + def a_pause_a_question_pause_a_question_a_question_mark_accent_phrases() -> ( + list[AccentPhrase] + ): return [ AccentPhrase( moras=[ @@ -538,7 +540,7 @@ def _assert_error_code(self, kana: str, code: ParseKanaErrorCode) -> None: parse_kana(kana) self.assertEqual(err.exception.errcode, code) - def test_exceptions(self): + def test_exceptions(self) -> None: self._assert_error_code("アクセント", ParseKanaErrorCode.ACCENT_NOTFOUND) self._assert_error_code("'アクセント", ParseKanaErrorCode.ACCENT_TOP) self._assert_error_code("ア'ク'セント", ParseKanaErrorCode.ACCENT_TWICE) @@ -566,8 +568,8 @@ def test_exceptions(self): class TestCreateKana(TestCase): - def test_create_kana_interrogative(self): - def koreha_arimasuka_accent_phrases(): + def test_create_kana_interrogative(self) -> None: + def koreha_arimasuka_accent_phrases() -> list[AccentPhrase]: return [ AccentPhrase( moras=[ @@ -656,7 +658,7 @@ def koreha_arimasuka_accent_phrases(): accent_phrases[-1].is_interrogative = True self.assertEqual(create_kana(accent_phrases), "コレワ'/アリマ'_スカ?") - def kya_accent_phrases(): + def kya_accent_phrases() -> list[AccentPhrase]: return [ AccentPhrase( moras=[ diff --git a/test/tts_pipeline/test_mora_mapping.py b/test/tts_pipeline/test_mora_mapping.py index 0791c0ef4..ed327fa6c 100644 --- a/test/tts_pipeline/test_mora_mapping.py +++ b/test/tts_pipeline/test_mora_mapping.py @@ -4,7 +4,7 @@ class TestOpenJTalkMoraList(TestCase): - def test_mora2text(self): + def test_mora2text(self) -> None: self.assertEqual("ッ", mora_phonemes_to_mora_kana["cl"]) self.assertEqual("ティ", mora_phonemes_to_mora_kana["ti"]) self.assertEqual("トゥ", mora_phonemes_to_mora_kana["tu"]) @@ -13,7 +13,7 @@ def test_mora2text(self): self.assertEqual("ギェ", mora_phonemes_to_mora_kana["gye"]) self.assertEqual("イェ", mora_phonemes_to_mora_kana["ye"]) - def test_mora2text_injective(self): + def test_mora2text_injective(self) -> None: """異なるモーラが同じ読みがなに対応しないか確認する""" values = list(mora_phonemes_to_mora_kana.values()) uniq_values = list(set(values)) diff --git a/test/tts_pipeline/test_phoneme.py b/test/tts_pipeline/test_phoneme.py index cc6dd8315..e13a39ddb 100644 --- a/test/tts_pipeline/test_phoneme.py +++ b/test/tts_pipeline/test_phoneme.py @@ -7,7 +7,7 @@ TRUE_NUM_PHONEME = 45 -def test_unknown_phoneme(): +def test_unknown_phoneme() -> None: """Unknown音素 `xx` のID取得を拒否する""" # Inputs unknown_phoneme = Phoneme("xx") @@ -18,13 +18,13 @@ def test_unknown_phoneme(): class TestPhoneme(TestCase): - def setUp(self): + def setUp(self) -> None: super().setUp() # list_idx 0 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 hello_hiho = "sil k o N n i ch i w a pau h i h o d e s U sil".split() self.ojt_hello_hiho = [Phoneme(s) for s in hello_hiho] - def test_const(self): + def test_const(self) -> None: self.assertEqual(Phoneme._NUM_PHONEME, TRUE_NUM_PHONEME) self.assertEqual(Phoneme._PHONEME_LIST[1], "A") self.assertEqual(Phoneme._PHONEME_LIST[14], "e") @@ -32,17 +32,17 @@ def test_const(self): self.assertEqual(Phoneme._PHONEME_LIST[38], "ts") self.assertEqual(Phoneme._PHONEME_LIST[41], "v") - def test_convert(self): + def test_convert(self) -> None: sil_phoneme = Phoneme("sil") self.assertEqual(sil_phoneme._phoneme, "pau") - def test_phoneme_id(self): + def test_phoneme_id(self) -> None: ojt_str_hello_hiho = " ".join([str(p.id) for p in self.ojt_hello_hiho]) self.assertEqual( ojt_str_hello_hiho, "0 23 30 4 28 21 10 21 42 7 0 19 21 19 30 12 14 35 6 0" ) - def test_onehot(self): + def test_onehot(self) -> None: phoneme_id_list = [ 0, 23, diff --git a/test/tts_pipeline/test_text_analyzer.py b/test/tts_pipeline/test_text_analyzer.py index ebaf30977..29f9ed652 100644 --- a/test/tts_pipeline/test_text_analyzer.py +++ b/test/tts_pipeline/test_text_analyzer.py @@ -40,7 +40,7 @@ def features(ojt_container: OjtContainer) -> list[str]: class TestBaseLabels(TestCase): - def setUp(self): + def setUp(self) -> None: super().setUp() # pyopenjtalk.extract_fullcontext("こんにちは、ヒホです。")の結果 # 出来る限りテスト内で他のライブラリに依存しないため、 @@ -143,14 +143,14 @@ def space_jointed_phonemes(ojt_container: OjtContainer) -> str: class TestLabel(TestBaseLabels): - def test_phoneme(self): + def test_phoneme(self) -> None: """Label に含まれる音素をテスト""" self.assertEqual( " ".join([label.phoneme for label in self.labels_hello_hiho]), "sil k o N n i ch i w a pau h i h o d e s U sil", ) - def test_is_pause(self): + def test_is_pause(self) -> None: """Label のポーズ判定をテスト""" self.assertEqual( [label.is_pause() for label in self.labels_hello_hiho], @@ -262,19 +262,19 @@ def setUp(self) -> None: self.labels_hello_hiho[11:19] ) - def test_accent(self): + def test_accent(self) -> None: """AccentPhraseLabel に含まれるアクセント位置をテスト""" self.assertEqual(self.accent_phrase_hello.accent, 5) self.assertEqual(self.accent_phrase_hiho.accent, 1) - def test_phonemes(self): + def test_phonemes(self) -> None: """AccentPhraseLabel に含まれる音素系列をテスト""" outputs_hello = space_jointed_phonemes(self.accent_phrase_hello) outputs_hiho = space_jointed_phonemes(self.accent_phrase_hiho) self.assertEqual(outputs_hello, "k o N n i ch i w a") self.assertEqual(outputs_hiho, "h i h o d e s U") - def test_features(self): + def test_features(self) -> None: """AccentPhraseLabel に含まれる features をテスト""" expects = self.test_case_hello_hiho self.assertEqual(features(self.accent_phrase_hello), expects[1:10]) @@ -291,14 +291,14 @@ def setUp(self) -> None: self.labels_hello_hiho[11:19] ) - def test_phonemes(self): + def test_phonemes(self) -> None: """BreathGroupLabel に含まれる音素系列をテスト""" outputs_hello = space_jointed_phonemes(self.breath_group_hello) outputs_hiho = space_jointed_phonemes(self.breath_group_hiho) self.assertEqual(outputs_hello, "k o N n i ch i w a") self.assertEqual(outputs_hiho, "h i h o d e s U") - def test_features(self): + def test_features(self) -> None: """BreathGroupLabel に含まれる features をテスト""" expects = self.test_case_hello_hiho self.assertEqual(features(self.breath_group_hello), expects[1:10]) @@ -310,19 +310,19 @@ def setUp(self) -> None: super().setUp() self.utterance_hello_hiho = UtteranceLabel.from_labels(self.labels_hello_hiho) - def test_phonemes(self): + def test_phonemes(self) -> None: """UtteranceLabel に含まれる音素系列をテスト""" outputs_hello_hiho = space_jointed_phonemes(self.utterance_hello_hiho) expects_hello_hiho = "sil k o N n i ch i w a pau h i h o d e s U sil" self.assertEqual(outputs_hello_hiho, expects_hello_hiho) - def test_features(self): + def test_features(self) -> None: """UtteranceLabel に含まれる features をテスト""" self.assertEqual(features(self.utterance_hello_hiho), self.test_case_hello_hiho) class TestMoraToText(TestCase): - def test_voice(self): + def test_voice(self) -> None: self.assertEqual(mora_to_text("a"), "ア") self.assertEqual(mora_to_text("i"), "イ") self.assertEqual(mora_to_text("ka"), "カ") @@ -332,7 +332,7 @@ def test_voice(self): self.assertEqual(mora_to_text("ye"), "イェ") self.assertEqual(mora_to_text("wo"), "ウォ") - def test_unvoice(self): + def test_unvoice(self) -> None: self.assertEqual(mora_to_text("A"), "ア") self.assertEqual(mora_to_text("I"), "イ") self.assertEqual(mora_to_text("kA"), "カ") @@ -340,7 +340,7 @@ def test_unvoice(self): self.assertEqual(mora_to_text("yE"), "イェ") self.assertEqual(mora_to_text("wO"), "ウォ") - def test_invalid_mora(self): + def test_invalid_mora(self) -> None: """変なモーラが来ても例外を投げない""" self.assertEqual(mora_to_text("x"), "x") self.assertEqual(mora_to_text(""), "") @@ -357,7 +357,7 @@ def _gen_mora(text: str, consonant: str | None, vowel: str) -> Mora: ) -def test_text_to_accent_phrases_normal(): +def test_text_to_accent_phrases_normal() -> None: """`text_to_accent_phrases` は正常な日本語文をパースする""" # Inputs text = "こんにちは、ヒホです。" @@ -402,7 +402,7 @@ def stub_unknown_features_koxx(_: str) -> list[str]: ] -def test_text_to_accent_phrases_unknown(): +def test_text_to_accent_phrases_unknown() -> None: """`text_to_accent_phrases` は unknown 音素を含む features をパースする""" # Expects true_accent_phrases = [ diff --git a/test/tts_pipeline/test_tts_engine.py b/test/tts_pipeline/test_tts_engine.py index 8d4c322b6..57598155b 100644 --- a/test/tts_pipeline/test_tts_engine.py +++ b/test/tts_pipeline/test_tts_engine.py @@ -93,13 +93,13 @@ class MockCore: yukarin_sa_forward = Mock(side_effect=yukarin_sa_mock) decode_forward = Mock(side_effect=decode_mock) - def metas(self): + def metas(self) -> str: return "" - def supported_devices(self): + def supported_devices(self) -> str: return "" - def is_model_loaded(self, style_id): + def is_model_loaded(self, style_id: str) -> bool: return True @@ -122,7 +122,7 @@ def _gen_mora( ) -def test_to_flatten_phonemes(): +def test_to_flatten_phonemes() -> None: """Test `to_flatten_phonemes`.""" # Inputs moras = [ @@ -205,7 +205,7 @@ def _gen_doremi_score() -> Score: class TestTTSEngine(TestCase): - def setUp(self): + def setUp(self) -> None: super().setUp() core = MockCore() self.yukarin_s_mock = core.yukarin_s_forward @@ -213,7 +213,7 @@ def setUp(self): self.decode_mock = core.decode_forward self.tts_engine = TTSEngine(core=core) # type: ignore[arg-type] - def test_to_flatten_moras(self): + def test_to_flatten_moras(self) -> None: flatten_moras = to_flatten_moras(_gen_hello_hiho_accent_phrases()) true_accent_phrases_hello_hiho = _gen_hello_hiho_accent_phrases() self.assertEqual( @@ -223,7 +223,7 @@ def test_to_flatten_moras(self): + true_accent_phrases_hello_hiho[1].moras, ) - def test_update_length(self): + def test_update_length(self) -> None: # Inputs hello_hiho = _gen_hello_hiho_accent_phrases() # Indirect Outputs(yukarin_sに渡される値) @@ -247,7 +247,7 @@ def test_update_length(self): np.array(true_phoneme_list, dtype=np.int64), ) - def test_update_pitch(self): + def test_update_pitch(self) -> None: # 空のリストでエラーを吐かないか # Inputs phrases: list = [] @@ -296,7 +296,7 @@ def test_update_pitch(self): np.testing.assert_array_equal(end_accent_phrase_list, true_phrase_ends) -def test_create_accent_phrases_toward_unknown(): +def test_create_accent_phrases_toward_unknown() -> None: """`TTSEngine.create_accent_phrases()` は unknown 音素の Phoneme 化に失敗する""" engine = TTSEngine(MockCoreWrapper()) @@ -416,7 +416,7 @@ def test_mocked_synthesize_wave_from_score_output( ) -def koreha_arimasuka_base_expected(): +def koreha_arimasuka_base_expected() -> list[AccentPhrase]: return [ AccentPhrase( moras=[ @@ -500,7 +500,7 @@ def koreha_arimasuka_base_expected(): class TestTTSEngineBase(TestCase): - def setUp(self): + def setUp(self) -> None: super().setUp() self.tts_engine = TTSEngine(core=MockCoreWrapper()) @@ -517,7 +517,7 @@ def create_synthesis_test_base( outputs = apply_interrogative_upspeak(inputs, enable_interrogative_upspeak) self.assertEqual(expected, outputs, f"case(text:{text})") - def test_create_accent_phrases(self): + def test_create_accent_phrases(self) -> None: """accent_phrasesの作成時では疑問文モーラ処理を行わない (https://github.com/VOICEVOX/voicevox_engine/issues/272#issuecomment-1022610866) """ @@ -527,7 +527,7 @@ def test_create_accent_phrases(self): actual = self.tts_engine.create_accent_phrases(text, StyleId(1)) self.assertEqual(expected, actual, f"case(text:{text})") - def test_upspeak_voiced_last_mora(self): + def test_upspeak_voiced_last_mora(self) -> None: # voiced + "?" + flagON -> upspeak expected = koreha_arimasuka_base_expected() expected[-1].is_interrogative = True @@ -564,8 +564,8 @@ def test_upspeak_voiced_last_mora(self): enable_interrogative_upspeak=True, ) - def test_upspeak_voiced_N_last_mora(self): - def nn_base_expected(): + def test_upspeak_voiced_N_last_mora(self) -> None: + def nn_base_expected() -> list[AccentPhrase]: return [ AccentPhrase( moras=[ @@ -620,8 +620,8 @@ def nn_base_expected(): enable_interrogative_upspeak=False, ) - def test_upspeak_unvoiced_last_mora(self): - def ltu_base_expected(): + def test_upspeak_unvoiced_last_mora(self) -> None: + def ltu_base_expected() -> list[AccentPhrase]: return [ AccentPhrase( moras=[ @@ -666,8 +666,8 @@ def ltu_base_expected(): enable_interrogative_upspeak=False, ) - def test_upspeak_voiced_u_last_mora(self): - def su_base_expected(): + def test_upspeak_voiced_u_last_mora(self) -> None: + def su_base_expected() -> list[AccentPhrase]: return [ AccentPhrase( moras=[ diff --git a/test/tts_pipeline/test_wave_synthesizer.py b/test/tts_pipeline/test_wave_synthesizer.py index 084edcec6..fdddb2f6b 100644 --- a/test/tts_pipeline/test_wave_synthesizer.py +++ b/test/tts_pipeline/test_wave_synthesizer.py @@ -64,7 +64,7 @@ def _gen_mora( ) -def test_apply_prepost_silence(): +def test_apply_prepost_silence() -> None: """Test `apply_prepost_silence`.""" # Inputs query = _gen_query(prePhonemeLength=2 * 0.01067, postPhonemeLength=6 * 0.01067) @@ -85,7 +85,7 @@ def test_apply_prepost_silence(): assert moras_with_silence == true_moras_with_silence -def test_apply_speed_scale(): +def test_apply_speed_scale() -> None: """Test `apply_speed_scale`.""" # Inputs query = _gen_query(speedScale=2.0) @@ -112,7 +112,7 @@ def test_apply_speed_scale(): assert moras == true_moras -def test_apply_pitch_scale(): +def test_apply_pitch_scale() -> None: """Test `apply_pitch_scale`.""" # Inputs query = _gen_query(pitchScale=2.0) @@ -139,7 +139,7 @@ def test_apply_pitch_scale(): assert moras == true_moras -def test_apply_intonation_scale(): +def test_apply_intonation_scale() -> None: """Test `apply_intonation_scale`.""" # Inputs query = _gen_query(intonationScale=0.5) @@ -166,7 +166,7 @@ def test_apply_intonation_scale(): assert moras == true_moras -def test_apply_volume_scale(): +def test_apply_volume_scale() -> None: """Test `apply_volume_scale`.""" # Inputs query = _gen_query(volumeScale=3.0) @@ -181,7 +181,7 @@ def test_apply_volume_scale(): assert np.allclose(wave, true_wave) -def test_apply_output_sampling_rate(): +def test_apply_output_sampling_rate() -> None: """Test `apply_output_sampling_rate`.""" # Inputs query = _gen_query(outputSamplingRate=12000) @@ -198,7 +198,7 @@ def test_apply_output_sampling_rate(): assert wave.shape[0] == true_wave.shape[0] -def test_apply_output_stereo(): +def test_apply_output_stereo() -> None: """Test `apply_output_stereo`.""" # Inputs query = _gen_query(outputStereo=True) @@ -213,7 +213,7 @@ def test_apply_output_stereo(): assert np.array_equal(wave, true_wave) -def test_count_frame_per_unit(): +def test_count_frame_per_unit() -> None: """Test `count_frame_per_unit`.""" # Inputs moras = [ @@ -241,7 +241,7 @@ def test_count_frame_per_unit(): assert np.array_equal(frame_per_mora, true_frame_per_mora) -def test_query_to_decoder_feature(): +def test_query_to_decoder_feature() -> None: """Test `query_to_decoder_feature`.""" # Inputs accent_phrases = [ @@ -300,7 +300,7 @@ def test_query_to_decoder_feature(): assert np.array_equal(f0, true_f0) -def test_raw_wave_to_output_wave_with_resample(): +def test_raw_wave_to_output_wave_with_resample() -> None: """Test `raw_wave_to_output_wave` with resampling option.""" # Inputs query = _gen_query(volumeScale=2, outputSamplingRate=48000, outputStereo=True) @@ -316,7 +316,7 @@ def test_raw_wave_to_output_wave_with_resample(): assert wave.shape == true_wave_shape -def test_raw_wave_to_output_wave_without_resample(): +def test_raw_wave_to_output_wave_without_resample() -> None: """Test `raw_wave_to_output_wave` without resampling option.""" # Inputs query = _gen_query(volumeScale=2, outputStereo=True) diff --git a/test/user_dict/test_user_dict.py b/test/user_dict/test_user_dict.py index 446156eea..cb938a689 100644 --- a/test/user_dict/test_user_dict.py +++ b/test/user_dict/test_user_dict.py @@ -76,21 +76,21 @@ def get_new_word(user_dict: dict[str, UserDictWord]) -> UserDictWord: class TestUserDict(TestCase): - def setUp(self): + def setUp(self) -> None: self.tmp_dir = TemporaryDirectory() self.tmp_dir_path = Path(self.tmp_dir.name) - def tearDown(self): + def tearDown(self) -> None: unset_user_dict() self.tmp_dir.cleanup() - def test_read_not_exist_json(self): + def test_read_not_exist_json(self) -> None: self.assertEqual( read_dict(user_dict_path=(self.tmp_dir_path / "not_exist.json")), {}, ) - def test_create_word(self): + def test_create_word(self) -> None: # 将来的に品詞などが追加された時にテストを増やす self.assertEqual( _create_word(surface="test", pronunciation="テスト", accent_type=1), @@ -112,7 +112,7 @@ def test_create_word(self): ), ) - def test_apply_word_without_json(self): + def test_apply_word_without_json(self) -> None: user_dict_path = self.tmp_dir_path / "test_apply_word_without_json.json" apply_word( surface="test", @@ -133,7 +133,7 @@ def test_apply_word_without_json(self): ("test", "テスト", 1), ) - def test_apply_word_with_json(self): + def test_apply_word_with_json(self) -> None: user_dict_path = self.tmp_dir_path / "test_apply_word_with_json.json" user_dict_path.write_text( json.dumps(valid_dict_dict_json, ensure_ascii=False), encoding="utf-8" @@ -157,7 +157,7 @@ def test_apply_word_with_json(self): ("test2", "テストツー", 3), ) - def test_rewrite_word_invalid_id(self): + def test_rewrite_word_invalid_id(self) -> None: user_dict_path = self.tmp_dir_path / "test_rewrite_word_invalid_id.json" user_dict_path.write_text( json.dumps(valid_dict_dict_json, ensure_ascii=False), encoding="utf-8" @@ -173,7 +173,7 @@ def test_rewrite_word_invalid_id(self): compiled_dict_path=(self.tmp_dir_path / "test_rewrite_word_invalid_id.dic"), ) - def test_rewrite_word_valid_id(self): + def test_rewrite_word_valid_id(self) -> None: user_dict_path = self.tmp_dir_path / "test_rewrite_word_valid_id.json" user_dict_path.write_text( json.dumps(valid_dict_dict_json, ensure_ascii=False), encoding="utf-8" @@ -194,7 +194,7 @@ def test_rewrite_word_valid_id(self): ("test2", "テストツー", 2), ) - def test_delete_word_invalid_id(self): + def test_delete_word_invalid_id(self) -> None: user_dict_path = self.tmp_dir_path / "test_delete_word_invalid_id.json" user_dict_path.write_text( json.dumps(valid_dict_dict_json, ensure_ascii=False), encoding="utf-8" @@ -207,7 +207,7 @@ def test_delete_word_invalid_id(self): compiled_dict_path=(self.tmp_dir_path / "test_delete_word_invalid_id.dic"), ) - def test_delete_word_valid_id(self): + def test_delete_word_valid_id(self) -> None: user_dict_path = self.tmp_dir_path / "test_delete_word_valid_id.json" user_dict_path.write_text( json.dumps(valid_dict_dict_json, ensure_ascii=False), encoding="utf-8" @@ -219,7 +219,7 @@ def test_delete_word_valid_id(self): ) self.assertEqual(len(read_dict(user_dict_path=user_dict_path)), 0) - def test_priority(self): + def test_priority(self) -> None: for pos in part_of_speech_data: for i in range(MAX_PRIORITY + 1): self.assertEqual( @@ -233,7 +233,7 @@ def test_priority(self): i, ) - def test_import_dict(self): + def test_import_dict(self) -> None: user_dict_path = self.tmp_dir_path / "test_import_dict.json" compiled_dict_path = self.tmp_dir_path / "test_import_dict.dic" user_dict_path.write_text( @@ -254,7 +254,7 @@ def test_import_dict(self): UserDictWord(**valid_dict_dict_api["aab7dda2-0d97-43c8-8cb7-3f440dab9b4e"]), ) - def test_import_dict_no_override(self): + def test_import_dict_no_override(self) -> None: user_dict_path = self.tmp_dir_path / "test_import_dict_no_override.json" compiled_dict_path = self.tmp_dir_path / "test_import_dict_no_override.dic" user_dict_path.write_text( @@ -271,7 +271,7 @@ def test_import_dict_no_override(self): UserDictWord(**valid_dict_dict_api["aab7dda2-0d97-43c8-8cb7-3f440dab9b4e"]), ) - def test_import_dict_override(self): + def test_import_dict_override(self) -> None: user_dict_path = self.tmp_dir_path / "test_import_dict_override.json" compiled_dict_path = self.tmp_dir_path / "test_import_dict_override.dic" user_dict_path.write_text( @@ -288,7 +288,7 @@ def test_import_dict_override(self): import_word, ) - def test_import_invalid_word(self): + def test_import_invalid_word(self) -> None: user_dict_path = self.tmp_dir_path / "test_import_invalid_dict.json" compiled_dict_path = self.tmp_dir_path / "test_import_invalid_dict.dic" invalid_accent_associative_rule_word = deepcopy(import_word) @@ -321,7 +321,7 @@ def test_import_invalid_word(self): compiled_dict_path=compiled_dict_path, ) - def test_update_dict(self): + def test_update_dict(self) -> None: user_dict_path = self.tmp_dir_path / "test_update_dict.json" compiled_dict_path = self.tmp_dir_path / "test_update_dict.dic" update_dict( diff --git a/test/user_dict/test_user_dict_model.py b/test/user_dict/test_user_dict_model.py index 2c00309b4..686cd0893 100644 --- a/test/user_dict/test_user_dict_model.py +++ b/test/user_dict/test_user_dict_model.py @@ -44,26 +44,26 @@ def generate_model() -> TestModel: class TestUserDictWords(TestCase): - def setUp(self): + def setUp(self) -> None: pass - def test_valid_word(self): + def test_valid_word(self) -> None: test_value = generate_model() try: UserDictWord(**test_value) except ValidationError as e: self.fail(f"Unexpected Validation Error\n{str(e)}") - def test_convert_to_zenkaku(self): + def test_convert_to_zenkaku(self) -> None: test_value = generate_model() test_value["surface"] = "test" self.assertEqual(UserDictWord(**test_value).surface, "test") - def test_count_mora(self): + def test_count_mora(self) -> None: test_value = generate_model() self.assertEqual(UserDictWord(**test_value).mora_count, 3) - def test_count_mora_x(self): + def test_count_mora_x(self) -> None: test_value = generate_model() for s in [chr(i) for i in range(12449, 12533)]: if s in ["ァ", "ィ", "ゥ", "ェ", "ォ", "ッ", "ャ", "ュ", "ョ", "ヮ"]: @@ -81,7 +81,7 @@ def test_count_mora_x(self): expected_count, ) - def test_count_mora_xwa(self): + def test_count_mora_xwa(self) -> None: test_value = generate_model() test_value["pronunciation"] = "クヮンセイ" expected_count = 0 @@ -94,36 +94,36 @@ def test_count_mora_xwa(self): expected_count, ) - def test_invalid_pronunciation_not_katakana(self): + def test_invalid_pronunciation_not_katakana(self) -> None: test_value = generate_model() test_value["pronunciation"] = "ぼいぼ" with self.assertRaises(ValidationError): UserDictWord(**test_value) - def test_invalid_pronunciation_invalid_sutegana(self): + def test_invalid_pronunciation_invalid_sutegana(self) -> None: test_value = generate_model() test_value["pronunciation"] = "アィウェォ" with self.assertRaises(ValidationError): UserDictWord(**test_value) - def test_invalid_pronunciation_invalid_xwa(self): + def test_invalid_pronunciation_invalid_xwa(self) -> None: test_value = generate_model() test_value["pronunciation"] = "アヮ" with self.assertRaises(ValidationError): UserDictWord(**test_value) - def test_count_mora_voiced_sound(self): + def test_count_mora_voiced_sound(self) -> None: test_value = generate_model() test_value["pronunciation"] = "ボイボ" self.assertEqual(UserDictWord(**test_value).mora_count, 3) - def test_invalid_accent_type(self): + def test_invalid_accent_type(self) -> None: test_value = generate_model() test_value["accent_type"] = 4 with self.assertRaises(ValidationError): UserDictWord(**test_value) - def test_invalid_accent_type_2(self): + def test_invalid_accent_type_2(self) -> None: test_value = generate_model() test_value["accent_type"] = -1 with self.assertRaises(ValidationError): diff --git a/test/user_dict/test_word_types.py b/test/user_dict/test_word_types.py index e26ce192f..0e64dd10d 100644 --- a/test/user_dict/test_word_types.py +++ b/test/user_dict/test_word_types.py @@ -5,5 +5,5 @@ class TestWordTypes(TestCase): - def test_word_types(self): + def test_word_types(self) -> None: self.assertCountEqual(list(WordTypes), list(part_of_speech_data.keys())) diff --git a/voicevox_engine/dev/core/mock.py b/voicevox_engine/dev/core/mock.py index 25190ea55..8833ad0df 100644 --- a/voicevox_engine/dev/core/mock.py +++ b/voicevox_engine/dev/core/mock.py @@ -228,7 +228,7 @@ def sf_decode_forward( ] * 256 return np.array(result, dtype=np.float32) - def supported_devices(self): + def supported_devices(self) -> str: return json.dumps( { "cpu": True, diff --git a/voicevox_engine/dev/tts_engine/mock.py b/voicevox_engine/dev/tts_engine/mock.py index 9373cb0ce..fc4e4d415 100644 --- a/voicevox_engine/dev/tts_engine/mock.py +++ b/voicevox_engine/dev/tts_engine/mock.py @@ -16,7 +16,7 @@ class MockTTSEngine(TTSEngine): """製品版コア無しに音声合成が可能なモック版TTSEngine""" - def __init__(self): + def __init__(self) -> None: super().__init__(MockCoreWrapper()) def synthesize_wave( diff --git a/voicevox_engine/model.py b/voicevox_engine/model.py index b0013b1b0..892753865 100644 --- a/voicevox_engine/model.py +++ b/voicevox_engine/model.py @@ -21,7 +21,7 @@ class Mora(BaseModel): title="音高" ) # デフォルト値をつけるとts側のOpenAPIで生成されたコードの型がOptionalになる - def __hash__(self): + def __hash__(self) -> int: items = [ (k, tuple(v)) if isinstance(v, List) else (k, v) for k, v in self.__dict__.items() @@ -42,7 +42,7 @@ class AccentPhrase(BaseModel): pause_mora: Optional[Mora] = Field(title="後ろに無音を付けるかどうか") is_interrogative: bool = Field(default=False, title="疑問系かどうか") - def __hash__(self): + def __hash__(self) -> int: items = [ (k, tuple(v)) if isinstance(v, List) else (k, v) for k, v in self.__dict__.items() @@ -68,7 +68,7 @@ class AudioQuery(BaseModel): title="[読み取り専用]AquesTalk 風記法によるテキスト。音声合成用のクエリとしては無視される" ) - def __hash__(self): + def __hash__(self) -> int: items = [ (k, tuple(v)) if isinstance(v, List) else (k, v) for k, v in self.__dict__.items() diff --git a/voicevox_engine/preset/PresetManager.py b/voicevox_engine/preset/PresetManager.py index cfb8dc161..c554e3e46 100644 --- a/voicevox_engine/preset/PresetManager.py +++ b/voicevox_engine/preset/PresetManager.py @@ -174,7 +174,7 @@ def delete_preset(self, id: int) -> int: return id - def _write_on_file(self): + def _write_on_file(self) -> None: """プリセット情報のファイル(簡易データベース)書き込み""" with open(self.preset_path, mode="w", encoding="utf-8") as f: yaml.safe_dump( diff --git a/voicevox_engine/tts_pipeline/text_analyzer.py b/voicevox_engine/tts_pipeline/text_analyzer.py index 70ea83b12..dd9981074 100644 --- a/voicevox_engine/tts_pipeline/text_analyzer.py +++ b/voicevox_engine/tts_pipeline/text_analyzer.py @@ -115,7 +115,7 @@ def breath_group_index(self) -> str: """BreathGroupのインデックス""" return self.contexts["i3"] - def __repr__(self): + def __repr__(self) -> str: return f"