dream

Форк
0
46 строк · 1.5 Кб
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
LANGUAGE = os.getenv("LANGUAGE", "EN")
11

12
FAKE_SERVER = os.getenv("FAKE", True)
13

14

15
def handler(requested_data, random_seed):
16
    hypothesis = requests.post(URL, json={**requested_data, "random_seed": random_seed}).json()
17
    return hypothesis
18

19

20
def run_test(handler):
21
    in_data, out_data = test_utils.get_dataset()
22
    for test_name in in_data:
23
        if LANGUAGE == "RU" and "RU" not in test_name:
24
            # if russian language, skip english tests
25
            continue
26
        elif LANGUAGE == "EN" and "EN" not in test_name:
27
            # if russian language, skip english tests
28
            continue
29
        if not FAKE_SERVER and "FAKE" in test_name:
30
            # skip fake server tests if the server is real
31
            continue
32

33
        hypothesis = handler(in_data[test_name], RANDOM_SEED)
34
        print(f"test name: {test_name}")
35
        is_equal_flag, msg = test_utils.compare_structs(out_data[test_name], hypothesis, ignored_keys=["id"])
36
        if msg and len(msg.split("`")) == 5:
37
            _, ground_truth_text, _, hypothesis_text, _ = msg.split("`")
38
            is_equal_flag, ratio = test_utils.compare_text(ground_truth_text, hypothesis_text, 0.80)
39
            if not is_equal_flag:
40
                msg = f"{msg} ratio = {ratio}"
41
        assert is_equal_flag, msg
42
        print("Success")
43

44

45
if __name__ == "__main__":
46
    run_test(handler)
47

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

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

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

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