Skip to content

Commit db100d9

Browse files
authored
Merge pull request #582 from FlorentinD/reduce-test-warnings
Avoid db warnings in test queries
2 parents e2fda15 + 3636c22 commit db100d9

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

graphdatascience/tests/integration/test_database_ops.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@ def test_switching_db(runner: Neo4jQueryRunner) -> None:
1818
default_database = runner.database()
1919
runner.run_cypher("CREATE (a: Node)")
2020

21-
pre_count = runner.run_cypher("MATCH (n: Node) RETURN COUNT(n) AS c")["c"][0]
21+
pre_count = runner.run_cypher("MATCH (n: Node) RETURN COUNT(n) AS c").squeeze()
2222
assert pre_count == 1
2323

2424
MY_DB_NAME = "my-db"
2525
runner.run_cypher("CREATE DATABASE $dbName WAIT", {"dbName": MY_DB_NAME})
2626
try:
2727
runner.set_database(MY_DB_NAME)
28-
29-
with pytest.raises(RuntimeWarning, match="One of the labels in your query is not available in the database"):
30-
post_count = runner.run_cypher("MATCH (n: Node) RETURN COUNT(n) AS c")["c"][0]
31-
assert post_count == 0
28+
post_count = runner.run_cypher("MATCH (n) RETURN COUNT(n) AS c").squeeze()
29+
assert post_count == 0
3230
finally:
3331
runner.set_database(default_database) # type: ignore
3432
runner.run_cypher("MATCH (n) DETACH DELETE n")
@@ -63,16 +61,15 @@ def test_switching_db_and_use_graph(gds: GraphDataScience) -> None:
6361
def test_run_query_with_db(runner: Neo4jQueryRunner) -> None:
6462
runner.run_cypher("CREATE (a: Node)")
6563

66-
default_db_count = runner.run_cypher("MATCH (n: Node) RETURN COUNT(n) AS c")["c"][0]
64+
default_db_count = runner.run_cypher("MATCH (n: Node) RETURN COUNT(n) AS c").squeeze()
6765
assert default_db_count == 1
6866

6967
MY_DB_NAME = "my-db"
7068
runner.run_cypher("CREATE DATABASE $dbName WAIT", {"dbName": MY_DB_NAME})
7169

7270
try:
73-
with pytest.raises(RuntimeWarning, match="One of the labels in your query is not available in the database"):
74-
specified_db_count = runner.run_cypher("MATCH (n: Node) RETURN COUNT(n) AS c", database=MY_DB_NAME)["c"][0]
75-
assert specified_db_count == 0
71+
specified_db_count = runner.run_cypher("MATCH (n) RETURN COUNT(n) AS c", database=MY_DB_NAME).squeeze()
72+
assert specified_db_count == 0
7673
finally:
7774
runner.run_cypher("MATCH (n) DETACH DELETE n")
7875
runner.run_cypher("DROP DATABASE $dbName WAIT", {"dbName": MY_DB_NAME})
@@ -82,7 +79,7 @@ def test_run_query_with_db(runner: Neo4jQueryRunner) -> None:
8279
def test_initialize_with_db(runner: Neo4jQueryRunner) -> None:
8380
runner.run_cypher("CREATE (a: Node)")
8481

85-
default_db_count = runner.run_cypher("MATCH (n: Node) RETURN COUNT(n) AS c")["c"][0]
82+
default_db_count = runner.run_cypher("MATCH (n: Node) RETURN COUNT(n) AS c").squeeze()
8683
assert default_db_count == 1
8784

8885
MY_DB_NAME = "my-db"
@@ -91,11 +88,10 @@ def test_initialize_with_db(runner: Neo4jQueryRunner) -> None:
9188
gds_with_specified_db = GraphDataScience(URI, AUTH, database=MY_DB_NAME)
9289

9390
try:
94-
with pytest.raises(RuntimeWarning, match="One of the labels in your query is not available in the database"):
95-
specified_db_count = gds_with_specified_db.run_cypher(
96-
"MATCH (n: Node) RETURN COUNT(n) AS c", database=MY_DB_NAME
97-
)["c"][0]
98-
assert specified_db_count == 0
91+
specified_db_count = gds_with_specified_db.run_cypher(
92+
"MATCH (n) RETURN COUNT(n) AS c", database=MY_DB_NAME
93+
).squeeze()
94+
assert specified_db_count == 0
9995
finally:
10096
runner.run_cypher("MATCH (n) DETACH DELETE n")
10197
runner.run_cypher("DROP DATABASE $dbName WAIT", {"dbName": MY_DB_NAME})
@@ -169,10 +165,10 @@ def test_no_db_explicitly_set() -> None:
169165

170166

171167
def test_warning_when_logging_fails(runner: Neo4jQueryRunner) -> None:
172-
pool = f.ThreadPoolExecutor(1)
173-
future = pool.submit(lambda: time.sleep(2))
174-
with pytest.warns(RuntimeWarning, match=r"^Unable to get progress:"):
175-
runner._log("DUMMY", future, "bad_database")
168+
with f.ThreadPoolExecutor(1) as pool:
169+
future = pool.submit(lambda: time.sleep(2))
170+
with pytest.warns(RuntimeWarning, match=r"^Unable to get progress:"):
171+
runner._log("DUMMY", future, "bad_database")
176172

177173

178174
def test_bookmarks(runner: Neo4jQueryRunner) -> None:

graphdatascience/tests/integration/test_graph_ops.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import warnings
12
from typing import Generator
23

34
import numpy as np
@@ -738,14 +739,23 @@ def test_graph_relationships_stream_without_arrow(gds_without_arrow: GraphDataSc
738739
else:
739740
result = gds_without_arrow.beta.graph.relationships.stream(G, ["REL", "REL2"])
740741

741-
with pytest.raises(DeprecationWarning):
742-
expected = gds_without_arrow.run_cypher(
743-
"MATCH (n)-[r]->(m) RETURN id(n) AS src_id, id(m) AS trg_id, type(r) AS rel_type"
744-
)
742+
warnings.filterwarnings(
743+
"ignore", category=DeprecationWarning, message="The query used a deprecated function: `id`."
744+
)
745+
expected = gds_without_arrow.run_cypher(
746+
"MATCH (n)-[r]->(m) RETURN id(n) AS src_id, id(m) AS trg_id, type(r) AS rel_type"
747+
)
745748

746-
assert result.shape[0] == expected.shape[0]
747-
for _, row in expected.iterrows():
748-
assert (result == np.array(row)).all(1).any()
749+
# Pandas 2.2.0 deprecated an API used by the following assertion (in the underlying impl of pandas)
750+
warnings.filterwarnings(
751+
"ignore",
752+
category=DeprecationWarning,
753+
message=r"Passing a BlockManager to TopologyDataFrame is deprecated",
754+
)
755+
756+
assert result.shape[0] == expected.shape[0]
757+
for _, row in expected.iterrows():
758+
assert (result == np.array(row)).all(1).any()
749759

750760
assert list(result.keys()) == ["sourceNodeId", "targetNodeId", "relationshipType"]
751761

0 commit comments

Comments
 (0)