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

整理: 返り値型 #1078

Merged
merged 3 commits into from
Feb 27, 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
8 changes: 4 additions & 4 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
from typing import Any

import pytest
from fastapi import FastAPI
Expand All @@ -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()))
Expand Down
42 changes: 21 additions & 21 deletions test/preset/test_preset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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="プリセットの設定ファイルにミスがあります"
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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="プリセットの設定ファイルにミスがあります"
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions test/setting/test_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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")
)
Expand All @@ -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")
)
Expand All @@ -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")
)
Expand All @@ -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")
)
Expand All @@ -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()
12 changes: 6 additions & 6 deletions test/test_connect_base64_waves.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
Expand All @@ -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)
Expand All @@ -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
)
Expand All @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions test/test_core_version_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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=[
Expand Down
10 changes: 5 additions & 5 deletions test/test_library_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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(
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
Loading
Loading