13
13
14
14
import nx_arangodb as nxadb
15
15
from nx_arangodb .classes .dict .adj import AdjListOuterDict , EdgeAttrDict , EdgeKeyDict
16
+ from nx_arangodb .classes .dict .graph import GRAPH_FIELD
16
17
from nx_arangodb .classes .dict .node import NodeAttrDict , NodeDict
17
18
18
19
from .conftest import create_grid_graph , create_line_graph , db , run_gpu_tests
@@ -1638,7 +1639,7 @@ def test_multidigraph_edges_crud(load_karate_graph: Any) -> None:
1638
1639
def test_graph_dict_init (load_karate_graph : Any ) -> None :
1639
1640
G = nxadb .Graph (name = "KarateGraph" , default_node_type = "person" )
1640
1641
assert db .collection ("_graphs" ).has ("KarateGraph" )
1641
- graph_document = db .collection ( "_graphs" ). get ( "KarateGraph " )
1642
+ graph_document = db .document ( f "_graphs/ { G . name } " )
1642
1643
assert graph_document ["_key" ] == "KarateGraph"
1643
1644
assert graph_document ["edgeDefinitions" ] == [
1644
1645
{"collection" : "knows" , "from" : ["person" ], "to" : ["person" ]},
@@ -1655,33 +1656,31 @@ def test_graph_dict_init_extended(load_karate_graph: Any) -> None:
1655
1656
G = nxadb .Graph (name = "KarateGraph" , foo = "bar" , bar = {"baz" : True })
1656
1657
G .graph ["foo" ] = "!!!"
1657
1658
G .graph ["bar" ]["baz" ] = False
1658
- assert db .document (G .graph .graph_id )["foo" ] == "!!!"
1659
- assert db .document (G .graph .graph_id )["bar" ]["baz" ] is False
1660
- assert "baz" not in db .document (G .graph .graph_id )
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 ]
1661
1662
1662
1663
1663
1664
def test_graph_dict_clear_will_not_remove_remote_data (load_karate_graph : Any ) -> None :
1664
- G_adb = nxadb .Graph (
1665
+ G = nxadb .Graph (
1665
1666
name = "KarateGraph" ,
1666
1667
foo = "bar" ,
1667
1668
bar = {"a" : 4 },
1668
1669
)
1669
1670
1670
- G_adb .graph ["ant" ] = {"b" : 5 }
1671
- G_adb .graph ["ant" ]["b" ] = 6
1672
- G_adb .clear ()
1671
+ G .graph ["ant" ] = {"b" : 5 }
1672
+ G .graph ["ant" ]["b" ] = 6
1673
+ G .clear ()
1673
1674
try :
1674
- G_adb .graph ["ant" ]
1675
+ G .graph ["ant" ]
1675
1676
except KeyError :
1676
1677
raise AssertionError ("Not allowed to fail." )
1677
1678
1678
- assert db .document (G_adb .graph .graph_id )["ant" ] == {"b" : 6 }
1679
+ assert db .document (G .graph .graph_id )[ GRAPH_FIELD ] ["ant" ] == {"b" : 6 }
1679
1680
1680
1681
1681
1682
def test_graph_dict_set_item (load_karate_graph : Any ) -> None :
1682
- name = "KarateGraph"
1683
- db .collection ("nxadb_graphs" ).delete (name , ignore_missing = True )
1684
- G = nxadb .Graph (name = name , default_node_type = "person" )
1683
+ G = nxadb .Graph (name = "KarateGraph" , default_node_type = "person" )
1685
1684
1686
1685
json_values = [
1687
1686
"aString" ,
@@ -1699,122 +1698,124 @@ def test_graph_dict_set_item(load_karate_graph: Any) -> None:
1699
1698
G .graph ["json" ] = value
1700
1699
1701
1700
if value is None :
1702
- assert "json" not in db .document (G .graph .graph_id )
1701
+ assert "json" not in db .document (G .graph .graph_id )[ GRAPH_FIELD ]
1703
1702
else :
1704
1703
assert G .graph ["json" ] == value
1705
- assert db .document (G .graph .graph_id )["json" ] == value
1704
+ assert db .document (G .graph .graph_id )[GRAPH_FIELD ][ "json" ] == value
1706
1705
1707
1706
1708
1707
def test_graph_dict_update (load_karate_graph : Any ) -> None :
1709
1708
G = nxadb .Graph (name = "KarateGraph" , default_node_type = "person" )
1710
- G .clear ()
1711
1709
1712
1710
G .graph ["a" ] = "b"
1713
1711
to_update = {"c" : "d" }
1714
1712
G .graph .update (to_update )
1715
1713
1716
1714
# local
1717
- assert G .graph ["a" ] == "b"
1718
- assert G .graph ["c" ] == "d"
1715
+ assert G .graph . data [ "a" ] == G . graph ["a" ] == "b"
1716
+ assert G .graph . data [ "c" ] == G . graph ["c" ] == "d"
1719
1717
1720
1718
# remote
1721
- adb_doc = db .collection ( "nxadb_graphs" ). get ( G .name )
1719
+ adb_doc = db .document ( f"_graphs/ { G .name } " )[ GRAPH_FIELD ]
1722
1720
assert adb_doc ["a" ] == "b"
1723
1721
assert adb_doc ["c" ] == "d"
1724
1722
1725
1723
1726
1724
def test_graph_attr_dict_nested_update (load_karate_graph : Any ) -> None :
1727
1725
G = nxadb .Graph (name = "KarateGraph" , default_node_type = "person" )
1728
- G .clear ()
1729
1726
1730
1727
G .graph ["a" ] = {"b" : "c" }
1731
1728
G .graph ["a" ].update ({"d" : "e" })
1732
1729
assert G .graph ["a" ]["b" ] == "c"
1733
1730
assert G .graph ["a" ]["d" ] == "e"
1734
- assert db .document (G .graph .graph_id )["a" ]["b" ] == "c"
1735
- assert db .document (G .graph .graph_id )["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"
1736
1733
1737
1734
1738
1735
def test_graph_dict_nested_1 (load_karate_graph : Any ) -> None :
1739
1736
G = nxadb .Graph (name = "KarateGraph" , default_node_type = "person" )
1740
- G .clear ()
1741
1737
icon = {"football_icon" : "MJ7" }
1742
1738
1743
1739
G .graph ["a" ] = {"b" : icon }
1744
1740
assert G .graph ["a" ]["b" ] == icon
1745
- assert db .document (G .graph .graph_id )["a" ]["b" ] == icon
1741
+ assert db .document (G .graph .graph_id )[GRAPH_FIELD ][ "a" ]["b" ] == icon
1746
1742
1747
1743
1748
1744
def test_graph_dict_nested_2 (load_karate_graph : Any ) -> None :
1749
1745
G = nxadb .Graph (name = "KarateGraph" , default_node_type = "person" )
1750
- G .clear ()
1751
1746
icon = {"football_icon" : "MJ7" }
1752
1747
1753
1748
G .graph ["x" ] = {"y" : icon }
1754
1749
G .graph ["x" ]["y" ]["amount_of_goals" ] = 1337
1755
1750
1756
1751
assert G .graph ["x" ]["y" ]["amount_of_goals" ] == 1337
1757
- assert db .document (G .graph .graph_id )["x" ]["y" ]["amount_of_goals" ] == 1337
1752
+ assert (
1753
+ db .document (G .graph .graph_id )[GRAPH_FIELD ]["x" ]["y" ]["amount_of_goals" ] == 1337
1754
+ )
1758
1755
1759
1756
1760
1757
def test_graph_dict_empty_values (load_karate_graph : Any ) -> None :
1761
1758
G = nxadb .Graph (name = "KarateGraph" , default_node_type = "person" )
1762
- G .clear ()
1763
1759
1764
1760
G .graph ["empty" ] = {}
1765
1761
assert G .graph ["empty" ] == {}
1766
- assert db .document (G .graph .graph_id )["empty" ] == {}
1762
+ assert db .document (G .graph .graph_id )[GRAPH_FIELD ][ "empty" ] == {}
1767
1763
1768
1764
G .graph ["none" ] = None
1769
- assert "none" not in db .document (G .graph .graph_id )
1765
+ assert "none" not in db .document (G .graph .graph_id )[ GRAPH_FIELD ]
1770
1766
assert "none" not in G .graph
1771
1767
1772
1768
1773
1769
def test_graph_dict_nested_overwrite (load_karate_graph : Any ) -> None :
1774
1770
G = nxadb .Graph (name = "KarateGraph" , default_node_type = "person" )
1775
- G .clear ()
1776
1771
icon1 = {"football_icon" : "MJ7" }
1777
1772
icon2 = {"basketball_icon" : "MJ23" }
1778
1773
1779
1774
G .graph ["a" ] = {"b" : icon1 }
1780
1775
G .graph ["a" ]["b" ]["football_icon" ] = "ChangedIcon"
1781
1776
assert G .graph ["a" ]["b" ]["football_icon" ] == "ChangedIcon"
1782
- assert db .document (G .graph .graph_id )["a" ]["b" ]["football_icon" ] == "ChangedIcon"
1777
+ assert (
1778
+ db .document (G .graph .graph_id )[GRAPH_FIELD ]["a" ]["b" ]["football_icon" ]
1779
+ == "ChangedIcon"
1780
+ )
1783
1781
1784
1782
# Overwrite entire nested dictionary
1785
1783
G .graph ["a" ] = {"b" : icon2 }
1786
1784
assert G .graph ["a" ]["b" ]["basketball_icon" ] == "MJ23"
1787
- assert db .document (G .graph .graph_id )["a" ]["b" ]["basketball_icon" ] == "MJ23"
1785
+ assert (
1786
+ db .document (G .graph .graph_id )[GRAPH_FIELD ]["a" ]["b" ]["basketball_icon" ]
1787
+ == "MJ23"
1788
+ )
1788
1789
1789
1790
1790
1791
def test_graph_dict_complex_nested (load_karate_graph : Any ) -> None :
1791
1792
G = nxadb .Graph (name = "KarateGraph" , default_node_type = "person" )
1792
- G .clear ()
1793
1793
1794
1794
complex_structure = {"level1" : {"level2" : {"level3" : {"key" : "value" }}}}
1795
1795
1796
1796
G .graph ["complex" ] = complex_structure
1797
1797
assert G .graph ["complex" ]["level1" ]["level2" ]["level3" ]["key" ] == "value"
1798
1798
assert (
1799
- db .document (G .graph .graph_id )["complex" ]["level1" ]["level2" ]["level3" ]["key" ]
1799
+ db .document (G .graph .graph_id )[GRAPH_FIELD ]["complex" ]["level1" ]["level2" ][
1800
+ "level3"
1801
+ ]["key" ]
1800
1802
== "value"
1801
1803
)
1802
1804
1803
1805
1804
1806
def test_graph_dict_nested_deletion (load_karate_graph : Any ) -> None :
1805
1807
G = nxadb .Graph (name = "KarateGraph" , default_node_type = "person" )
1806
- G .clear ()
1807
1808
icon = {"football_icon" : "MJ7" , "amount_of_goals" : 1337 }
1808
1809
1809
1810
G .graph ["x" ] = {"y" : icon }
1810
1811
del G .graph ["x" ]["y" ]["amount_of_goals" ]
1811
1812
assert "amount_of_goals" not in G .graph ["x" ]["y" ]
1812
- assert "amount_of_goals" not in db .document (G .graph .graph_id )["x" ]["y" ]
1813
+ assert "amount_of_goals" not in db .document (G .graph .graph_id )[GRAPH_FIELD ][ "x" ]["y" ]
1813
1814
1814
1815
# Delete top-level key
1815
1816
del G .graph ["x" ]
1816
1817
assert "x" not in G .graph
1817
- assert "x" not in db .document (G .graph .graph_id )
1818
+ assert "x" not in db .document (G .graph .graph_id )[ GRAPH_FIELD ]
1818
1819
1819
1820
1820
1821
def test_readme (load_karate_graph : Any ) -> None :
0 commit comments