11import TCT
22import pytest
3- from TCT .config import reset_config
4-
5-
6- @pytest .fixture (autouse = True )
7- def use_node_annotator_prod ():
8- """Run legacy Node Annotator expectations against production."""
9- TCT .configure (environment = "prod" )
10- yield
11- reset_config ()
12-
133
144CURIES_with_annotations = [
155 {
16- " curie" : " MONDO:0005148" ,
17- " expected" : {
18- " query" : " MONDO:0005148" ,
19- " disease_ontology.name" : " type 2 diabetes mellitus" ,
20- " sections" : [" disease_ontology" , " mondo" , " umls" ],
6+ ' curie' : ' MONDO:0005148' ,
7+ ' expected' : {
8+ ' query' : ' MONDO:0005148' ,
9+ ' disease_ontology.name' : ' type 2 diabetes mellitus' ,
10+ ' sections' : [' disease_ontology' , ' mondo' , ' umls' ],
2111 },
2212 },
2313 {
24- " curie" : " CHEBI:231601" ,
25- " expected" : {
26- " query" : " CHEBI:231601" ,
27- " sections" : [" chebi" ],
14+ ' curie' : ' CHEBI:231601' ,
15+ ' expected' : {
16+ ' query' : ' CHEBI:231601' ,
17+ ' sections' : [' chebi' ],
2818 },
2919 },
3020 {
31- "curie" : "CHEBI:15377" ,
32- "expected" : {
33- "query" : "CHEBI:15377" ,
34- "boxed_warning" : True ,
35- "sections" : [
36- "aeolus" ,
37- "chebi" ,
38- "chembl" ,
39- "clinical_approval" ,
40- "clinical_trials" ,
41- "drugbank" ,
42- "ndc" ,
43- "pubchem" ,
44- "unichem" ,
45- "unii" ,
46- ],
47- "chembl.availability_type" : 2 ,
21+ 'curie' : 'CHEBI:15377' ,
22+ 'expected' : {
23+ 'query' : 'CHEBI:15377' ,
24+ 'boxed_warning' : True ,
25+ 'sections' : ['aeolus' , 'chebi' , 'chembl' , 'clinical_approval' , 'clinical_trials' , 'drugbank' , 'ndc' , 'pubchem' , 'unichem' , 'unii' ],
26+ 'chembl.availability_type' : 2 ,
4827 },
4928 },
5029 {
51- " curie" : " NCIT:C34373" ,
52- " expected" : {},
30+ ' curie' : ' NCIT:C34373' ,
31+ ' expected' : {},
5332 },
5433 {
55- " curie" : " MONDO:0004976" ,
56- " expected" : {
57- " query" : " MONDO:0004976" ,
58- " disease_ontology.name" : " amyotrophic lateral sclerosis" ,
59- " sections" : [" disease_ontology" , " mondo" , " umls" ],
34+ ' curie' : ' MONDO:0004976' ,
35+ ' expected' : {
36+ ' query' : ' MONDO:0004976' ,
37+ ' disease_ontology.name' : ' amyotrophic lateral sclerosis' ,
38+ ' sections' : [' disease_ontology' , ' mondo' , ' umls' ],
6039 },
6140 },
6241 {
63- " curie" : " NCBIGene:1756" ,
64- " expected" : {
65- " query" : " 1756" ,
66- " taxid" : 9606 ,
67- " name" : " dystrophin" ,
68- " symbol" : " DMD" ,
69- " type_of_gene" : " protein-coding" ,
70- " sections" : ["go" , " interpro" ],
42+ ' curie' : ' NCBIGene:1756' ,
43+ ' expected' : {
44+ ' query' : ' 1756' ,
45+ ' taxid' : 9606 ,
46+ ' name' : ' dystrophin' ,
47+ ' symbol' : ' DMD' ,
48+ ' type_of_gene' : ' protein-coding' ,
49+ ' sections' : ['go' , ' interpro' ],
7150 },
7251 },
7352 {
74- " curie" : " UniProtKB:P00395" ,
75- " expected" : {
76- " query" : " P00395" ,
77- " symbol" : " MT-CO1" ,
78- " taxid" : 9606 ,
79- " type_of_gene" : " protein-coding" ,
80- " sections" : ["go" , " interpro" ],
81- " name" : " cytochrome c oxidase subunit I" ,
53+ ' curie' : ' UniProtKB:P00395' ,
54+ ' expected' : {
55+ ' query' : ' P00395' ,
56+ ' symbol' : ' MT-CO1' ,
57+ ' taxid' : 9606 ,
58+ ' type_of_gene' : ' protein-coding' ,
59+ ' sections' : ['go' , ' interpro' ],
60+ ' name' : ' cytochrome c oxidase subunit I' ,
8261 },
83- },
62+ }
8463]
8564
86-
8765def compare_result_with_expected (result , expected_result ):
8866 """
8967 Compares the actual result with the expected result across multiple fields and
@@ -102,70 +80,60 @@ def compare_result_with_expected(result, expected_result):
10280 assert result == {}
10381
10482 # Check sections.
105- if " sections" in expected_result :
106- for section in expected_result [" sections" ]:
83+ if ' sections' in expected_result :
84+ for section in expected_result [' sections' ]:
10785 assert section in result
10886
10987 # Check some top-level fields.
110- if " query" in expected_result :
111- assert result [" query" ] == expected_result [" query" ]
88+ if ' query' in expected_result :
89+ assert result [' query' ] == expected_result [' query' ]
11290
113- if " name" in expected_result :
114- assert result [" name" ] == expected_result [" name" ]
91+ if ' name' in expected_result :
92+ assert result [' name' ] == expected_result [' name' ]
11593
116- if " taxid" in expected_result :
117- assert result [" taxid" ] == expected_result [" taxid" ]
94+ if ' taxid' in expected_result :
95+ assert result [' taxid' ] == expected_result [' taxid' ]
11896
119- if " type_of_gene" in expected_result :
120- assert result [" type_of_gene" ] == expected_result [" type_of_gene" ]
97+ if ' type_of_gene' in expected_result :
98+ assert result [' type_of_gene' ] == expected_result [' type_of_gene' ]
12199
122- if " boxed_warning" in expected_result :
123- assert result [" boxed_warning" ] == expected_result [" boxed_warning" ]
100+ if ' boxed_warning' in expected_result :
101+ assert result [' boxed_warning' ] == expected_result [' boxed_warning' ]
124102
125103 # Check some subsection fields.
126- if "disease_ontology.name" in expected_result :
127- assert (
128- result ["disease_ontology" ]["name" ]
129- == expected_result ["disease_ontology.name" ]
130- )
104+ if 'disease_ontology.name' in expected_result :
105+ assert result ['disease_ontology' ]['name' ] == expected_result ['disease_ontology.name' ]
131106
132- if "chembl.availability_type" in expected_result :
133- assert (
134- result ["chembl" ]["availability_type" ]
135- == expected_result ["chembl.availability_type" ]
136- )
107+ if 'chembl.availability_type' in expected_result :
108+ assert result ['chembl' ]['availability_type' ] == expected_result ['chembl.availability_type' ]
137109
138110
139111def test_status ():
140- """Test that the status function returns a success message."""
112+ """ Test that the status function returns a success message. """
141113 result = TCT .node_annotator .status ()
142- assert result [" success" ]
114+ assert result [' success' ]
143115
144116
145117def test_lookup_curies ():
146- curies = list (map (lambda x : x [" curie" ], CURIES_with_annotations ))
118+ curies = list (map (lambda x : x [' curie' ], CURIES_with_annotations ))
147119 results = TCT .node_annotator .lookup_curies (curies )
148120 assert len (results ) == len (curies )
149121 for curie in curies :
150122 assert curie in results
151123 if isinstance (results [curie ], list ):
152- raise RuntimeError (
153- f"Multiple results found for CURIE '{ curie } ': { results [curie ]} "
154- )
124+ raise RuntimeError (f"Multiple results found for CURIE '{ curie } ': { results [curie ]} " )
155125
156126 actual_result = results [curie ]
157- expected_result = list (
158- filter (lambda x : x ["curie" ] == curie , CURIES_with_annotations )
159- )[0 ]["expected" ]
127+ expected_result = list (filter (lambda x : x ['curie' ] == curie , CURIES_with_annotations ))[0 ]['expected' ]
160128
161129 compare_result_with_expected (actual_result , expected_result )
162130
163131
164132@pytest .mark .parametrize ("curie_with_annotations" , CURIES_with_annotations )
165133def test_lookup_curie (curie_with_annotations ):
166- curie = curie_with_annotations [" curie" ]
134+ curie = curie_with_annotations [' curie' ]
167135 result = TCT .node_annotator .lookup_curie (curie )
168- if result == {} and curie_with_annotations [" expected" ] == {}:
136+ if result == {} and curie_with_annotations [' expected' ] == {}:
169137 # We expected no annotations and got no annotations.
170138 pytest .skip (f"No annotations found for CURIE '{ curie } '" )
171139
@@ -174,4 +142,4 @@ def test_lookup_curie(curie_with_annotations):
174142 raise RuntimeError (f"Multiple results found for CURIE '{ curie } ': { result } " )
175143
176144 # Compare the result with the expected annotations.
177- compare_result_with_expected (result , curie_with_annotations [" expected" ])
145+ compare_result_with_expected (result , curie_with_annotations [' expected' ])
0 commit comments