dream
35 строк · 1.2 Кб
1import requests
2import os
3
4import common.test_utils as test_utils
5
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}, timeout=4).json()
14return hypothesis
15
16
17def run_test(handler):
18in_data, out_data = test_utils.get_dataset()
19for test_name in in_data:
20hypothesis = handler(in_data[test_name], RANDOM_SEED)
21# do not compare first elements of the structs - generated texts
22is_equal_flag, msg = test_utils.compare_structs(
23out_data[test_name][1:], hypothesis[1:], ignored_keys=["id", "responses"]
24)
25if msg and len(msg.split("`")) == 3:
26_, ground_truth_text, _, hypothesis_text, _ = msg.split("`")
27is_equal_flag, ratio = test_utils.compare_text(ground_truth_text, hypothesis_text, 0.2)
28if not is_equal_flag:
29msg = f"{msg} ratio = {ratio}"
30assert is_equal_flag, msg
31print("Success")
32
33
34if __name__ == "__main__":
35run_test(handler)
36