Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add statistics for node and edge statements procuded #120

Open
PhilippWillms opened this issue Nov 18, 2020 · 1 comment
Open

Add statistics for node and edge statements procuded #120

PhilippWillms opened this issue Nov 18, 2020 · 1 comment

Comments

@PhilippWillms
Copy link

After adding edges and nodes via the straight-forward methods of classes "Graph" and "Digraph", it would be highly helpful to quickly retrieve the total count of nodes and edges via getter-methods. Currently, I just see the "source"-method to get dot source code, but this rather provides a list of edges than the integer count. The latter one would be relevant for consistency checks and assertions.

@xflr6
Copy link
Owner

xflr6 commented Nov 18, 2020

Thanks for the proposal.

Re: testing your code, I think you might want to go further than checking numbers of calls. This can be done by using the mock module as a 'spy' with the wraps keyword (you can assert on number of calls but also unpack arguments to make more specific assertions and hopefully also get useful diffing, see https://docs.python.org/3/library/unittest.mock.html):

In [1]: import mock
   ...: 
   ...: import graphviz
   ...: 
   ...: g = graphviz.Graph()
   ...: 
   ...: with mock.patch.object(g, 'node', wraps=g.node) as node_spy,\
   ...:     mock.patch.object(g, 'edge', wraps=g.edge) as edge_spy:
   ...:     g.node('spam')
   ...:     g.edge('spam', 'eggs')
   ...: 
   ...: node_spy.mock_calls, edge_spy.mock_calls
Out[1]: ([call('spam')], [call('spam', 'eggs')])
In [2]: g
Out[2]: 

spam

At the same time, I totally agree that it would be nice, e.g. for the repr() of a Graph instance to include the node and edge count (in general, statistics about the kinds of statements produced), and I also think that it would be nice to make them easily accessible (probably via properties). I currently don't see any blocker, marking this as enhancement.

Would you like to contribute here?

@xflr6 xflr6 changed the title Add calc methods for node and edge count Add statistics for node and edge statements procuded Nov 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants