MCPcopy
hub / github.com/networkx/networkx / test_add_nodes_from

Method test_add_nodes_from

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

Source from the content-addressed store, hash-verified

654 assert G.nodes[3]["c"] == "blue"
655
656 def test_add_nodes_from(self):
657 G = self.Graph()
658 G.add_nodes_from([0, 1, 2])
659 assert G.adj == {0: {}, 1: {}, 2: {}}
660 # test add attributes
661 G.add_nodes_from([0, 1, 2], c="red")
662 assert G.nodes[0]["c"] == "red"
663 assert G.nodes[2]["c"] == "red"
664 # test that attribute dicts are not the same
665 assert G.nodes[0] is not G.nodes[1]
666 # test updating attributes
667 G.add_nodes_from([0, 1, 2], c="blue")
668 assert G.nodes[0]["c"] == "blue"
669 assert G.nodes[2]["c"] == "blue"
670 assert G.nodes[0] is not G.nodes[1]
671 # test tuple input
672 H = self.Graph()
673 H.add_nodes_from(G.nodes(data=True))
674 assert H.nodes[0]["c"] == "blue"
675 assert H.nodes[2]["c"] == "blue"
676 assert H.nodes[0] is not H.nodes[1]
677 # specific overrides general
678 H.add_nodes_from([0, (1, {"c": "green"}), (3, {"c": "cyan"})], c="red")
679 assert H.nodes[0]["c"] == "red"
680 assert H.nodes[1]["c"] == "green"
681 assert H.nodes[2]["c"] == "blue"
682 assert H.nodes[3]["c"] == "cyan"
683
684 def test_remove_node(self):
685 G = self.K3.copy()

Callers

nothing calls this directly

Calls 2

add_nodes_fromMethod · 0.95
nodesMethod · 0.95

Tested by

no test coverage detected