dream
43 строки · 1.4 Кб
1import requests2import os3
4import common.test_utils as test_utils5
6
7SERVICE_PORT = int(os.getenv("SERVICE_PORT"))8RANDOM_SEED = int(os.getenv("RANDOM_SEED", 2718))9URL = f"http://0.0.0.0:{SERVICE_PORT}/respond"10
11
12def handler(requested_data, random_seed):13hypothesis = requests.post(URL, json={**requested_data, "random_seed": random_seed}).json()14return hypothesis15
16
17def run_test(handler):18in_data, out_data = test_utils.get_dataset()19global_is_equal_flag = True20global_msg = ""21for test_name in in_data:22hypothesis = handler(in_data[test_name], RANDOM_SEED)23print(f"test name: {test_name}")24is_equal_flag, msg = test_utils.compare_structs(25out_data[test_name], hypothesis, ignored_keys=["id", "used_phrases"]26)27if msg and len(msg.split("`")) == 5:28_, ground_truth_text, _, hypothesis_text, _ = msg.split("`")29is_equal_flag, ratio = test_utils.compare_text(ground_truth_text, hypothesis_text, 0.80)30if not is_equal_flag:31msg = f"{msg} ratio = {ratio}"32# assert is_equal_flag, msg33if is_equal_flag:34print("Success")35else:36print(is_equal_flag, msg)37global_msg += f"\nFailed test_name: {test_name} <-> msg: {msg}"38global_is_equal_flag = False39assert global_is_equal_flag, global_msg40
41
42if __name__ == "__main__":43run_test(handler)44