Skip to content

Commit 43d3f86

Browse files
committed
Extract remote util ops test
Easier to define the test setup
1 parent 7bcbab1 commit 43d3f86

File tree

2 files changed

+72
-32
lines changed

2 files changed

+72
-32
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from typing import Generator
2+
3+
import pytest
4+
5+
from graphdatascience.graph.graph_object import Graph
6+
from graphdatascience.graph_data_science import GraphDataScience
7+
from graphdatascience.server_version.server_version import ServerVersion
8+
from graphdatascience.session.aura_graph_data_science import AuraGraphDataScience
9+
10+
11+
@pytest.fixture(autouse=True)
12+
def G(gds_with_cloud_setup: GraphDataScience) -> Generator[Graph, None, None]:
13+
gds_with_cloud_setup.run_cypher(
14+
"""
15+
CREATE
16+
(a:Location {name: 'A', population: 1337}),
17+
(b:Location {name: 'B'}),
18+
(c:Location {name: 'C'}),
19+
(d:Location {name: 'D'}),
20+
(e:Location {name: 'G'}),
21+
(f:Location {name: 2}),
22+
(a)-[:ROAD {cost: 50}]->(b),
23+
(a)-[:ROAD {cost: 50}]->(c),
24+
(a)-[:ROAD {cost: 100}]->(d),
25+
(b)-[:ROAD {cost: 40}]->(d),
26+
(c)-[:ROAD {cost: 40}]->(d),
27+
(c)-[:ROAD {cost: 80}]->(e),
28+
(d)-[:ROAD {cost: 30}]->(e),
29+
(d)-[:ROAD {cost: 80}]->(f),
30+
(e)-[:ROAD {cost: 40}]->(f)
31+
"""
32+
)
33+
G, _ = gds_with_cloud_setup.graph.project(
34+
"g",
35+
{"Location": {"properties": "population"}},
36+
{"ROAD": {"properties": "cost"}},
37+
)
38+
39+
yield G
40+
41+
G.drop()
42+
gds_with_cloud_setup.run_cypher("MATCH (n) DETACH DELETE n")
43+
44+
45+
@pytest.mark.cloud_architecture
46+
@pytest.mark.compatible_with(min_inclusive=ServerVersion(2, 7, 0))
47+
def test_remote_util_as_node(gds_with_cloud_setup: AuraGraphDataScience) -> None:
48+
id = gds_with_cloud_setup.find_node_id(["Location"], {"name": "A"})
49+
result = gds_with_cloud_setup.util.asNode(id)
50+
assert result["name"] == "A"
51+
52+
53+
@pytest.mark.cloud_architecture
54+
@pytest.mark.compatible_with(min_inclusive=ServerVersion(2, 7, 0))
55+
def test_remote_util_as_nodes(gds_with_cloud_setup: AuraGraphDataScience) -> None:
56+
ids = [
57+
gds_with_cloud_setup.find_node_id(["Location"], {"name": "A"}),
58+
gds_with_cloud_setup.find_node_id(["Location"], {"name": 2}),
59+
]
60+
result = gds_with_cloud_setup.util.asNodes(ids)
61+
assert len(result) == 2
62+
63+
64+
@pytest.mark.cloud_architecture
65+
@pytest.mark.compatible_with(min_inclusive=ServerVersion(2, 7, 0))
66+
def test_util_nodeProperty(gds_with_cloud_setup: GraphDataScience, G: Graph) -> None:
67+
id = gds_with_cloud_setup.find_node_id(["Location"], {"name": "A"})
68+
result = gds_with_cloud_setup.util.nodeProperty(G, id, "population")
69+
assert result == 1337

graphdatascience/tests/integration/test_util_ops.py

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
from graphdatascience.graph_data_science import GraphDataScience
77
from graphdatascience.query_runner.neo4j_query_runner import Neo4jQueryRunner
88
from graphdatascience.server_version.server_version import ServerVersion
9-
from graphdatascience.session.aura_graph_data_science import AuraGraphDataScience
109

1110

1211
@pytest.fixture(autouse=True)
13-
def G(runner: Neo4jQueryRunner, gds: GraphDataScience) -> Generator[Graph, None, None]:
14-
runner.run_cypher(
12+
def G(gds: GraphDataScience) -> Generator[Graph, None, None]:
13+
gds.run_cypher(
1514
"""
1615
CREATE
1716
(a:Location {name: 'A', population: 1337}),
@@ -40,7 +39,7 @@ def G(runner: Neo4jQueryRunner, gds: GraphDataScience) -> Generator[Graph, None,
4039
yield G
4140

4241
G.drop()
43-
runner.run_cypher("MATCH (n) DETACH DELETE n")
42+
gds.run_cypher("MATCH (n) DETACH DELETE n")
4443

4544

4645
def test_find_node_id(runner: Neo4jQueryRunner, gds: GraphDataScience) -> None:
@@ -98,34 +97,6 @@ def test_util_asNode(gds: GraphDataScience) -> None:
9897
assert result["name"] == "A"
9998

10099

101-
@pytest.mark.cloud_architecture
102-
@pytest.mark.compatible_with(min_inclusive=ServerVersion(2, 7, 0))
103-
def test_remote_util_as_node(gds_with_cloud_setup: AuraGraphDataScience) -> None:
104-
id = gds_with_cloud_setup.find_node_id(["Location"], {"name": "A"})
105-
result = gds_with_cloud_setup.util.asNode(id)
106-
assert result["name"] == "A"
107-
108-
109-
def test_util_asNodes(gds: GraphDataScience) -> None:
110-
ids = [
111-
gds.find_node_id(["Location"], {"name": "A"}),
112-
gds.find_node_id(["Location"], {"name": 2}),
113-
]
114-
result = gds.util.asNodes(ids)
115-
assert len(result) == 2
116-
117-
118-
@pytest.mark.cloud_architecture
119-
@pytest.mark.compatible_with(min_inclusive=ServerVersion(2, 7, 0))
120-
def test_remote_util_as_nodes(gds_with_cloud_setup: AuraGraphDataScience) -> None:
121-
ids = [
122-
gds_with_cloud_setup.find_node_id(["Location"], {"name": "A"}),
123-
gds_with_cloud_setup.find_node_id(["Location"], {"name": 2}),
124-
]
125-
result = gds_with_cloud_setup.util.asNodes(ids)
126-
assert len(result) == 2
127-
128-
129100
def test_util_nodeProperty(gds: GraphDataScience, G: Graph) -> None:
130101
id = gds.find_node_id(["Location"], {"name": "A"})
131102
result = gds.util.nodeProperty(G, id, "population")

0 commit comments

Comments
 (0)