1
- from comptox_ai .db import GraphDB
1
+ import os
2
+ import warnings
2
3
3
4
import pytest
4
- import warnings
5
- import os
5
+
6
+ from comptox_ai . db import GraphDB
6
7
7
8
TEST_DIR = os .path .dirname (os .path .realpath (__file__ ))
8
9
9
10
10
11
# Module-level scope so we don't keep reconnecting with every test
11
12
@pytest .fixture (scope = "module" )
12
13
def G ():
13
- G = GraphDB (verbose = True , hostname = "neo4j.comptox.ai" )
14
- return G
14
+ G = GraphDB (verbose = True , hostname = "neo4j.comptox.ai" )
15
+ return G
16
+
15
17
16
18
class TestGraphDB (object ):
17
-
18
- < << << << HEAD
19
- == == == =
20
-
21
- >> >> >> > master
22
- def test_neo4j_connection_does_exist (self , G ):
23
- with warnings .catch_warnings ():
24
- # Supress the ExperimentalWarning for now
25
- warnings .simplefilter ("ignore" )
26
- assert G ._driver .verify_connectivity () is not None
27
-
28
- def test_cypher_query_does_run (self , G ):
29
- x = G .run_cypher ("RETURN 'hello';" )
30
- assert len (x [0 ]) > 0
31
-
32
- def test_dsstox_to_casrn_converts (self , G ):
33
- converted_ids = G .convert_ids (
34
- node_type = 'Chemical' ,
35
- from_id = 'xrefDTXSID' ,
36
- to_id = 'xrefCasRN' ,
37
- ids = ['DTXSID40857898' , 'DTXSID40858749' ]
38
- )
39
-
40
- # Hopefully DSSTOX -> CASRN mappings are stable between versions...
41
- assert converted_ids == ['69313-80-0' , '4559-79-9' ]
42
-
43
- ## THE FOLLOWING ARE OBSOLETE UNTIL GDS GRAPH CATALOG IS COMPATIBLE WITH
44
- # def test_raise_when_config_file_not_found(self):
45
- # with pytest.raises(RuntimeError) as e_info:
46
- # G_pre = GraphDB(config_file="/dev/null")
47
-
48
- # def test_raise_when_bad_config_given(self):
49
- # bad_config_file = os.path.join(TEST_DIR, 'badconfig.txt')
50
- # with pytest.raises(RuntimeError) as e_info:
51
- # G_pre = GraphDB(config_file=bad_config_file)
52
-
53
- # def test_raise_when_database_unavailable(self):
54
- # unavail_config_file = os.path.join(TEST_DIR, 'unavailconfig.txt')
55
- # with pytest.raises(RuntimeError) as e_info:
56
- # G_pre = GraphDB(config_file=unavail_config_file)
57
- ## STRING PROPERTIES:
58
-
59
- # def test_gds_list_existing_graphs(self, G):
60
- # x = G.list_existing_graphs()
61
- # assert isinstance(x, list)
62
-
63
- # def test_gds_delete_existing_graphs(self, G):
64
- # x = G.drop_all_existing_graphs()
65
-
66
- # y = G.list_existing_graphs()
67
-
68
- # assert len(y) is 0
69
-
70
- # def test_gds_create_graph_native_projection(self, G):
71
- # newgraph1 = G.build_graph_native_projection(
72
- # "testgraph1",
73
- # ["Chemical", "Disease"],
74
- # "*",
75
- # )
76
-
77
- # def test_gds_new_num_graphs_is_1(self, G):
78
- # y = G.list_existing_graphs()
79
- # assert len(y) == 1
80
-
81
- # def test_gds_delete_graph_native_projection(self, G):
82
- # x = G.drop_existing_graph("testgraph1")
83
- # assert x['graphName'] == "testgraph1"
84
-
85
- # def test_gds_create_graph_cypher_projection(self, G):
86
- # newgraph2 = G.build_graph_cypher_projection(
87
- # "testgraph2",
88
- # "MATCH (n) WHERE n:Chemical OR n:Disease RETURN id(n) AS id, labels(n) AS labels",
89
- # "MATCH (c:Chemical)-->(d:Disease) RETURN id(c) as source, id(d) as target"
90
- # )
91
-
92
- # def test_gds_delete_graph_cypher_projection(self, G):
93
- # # Note: this test will fail if the previous test fails
94
- # x = G.drop_existing_graph("testgraph2")
95
- # assert x['graphName'] == "testgraph2"
19
+
20
+ def test_neo4j_connection_does_exist (self , G ):
21
+ with warnings .catch_warnings ():
22
+ # Supress the ExperimentalWarning for now
23
+ warnings .simplefilter ("ignore" )
24
+ assert G ._driver .verify_connectivity () is not None
25
+
26
+ def test_cypher_query_does_run (self , G ):
27
+ x = G .run_cypher ("RETURN 'hello';" )
28
+ assert len (x [0 ]) > 0
29
+
30
+ def test_dsstox_to_casrn_converts (self , G ):
31
+ converted_ids = G .convert_ids (
32
+ node_type = 'Chemical' ,
33
+ from_id = 'xrefDTXSID' ,
34
+ to_id = 'xrefCasRN' ,
35
+ ids = ['DTXSID40857898' , 'DTXSID40858749' ]
36
+ )
37
+
38
+ # Hopefully DSSTOX -> CASRN mappings are stable between versions...
39
+ assert converted_ids == ['69313-80-0' , '4559-79-9' ]
40
+
41
+ # THE FOLLOWING ARE OBSOLETE UNTIL GDS GRAPH CATALOG IS COMPATIBLE WITH
42
+ # def test_raise_when_config_file_not_found(self):
43
+ # with pytest.raises(RuntimeError) as e_info:
44
+ # G_pre = GraphDB(config_file="/dev/null")
45
+
46
+ # def test_raise_when_bad_config_given(self):
47
+ # bad_config_file = os.path.join(TEST_DIR, 'badconfig.txt')
48
+ # with pytest.raises(RuntimeError) as e_info:
49
+ # G_pre = GraphDB(config_file=bad_config_file)
50
+
51
+ # def test_raise_when_database_unavailable(self):
52
+ # unavail_config_file = os.path.join(TEST_DIR, 'unavailconfig.txt')
53
+ # with pytest.raises(RuntimeError) as e_info:
54
+ # G_pre = GraphDB(config_file=unavail_config_file)
55
+ # STRING PROPERTIES:
56
+
57
+ # def test_gds_list_existing_graphs(self, G):
58
+ # x = G.list_existing_graphs()
59
+ # assert isinstance(x, list)
60
+
61
+ # def test_gds_delete_existing_graphs(self, G):
62
+ # x = G.drop_all_existing_graphs()
63
+
64
+ # y = G.list_existing_graphs()
65
+
66
+ # assert len(y) is 0
67
+
68
+ # def test_gds_create_graph_native_projection(self, G):
69
+ # newgraph1 = G.build_graph_native_projection(
70
+ # "testgraph1",
71
+ # ["Chemical", "Disease"],
72
+ # "*",
73
+ # )
74
+
75
+ # def test_gds_new_num_graphs_is_1(self, G):
76
+ # y = G.list_existing_graphs()
77
+ # assert len(y) == 1
78
+
79
+ # def test_gds_delete_graph_native_projection(self, G):
80
+ # x = G.drop_existing_graph("testgraph1")
81
+ # assert x['graphName'] == "testgraph1"
82
+
83
+ # def test_gds_create_graph_cypher_projection(self, G):
84
+ # newgraph2 = G.build_graph_cypher_projection(
85
+ # "testgraph2",
86
+ # "MATCH (n) WHERE n:Chemical OR n:Disease RETURN id(n) AS id, labels(n) AS labels",
87
+ # "MATCH (c:Chemical)-->(d:Disease) RETURN id(c) as source, id(d) as target"
88
+ # )
89
+
90
+ # def test_gds_delete_graph_cypher_projection(self, G):
91
+ # # Note: this test will fail if the previous test fails
92
+ # x = G.drop_existing_graph("testgraph2")
93
+ # assert x['graphName'] == "testgraph2"
0 commit comments