dream

Форк
0
43 строки · 1.4 Кб
1
import requests
2
import os
3

4
import common.test_utils as test_utils
5

6

7
SERVICE_PORT = int(os.getenv("SERVICE_PORT"))
8
RANDOM_SEED = int(os.getenv("RANDOM_SEED", 2718))
9
URL = f"http://0.0.0.0:{SERVICE_PORT}/respond"
10

11

12
def handler(requested_data, random_seed):
13
    hypothesis = requests.post(URL, json={**requested_data, "random_seed": random_seed}).json()
14
    return hypothesis
15

16

17
def run_test(handler):
18
    in_data, out_data = test_utils.get_dataset()
19
    global_is_equal_flag = True
20
    global_msg = ""
21
    for test_name in in_data:
22
        hypothesis = handler(in_data[test_name], RANDOM_SEED)
23
        print(f"test name: {test_name}")
24
        is_equal_flag, msg = test_utils.compare_structs(
25
            out_data[test_name], hypothesis, ignored_keys=["id", "used_phrases"]
26
        )
27
        if msg and len(msg.split("`")) == 5:
28
            _, ground_truth_text, _, hypothesis_text, _ = msg.split("`")
29
            is_equal_flag, ratio = test_utils.compare_text(ground_truth_text, hypothesis_text, 0.80)
30
            if not is_equal_flag:
31
                msg = f"{msg} ratio = {ratio}"
32
        # assert is_equal_flag, msg
33
        if is_equal_flag:
34
            print("Success")
35
        else:
36
            print(is_equal_flag, msg)
37
            global_msg += f"\nFailed test_name: {test_name} <-> msg: {msg}"
38
            global_is_equal_flag = False
39
    assert global_is_equal_flag, global_msg
40

41

42
if __name__ == "__main__":
43
    run_test(handler)
44

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.