From 7dbd947bff9bcd45407750b21b4ac5178e0e80aa Mon Sep 17 00:00:00 2001 From: tarepan Date: Wed, 19 Jun 2024 18:27:12 +0000 Subject: [PATCH] =?UTF-8?q?refactor:=20`SettingHandler`=20=E3=81=AE?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E7=B0=A1=E7=95=A5=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/unit/setting/test_setting.py | 39 ++++++++++++------------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/test/unit/setting/test_setting.py b/test/unit/setting/test_setting.py index a249c923b..d5781fca3 100644 --- a/test/unit/setting/test_setting.py +++ b/test/unit/setting/test_setting.py @@ -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 @@ -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 @@ -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 @@ -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 @@ -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