Skip to content

Commit 9d35f57

Browse files
committed
Make tests write with different db more robust
make sure the db is correct. And only expects a warning from neo4j driver if property is not known
1 parent e17a925 commit 9d35f57

File tree

2 files changed

+44
-26
lines changed

2 files changed

+44
-26
lines changed

graphdatascience/tests/integration/test_graph_ops.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,15 @@ def test_graph_export(runner: QueryRunner, gds: GraphDataScience) -> None:
253253
assert result["graphName"] == GRAPH_NAME
254254
assert result["dbName"] == MY_DB_NAME
255255

256-
runner.run_cypher("CREATE DATABASE $dbName WAIT", {"dbName": MY_DB_NAME})
257-
runner.set_database(MY_DB_NAME)
258-
node_count = runner.run_cypher("MATCH (n) RETURN COUNT(n) AS c").squeeze()
259-
260-
assert node_count == 3
261-
runner.set_database(DB)
262-
runner.run_cypher("DROP DATABASE $dbName WAIT", {"dbName": MY_DB_NAME})
256+
try:
257+
runner.run_cypher("CREATE DATABASE $dbName WAIT", {"dbName": MY_DB_NAME})
258+
runner.set_database(MY_DB_NAME)
259+
node_count = runner.run_cypher("MATCH (n) RETURN COUNT(n) AS c").squeeze()
260+
261+
assert node_count == 3
262+
finally:
263+
runner.set_database(DB)
264+
runner.run_cypher("DROP DATABASE $dbName WAIT", {"dbName": MY_DB_NAME})
263265

264266

265267
@pytest.mark.filterwarnings("ignore: The query used a deprecated procedure.")

graphdatascience/tests/integration/test_remote_graph_ops.py

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
@pytest.fixture(autouse=True, scope="class")
1212
def run_around_tests(gds_with_cloud_setup: AuraGraphDataScience) -> Generator[None, None, None]:
1313
# Runs before each test
14+
gds_with_cloud_setup.set_database("neo4j")
1415
gds_with_cloud_setup.run_cypher(
1516
"""
1617
CREATE
@@ -27,6 +28,7 @@ def run_around_tests(gds_with_cloud_setup: AuraGraphDataScience) -> Generator[No
2728
yield # Test runs here
2829

2930
# Runs after each test
31+
gds_with_cloud_setup.set_database("neo4j")
3032
gds_with_cloud_setup.run_cypher("MATCH (n) DETACH DELETE n")
3133

3234
res = gds_with_cloud_setup.graph.list()
@@ -43,31 +45,45 @@ def test_remote_projection(gds_with_cloud_setup: AuraGraphDataScience) -> None:
4345
assert result["nodeCount"] == 3
4446

4547

46-
@pytest.mark.cloud_architecture
48+
# @pytest.mark.cloud_architecture
4749
@pytest.mark.compatible_with(min_inclusive=ServerVersion(2, 7, 0))
4850
def test_remote_projection_and_writeback_custom_database_name(gds_with_cloud_setup: AuraGraphDataScience) -> None:
4951
gds_with_cloud_setup.run_cypher("CREATE DATABASE test1234 IF NOT EXISTS")
5052
gds_with_cloud_setup.set_database("test1234")
51-
gds_with_cloud_setup.run_cypher("CREATE ()-[:T]->()")
52-
G, projection_result = gds_with_cloud_setup.graph.project(
53-
GRAPH_NAME, "MATCH (n)-->(m) RETURN gds.graph.project.remote(n, m)"
54-
)
5553

56-
assert G.name() == GRAPH_NAME
57-
assert projection_result["nodeCount"] == 2
58-
assert projection_result["relationshipCount"] == 1
59-
60-
write_result = gds_with_cloud_setup.wcc.write(G, writeProperty="wcc")
61-
62-
assert write_result["nodePropertiesWritten"] == 2
63-
count_wcc_nodes_query = "MATCH (n WHERE n.wcc IS NOT NULL) RETURN count(*) AS c"
64-
nodes_with_wcc_custom_db = gds_with_cloud_setup.run_cypher(count_wcc_nodes_query).squeeze()
65-
assert nodes_with_wcc_custom_db == 2
66-
gds_with_cloud_setup.set_database("neo4j")
67-
# we get a warning because property wcc doesn't exist in the database -- which is good!
68-
with pytest.warns(RuntimeWarning):
69-
nodes_with_wcc_default_db = gds_with_cloud_setup.run_cypher(count_wcc_nodes_query).squeeze()
54+
try:
55+
gds_with_cloud_setup.run_cypher("CREATE ()-[:T]->()")
56+
G, projection_result = gds_with_cloud_setup.graph.project(
57+
GRAPH_NAME, "MATCH (n)-->(m) RETURN gds.graph.project.remote(n, m)"
58+
)
59+
60+
assert G.name() == GRAPH_NAME
61+
assert projection_result["nodeCount"] == 2
62+
assert projection_result["relationshipCount"] == 1
63+
64+
write_result = gds_with_cloud_setup.wcc.write(G, writeProperty="wcc")
65+
66+
assert write_result["nodePropertiesWritten"] == 2
67+
count_wcc_nodes_query = "MATCH (n WHERE n.wcc IS NOT NULL) RETURN count(*) AS c"
68+
nodes_with_wcc_custom_db = gds_with_cloud_setup.run_cypher(count_wcc_nodes_query).squeeze()
69+
assert nodes_with_wcc_custom_db == 2
70+
gds_with_cloud_setup.set_database("neo4j")
71+
72+
db_knows_wcc = gds_with_cloud_setup.run_cypher(
73+
"CALL db.propertyKeys() YIELD propertyKey WHERE propertyKey = 'wcc' RETURN count(*) > 0"
74+
).squeeze()
75+
76+
if db_knows_wcc:
77+
# this is the case if you have a dirty neo4j database with wcc set earlier
78+
nodes_with_wcc_default_db = gds_with_cloud_setup.run_cypher(count_wcc_nodes_query).squeeze()
79+
else:
80+
# we get a warning because property wcc doesn't exist in the database -- which is good!
81+
with pytest.warns(RuntimeWarning):
82+
nodes_with_wcc_default_db = gds_with_cloud_setup.run_cypher(count_wcc_nodes_query).squeeze()
7083
assert nodes_with_wcc_default_db == 0
84+
finally:
85+
gds_with_cloud_setup.run_cypher("DROP DATABASE test1234 IF EXISTS")
86+
gds_with_cloud_setup.set_database("neo4j")
7187

7288

7389
@pytest.mark.cloud_architecture

0 commit comments

Comments
 (0)