dream
58 строк · 2.5 Кб
1import requests
2import json
3from copy import deepcopy
4
5
6def get_input_json(fname):
7with open(fname, "r") as f:
8res = json.load(f)
9return {"dialogs": res}
10
11
12def slice_(input_data, i):
13tmp_data = deepcopy(input_data)
14tmp_data["dialogs"][0]["utterances"] = input_data["dialogs"][0]["utterances"][:i]
15tmp_data["dialogs"][0]["human_utterances"] = []
16tmp_data["dialogs"][0]["bot_utterances"] = []
17
18for uttr in tmp_data["dialogs"][0]["utterances"]:
19if uttr["user"]["user_type"] == "human":
20tmp_data["dialogs"][0]["human_utterances"].append(deepcopy(uttr))
21else:
22tmp_data["dialogs"][0]["bot_utterances"].append(deepcopy(uttr))
23
24return tmp_data
25
26
27def main_test():
28url = "http://0.0.0.0:8052/respond"
29input_data = get_input_json("test_dialog.json")
30sliced_data = [slice_(input_data, i) for i in range(3, 21, 2)]
31responses = [requests.post(url, json=tmp).json()[0][0] for tmp in sliced_data]
32gold_phrases = [
33"i mainly like marvel. apparently they published a generic comic book so they could trade mark "
34"super-hero and super-villian.",
35"i know right, it's strange that was even an option. dc actually stands for detective comics. "
36"i didn't know that.",
37"they said to make the name redundant. so weird. " "i thought stan lee was an amazing human, did you like him?",
38"i would have liked to as well. "
39"i never thought about when the marvel cinematic universe took place,"
40" it takes place in earth-199999. not sure what that means "
41"but it's a multiverse and different from the original earth-616.",
42"oh that makes sense. have you ever been to the michigan state library? "
43"it has the largest comic book collection in the world.",
44"wow, that is cool! i wonder how many actually exist.",
45"i never really got into the batman comics but i do love the movies.",
46"i enjoyed the animated series as well as some of the new ones, " "my kids and i enjoy teen titans go!",
47"i heard about titans not streaming on dc universe's streaming service but haven't watched it. "
48"have you seen it yet?",
49"oh well, maybe it'll be good, if not kids still have teen titans! haha, well it was nice talking "
50"to you, i've gotta run now, bye!",
51]
52
53for response, gold_phrase in zip(responses, gold_phrases):
54assert response == gold_phrase, print(f"Expect: {gold_phrase}. Got: {response}.")
55
56
57if __name__ == "__main__":
58main_test()
59