MCPcopy
hub / github.com/networkx/networkx / test_update

Method test_update

networkx/classes/tests/test_graph.py:783–853  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

781 assert G.get_edge_data(-1, 0, default=1) == 1
782
783 def test_update(self):
784 # specify both edges and nodes
785 G = self.K3.copy()
786 G.update(nodes=[3, (4, {"size": 2})], edges=[(4, 5), (6, 7, {"weight": 2})])
787 nlist = [
788 (0, {}),
789 (1, {}),
790 (2, {}),
791 (3, {}),
792 (4, {"size": 2}),
793 (5, {}),
794 (6, {}),
795 (7, {}),
796 ]
797 assert sorted(G.nodes.data()) == nlist
798 if G.is_directed():
799 elist = [
800 (0, 1, {}),
801 (0, 2, {}),
802 (1, 0, {}),
803 (1, 2, {}),
804 (2, 0, {}),
805 (2, 1, {}),
806 (4, 5, {}),
807 (6, 7, {"weight": 2}),
808 ]
809 else:
810 elist = [
811 (0, 1, {}),
812 (0, 2, {}),
813 (1, 2, {}),
814 (4, 5, {}),
815 (6, 7, {"weight": 2}),
816 ]
817 assert sorted(G.edges.data()) == elist
818 assert G.graph == {}
819
820 # no keywords -- order is edges, nodes
821 G = self.K3.copy()
822 G.update([(4, 5), (6, 7, {"weight": 2})], [3, (4, {"size": 2})])
823 assert sorted(G.nodes.data()) == nlist
824 assert sorted(G.edges.data()) == elist
825 assert G.graph == {}
826
827 # update using only a graph
828 G = self.Graph()
829 G.graph["foo"] = "bar"
830 G.add_node(2, data=4)
831 G.add_edge(0, 1, weight=0.5)
832 GG = G.copy()
833 H = self.Graph()
834 GG.update(H)
835 assert graphs_equal(G, GG)
836 H.update(G)
837 assert graphs_equal(H, G)
838
839 # update nodes only
840 H = self.Graph()

Callers

nothing calls this directly

Calls 8

copyMethod · 0.95
updateMethod · 0.95
is_directedMethod · 0.95
add_nodeMethod · 0.95
add_edgeMethod · 0.95
sizeMethod · 0.95
graphs_equalFunction · 0.90
dataMethod · 0.45

Tested by

no test coverage detected