Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit ed84381

Browse files
authoredOct 15, 2020
test: add southpark test
1 parent 5efaef6 commit ed84381

File tree

6 files changed

+197
-3
lines changed

6 files changed

+197
-3
lines changed
 

‎.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,5 @@ shell/jina-wizard.sh
130130
/tests/junit/
131131
jina-profile*.json
132132

133-
.vscode/
133+
.vscode/
134+
*/workspace

‎pytest.ini

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pytest]
2+
norecursedirs = cross-modal-search/img_emb/* cross-modal-search/txt_emb/* openapi/python-flask/openapi_server/*

‎southpark-search/requirements.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
click
2-
transformers
2+
transformers==3.3.1
33
torch
4-
jina[scipy]==0.5.5
4+
jina[scipy]

‎southpark-search/tests/__init__.py

Whitespace-only changes.

‎southpark-search/tests/data-index.csv

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
Randy[SEP]I wish I could!
2+
Chef[SEP]OOH
3+
Cartman[SEP]How about we have us
4+
KurtRussell[SEP]They're raping us and it huuurts!
5+
Cartman[SEP]This way
6+
Kyle[SEP]I'm not happy with the direction this company is taking.
7+
Butler[SEP]Here he is.
8+
Clyde[SEP]Uh.
9+
Stan[SEP]That's my silly grampa.
10+
Sharon[SEP]Sorry
11+
KyleBroflovski[SEP]OooOoOoOooOOO!
12+
Coon[SEP]I work on my own now.
13+
LeadBiker[SEP]I'm trying to talk
14+
MrDawkins[SEP]I'll thell them.
15+
Marvin[SEP]Who's Stan?
16+
Stockbroker[SEP]Just talk to the Treasury Department in DC.
17+
Jimbo[SEP]Christ
18+
Stan[SEP]Hey
19+
Charlie[SEP]Of next year.
20+
Kyle[SEP]Nothing's changed.
21+
EmoGirl[SEP]I'd rather kill myself than put on gym shorts.
22+
Stan[SEP]I just wanna be a normal kid again.
23+
Terrance[SEP]I was an asshole
24+
Teresa[SEP]What a stupid bitch!
25+
Jimmy[SEP]I just think it's a fabulous app
26+
AlecBaldwin[SEP]Some little faggot in my head.
27+
MrMackey[SEP]Freely?
28+
Fiancée[SEP]I'll pilot!
29+
Man[SEP]Allб
30+
Cartman[SEP]Gahaaa!
31+
Kelly[SEP]Come on
32+
Clyde[SEP]She's totally staring you down.
33+
Butters[SEP]Leave me alone!
34+
Stan[SEP]We don't have any weapons.
35+
Cartman[SEP]I can hear Kyle
36+
LeadBiker[SEP]Ju-just ignore him!
37+
Cartman[SEP]I'm going to find out where it is!
38+
Kyle[SEP]Then we'll wait
39+
Kyle[SEP]Oh
40+
Wendy[SEP]Mayor
41+
Jimbo[SEP]Surrender your men
42+
Stan[SEP]All right Avengers
43+
Rod[SEP]Oh.
44+
Butters[SEP]Ah-I'm grounded for lookin' stupid in my school picture.
45+
Bebe[SEP]They called me a slut
46+
Postum[SEP]Oh
47+
Cartman[SEP]I can't-
48+
Scout[SEP]Kid
49+
MrsGarrison[SEP]My eyes are opened!
50+
Cartman[SEP]Dude
51+
PresidentWulff[SEP]Ich werde zuerst umbringen!
52+
Randy[SEP]To be honest
53+
Linda[SEP]Why do you children live in this town alone?
54+
Cartman[SEP]It's the only way.
55+
Cartman[SEP]Age
56+
Kyle[SEP]Timmy saw the turkey and wanted to get it.
57+
Cartman[SEP]Get a hold of yourself
58+
Cartman[SEP]Fuck you Bebe!
59+
Cartman[SEP]You serve
60+
Pablo[SEP]Quite an amazing creature.
61+
Man10[SEP]'Scuse me
62+
Jimbo[SEP]Ned
63+
Kyle[SEP]Quit it
64+
Homeowner[SEP]They're gonna betray you at the Red Robin wedding!
65+
PrincipalVictoria[SEP]Listen Eric!
66+
Chef[SEP]Oh
67+
Kyle[SEP]Yes
68+
Randy[SEP]Yuh
69+
Lucas[SEP]Don't say anything
70+
Craig[SEP]Nope.
71+
MrGarrison[SEP]Jimbo
72+
Kyle[SEP]Because you're a fucking fatass
73+
Janet[SEP]are Lesbos!
74+
Cartman[SEP]Yes
75+
Cartman[SEP]Outlander
76+
Stan[SEP]Disqualified?
77+
Man[SEP]Nadia
78+
ATFlead[SEP]Even if it means we have to kill each and every one of them.
79+
Liane[SEP]How are you doing?
80+
Harry[SEP]It was a tough time for all of Canada.
81+
Cartman[SEP]next week sometime.
82+
Randy[SEP]Yes
83+
Cartman[SEP]It's simple science
84+
Katherine[SEP]Could you get that
85+
Producer[SEP]Stallone thinks your singer has a lot of talent.
86+
Sharon[SEP]Stanley
87+
Stephen[SEP]Look
88+
Cartman[SEP]Ringy-ding?
89+
Cartman[SEP]AAAAAA!
90+
JimRome[SEP]Check that: I'll watch that game.
91+
Cartman[SEP]Nice
92+
Gerald[SEP]get out of the house?
93+
SgtYates[SEP]You boys say you can identify the Red Box thieves?
94+
Aussie[SEP]Come back here
95+
ABritishPerson[SEP]But every single day Pip's love for Estella grew.
96+
Stan[SEP]I hate that toy!
97+
Man1[SEP]Uh
98+
Doorman[SEP]Come in.
99+
CheesyPoofCartman[SEP]Lame.
100+
Stan[SEP]persecrute our religious beliefs.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import pytest
2+
3+
import json
4+
import os
5+
import sys
6+
import shutil
7+
import subprocess
8+
from typing import List
9+
10+
from jina.flow import Flow
11+
12+
13+
os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..' ))
14+
15+
16+
num_docs = 100
17+
top_k = 3
18+
index_flow_file_path = "flow-index.yml"
19+
query_flow_file_path = "flow-query.yml"
20+
21+
22+
def config():
23+
os.environ["JINA_DATA_FILE"] = os.environ.get("JINA_DATA_FILE", "tests/data-index.csv")
24+
os.environ["JINA_WORKSPACE"] = os.environ.get("JINA_WORKSPACE", "workspace")
25+
os.environ["JINA_PORT"] = os.environ.get("JINA_PORT", str(45678))
26+
27+
28+
def prepare_data():
29+
pass
30+
31+
32+
def setup_env():
33+
subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
34+
subprocess.check_call([sys.executable, "-m", "pip", "install", "requests", "jina[http]"])
35+
36+
37+
def index_documents():
38+
f = Flow().load_config(index_flow_file_path)
39+
40+
with f:
41+
f.index_lines(
42+
filepath=os.environ["JINA_DATA_FILE"],
43+
batch_size=8,
44+
size=num_docs,
45+
)
46+
47+
48+
def call(method, url, payload=None, headers={'Content-Type': 'application/json'}):
49+
import requests
50+
return getattr(getattr(requests, method)(url, data=json.dumps(payload), headers=headers), 'json')()
51+
52+
53+
def get_results(query, top_k=top_k):
54+
return call('post',
55+
'http://0.0.0.0:45678/api/search',
56+
payload={"top_k": top_k, "mode": "search", "data": [f"text:{query}"]}
57+
)
58+
59+
60+
def set_flow():
61+
f = Flow().load_config(query_flow_file_path)
62+
f.use_rest_gateway()
63+
return f
64+
65+
66+
@pytest.fixture
67+
def queries():
68+
return [('hey dude', ["Don't say anything\n", "Check that: I'll watch that game.\n", "Because you're a fucking fatass\n"]),
69+
('sister', ['Sorry\n', 'Lame.\n', 'Christ\n']),
70+
("Ill watch that game", ["Check that: I'll watch that game.\n", 'Quit it\n', 'Sorry\n'])]
71+
72+
73+
def test_query(queries):
74+
config()
75+
setup_env()
76+
prepare_data()
77+
index_documents()
78+
f = set_flow()
79+
with f:
80+
for query, exp_result in queries:
81+
output = get_results(query)
82+
matches = output['search']['docs'][0]['matches']
83+
assert len(matches) == top_k #check the number of docs returned
84+
result = []
85+
for match in matches:
86+
result.append(match['text'])
87+
assert result == exp_result
88+
89+
90+
def test_cleanup():
91+
shutil.rmtree(os.environ['JINA_WORKSPACE'])

0 commit comments

Comments
 (0)
This repository has been archived.