def test_node_attr_update(self): g = DiGraph() g.add_node("foo", my_attr=1) self.assertEqual(g.nodes["foo"]["my_attr"], 1) g.add_node("foo", my_attr="different") self.assertEqual(g.nodes["foo"]["my_attr"], "different")
def test_successors(self): g = DiGraph() g.add_edge("foo", "bar") g.add_edge("foo", "baz") g.add_node("qux") self.assertIn("bar", list(g.successors("foo"))) self.assertIn("baz", list(g.successors("foo"))) self.assertEqual(len(list(g.successors("qux"))), 0)
def test_iter(self): g = DiGraph() g.add_node(1) g.add_node(2) g.add_node(3) nodes = set() for n in g: nodes.add(n) self.assertEqual(nodes, set([1, 2, 3]))
def test_contains(self): g = DiGraph() g.add_node("yup") self.assertTrue("yup" in g) self.assertFalse("nup" in g)
def test_node_attrs(self): g = DiGraph() g.add_node("foo", my_attr=1, other_attr=2) self.assertEqual(g.nodes["foo"]["my_attr"], 1) self.assertEqual(g.nodes["foo"]["other_attr"], 2)