dream

Форк
0
35 строк · 1.2 Кб
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}, timeout=4).json()
14
    return hypothesis
15

16

17
def run_test(handler):
18
    in_data, out_data = test_utils.get_dataset()
19
    for test_name in in_data:
20
        hypothesis = handler(in_data[test_name], RANDOM_SEED)
21
        # do not compare first elements of the structs - generated texts
22
        is_equal_flag, msg = test_utils.compare_structs(
23
            out_data[test_name][1:], hypothesis[1:], ignored_keys=["id", "responses"]
24
        )
25
        if msg and len(msg.split("`")) == 3:
26
            _, ground_truth_text, _, hypothesis_text, _ = msg.split("`")
27
            is_equal_flag, ratio = test_utils.compare_text(ground_truth_text, hypothesis_text, 0.2)
28
            if not is_equal_flag:
29
                msg = f"{msg} ratio = {ratio}"
30
        assert is_equal_flag, msg
31
        print("Success")
32

33

34
if __name__ == "__main__":
35
    run_test(handler)
36

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

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

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

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