Skip to content

Commit fe554ae

Browse files
committed
new: test_multiple_graph_sessions
1 parent ed34107 commit fe554ae

File tree

2 files changed

+48
-7
lines changed

2 files changed

+48
-7
lines changed

tests/conftest.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import logging
22
import os
3-
import sys
4-
from io import StringIO
5-
from typing import Any
3+
from typing import Any, Dict
64

75
import networkx as nx
86
import pytest
@@ -15,6 +13,8 @@
1513

1614
logger.setLevel(logging.INFO)
1715

16+
con: Dict[str, Any]
17+
client: ArangoClient
1818
db: StandardDatabase
1919
run_gpu_tests: bool
2020

@@ -30,6 +30,7 @@ def pytest_addoption(parser: Any) -> None:
3030

3131

3232
def pytest_configure(config: Any) -> None:
33+
global con
3334
con = {
3435
"url": config.getoption("url"),
3536
"username": config.getoption("username"),
@@ -43,10 +44,11 @@ def pytest_configure(config: Any) -> None:
4344
print("Password: " + con["password"])
4445
print("Database: " + con["dbName"])
4546

47+
global client
48+
client = ArangoClient(hosts=con["url"])
49+
4650
global db
47-
db = ArangoClient(hosts=con["url"]).db(
48-
con["dbName"], con["username"], con["password"], verify=True
49-
)
51+
db = client.db(con["dbName"], con["username"], con["password"], verify=True)
5052

5153
print("Version: " + db.version())
5254
print("----------------------------------------")
@@ -99,6 +101,12 @@ def load_two_relation_graph() -> None:
99101
)
100102

101103

104+
def get_db(db_name: str) -> StandardDatabase:
105+
global con
106+
global client
107+
return client.db(db_name, con["username"], con["password"], verify=True)
108+
109+
102110
def create_line_graph(load_attributes: set[str]) -> nxadb.Graph:
103111
G = nx.Graph()
104112
G.add_edge(1, 2, my_custom_weight=1)

tests/test.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from nx_arangodb.classes.dict.graph import GRAPH_FIELD
1717
from nx_arangodb.classes.dict.node import NodeAttrDict, NodeDict
1818

19-
from .conftest import create_grid_graph, create_line_graph, db, run_gpu_tests
19+
from .conftest import create_grid_graph, create_line_graph, db, get_db, run_gpu_tests
2020

2121
G_NX: nx.Graph = nx.karate_club_graph()
2222
G_NX_digraph = nx.DiGraph(G_NX)
@@ -88,6 +88,39 @@ def test_adb_graph_init(graph_cls: type[nxadb.Graph]) -> None:
8888
G.name = "RenamedTestGraph"
8989

9090

91+
def test_multiple_graph_sessions():
92+
db_1_name = "test_db_1"
93+
db_2_name = "test_db_2"
94+
95+
db.delete_database(db_1_name, ignore_missing=True)
96+
db.delete_database(db_2_name, ignore_missing=True)
97+
98+
db.create_database(db_1_name)
99+
db.create_database(db_2_name)
100+
101+
db_1 = get_db(db_1_name)
102+
db_2 = get_db(db_2_name)
103+
104+
G_1 = nxadb.Graph(name="TestGraph", db=db_1)
105+
G_2 = nxadb.Graph(name="TestGraph", db=db_2)
106+
107+
G_1.add_node(1, foo="bar")
108+
G_1.add_node(2)
109+
G_1.add_edge(1, 2)
110+
111+
G_2.add_node(1)
112+
G_2.add_node(2)
113+
G_2.add_node(3)
114+
G_2.add_edge(1, 2)
115+
G_2.add_edge(2, 3)
116+
117+
res_1 = nx.pagerank(G_1)
118+
res_2 = nx.pagerank(G_2)
119+
120+
assert len(res_1) == 2
121+
assert len(res_2) == 3
122+
123+
91124
def test_load_graph_from_nxadb():
92125
graph_name = "KarateGraph"
93126

0 commit comments

Comments
 (0)