Skip to content

Commit 60b1c2f

Browse files
Adjust cloud architecture test session URI to recent changes (#764)
* Adjust cloud architecture test session URI to recent changes * Switch default session uri to docker host network * Initialize fixtures only when needed * Get server version from correct bolt address * Implement enter and exit for GDS * Remove condition in cloud setup and set cleanup autouse to false * Skip cleanup on cloud-architecture * Explicitly invoke clean_up instead of making it a fixture * Try autouse clean_up again and use updated bolt endpoints * Use URI and AUTH variables for session connection info * Revert uri and auth changes in conftest option parsing * Guard cleanup against read-only db exception * Reset aura db bolt port to 7687 * Fix checkstyle * Revert changes to clean_up method
1 parent 5832db9 commit 60b1c2f

File tree

2 files changed

+34
-28
lines changed

2 files changed

+34
-28
lines changed

graphdatascience/graph_data_science.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,10 @@ def close(self) -> None:
246246
Close the GraphDataScience object and release any resources held by it.
247247
"""
248248
self._query_runner.close()
249+
250+
def __enter__(self) -> GraphDataScience:
251+
return self
252+
253+
def __exit__(self, exc_type, exc_val, exc_tb) -> bool:
254+
self.close()
255+
return False

graphdatascience/tests/integration/conftest.py

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import os
22
from pathlib import Path
3-
from typing import Any, Generator, Optional
3+
from typing import Any, Generator
44

5+
import neo4j.exceptions
56
import pytest
67
from neo4j import Driver, GraphDatabase
78

@@ -23,11 +24,11 @@
2324

2425
DB = os.environ.get("NEO4J_DB", "neo4j")
2526

26-
AURA_DB_URI = os.environ.get("NEO4J_AURA_DB_URI", "bolt://localhost:7689")
27+
AURA_DB_URI = os.environ.get("AURA_DB_URI", "bolt://localhost:7687")
2728
AURA_DB_AUTH = ("neo4j", "password")
2829

2930

30-
@pytest.fixture(scope="package")
31+
@pytest.fixture(scope="package", autouse=False)
3132
def neo4j_driver() -> Generator[Driver, None, None]:
3233
driver = GraphDatabase.driver(URI, auth=AUTH)
3334

@@ -36,7 +37,7 @@ def neo4j_driver() -> Generator[Driver, None, None]:
3637
driver.close()
3738

3839

39-
@pytest.fixture(scope="package")
40+
@pytest.fixture(scope="package", autouse=False)
4041
def runner(neo4j_driver: Driver) -> Generator[Neo4jQueryRunner, None, None]:
4142
_runner = Neo4jQueryRunner.create(neo4j_driver)
4243
_runner.set_database(DB)
@@ -46,7 +47,7 @@ def runner(neo4j_driver: Driver) -> Generator[Neo4jQueryRunner, None, None]:
4647
_runner.close()
4748

4849

49-
@pytest.fixture(scope="package")
50+
@pytest.fixture(scope="package", autouse=False)
5051
def gds() -> Generator[GraphDataScience, None, None]:
5152
_gds = GraphDataScience(URI, auth=AUTH)
5253
_gds.set_database(DB)
@@ -56,7 +57,7 @@ def gds() -> Generator[GraphDataScience, None, None]:
5657
_gds.close()
5758

5859

59-
@pytest.fixture(scope="package")
60+
@pytest.fixture(scope="package", autouse=False)
6061
def gds_with_tls() -> Generator[GraphDataScience, None, None]:
6162
integration_test_dir = Path(__file__).resolve().parent
6263
cert = os.path.join(integration_test_dir, "resources", "arrow-flight-gds-test.crt")
@@ -78,7 +79,7 @@ def gds_with_tls() -> Generator[GraphDataScience, None, None]:
7879
_gds.close()
7980

8081

81-
@pytest.fixture(scope="package")
82+
@pytest.fixture(scope="package", autouse=False)
8283
def gds_without_arrow() -> Generator[GraphDataScience, None, None]:
8384
_gds = GraphDataScience(URI, auth=AUTH, arrow=False)
8485
_gds.set_database(DB)
@@ -89,19 +90,17 @@ def gds_without_arrow() -> Generator[GraphDataScience, None, None]:
8990

9091

9192
@pytest.fixture(scope="package", autouse=False)
92-
def gds_with_cloud_setup(request: pytest.FixtureRequest) -> Optional[Generator[AuraGraphDataScience, None, None]]:
93-
if "cloud_architecture" not in request.keywords:
94-
_gds = AuraGraphDataScience.create(
95-
gds_session_connection_info=DbmsConnectionInfo(URI, AUTH[0], AUTH[1]),
96-
db_connection_info=DbmsConnectionInfo(AURA_DB_URI, AURA_DB_AUTH[0], AURA_DB_AUTH[1]),
97-
delete_fn=lambda: True,
98-
)
99-
_gds.set_database(DB)
93+
def gds_with_cloud_setup(request: pytest.FixtureRequest) -> Generator[AuraGraphDataScience, None, None]:
94+
_gds = AuraGraphDataScience.create(
95+
gds_session_connection_info=DbmsConnectionInfo(URI, AUTH[0], AUTH[1]),
96+
db_connection_info=DbmsConnectionInfo(AURA_DB_URI, AURA_DB_AUTH[0], AURA_DB_AUTH[1]),
97+
delete_fn=lambda: True,
98+
)
99+
_gds.set_database(DB)
100100

101-
yield _gds
101+
yield _gds
102102

103-
_gds.close()
104-
return None
103+
_gds.close()
105104

106105

107106
@pytest.fixture(autouse=True)
@@ -131,7 +130,10 @@ def clean_up(gds: GraphDataScience) -> Generator[None, None, None]:
131130
if model.exists():
132131
model.drop(failIfMissing=True)
133132

134-
gds.run_cypher("MATCH (n) DETACH DELETE (n)")
133+
try:
134+
gds.run_cypher("MATCH (n) DETACH DELETE (n)")
135+
except neo4j.exceptions.ClientError as e:
136+
print(e)
135137

136138

137139
def pytest_collection_modifyitems(config: Any, items: Any) -> None:
@@ -188,15 +190,12 @@ def pytest_collection_modifyitems(config: Any, items: Any) -> None:
188190
if "cloud_architecture" in item.keywords:
189191
item.add_marker(skip_cloud_architecture)
190192

191-
gds = GraphDataScience(URI, auth=AUTH)
192-
193-
try:
194-
server_version = gds._server_version
195-
except Exception as e:
196-
print("Could not derive GDS library server version")
197-
raise e
198-
finally:
199-
gds.close()
193+
with GraphDataScience(URI, auth=AUTH) as gds:
194+
try:
195+
server_version = gds._server_version
196+
except Exception as e:
197+
print("Could not derive GDS library server version")
198+
raise e
200199

201200
skip_incompatible_versions = pytest.mark.skip(reason=f"incompatible with GDS server version {server_version}")
202201

0 commit comments

Comments
 (0)