Skip to content

Commit db0f0c6

Browse files
committed
Support Neo4j 4.4 in tests
1 parent 5f3ebc1 commit db0f0c6

File tree

4 files changed

+103
-14
lines changed

4 files changed

+103
-14
lines changed

graphdatascience/tests/integration/conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ def gds_with_cloud_setup(request: pytest.FixtureRequest) -> Generator[AuraGraphD
103103
_gds.close()
104104

105105

106+
def is_neo4j_44(gds: GraphDataScience) -> bool:
107+
try:
108+
result = gds.run_cypher(
109+
"CALL dbms.components() YIELD name, versions, edition unwind versions as version RETURN name, version, edition"
110+
)
111+
version = result["version"][0]
112+
return version.startswith("4.4") # type: ignore
113+
except Exception as e:
114+
print(e)
115+
return False
116+
117+
106118
@pytest.fixture(autouse=True)
107119
def clean_up(gds: GraphDataScience) -> Generator[None, None, None]:
108120
yield

graphdatascience/tests/integration/test_error_handling.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from graphdatascience import GraphDataScience
77
from graphdatascience.server_version.server_version import ServerVersion
8-
from graphdatascience.tests.integration.conftest import AUTH, URI
8+
from graphdatascience.tests.integration.conftest import AUTH, URI, is_neo4j_44
99

1010
GRAPH_NAME = "g"
1111

@@ -204,6 +204,9 @@ def test_auto_completion_false_positives(gds: GraphDataScience) -> None:
204204

205205

206206
def test_forward_server_side_warning(gds: GraphDataScience) -> None:
207+
if is_neo4j_44(gds):
208+
return
209+
207210
with pytest.raises(Warning, match="The query used a deprecated function: `id`."):
208211
gds.run_cypher("MATCH (n) RETURN id(n)")
209212

@@ -213,6 +216,9 @@ def test_forward_server_side_warning(gds: GraphDataScience) -> None:
213216
def test_forward_driver_configured_warning(warning_driver: Driver) -> None:
214217
gds = GraphDataScience(warning_driver)
215218

219+
if is_neo4j_44(gds):
220+
return
221+
216222
with pytest.raises(Warning, match="The query used a deprecated function: `id`."):
217223
gds.run_cypher("MATCH (n) RETURN id(n)")
218224

graphdatascience/tests/integration/test_graph_ops.py

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from graphdatascience.query_runner.arrow_query_runner import ArrowQueryRunner
1010
from graphdatascience.query_runner.query_runner import QueryRunner
1111
from graphdatascience.server_version.server_version import ServerVersion
12-
from graphdatascience.tests.integration.conftest import AUTH, DB, URI
12+
from graphdatascience.tests.integration.conftest import AUTH, DB, URI, is_neo4j_44
1313

1414
GRAPH_NAME = "g"
1515

@@ -56,7 +56,7 @@ def test_project_graph_cypher(gds: GraphDataScience) -> None:
5656
node_query = "MATCH (n:Node) RETURN id(n) as id"
5757
relationship_query = "MATCH (n:Node)-->(m:Node) RETURN id(n) as source, id(m) as target, 'T' as type"
5858

59-
if gds.server_version() >= ServerVersion(2, 4, 0):
59+
if gds.server_version() >= ServerVersion(2, 4, 0) and not is_neo4j_44(gds):
6060
with pytest.warns(DeprecationWarning):
6161
G, result = gds.graph.project.cypher(GRAPH_NAME, node_query, relationship_query)
6262
else:
@@ -73,7 +73,7 @@ def test_project_graph_cypher_estimate(gds: GraphDataScience) -> None:
7373
node_query = "MATCH (n:Node) RETURN id(n) as id"
7474
relationship_query = "MATCH (n:Node)-->(m:Node) RETURN id(n) as source, id(m) as target, 'T' as type"
7575

76-
if gds.server_version() >= ServerVersion(2, 5, 0):
76+
if gds.server_version() >= ServerVersion(2, 5, 0) and not is_neo4j_44(gds):
7777
with pytest.warns(DeprecationWarning):
7878
result = gds.graph.project.cypher.estimate(node_query, relationship_query)
7979
else:
@@ -103,7 +103,7 @@ def test_cypher_projection_empty_graph(gds: GraphDataScience) -> None:
103103
def test_beta_project_subgraph(runner: QueryRunner, gds: GraphDataScience) -> None:
104104
from_G, _ = gds.graph.project(GRAPH_NAME, {"Node": {"properties": "x"}}, "*")
105105

106-
if gds.server_version() >= ServerVersion(2, 5, 0):
106+
if gds.server_version() >= ServerVersion(2, 5, 0) and not is_neo4j_44(gds):
107107
with pytest.warns(DeprecationWarning):
108108
sub_G, result = gds.beta.graph.project.subgraph("s", from_G, "n.x > 1", "*", concurrency=2)
109109
else:
@@ -153,7 +153,7 @@ def test_sample_rwr(runner: QueryRunner, gds: GraphDataScience) -> None:
153153
def test_sample_rwr_alpha(runner: QueryRunner, gds: GraphDataScience) -> None:
154154
from_G, _ = gds.graph.project(GRAPH_NAME, {"Node": {"properties": "x"}}, "*")
155155

156-
if gds.server_version() >= ServerVersion(2, 4, 0):
156+
if gds.server_version() >= ServerVersion(2, 4, 0) and not is_neo4j_44(gds):
157157
with pytest.warns(DeprecationWarning):
158158
rwr_G, result = gds.alpha.graph.sample.rwr("s", from_G, samplingRatio=0.6, concurrency=1, randomSeed=42)
159159
else:
@@ -267,7 +267,7 @@ def test_graph_export(runner: QueryRunner, gds: GraphDataScience) -> None:
267267
def test_beta_graph_export_csv_estimate(gds: GraphDataScience) -> None:
268268
G, _ = gds.graph.project(GRAPH_NAME, "*", "*")
269269

270-
if gds.server_version() >= ServerVersion(2, 5, 0):
270+
if gds.server_version() >= ServerVersion(2, 5, 0) and not is_neo4j_44(gds):
271271
with pytest.warns(DeprecationWarning):
272272
result = gds.beta.graph.export.csv.estimate(G, exportName="dummy")
273273
else:
@@ -338,6 +338,9 @@ def test_graph_nodeProperty_stream_with_arrow_no_db() -> None:
338338
def test_graph_streamNodeProperty_without_arrow(gds_without_arrow: GraphDataScience) -> None:
339339
G, _ = gds_without_arrow.graph.project(GRAPH_NAME, {"Node": {"properties": "x"}}, "*")
340340

341+
if is_neo4j_44(gds_without_arrow):
342+
return
343+
341344
with pytest.warns(DeprecationWarning):
342345
result = gds_without_arrow.graph.streamNodeProperty(G, "x", concurrency=2)
343346

@@ -518,6 +521,9 @@ def test_graph_nodeProperties_stream_raise_error_with_duplicate_keys(gds: GraphD
518521
def test_graph_streamNodeProperties_without_arrow(gds_without_arrow: GraphDataScience) -> None:
519522
G, _ = gds_without_arrow.graph.project(GRAPH_NAME, {"Node": {"properties": ["x", "y"]}}, "*")
520523

524+
if is_neo4j_44(gds_without_arrow):
525+
return
526+
521527
with pytest.warns(DeprecationWarning):
522528
result = gds_without_arrow.graph.streamNodeProperties(G, ["x", "y"], concurrency=2)
523529

@@ -561,6 +567,9 @@ def test_graph_nodeProperties_stream_without_arrow(gds_without_arrow: GraphDataS
561567
def test_graph_nodeProperties_fail_on_duplicate_node_properties(gds: GraphDataScience) -> None:
562568
G, _ = gds.graph.project(GRAPH_NAME, {"Node": {"properties": ["x", "y"]}}, "*")
563569

570+
if is_neo4j_44(gds):
571+
return
572+
564573
with pytest.raises(ValueError, match="The provided node_properties contain duplicate property names"):
565574
gds.graph.nodeProperties.stream(G, ["x", "x", "y"], db_node_properties=["z", "name"], concurrency=2)
566575

@@ -573,6 +582,9 @@ def test_graph_streamNodeProperties_without_arrow_separate_property_columns(
573582
) -> None:
574583
G, _ = gds_without_arrow.graph.project(GRAPH_NAME, {"Node": {"properties": ["x", "z"]}}, "*")
575584

585+
if is_neo4j_44(gds_without_arrow):
586+
return
587+
576588
with pytest.warns(DeprecationWarning):
577589
result = gds_without_arrow.graph.streamNodeProperties(
578590
G, ["x", "z"], separate_property_columns=True, concurrency=2
@@ -626,6 +638,9 @@ def test_graph_relationshipProperty_stream_with_arrow(gds: GraphDataScience) ->
626638
def test_graph_streamRelationshipProperty_without_arrow(gds_without_arrow: GraphDataScience) -> None:
627639
G, _ = gds_without_arrow.graph.project(GRAPH_NAME, "*", {"REL": {"properties": "relX"}})
628640

641+
if is_neo4j_44(gds_without_arrow):
642+
return
643+
629644
with pytest.warns(DeprecationWarning):
630645
result = gds_without_arrow.graph.streamRelationshipProperty(G, "relX", concurrency=2)
631646
assert {e for e in result["propertyValue"]} == {4, 5, 6}
@@ -746,6 +761,9 @@ def test_graph_relationshipProperties_stream_with_arrow_rel_as_str_sep(gds: Grap
746761
def test_graph_streamRelationshipProperties_without_arrow(gds_without_arrow: GraphDataScience) -> None:
747762
G, _ = gds_without_arrow.graph.project(GRAPH_NAME, "*", {"REL": {"properties": ["relX", "relY"]}})
748763

764+
if is_neo4j_44(gds_without_arrow):
765+
return
766+
749767
with pytest.warns(DeprecationWarning):
750768
result = gds_without_arrow.graph.streamRelationshipProperties(G, ["relX", "relY"], concurrency=2)
751769

@@ -787,6 +805,8 @@ def test_graph_streamRelationshipProperties_without_arrow_separate_property_colu
787805
gds_without_arrow: GraphDataScience,
788806
) -> None:
789807
G, _ = gds_without_arrow.graph.project(GRAPH_NAME, "*", {"REL": {"properties": ["relX", "relY"]}})
808+
if is_neo4j_44(gds_without_arrow):
809+
return
790810

791811
with pytest.warns(DeprecationWarning):
792812
result = gds_without_arrow.graph.streamRelationshipProperties(
@@ -863,7 +883,7 @@ def test_graph_relationships_stream_with_arrow(gds: GraphDataScience) -> None:
863883
else:
864884
result = gds.beta.graph.relationships.stream(G, ["REL", "REL2"])
865885

866-
with pytest.warns(DeprecationWarning):
886+
def workload() -> None:
867887
expected = gds.run_cypher("MATCH (n)-[r]->(m) RETURN id(n) AS src_id, id(m) AS trg_id, type(r) AS rel_type")
868888

869889
assert list(result.keys()) == ["sourceNodeId", "targetNodeId", "relationshipType"]
@@ -872,6 +892,12 @@ def test_graph_relationships_stream_with_arrow(gds: GraphDataScience) -> None:
872892
for _, row in expected.iterrows():
873893
assert (result == np.array(row)).all(1).any()
874894

895+
if is_neo4j_44(gds):
896+
workload()
897+
else:
898+
with pytest.warns(DeprecationWarning):
899+
workload()
900+
875901
by_rel_type = result.by_rel_type()
876902

877903
num_rels = 0
@@ -888,7 +914,7 @@ def test_graph_relationships_stream_with_arrow(gds: GraphDataScience) -> None:
888914
def test_beta_graph_relationships_to_undirected(gds: GraphDataScience) -> None:
889915
G, _ = gds.graph.project(GRAPH_NAME, "Node", ["REL", "REL2"])
890916

891-
if gds.server_version() >= ServerVersion(2, 5, 0):
917+
if gds.server_version() >= ServerVersion(2, 5, 0) and not is_neo4j_44(gds):
892918
with pytest.warns(DeprecationWarning):
893919
result = gds.beta.graph.relationships.toUndirected(G, "REL", "REL_UNDIRECTED")
894920
else:
@@ -912,8 +938,12 @@ def test_graph_writeNodeProperties(gds: GraphDataScience) -> None:
912938

913939
gds.pageRank.mutate(G, mutateProperty="rank", dampingFactor=0.2, tolerance=0.3)
914940

915-
with pytest.warns(DeprecationWarning):
941+
if is_neo4j_44(gds):
916942
result = gds.graph.writeNodeProperties(G, ["rank"], concurrency=2)
943+
else:
944+
with pytest.warns(DeprecationWarning):
945+
result = gds.graph.writeNodeProperties(G, ["rank"], concurrency=2)
946+
917947
assert result["propertiesWritten"] == 3
918948

919949

@@ -922,8 +952,12 @@ def test_graph_writeRelationship(gds: GraphDataScience) -> None:
922952

923953
gds.nodeSimilarity.mutate(G, mutateRelationshipType="SIMILAR", mutateProperty="score", similarityCutoff=0)
924954

925-
with pytest.warns(DeprecationWarning):
955+
if is_neo4j_44(gds):
926956
result = gds.graph.writeRelationship(G, "SIMILAR", "score", concurrency=2)
957+
else:
958+
with pytest.warns(DeprecationWarning):
959+
result = gds.graph.writeRelationship(G, "SIMILAR", "score", concurrency=2)
960+
927961
assert result["relationshipsWritten"] == 2
928962
assert result["propertiesWritten"] == 2
929963

@@ -978,8 +1012,12 @@ def test_graph_nodeLabel_mutate(gds: GraphDataScience) -> None:
9781012
def test_graph_removeNodeProperties_21(gds: GraphDataScience) -> None:
9791013
G, _ = gds.graph.project(GRAPH_NAME, {"Node": {"properties": "x"}}, "*")
9801014

981-
with pytest.warns(DeprecationWarning):
1015+
if is_neo4j_44(gds):
9821016
result = gds.graph.removeNodeProperties(G, ["x"], concurrency=2)
1017+
else:
1018+
with pytest.warns(DeprecationWarning):
1019+
result = gds.graph.removeNodeProperties(G, ["x"], concurrency=2)
1020+
9831021
assert result["propertiesRemoved"] == 3
9841022

9851023

@@ -1003,8 +1041,11 @@ def test_graph_removeNodeProperties_20(gds: GraphDataScience) -> None:
10031041
def test_graph_deleteRelationships(gds: GraphDataScience) -> None:
10041042
G, _ = gds.graph.project(GRAPH_NAME, "*", ["REL", "REL2"])
10051043

1006-
with pytest.warns(DeprecationWarning):
1044+
if is_neo4j_44(gds):
10071045
result = gds.graph.deleteRelationships(G, "REL")
1046+
else:
1047+
with pytest.warns(DeprecationWarning):
1048+
result = gds.graph.deleteRelationships(G, "REL")
10081049
assert result["deletedRelationships"] == 3
10091050

10101051

@@ -1017,7 +1058,7 @@ def test_graph_relationships_drop(gds: GraphDataScience) -> None:
10171058

10181059

10191060
def test_beta_graph_generate(gds: GraphDataScience) -> None:
1020-
if gds.server_version() >= ServerVersion(2, 5, 0):
1061+
if gds.server_version() >= ServerVersion(2, 5, 0) and not is_neo4j_44(gds):
10211062
with pytest.warns(DeprecationWarning):
10221063
G, result = gds.beta.graph.generate(GRAPH_NAME, 12, 2)
10231064
else:
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
services:
2+
neo4j:
3+
image: neo4j:4.4-enterprise
4+
volumes:
5+
- ${HOME}/.gds_license:/licenses/.gds_license
6+
environment:
7+
- NEO4J_AUTH=none # for testing
8+
9+
- NEO4J_ACCEPT_LICENSE_AGREEMENT=yes
10+
- NEO4J_PLUGINS=["graph-data-science"]
11+
- NEO4J_dbms_security_procedures_allowlist=gds.*
12+
- NEO4J_dbms_security_procedures_unrestricted=gds.*
13+
- NEO4J_gds_enterprise_license__file=/licenses/.gds_license
14+
- NEO4J_gds_arrow_enabled=true
15+
- NEO4J_gds_export_location=/tmp/gds_graphs
16+
- NEO4J_gds_model_store__location=/tmp/gds_models
17+
18+
- NEO4J_gds_arrow_advertised__listen__address=0.0.0.0:8491
19+
- NEO4J_gds_arrow_listen__address=0.0.0.0:8491
20+
21+
- NEO4J_metrics_prometheus_enabled=true
22+
- NEO4J_metrics_prometheus_endpoint=0.0.0.0:2004
23+
- NEO4J_metrics_filter=*
24+
- NEO4J_metrics_enabled=true
25+
ports:
26+
- "7474:7474"
27+
- "7687:7687"
28+
- "8491:8491"
29+
- "2004:2004"
30+
restart: always

0 commit comments

Comments
 (0)