-
Notifications
You must be signed in to change notification settings - Fork 134
/
_test_all.py
58 lines (46 loc) · 1.7 KB
/
_test_all.py
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
import sys
import os
import shutil
import logging
import gensim.downloader as api
from gensim.downloader import base_dir
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
logger = logging.getLogger("test-downloader-api")
logger.info(sys.version.replace("\n", " "))
if os.path.exists(base_dir):
logger.warning("REMOVE {}".format(base_dir))
shutil.rmtree(base_dir)
info = api.info()
logger.info("Test models")
failed_models = []
for idx, model_name in enumerate(info["models"]):
logger.info("{} ({} of {})".format(model_name, idx + 1, len(info["models"])))
try:
logger.info(api.load(model_name).most_similar("who"))
except Exception as e:
logger.exception(e)
failed_models.append(model_name)
if failed_models:
logger.critical("FAILED MODELS: {}".format(", ".join(failed_models)))
logger.info("#" * 25)
logger.info("Test datasets")
failed_datasets = []
for idx, dataset_name in enumerate(info["corpora"]):
logger.info("{} ({} of {})".format(dataset_name, idx + 1, len(info["corpora"])))
try:
res = sum(1 for _ in api.load(dataset_name))
if res == 0:
raise Exception("empty dataset")
except Exception as e:
logger.exception(e)
failed_datasets.append(dataset_name)
if failed_datasets:
logger.critical("FAILED DATASETS: {}".format(", ".join(failed_datasets)))
logger.info("#" * 25)
if len(failed_datasets + failed_models) == 0:
logger.info("Successful finished without errors!")
else:
logger.critical("FIX THIS:")
logger.critical("Models: {}".format(", ".join(failed_models)))
logger.critical("Datasets: {}".format(", ".join(failed_datasets)))
logger.info("#" * 25)