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

整理: SettingHandler テストの想定出力を変更 #1410

Merged
merged 1 commit into from
Jun 20, 2024
Merged
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
39 changes: 15 additions & 24 deletions test/unit/setting/test_setting.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
from pathlib import Path

from voicevox_engine.setting.model import CorsPolicyMode
from voicevox_engine.setting.setting_manager import (
Setting,
SettingHandler,
_setting_adapter,
)
from voicevox_engine.setting.setting_manager import Setting, SettingHandler


def test_setting_handler_load_not_exist_file() -> None:
"""`SettingHandler` に存在しない設定ファイルのパスを渡すとデフォルト値になる。"""
# Inputs
setting_loader = SettingHandler(Path("not_exist.yaml"))
settings = setting_loader.load()
setting_path = Path("not_exist.yaml")
setting_loader = SettingHandler(setting_path)
# Expects
true_setting = {"allow_origin": None, "cors_policy_mode": CorsPolicyMode.localapps}
true_setting = Setting(cors_policy_mode=CorsPolicyMode.localapps, allow_origin=None)
# Outputs
setting = _setting_adapter.dump_python(settings)
setting = setting_loader.load()
# Test
assert true_setting == setting

Expand All @@ -26,11 +22,10 @@ def test_setting_handler_load_exist_file_1() -> None:
# Inputs
setting_path = Path("test/unit/setting/setting-test-load-1.yaml")
setting_loader = SettingHandler(setting_path)
settings = setting_loader.load()
# Expects
true_setting = {"allow_origin": None, "cors_policy_mode": CorsPolicyMode.localapps}
true_setting = Setting(cors_policy_mode=CorsPolicyMode.localapps, allow_origin=None)
# Outputs
setting = _setting_adapter.dump_python(settings)
setting = setting_loader.load()
# Test
assert true_setting == setting

Expand All @@ -40,11 +35,10 @@ def test_setting_handler_load_exist_file_2() -> None:
# Inputs
setting_path = Path("test/unit/setting/setting-test-load-2.yaml")
setting_loader = SettingHandler(setting_path)
settings = setting_loader.load()
# Expects
true_setting = {"allow_origin": None, "cors_policy_mode": "all"}
true_setting = Setting(cors_policy_mode=CorsPolicyMode.all, allow_origin=None)
# Outputs
setting = _setting_adapter.dump_python(settings)
setting = setting_loader.load()
# Test
assert true_setting == setting

Expand All @@ -54,14 +48,12 @@ def test_setting_handler_load_exist_file_3() -> None:
# Inputs
setting_path = Path("test/unit/setting/setting-test-load-3.yaml")
setting_loader = SettingHandler(setting_path)
settings = setting_loader.load()
# Expects
true_setting = {
"allow_origin": "192.168.254.255 192.168.255.255",
"cors_policy_mode": CorsPolicyMode.localapps,
}
true_policy = CorsPolicyMode.localapps
true_origin = "192.168.254.255 192.168.255.255"
true_setting = Setting(cors_policy_mode=true_policy, allow_origin=true_origin)
# Outputs
setting = _setting_adapter.dump_python(settings)
setting = setting_loader.load()
# Test
assert true_setting == setting

Expand All @@ -73,10 +65,9 @@ def test_setting_handler_save(tmp_path: Path) -> None:
setting_loader = SettingHandler(setting_path)
new_setting = Setting(cors_policy_mode=CorsPolicyMode.localapps)
# Expects
true_setting = {"allow_origin": None, "cors_policy_mode": CorsPolicyMode.localapps}
true_setting = Setting(cors_policy_mode=CorsPolicyMode.localapps, allow_origin=None)
# Outputs
setting_loader.save(new_setting)
# NOTE: `.load()` の正常動作を前提とする
setting = _setting_adapter.dump_python(setting_loader.load())
setting = setting_loader.load() # NOTE: `.load()` の正常動作を前提とする
# Test
assert true_setting == setting