-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_api.py
More file actions
62 lines (50 loc) · 2.23 KB
/
test_api.py
File metadata and controls
62 lines (50 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from api import *
import pytest
import shutil
import configparser
config = configparser.ConfigParser()
config.read(os.path.join(os.getcwd(), 'pytest.ini'))
download_all_top_entities = (config['api']['download_all_top_entities'] == 'True')
remove_textrazor_cache = (config['api']['remove_textrazor_cache'] == 'True')
class TestApi(object):
# @pytest.mark.skip(reason="just saving time")
def test_get_students(self):
students = get_students()
assert len(students) > 0
assert "Carlos Souza" in students
# @pytest.mark.skip(reason="just saving time")
def test_models_exist(self):
model_path = os.path.join(os.getcwd(), 'models')
for assignment in range(1, 6):
model_file = os.path.join(model_path, 'doc2vec_model_assignment_' + str(assignment))
assert os.path.isfile(model_file)
# @pytest.mark.skip(reason="just saving time")
def test_load_models(self):
for assignment in range(1, 6):
model = load_model(assignment)
assert type(model) is gensim.models.doc2vec.Doc2Vec
# @pytest.mark.skip(reason="just saving time")
def test_get_similar_docs(self):
student = "Carlos Souza"
assignment = 4
assert len(get_similar_docs(student, assignment)) > 0
# @pytest.mark.skip(reason="just saving time")
def test_initialize_textrazor(self):
client = initialize_textrazor()
assert type(client) is textrazor.TextRazor
# @pytest.mark.skip(reason="just saving time")
def test_get_top_entities(self):
student = "Carlos Souza"
assignment = 4
entities = get_top_entities(student, assignment, force_api=False)
assert len(entities) > 0
@pytest.mark.skipif(not download_all_top_entities, reason="only to download all files (long process)")
def test_download_all_top_entities(self):
path = os.path.join(os.getcwd(), 'models', 'textrazor_cache')
if remove_textrazor_cache:
if os.path.exists(path):
shutil.rmtree(path)
for student in get_students():
for assignment in [1, 2, 3, 4, 5]:
get_top_entities(student, assignment, force_api=remove_textrazor_cache)
assert len(os.listdir(path)) > 100