summaryrefslogtreecommitdiff
path: root/networkx/classes/tests/test_graph.py
Commit message (Collapse)AuthorAgeFilesLines
* Ignore weakrefs when testing for memory leak (#6466)Erik Welch2023-03-111-1/+14
| | | | | * Ignore weakrefs when testing for memory leak * Add educational comments about gc and weakrefs
* Improve test coverage for graph class (#6105)Alimi Qudirah2022-10-251-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * fixes #6036 * test load centrality * test dispersion * test dispersion * dispersion test * test dispersion * bug-fixes-for-issue-6088 * deleted * bug-fix-for-issue-6092 * bugfix-for-issue-6088 * bugfix-for-issue-6088 * bugfix-for-issue-6088 * bugfix-for-issue-6102 * bugfix-for-issue-6102 * bugfix-for-issue-6102
* Add cache reset for when G._node is changed (#5894)Dan Schult2022-07-251-0/+5
|
* Attempt to reverse slowdown from hasattr needed for cached_property (#5836)Dan Schult2022-07-161-0/+7
| | | | | | | | | | | | | | | | | * Automate reset of cache for _adj,_pred,_succ * Make G._adj a data descriptor that resets G.adj when needed. * update places in the code where both G._succ and G._adj are changed This is no longer needed since G._succ and G._adj are synced during __set__ * testing hasattr(G, `_adj`) no longer ensures an instance. * Make mypy happy * Switch to hardcode attribute names in the data descriptors * Improve doc_strings for the data descriptors
* Use isort with pre-commit to enforce import guidelines (#5659)Mridul Seth2022-06-021-2/+3
| | | | | * Add isort to pre-commit * Run isort on all python files (except __init__.py ones)
* Cache edges, degree, adj properties of Graph classes (#5614)Dan Schult2022-05-111-1/+5
| | | | * Make all graph properties cached properties * one test function is not needed due to test inheritance
* Cache `nodes` property on Graph (#5600)Stefan van der Walt2022-05-081-0/+4
|
* Fixed wrong dict factory usage on MultiDiGraph (#5456)FabianBall2022-04-041-0/+13
| | | | | | | | | * Fixed the issue that the wrong dict factory on a MultiDiGraph was used for edge attributes (edge_key_dict_factory instead of edge_attr_dict_factory) Extended tests to typecheck the dict factories and added a test that incorporates custom dict factories on a MultiDiGraph * Mypy ignore inferred types in MDG subclass. Co-authored-by: Fabian Ball <fabian@codagio.de> Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* Fix graph_class usage in to_undirected method (#4912)Tomohiro Endo2021-06-221-0/+47
| | | | | * fix error in the tests... now original code fails test Co-authored-by: Dan Schult <dschult@colgate.edu>
* Raise ValueError if None is added as a node. (#4892)Dan Schult2021-06-151-0/+11
| | | | | | | * Raise ValueError if None is added as a node. Removed some tests that checked that errors raised when None was a node. * update tutorial to make a stronger statement about None
* add special processing of `multigraph_input` upon graph init (#4823)Dan Schult2021-05-271-3/+0
| | | | | | | | | | | | | | | | | | * add special processing of `multigraph_input` upon graph init Fixes: #4720 Adding a keyword argument `multigraph_input=True` to a graph construction call should treat any incoming input data for the graph as a dict-of-dict-of-dict multigraph data structure. Previously the multigraph_input argument would be added to the graph attribute dict and ignored when processing the input data. * Change default and add tests * make default try mgi=True, and if fails try mgi=False * copy parameter docstring to main class
* Refactor testing utilities (#4829)Jarrod Millman2021-05-261-46/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Refactor testing utilities Change `assert_edges_equal`, `assert_graphs_equal`, and `assert_nodes_equal` to be more pytest-idiomatic. For example, `assert_edges_equal` becomes the Boolean function `edges_equal` and then the assert is done the testing file (i.e., `assert edges_equal(edges1, edges2)`). This also makes these utility functions useful in nontesting situations where you want to compare edges, but not raise an exception based on the result. * Move testing utility functions * Use new testing utilities * Deprecate assert_*_equal testing utilities * Document node, edge, and graph equality helper functions * text nits. * Update networkx/tests/test_convert_pandas.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Update networkx/readwrite/tests/test_sparse6.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Update networkx/readwrite/tests/test_graph6.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Update networkx/generators/tests/test_classic.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Update networkx/algorithms/tree/tests/test_operations.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Update networkx/algorithms/tree/tests/test_coding.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Update networkx/algorithms/tests/test_dag.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Update networkx/algorithms/minors/tests/test_contraction.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * add short equality description to docstring * Suppress known warnings Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> Co-authored-by: Dan Schult <dschult@colgate.edu>
* Update black (#4814)Jarrod Millman2021-05-181-2/+2
|
* Skip memory leak test for PyPy (#4385)Dan Schult2020-11-241-0/+4
| | | | | * Skip memory leak test for PyPy * add reason code for skipif
* TST: Refactor to improve coverage. (#4307)Ross Barnowski2020-10-311-2/+4
| | | Refactor exception handling and improve test specificity.
* Add nx.info to str dunder for graph classes (#4241)Ross Barnowski2020-10-091-1/+10
| | | | | | | | | | * Modify graph __str__ to return nx.info. Returns the result of nx.info(self) instead of only the instance name. * TST: Modify tests for new str dunder. * MAINT: move graph summary to __str__ from info
* Format w/ blackJarrod Millman2020-07-101-183/+216
|
* Add method to clear edges only (#3477)Paolo Lammens2020-07-051-0/+13
| | | | | | | | | | | | | | | | | | | | | | | * feat: `clear_edges` in `networkx.Graph` Method to clear all edges in a graph without altering nodes or graph attributes. Added corresponding test too. * tests: improve `test_clear` in `TestGraph` Added a graph attribute before clearing to test its proper deletion. too. * tests: add tests for `clear` and `clear_edges` specific to DiGraph To test that DiGraph-specific edge records are cleared as well. * fix: specific `clear_edges` for `DiGraph` So that DiGraph's pred/succ also get cleared. * Convert docstrings tests and docs reference links to add clear_edges Co-authored-by: Dan Schult <dschult@colgate.edu>
* Upgrade to Py36 syntaxJarrod Millman2020-01-011-4/+4
| | | | find networkx -name \*.py -exec pyupgrade --py36-plus {} \;
* Enable ThinGraph tests (#3681)Jarrod Millman2019-10-231-19/+11
| | | | | | | | * Enable ThinGraph tests * Rewrite test_special to make ThinGraph tested * fix pycodestyle for test_digraph.py
* PEP8 fixesJarrod Millman2019-10-181-5/+9
|
* PEP8 fixes to testsJarrod Millman2019-10-181-7/+7
|
* Replace nose.raises with pytest.raises context managerJarrod Millman2019-10-121-16/+16
|
* remove tests of deprecated views and fix use of deprecated G.nodeDan Schult2019-10-121-23/+0
|
* Fix some warningsJarrod Millman2019-10-121-6/+6
|
* Remove unused importsJarrod Millman2019-10-121-4/+0
|
* Convert nose.tools.assert_* functions into assertsJarrod Millman2019-10-121-144/+144
|
* Fix graph/digraph testsStefan van der Walt2019-10-121-34/+45
| | | | | | | | Note that pytest does not seem to inspect the stacktrace for multiple exceptions raised and caught, so I only checked the "outer" exception. Class setup had to be replaced with method setup: graphs get modified, so we need a fresh one for each method.
* Use class methods for class setup/teardownStefan van der Walt2019-10-121-11/+12
|
* Add base class method `update` (#3028)Dan Schult2018-06-281-7/+64
| | | Part of #1393
* Remove cyclic reference in G.root_graph (#3014)Dan Schult2018-06-161-8/+33
| | | | | | | | * Remove a second cyclic reference in G.root_graph Related to #3011 and #2885 and maybe #2793 * Add tests for memory leaks due to copy()
* Remove circular references between graphs and views. (#3011)Dan Schult2018-06-141-0/+8
| | | | | | Graphs no longer have references to views. Views still have references to the graph. This should ease subclassing the base graph classes because you don't have to worry about creating memory leaks.
* change variable names to avoid kwargs clobber (#2824)Dan Schult2018-01-101-1/+1
| | | | | | | I didn't change functions defined in tests. I also left drawing routines as is at least for now. Addresses #1582 Fixes #1583
* Removed unused imports (#2653)James Lamb2017-10-011-1/+0
|
* Add deprecated methods for moved base class methods. (#2639)Dan Schult2017-08-271-0/+17
| | | | | This eases creating code that works for both v1 and v2. It doesn't address the concerns of #2634 but it eases the transition to v2.
* Deprecate node (#2633)Jarrod Millman2017-08-261-0/+6
| | | Fix #2630.
* Simplify base classes. (#2604)Dan Schult2017-08-121-60/+60
| | | | | | | | | | * move selfloop methods out of graph classes into function.py * replace G.node with G.nodes. fix Pickle of views * Replace G.edge with G.edges * Add a few lines of docs for release realted to this PR.
* Next attempt to meld graphviews with base classes (#2593)Dan Schult2017-08-121-43/+42
| | | | | | | | | | | | | | | | | | | | | | * Update code to prepare for melding graphviews * Meld graphviews into graph classes * Cleanup subgraph calling sign. and remove duplicate code * Add some tests for raising exceptions * update edge_kcomponents to avoid readonly views. * Add root_graph attribute and tests Update tests for root_graph as well as fresh_copy. I left fresh_copy as an attribute even with root_graph because a view might switch the data structure of the view from directed to undirected. Going to the root_graph.__class__ may not give you what you need to create a graph like the view. Fresh_copy gives a null graph with the directed/multi type of that view or graph.
* Doc ordered graph classes (#2516)Jarrod Millman2017-07-161-291/+293
| | | | | | | | | | | | | | | | | | | * Add minimal docstrings * Add note about ordered graph variants * Mention ordered variant in `See Also` section * Comply with pep8 * Replace reference to LogGraph with PrintGraph LogGraph was a reference to a graph that logged each mutation. That's what PrintGraph does and is provided in the examples directory. * Do not claim OrderedGraphs maintain the order of adding edges * Remove OrderedGraph examples and minor cleanup for Sphinx
* Move data structure to private names and replace with readonly structures ↵Dan Schult2017-06-261-51/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (#2475) * Dont assume iterators for nodes/edges/degrees (prep for views) * Add graph view classes for nodes/edges/degree * Add right set operations (not present in python3.3 KeysView * Add nodes before adding edges so python36 tests work By only adding edges, the nodes were added in order (0,1,3,2) and with the ordered nature of python3.6 dicts the tests failed. Could also fix by using nodelist on each call to to_convert_... * weighted graph convert tests testing empty graphs The edge iterator was exhausted for source before being used for dest * allow DegreeView to include case of nbunch * Make node/edge/degree properties of Graph * View contains fix and Viewers can return self. More tests * Add more tests including one for #2347 * Add nbunch tests and pep8 * Rename to EdgeView and EdgeDataView * docs tweaks and pep8 * fix up nodeDataView contains. Add and clean up tests. * Change the graph attributes to read-only properties * Reframe views code and extend _node to all networkx (still need examples) * Clean up and pep8 for view changes * ername AtlasViews, simplify code and add docstrings * Make G[u] return a view, and catch some doc bugs * Update views to use _node,_adj. Add len to EdgeDataView * minor adjustments to example subclass/printgraph
* Add graph view classes for nodes/edge/degrees (#2458)Dan Schult2017-06-131-6/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Dont assume iterators for nodes/edges/degrees (prep for views) * Add graph view classes for nodes/edges/degree * Add right set operations (not present in python3.3 KeysView * Add nodes before adding edges so python36 tests work By only adding edges, the nodes were added in order (0,1,3,2) and with the ordered nature of python3.6 dicts the tests failed. Could also fix by using nodelist on each call to to_convert_... * weighted graph convert tests testing empty graphs The edge iterator was exhausted for source before being used for dest * allow DegreeView to include case of nbunch * Make node/edge/degree properties of Graph * View contains fix and Viewers can return self. More tests * Add more tests including one for #2347 * Add nbunch tests and pep8 * Rename to EdgeView and EdgeDataView * docs tweaks and pep8 * fix up nodeDataView contains. Add and clean up tests. * Tweaks to improve speed for nodes and edges. * improve views dependence on ABCs, remove len from dataviews * First pass on docs in views.py * Change property to lazy attribute
* Change docstring in tests to avoid name with "fail" in testing output.Dan Schult2016-12-191-6/+4
|
* Apply suggestions from @hagberg on GH-2207.Valentin Lorentz2016-07-311-5/+5
|
* Fix tests failing because of ordering issues.Valentin Lorentz2016-07-301-39/+40
|
* Remove attr_dict from add_edges_from method.thegreathippo2016-05-011-7/+0
| | | | | Doing this invalidated the test in test_graph.py (test_attr_dict_not_dict), so I removed the test entirely.
* Remove attr_dict from add_node, add_edgethegreathippo2016-05-011-1/+1
| | | | | | | In doing so, I found a few attr_dict assignments I missed, and cleaned up in a few spots. I also made sure to use the update method rather than keyword assignment in json_graph/adjacency.py to allow for some (likely VERY corner) cases where edge and node attributes might not be strings.
* Modified all add_node, add_edge, and add_edges_from methods.thegreathippo2016-04-261-8/+7
| | | | | | | | I also went through and modified all attr_dict references to either directly assign keywords to node/edge attributes, or use the ** syntax to unpack the dictionaries. The only case of these I couldn't do is networkx.convert.py -- largely because I don't understand how multigraph edges work.
* Remove attr_dict calls to graph's add_node; replace with **.thegreathippo2016-04-261-15/+11
| | | | | | Combing through the code for any point where it pushes a dictionary to the add_node method rather than keywords; augmenting these arguments with ** to turn them into keyword arguments.
* Modified Graph.add_edge, Graph.add_edges_from, and test_add_edges_fromthegreathippo2016-04-251-2/+2
| | | | | | | | The same mutation (attr_dict mutations) that occurred in add_node occurred in the add_edges and add_edges_from methods; also, the same test failure (passing an empty sequence shouldn't really raise an error, since you can update a dictionary with an empty sequence without raising an error).
* Modified Graph.add_node and test_add_node.thegreathippo2016-04-251-1/+1
| | | | | | | | | Graph.add_node mutated the attr_dict parameter and assigned it directly to the graph's node dictionary, creating potential for unexpected behavior. Creating a new dictionary based on the supplied attr_dict (and updated with the supplied kwargs) avoids this problem -- also had to update the test for adding nodes, since sending an empty sequence no longer raises an error (which seems reasonable).