diff --git a/nx_arangodb/classes/dict/graph.py b/nx_arangodb/classes/dict/graph.py index 2ed63c0..2365c68 100644 --- a/nx_arangodb/classes/dict/graph.py +++ b/nx_arangodb/classes/dict/graph.py @@ -40,7 +40,7 @@ def graph_attr_dict_factory( # Graph # ######### -GRAPH_KEY = "networkx" +GRAPH_FIELD = "networkx" def build_graph_attr_dict_data( @@ -148,7 +148,7 @@ def __init__( ) self.graph_id = f"{self.collection_name}/{self.graph_name}" - self.parent_keys = [GRAPH_KEY] + self.parent_keys = [GRAPH_FIELD] self.collection = create_collection(db, self.collection_name) self.graph_attr_dict_factory = graph_attr_dict_factory( @@ -156,7 +156,7 @@ def __init__( ) result = doc_get_or_insert(self.db, self.collection_name, self.graph_id) - for k, v in result.get(GRAPH_KEY, {}).items(): + for k, v in result.get(GRAPH_FIELD, {}).items(): self.data[k] = self.__process_graph_dict_value(k, v) def __process_graph_dict_value(self, key: str, value: Any) -> Any: @@ -277,7 +277,7 @@ def __init__( self.graph = graph self.graph_id: str = graph_id - self.parent_keys: list[str] = [GRAPH_KEY] + self.parent_keys: list[str] = [GRAPH_FIELD] self.graph_attr_dict_factory = graph_attr_dict_factory( self.db, self.graph, self.graph_id ) diff --git a/tests/test.py b/tests/test.py index 8c648a9..db1e7e8 100644 --- a/tests/test.py +++ b/tests/test.py @@ -13,6 +13,7 @@ import nx_arangodb as nxadb from nx_arangodb.classes.dict.adj import AdjListOuterDict, EdgeAttrDict, EdgeKeyDict +from nx_arangodb.classes.dict.graph import GRAPH_FIELD from nx_arangodb.classes.dict.node import NodeAttrDict, NodeDict 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: G = nxadb.Graph(name="KarateGraph", foo="bar", bar={"baz": True}) G.graph["foo"] = "!!!" G.graph["bar"]["baz"] = False - assert db.document(G.graph.graph_id)["networkx"]["foo"] == "!!!" - assert db.document(G.graph.graph_id)["networkx"]["bar"]["baz"] is False - assert "baz" not in db.document(G.graph.graph_id)["networkx"] + assert db.document(G.graph.graph_id)[GRAPH_FIELD]["foo"] == "!!!" + assert db.document(G.graph.graph_id)[GRAPH_FIELD]["bar"]["baz"] is False + assert "baz" not in db.document(G.graph.graph_id)[GRAPH_FIELD] 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) -> except KeyError: raise AssertionError("Not allowed to fail.") - assert db.document(G.graph.graph_id)["networkx"]["ant"] == {"b": 6} + assert db.document(G.graph.graph_id)[GRAPH_FIELD]["ant"] == {"b": 6} 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: G.graph["json"] = value if value is None: - assert "json" not in db.document(G.graph.graph_id)["networkx"] + assert "json" not in db.document(G.graph.graph_id)[GRAPH_FIELD] else: assert G.graph["json"] == value - assert db.document(G.graph.graph_id)["networkx"]["json"] == value + assert db.document(G.graph.graph_id)[GRAPH_FIELD]["json"] == value def test_graph_dict_update(load_karate_graph: Any) -> None: @@ -1715,7 +1716,7 @@ def test_graph_dict_update(load_karate_graph: Any) -> None: assert G.graph.data["c"] == G.graph["c"] == "d" # remote - adb_doc = db.document(f"_graphs/{G.name}")["networkx"] + adb_doc = db.document(f"_graphs/{G.name}")[GRAPH_FIELD] assert adb_doc["a"] == "b" assert adb_doc["c"] == "d" @@ -1727,8 +1728,8 @@ def test_graph_attr_dict_nested_update(load_karate_graph: Any) -> None: G.graph["a"].update({"d": "e"}) assert G.graph["a"]["b"] == "c" assert G.graph["a"]["d"] == "e" - assert db.document(G.graph.graph_id)["networkx"]["a"]["b"] == "c" - assert db.document(G.graph.graph_id)["networkx"]["a"]["d"] == "e" + assert db.document(G.graph.graph_id)[GRAPH_FIELD]["a"]["b"] == "c" + assert db.document(G.graph.graph_id)[GRAPH_FIELD]["a"]["d"] == "e" 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: G.graph["a"] = {"b": icon} assert G.graph["a"]["b"] == icon - assert db.document(G.graph.graph_id)["networkx"]["a"]["b"] == icon + assert db.document(G.graph.graph_id)[GRAPH_FIELD]["a"]["b"] == icon 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: assert G.graph["x"]["y"]["amount_of_goals"] == 1337 assert ( - db.document(G.graph.graph_id)["networkx"]["x"]["y"]["amount_of_goals"] == 1337 + db.document(G.graph.graph_id)[GRAPH_FIELD]["x"]["y"]["amount_of_goals"] == 1337 ) @@ -1758,10 +1759,10 @@ def test_graph_dict_empty_values(load_karate_graph: Any) -> None: G.graph["empty"] = {} assert G.graph["empty"] == {} - assert db.document(G.graph.graph_id)["networkx"]["empty"] == {} + assert db.document(G.graph.graph_id)[GRAPH_FIELD]["empty"] == {} G.graph["none"] = None - assert "none" not in db.document(G.graph.graph_id)["networkx"] + assert "none" not in db.document(G.graph.graph_id)[GRAPH_FIELD] assert "none" not in G.graph @@ -1774,7 +1775,7 @@ def test_graph_dict_nested_overwrite(load_karate_graph: Any) -> None: G.graph["a"]["b"]["football_icon"] = "ChangedIcon" assert G.graph["a"]["b"]["football_icon"] == "ChangedIcon" assert ( - db.document(G.graph.graph_id)["networkx"]["a"]["b"]["football_icon"] + db.document(G.graph.graph_id)[GRAPH_FIELD]["a"]["b"]["football_icon"] == "ChangedIcon" ) @@ -1782,7 +1783,8 @@ def test_graph_dict_nested_overwrite(load_karate_graph: Any) -> None: G.graph["a"] = {"b": icon2} assert G.graph["a"]["b"]["basketball_icon"] == "MJ23" assert ( - db.document(G.graph.graph_id)["networkx"]["a"]["b"]["basketball_icon"] == "MJ23" + db.document(G.graph.graph_id)[GRAPH_FIELD]["a"]["b"]["basketball_icon"] + == "MJ23" ) @@ -1794,7 +1796,7 @@ def test_graph_dict_complex_nested(load_karate_graph: Any) -> None: G.graph["complex"] = complex_structure assert G.graph["complex"]["level1"]["level2"]["level3"]["key"] == "value" assert ( - db.document(G.graph.graph_id)["networkx"]["complex"]["level1"]["level2"][ + db.document(G.graph.graph_id)[GRAPH_FIELD]["complex"]["level1"]["level2"][ "level3" ]["key"] == "value" @@ -1808,12 +1810,12 @@ def test_graph_dict_nested_deletion(load_karate_graph: Any) -> None: G.graph["x"] = {"y": icon} del G.graph["x"]["y"]["amount_of_goals"] assert "amount_of_goals" not in G.graph["x"]["y"] - assert "amount_of_goals" not in db.document(G.graph.graph_id)["networkx"]["x"]["y"] + assert "amount_of_goals" not in db.document(G.graph.graph_id)[GRAPH_FIELD]["x"]["y"] # Delete top-level key del G.graph["x"] assert "x" not in G.graph - assert "x" not in db.document(G.graph.graph_id)["networkx"] + assert "x" not in db.document(G.graph.graph_id)[GRAPH_FIELD] def test_readme(load_karate_graph: Any) -> None: diff --git a/tests/test_graph.py b/tests/test_graph.py index a7628b6..2d48d97 100644 --- a/tests/test_graph.py +++ b/tests/test_graph.py @@ -17,7 +17,7 @@ AdjListOuterDict, EdgeAttrDict, ) -from nx_arangodb.classes.dict.graph import GraphDict +from nx_arangodb.classes.dict.graph import GRAPH_FIELD, GraphDict from nx_arangodb.classes.dict.node import NodeAttrDict, NodeDict from .conftest import db @@ -463,11 +463,11 @@ def test_graph_attr(self): assert isinstance(G.graph, GraphDict) assert G.graph["foo"] == "bar" del G.graph["foo"] - graph_doc = get_doc(f"_graphs/{GRAPH_NAME}")["networkx"] + graph_doc = get_doc(f"_graphs/{GRAPH_NAME}")[GRAPH_FIELD] assert G.graph == graph_doc H = self.K3Graph(foo="bar") assert H.graph["foo"] == "bar" - graph_doc = get_doc(f"_graphs/{GRAPH_NAME}")["networkx"] + graph_doc = get_doc(f"_graphs/{GRAPH_NAME}")[GRAPH_FIELD] assert H.graph == graph_doc def test_node_attr(self): @@ -1105,7 +1105,7 @@ def test_update(self): else: for src, dst in G.edges(): assert G.adj[dst][src] == G.adj[src][dst] - assert G.graph == get_doc(G.graph.graph_id)["networkx"] + assert G.graph == get_doc(G.graph.graph_id)[GRAPH_FIELD] # no keywords -- order is edges, nodes G = self.K3Graph() @@ -1126,7 +1126,7 @@ def test_update(self): else: for src, dst in G.edges(): assert G.adj[dst][src] == G.adj[src][dst] - assert G.graph == get_doc(G.graph.graph_id)["networkx"] + assert G.graph == get_doc(G.graph.graph_id)[GRAPH_FIELD] # update using only a graph G = self.K3Graph()