Skip to content

Commit

Permalink
Merge pull request #67 from mmarkov/master
Browse files Browse the repository at this point in the history
Implement changes to AGraph.clear() to handle custom attributes
  • Loading branch information
hagberg committed Aug 31, 2015
2 parents 1608aa6 + fa3d029 commit e6cf36f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pygraphviz/agraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,8 +948,8 @@ def size(self):

def clear(self):
"""Remove all nodes, edges, and attributes from the graph."""
self.edge_attr.clear()
self.node_attr.clear()
self.remove_edges_from(self.edges())
self.remove_nodes_from(self.nodes())
self.graph_attr.clear()
# now "close" existing graph and create a new graph
name = gv.agnameof(self.handle)
Expand Down
20 changes: 20 additions & 0 deletions pygraphviz/tests/test_clear.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from nose.tools import *
import pygraphviz as pgv


def test_del():
A = pgv.AGraph()
A.add_node(1,foo='bar')
# For some reasons after porting to Python 3 clear often cause infinite loop
A.delete_node('1')
assert_equal(len(A), 0)

def test_clear_node_with_attributes():
A = pgv.AGraph()
A.add_node(1,foo='bar')
# For some reasons after porting to Python 3 clear often cause infinite loop
A.clear()
assert_equal(len(A), 0)
assert_equal(A.nodes(), [])
assert_equal(A.node_attr.keys(), [])

0 comments on commit e6cf36f

Please sign in to comment.