Skip to content

Commit 209e9cd

Browse files
committed
cleanup: use GRAPH_FIELD
1 parent abf20dc commit 209e9cd

File tree

3 files changed

+29
-27
lines changed

3 files changed

+29
-27
lines changed

nx_arangodb/classes/dict/graph.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def graph_attr_dict_factory(
4040
# Graph #
4141
#########
4242

43-
GRAPH_KEY = "networkx"
43+
GRAPH_FIELD = "networkx"
4444

4545

4646
def build_graph_attr_dict_data(
@@ -148,15 +148,15 @@ def __init__(
148148
)
149149

150150
self.graph_id = f"{self.collection_name}/{self.graph_name}"
151-
self.parent_keys = [GRAPH_KEY]
151+
self.parent_keys = [GRAPH_FIELD]
152152

153153
self.collection = create_collection(db, self.collection_name)
154154
self.graph_attr_dict_factory = graph_attr_dict_factory(
155155
self.db, self.adb_graph, self.graph_id
156156
)
157157

158158
result = doc_get_or_insert(self.db, self.collection_name, self.graph_id)
159-
for k, v in result.get(GRAPH_KEY, {}).items():
159+
for k, v in result.get(GRAPH_FIELD, {}).items():
160160
self.data[k] = self.__process_graph_dict_value(k, v)
161161

162162
def __process_graph_dict_value(self, key: str, value: Any) -> Any:
@@ -277,7 +277,7 @@ def __init__(
277277
self.graph = graph
278278
self.graph_id: str = graph_id
279279

280-
self.parent_keys: list[str] = [GRAPH_KEY]
280+
self.parent_keys: list[str] = [GRAPH_FIELD]
281281
self.graph_attr_dict_factory = graph_attr_dict_factory(
282282
self.db, self.graph, self.graph_id
283283
)

tests/test.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import nx_arangodb as nxadb
1515
from nx_arangodb.classes.dict.adj import AdjListOuterDict, EdgeAttrDict, EdgeKeyDict
16+
from nx_arangodb.classes.dict.graph import GRAPH_FIELD
1617
from nx_arangodb.classes.dict.node import NodeAttrDict, NodeDict
1718

1819
from .conftest import create_grid_graph, create_line_graph, db, run_gpu_tests
@@ -1655,9 +1656,9 @@ def test_graph_dict_init_extended(load_karate_graph: Any) -> None:
16551656
G = nxadb.Graph(name="KarateGraph", foo="bar", bar={"baz": True})
16561657
G.graph["foo"] = "!!!"
16571658
G.graph["bar"]["baz"] = False
1658-
assert db.document(G.graph.graph_id)["networkx"]["foo"] == "!!!"
1659-
assert db.document(G.graph.graph_id)["networkx"]["bar"]["baz"] is False
1660-
assert "baz" not in db.document(G.graph.graph_id)["networkx"]
1659+
assert db.document(G.graph.graph_id)[GRAPH_FIELD]["foo"] == "!!!"
1660+
assert db.document(G.graph.graph_id)[GRAPH_FIELD]["bar"]["baz"] is False
1661+
assert "baz" not in db.document(G.graph.graph_id)[GRAPH_FIELD]
16611662

16621663

16631664
def test_graph_dict_clear_will_not_remove_remote_data(load_karate_graph: Any) -> None:
@@ -1675,7 +1676,7 @@ def test_graph_dict_clear_will_not_remove_remote_data(load_karate_graph: Any) ->
16751676
except KeyError:
16761677
raise AssertionError("Not allowed to fail.")
16771678

1678-
assert db.document(G.graph.graph_id)["networkx"]["ant"] == {"b": 6}
1679+
assert db.document(G.graph.graph_id)[GRAPH_FIELD]["ant"] == {"b": 6}
16791680

16801681

16811682
def test_graph_dict_set_item(load_karate_graph: Any) -> None:
@@ -1697,10 +1698,10 @@ def test_graph_dict_set_item(load_karate_graph: Any) -> None:
16971698
G.graph["json"] = value
16981699

16991700
if value is None:
1700-
assert "json" not in db.document(G.graph.graph_id)["networkx"]
1701+
assert "json" not in db.document(G.graph.graph_id)[GRAPH_FIELD]
17011702
else:
17021703
assert G.graph["json"] == value
1703-
assert db.document(G.graph.graph_id)["networkx"]["json"] == value
1704+
assert db.document(G.graph.graph_id)[GRAPH_FIELD]["json"] == value
17041705

17051706

17061707
def test_graph_dict_update(load_karate_graph: Any) -> None:
@@ -1715,7 +1716,7 @@ def test_graph_dict_update(load_karate_graph: Any) -> None:
17151716
assert G.graph.data["c"] == G.graph["c"] == "d"
17161717

17171718
# remote
1718-
adb_doc = db.document(f"_graphs/{G.name}")["networkx"]
1719+
adb_doc = db.document(f"_graphs/{G.name}")[GRAPH_FIELD]
17191720
assert adb_doc["a"] == "b"
17201721
assert adb_doc["c"] == "d"
17211722

@@ -1727,8 +1728,8 @@ def test_graph_attr_dict_nested_update(load_karate_graph: Any) -> None:
17271728
G.graph["a"].update({"d": "e"})
17281729
assert G.graph["a"]["b"] == "c"
17291730
assert G.graph["a"]["d"] == "e"
1730-
assert db.document(G.graph.graph_id)["networkx"]["a"]["b"] == "c"
1731-
assert db.document(G.graph.graph_id)["networkx"]["a"]["d"] == "e"
1731+
assert db.document(G.graph.graph_id)[GRAPH_FIELD]["a"]["b"] == "c"
1732+
assert db.document(G.graph.graph_id)[GRAPH_FIELD]["a"]["d"] == "e"
17321733

17331734

17341735
def test_graph_dict_nested_1(load_karate_graph: Any) -> None:
@@ -1737,7 +1738,7 @@ def test_graph_dict_nested_1(load_karate_graph: Any) -> None:
17371738

17381739
G.graph["a"] = {"b": icon}
17391740
assert G.graph["a"]["b"] == icon
1740-
assert db.document(G.graph.graph_id)["networkx"]["a"]["b"] == icon
1741+
assert db.document(G.graph.graph_id)[GRAPH_FIELD]["a"]["b"] == icon
17411742

17421743

17431744
def test_graph_dict_nested_2(load_karate_graph: Any) -> None:
@@ -1749,7 +1750,7 @@ def test_graph_dict_nested_2(load_karate_graph: Any) -> None:
17491750

17501751
assert G.graph["x"]["y"]["amount_of_goals"] == 1337
17511752
assert (
1752-
db.document(G.graph.graph_id)["networkx"]["x"]["y"]["amount_of_goals"] == 1337
1753+
db.document(G.graph.graph_id)[GRAPH_FIELD]["x"]["y"]["amount_of_goals"] == 1337
17531754
)
17541755

17551756

@@ -1758,10 +1759,10 @@ def test_graph_dict_empty_values(load_karate_graph: Any) -> None:
17581759

17591760
G.graph["empty"] = {}
17601761
assert G.graph["empty"] == {}
1761-
assert db.document(G.graph.graph_id)["networkx"]["empty"] == {}
1762+
assert db.document(G.graph.graph_id)[GRAPH_FIELD]["empty"] == {}
17621763

17631764
G.graph["none"] = None
1764-
assert "none" not in db.document(G.graph.graph_id)["networkx"]
1765+
assert "none" not in db.document(G.graph.graph_id)[GRAPH_FIELD]
17651766
assert "none" not in G.graph
17661767

17671768

@@ -1774,15 +1775,16 @@ def test_graph_dict_nested_overwrite(load_karate_graph: Any) -> None:
17741775
G.graph["a"]["b"]["football_icon"] = "ChangedIcon"
17751776
assert G.graph["a"]["b"]["football_icon"] == "ChangedIcon"
17761777
assert (
1777-
db.document(G.graph.graph_id)["networkx"]["a"]["b"]["football_icon"]
1778+
db.document(G.graph.graph_id)[GRAPH_FIELD]["a"]["b"]["football_icon"]
17781779
== "ChangedIcon"
17791780
)
17801781

17811782
# Overwrite entire nested dictionary
17821783
G.graph["a"] = {"b": icon2}
17831784
assert G.graph["a"]["b"]["basketball_icon"] == "MJ23"
17841785
assert (
1785-
db.document(G.graph.graph_id)["networkx"]["a"]["b"]["basketball_icon"] == "MJ23"
1786+
db.document(G.graph.graph_id)[GRAPH_FIELD]["a"]["b"]["basketball_icon"]
1787+
== "MJ23"
17861788
)
17871789

17881790

@@ -1794,7 +1796,7 @@ def test_graph_dict_complex_nested(load_karate_graph: Any) -> None:
17941796
G.graph["complex"] = complex_structure
17951797
assert G.graph["complex"]["level1"]["level2"]["level3"]["key"] == "value"
17961798
assert (
1797-
db.document(G.graph.graph_id)["networkx"]["complex"]["level1"]["level2"][
1799+
db.document(G.graph.graph_id)[GRAPH_FIELD]["complex"]["level1"]["level2"][
17981800
"level3"
17991801
]["key"]
18001802
== "value"
@@ -1808,12 +1810,12 @@ def test_graph_dict_nested_deletion(load_karate_graph: Any) -> None:
18081810
G.graph["x"] = {"y": icon}
18091811
del G.graph["x"]["y"]["amount_of_goals"]
18101812
assert "amount_of_goals" not in G.graph["x"]["y"]
1811-
assert "amount_of_goals" not in db.document(G.graph.graph_id)["networkx"]["x"]["y"]
1813+
assert "amount_of_goals" not in db.document(G.graph.graph_id)[GRAPH_FIELD]["x"]["y"]
18121814

18131815
# Delete top-level key
18141816
del G.graph["x"]
18151817
assert "x" not in G.graph
1816-
assert "x" not in db.document(G.graph.graph_id)["networkx"]
1818+
assert "x" not in db.document(G.graph.graph_id)[GRAPH_FIELD]
18171819

18181820

18191821
def test_readme(load_karate_graph: Any) -> None:

tests/test_graph.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
AdjListOuterDict,
1818
EdgeAttrDict,
1919
)
20-
from nx_arangodb.classes.dict.graph import GraphDict
20+
from nx_arangodb.classes.dict.graph import GRAPH_FIELD, GraphDict
2121
from nx_arangodb.classes.dict.node import NodeAttrDict, NodeDict
2222

2323
from .conftest import db
@@ -463,11 +463,11 @@ def test_graph_attr(self):
463463
assert isinstance(G.graph, GraphDict)
464464
assert G.graph["foo"] == "bar"
465465
del G.graph["foo"]
466-
graph_doc = get_doc(f"_graphs/{GRAPH_NAME}")["networkx"]
466+
graph_doc = get_doc(f"_graphs/{GRAPH_NAME}")[GRAPH_FIELD]
467467
assert G.graph == graph_doc
468468
H = self.K3Graph(foo="bar")
469469
assert H.graph["foo"] == "bar"
470-
graph_doc = get_doc(f"_graphs/{GRAPH_NAME}")["networkx"]
470+
graph_doc = get_doc(f"_graphs/{GRAPH_NAME}")[GRAPH_FIELD]
471471
assert H.graph == graph_doc
472472

473473
def test_node_attr(self):
@@ -1105,7 +1105,7 @@ def test_update(self):
11051105
else:
11061106
for src, dst in G.edges():
11071107
assert G.adj[dst][src] == G.adj[src][dst]
1108-
assert G.graph == get_doc(G.graph.graph_id)["networkx"]
1108+
assert G.graph == get_doc(G.graph.graph_id)[GRAPH_FIELD]
11091109

11101110
# no keywords -- order is edges, nodes
11111111
G = self.K3Graph()
@@ -1126,7 +1126,7 @@ def test_update(self):
11261126
else:
11271127
for src, dst in G.edges():
11281128
assert G.adj[dst][src] == G.adj[src][dst]
1129-
assert G.graph == get_doc(G.graph.graph_id)["networkx"]
1129+
assert G.graph == get_doc(G.graph.graph_id)[GRAPH_FIELD]
11301130

11311131
# update using only a graph
11321132
G = self.K3Graph()

0 commit comments

Comments
 (0)