dream
33 строки · 1.1 Кб
1import requests2import os3
4import common.test_utils as test_utils5
6SERVICE_NAME = os.getenv("SERVICE_NAME")7SERVICE_PORT = int(os.getenv("SERVICE_PORT"))8URL = f"http://0.0.0.0:{SERVICE_PORT}/comet"9
10
11def handler(requested_data):12hypothesis = requests.post(URL, json={**requested_data}).json()13return hypothesis14
15
16def run_test(handler):17in_data, out_data = test_utils.get_dataset()18for test_name in in_data:19if test_name in SERVICE_NAME:20hypothesis = handler(in_data[test_name])21print(f"test name: {test_name}")22is_equal_flag, msg = test_utils.compare_structs(out_data[test_name], hypothesis)23if msg and len(msg.split("`")) == 5:24_, ground_truth_text, _, hypothesis_text, _ = msg.split("`")25is_equal_flag, ratio = test_utils.compare_text(ground_truth_text, hypothesis_text, 0.80)26if not is_equal_flag:27msg = f"{msg} ratio = {ratio}"28assert is_equal_flag, msg29print("Success")30
31
32if __name__ == "__main__":33run_test(handler)34