-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_aop.py
190 lines (160 loc) · 7.23 KB
/
test_aop.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
"""Test the AOP module methods and submodules."""
import pandas as pd
from sqlalchemy_utils import database_exists
from aop2db.aop.importer import import_aop_data
from aop2db.aop.query import (get_aops, get_bio_actions, get_bio_events,
get_bio_objects, get_bio_processes,
get_cell_terms, get_chemicals,
get_key_event_relationships, get_key_events,
get_life_stages, get_organ_terms, get_sexes,
get_stressors, get_taxonomies)
from aop2db.orm.manager import CONN, engine
class TestImporter:
"""Tests for the importer submodule."""
def test_importer(self):
"""Test the general import method."""
import_aop_data()
assert database_exists(CONN)
# TODO Check why certain tables empty
required_tables = {
"aop",
"aop_bio_action",
"aop_bio_event",
"aop_bio_object",
"aop_bio_process",
"aop_cell_term",
"aop_chemical",
"aop_chemical_synonym",
"aop_kers_aop_association",
"aop_key_event",
"aop_key_event_aop_association",
"aop_key_event_relationship",
"aop_life_stage",
"aop_life_stage_aop_association",
# "aop_life_stage_ker_association", # Currently no entries
"aop_life_stage_key_event_association",
"aop_organ_term",
"aop_sex",
"aop_sex_aop_association",
# "aop_sex_ker_association", # Currently no entries
"aop_sex_key_event_association",
"aop_stressor",
"aop_stressor_aop_association",
"aop_taxonomy",
# "aop_taxonomy_aop_association", # Currently no entries
# "aop_taxonomy_ker_association", # Currently no entries
"aop_taxonomy_key_event_association",
"key_event_bio_event_association",
"stressor_chemical_association",
"stressor_key_event_association",
}
# Check tables are all there
conn = engine.connect()
if engine.name == "sqlite":
query = "SELECT name FROM sqlite_master WHERE type='table';"
else:
query = "SHOW TABLES;"
tables_in_db = set([x[0] for x in conn.execute(query).fetchall()])
missing_tables = required_tables - tables_in_db
assert not missing_tables
# Check none of the tables are empty
for table_name in required_tables:# No entries at the moment
entry = conn.execute(f"SELECT * FROM {table_name} LIMIT 1;").fetchone()
if entry is None:
print(table_name)
assert entry
class TestQuery:
"""Tests for the query submodule."""
@staticmethod
def check_query_results(results: pd.DataFrame, expected_columns: list):
"""Helper method for checking results made by query functions."""
assert isinstance(results, pd.DataFrame)
for col in expected_columns:
assert col in results.columns
assert len(results) > 1
def test_get_aops(self):
"""Test the get_aop method."""
expected_cols = [
'aop_id', 'aop_hash', 'title', 'background', 'short_name', 'abstract', 'source',
'creation', 'last_modified', 'authors', 'wiki_status', 'oecd_status',
'saaop_status', 'oecd_project', 'essentiality_support',
'potential_applications', 'key_event_id', 'key_event_type',
'stressor', 'stressor_evidence', 'life_stage'
]
self.check_query_results(get_aops(), expected_cols)
def test_get_chemicals(self):
"""Test the get_chemicals method."""
expected_cols = [
'aop_hash', 'casrn', 'jchem_inchi_key', 'indigo_inchi_key', 'name', 'dsstox_id'
]
self.check_query_results(get_chemicals(), expected_cols)
def test_get_stressors(self):
"""Test the get_stressors method."""
expected_cols = [
'aop_hash', 'name', 'chemical_name', 'chemical_casrn'
]
self.check_query_results(get_stressors(), expected_cols)
def test_get_taxonomies(self):
"""Test the get_taxonomies method."""
expected_cols = [
'aop_hash', 'source', 'source_id', 'tax_id', 'species', 'name'
]
self.check_query_results(get_taxonomies(), expected_cols)
def test_get_life_stages(self):
"""Test the get_life_stages method."""
expected_cols = ['life_stage']
self.check_query_results(get_life_stages(), expected_cols)
def test_get_sexes(self):
"""Test the get_sexes method."""
expected_cols = ['sex']
self.check_query_results(get_sexes(), expected_cols)
def test_get_cell_terms(self):
"""Test the get_cell_terms method."""
expected_cols = ['source', 'source_id', 'name']
self.check_query_results(get_cell_terms(), expected_cols)
def test_get_organ_terms(self):
"""Test the get_organ_terms method."""
expected_cols = ['source', 'source_id', 'name']
self.check_query_results(get_organ_terms(), expected_cols)
def test_get_key_events(self):
"""Test the get_key_events method."""
expected_cols = [
'aop_id', 'aop_hash', 'title', 'short_name', 'biological_organization_level', 'cell_term', 'organ_term', 'tax_id'
]
self.check_query_results(get_key_events(), expected_cols)
def test_get_key_event_relationships(self):
"""Test the get_key_event_relationships method."""
expected_cols = [
'aop_hash',
'description',
'quantitative_understanding',
'evidence_supporting_taxonomic_applicability',
'source',
'creation',
'last_modified',
'up_event_id',
'down_event_id',
'evidence_value',
'evidence_biological_plausibility',
'evidence_emperical_support_linkage',
'evidence_uncertainties_or_inconsistencies',
'tax_id',
'life_stage',
]
self.check_query_results(get_key_event_relationships(), expected_cols)
def test_get_bio_events(self):
"""Test the get_bio_events method."""
expected_cols = ['key_event_id', 'key_event_title', 'bio_action_source', 'bio_action_source_id', 'bio_action_name', 'bio_process_source', 'bio_process_name', 'bio_process_source_id', 'bio_object_source', 'bio_object_source_id', 'bio_object_name']
self.check_query_results(get_bio_events(), expected_cols)
def test_get_bio_objects(self):
"""Test the get_bio_objects method."""
expected_cols = ['aop_hash', 'source', 'source_id', 'name']
self.check_query_results(get_bio_objects(), expected_cols)
def test_get_bio_actions(self):
"""Test the get_bio_actions method."""
expected_cols = ['aop_hash', 'source', 'source_id', 'name']
self.check_query_results(get_bio_actions(), expected_cols)
def test_get_bio_processes(self):
"""Test the get_bio_processes method."""
expected_cols = ['aop_hash', 'source', 'source_id', 'name']
self.check_query_results(get_bio_processes(), expected_cols)