エンドポイントテストの期待されるステータスを強化し、リクエスト処理の結果を改善。データ設定系のエンドポイントにおけるランダムデータの範囲を拡大し、出力メッセージをフラッシュするように修正。

This commit is contained in:
misyaguziya
2025-09-24 23:51:22 +09:00
parent 1b0e93b8f8
commit 53f1b95843

View File

@@ -50,10 +50,10 @@ class TestMainloop():
self.config_dict = {} self.config_dict = {}
for endpoint in self.main.mapping.keys(): for endpoint in self.main.mapping.keys():
if endpoint.startswith("/get/data/"): if endpoint.startswith("/get/data/"):
self.config_dict[endpoint.split("/")[-1]] = self.main.handleRequest(endpoint, None)[0] self.config_dict[endpoint.split("/")[-1]], _ = self.main.handleRequest(endpoint, None)
elif endpoint.startswith("/set/disable/"): elif endpoint.startswith("/set/disable/"):
self.config_dict[endpoint.split("/")[-1]] = self.main.handleRequest(endpoint, None)[0] self.config_dict[endpoint.split("/")[-1]], _ = self.main.handleRequest(endpoint, None)
print(self.config_dict) print(self.config_dict, flush=True)
self.validity_endpoints = [ self.validity_endpoints = [
"/set/enable/translation", "/set/enable/translation",
@@ -112,7 +112,7 @@ class TestMainloop():
"/set/data/selected_tab_no", "/set/data/selected_tab_no",
"/set/data/selected_translation_engines", "/set/data/selected_translation_engines",
"/set/data/selected_your_languages", "/set/data/selected_your_languages",
"/set/data/selected_target_languages" "/set/data/selected_target_languages",
"/set/data/selected_transcription_engine", "/set/data/selected_transcription_engine",
"/set/data/transparency", "/set/data/transparency",
"/set/data/ui_scaling", "/set/data/ui_scaling",
@@ -215,9 +215,17 @@ class TestMainloop():
def test_endpoints_on_off_single(self, endpoint): def test_endpoints_on_off_single(self, endpoint):
success = False success = False
expected_status = [200]
if endpoint.startswith("/set/enable/"): if endpoint.startswith("/set/enable/"):
match endpoint:
case "/set/enable/websocket_server":
expected_status = [200, 400]
case _:
pass
result, status = self.main.handleRequest(endpoint, None) result, status = self.main.handleRequest(endpoint, None)
if result is True and status == 200: if status in expected_status:
if status == 200:
self.config_dict[endpoint.split("/")[-1]] = result self.config_dict[endpoint.split("/")[-1]] = result
print(f"-> {Color.GREEN}[PASS]{Color.RESET} endpoint:{endpoint} Status: {status}, Result: {result}") print(f"-> {Color.GREEN}[PASS]{Color.RESET} endpoint:{endpoint} Status: {status}, Result: {result}")
success = True success = True
@@ -226,7 +234,8 @@ class TestMainloop():
print(f"Current config_dict: {self.config_dict}") print(f"Current config_dict: {self.config_dict}")
elif endpoint.startswith("/set/disable/"): elif endpoint.startswith("/set/disable/"):
result, status = self.main.handleRequest(endpoint, None) result, status = self.main.handleRequest(endpoint, None)
if result is False and status == 200: if status in expected_status:
if status == 200:
self.config_dict[endpoint.split("/")[-1]] = result self.config_dict[endpoint.split("/")[-1]] = result
print(f"-> {Color.GREEN}[PASS]{Color.RESET} endpoint:{endpoint} Status: {status}, Result: {result}") print(f"-> {Color.GREEN}[PASS]{Color.RESET} endpoint:{endpoint} Status: {status}, Result: {result}")
success = True success = True
@@ -283,6 +292,7 @@ class TestMainloop():
def test_set_data_endpoints_single(self, endpoint): def test_set_data_endpoints_single(self, endpoint):
success = False success = False
expected_status = [200]
match endpoint: match endpoint:
case "/set/data/selected_tab_no": case "/set/data/selected_tab_no":
data = random.choice(["1", "2", "3"]) data = random.choice(["1", "2", "3"])
@@ -335,19 +345,36 @@ class TestMainloop():
case "/set/data/ctranslate2_weight_type": case "/set/data/ctranslate2_weight_type":
data = random.choice(list(self.config_dict["selectable_ctranslate2_weight_type_dict"].keys())) data = random.choice(list(self.config_dict["selectable_ctranslate2_weight_type_dict"].keys()))
case "/set/data/deepl_auth_key": case "/set/data/deepl_auth_key":
data = None # Set to None to avoid using a real key data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
expected_status = [400]
case "/set/data/selected_mic_host": case "/set/data/selected_mic_host":
data = random.choice(self.config_dict["mic_host_list"]) data = random.choice(self.config_dict["mic_host_list"])
case "/set/data/selected_mic_device": case "/set/data/selected_mic_device":
data = random.choice(self.config_dict["mic_device_list"]) data = random.choice(self.config_dict["mic_device_list"])
case "/set/data/mic_threshold": case "/set/data/mic_threshold":
data = random.randint(0, 100) data = random.randint(-1000, 3000)
if 0 <= data <= 2000:
expected_status = [200]
else:
expected_status = [400]
case "/set/data/mic_record_timeout": case "/set/data/mic_record_timeout":
data = random.randint(1, 3) data = random.randint(-1, 10)
if 0 <= data <= self.config_dict["mic_phrase_timeout"]:
expected_status = [200]
else:
expected_status = [400]
case "/set/data/mic_phrase_timeout": case "/set/data/mic_phrase_timeout":
data = random.randint(5, 10) data = random.randint(-1, 10)
if self.config_dict["mic_record_timeout"] <= data:
expected_status = [200]
else:
expected_status = [400]
case "/set/data/mic_max_phrases": case "/set/data/mic_max_phrases":
data = random.randint(1, 10) data = random.randint(-1, 10)
if 0 <= data:
expected_status = [200]
else:
expected_status = [400]
case "/set/data/hotkeys": case "/set/data/hotkeys":
data = { data = {
'toggle_vrct_visibility': None, 'toggle_vrct_visibility': None,
@@ -373,13 +400,29 @@ class TestMainloop():
case "/set/data/selected_speaker_device": case "/set/data/selected_speaker_device":
data = random.choice(self.config_dict["speaker_device_list"]) data = random.choice(self.config_dict["speaker_device_list"])
case "/set/data/speaker_threshold": case "/set/data/speaker_threshold":
data = random.randint(0, 100) data = random.randint(-1000, 5000)
if 0 <= data <= 4000:
expected_status = [200]
else:
expected_status = [400]
case "/set/data/speaker_record_timeout": case "/set/data/speaker_record_timeout":
data = random.randint(1, 3) data = random.randint(-1, 10)
if 0 <= data <= self.config_dict["speaker_phrase_timeout"]:
expected_status = [200]
else:
expected_status = [400]
case "/set/data/speaker_phrase_timeout": case "/set/data/speaker_phrase_timeout":
data = random.randint(5, 10) data = random.randint(-1, 10)
if self.config_dict["speaker_record_timeout"] <= data:
expected_status = [200]
else:
expected_status = [400]
case "/set/data/speaker_max_phrases": case "/set/data/speaker_max_phrases":
data = random.randint(1, 10) data = random.randint(-1, 10)
if 0 <= data:
expected_status = [200]
else:
expected_status = [400]
case "/set/data/speaker_avg_logprob": case "/set/data/speaker_avg_logprob":
data = random.uniform(-5, 0) data = random.uniform(-5, 0)
case "/set/data/speaker_no_speech_prob": case "/set/data/speaker_no_speech_prob":
@@ -419,11 +462,20 @@ class TestMainloop():
case "/set/data/received_message_format_parts": case "/set/data/received_message_format_parts":
data = self.config_dict["received_message_format_parts"] data = self.config_dict["received_message_format_parts"]
case "/set/data/websocket_host": case "/set/data/websocket_host":
data = "127.0.0.1" data = random.choice(["127.0.0.1", "aaaaadwafasdsd", "0210.1564.845.0"])
if data == "127.0.0.1":
expected_status = [200, 400]
else:
expected_status = [400]
case "/set/data/websocket_port": case "/set/data/websocket_port":
data = random.randint(1024, 65535) data = random.randint(1024, 65535)
expected_status = [200, 400]
case "/set/data/osc_ip_address": case "/set/data/osc_ip_address":
data = "127.0.0.1" data = random.choice(["127.0.0.1", "aaaaadwafasdsd", "0210.1564.845.0"])
if data == "127.0.0.1":
expected_status = [200]
else:
expected_status = [400]
case "/set/data/osc_port": case "/set/data/osc_port":
data = random.randint(1024, 65535) data = random.randint(1024, 65535)
case _: case _:
@@ -432,6 +484,7 @@ class TestMainloop():
if data is not None: if data is not None:
print(f"data: {data}", end=" ", flush=True) print(f"data: {data}", end=" ", flush=True)
result, status = self.main.handleRequest(endpoint, data) result, status = self.main.handleRequest(endpoint, data)
if status in expected_status:
if status == 200: if status == 200:
self.config_dict[endpoint.split("/")[-1]] = result self.config_dict[endpoint.split("/")[-1]] = result
print(f"-> {Color.GREEN}[PASS]{Color.RESET} endpoint:{endpoint} Status: {status}, Result: {result}") print(f"-> {Color.GREEN}[PASS]{Color.RESET} endpoint:{endpoint} Status: {status}, Result: {result}")
@@ -604,10 +657,10 @@ if __name__ == "__main__":
# test.test_endpoints_on_off_all() # test.test_endpoints_on_off_all()
# test.test_set_data_endpoints_all() # test.test_set_data_endpoints_all()
# test.test_run_endpoints_all() # test.test_run_endpoints_all()
# test.test_endpoints_all_random() test.test_endpoints_all_random()
# test.test_endpoints_on_off_continuous() # test.test_endpoints_on_off_continuous()
# test.test_endpoints_on_off_random() # test.test_endpoints_on_off_random()
test.test_endpoints_specific_random() # test.test_endpoints_specific_random()
except KeyboardInterrupt: except KeyboardInterrupt:
print("Interrupted by user, shutting down...") print("Interrupted by user, shutting down...")
except Exception as e: except Exception as e: