TST: add tests for unsupported graph types in MST algorithms#8353
Merged
rossbar merged 2 commits intonetworkx:mainfrom Nov 24, 2025
Merged
TST: add tests for unsupported graph types in MST algorithms#8353rossbar merged 2 commits intonetworkx:mainfrom
rossbar merged 2 commits intonetworkx:mainfrom
Conversation
Added tests ensuring that MST functions raise NetworkXNotImplemented on DiGraph (default case) and on MultiGraph for Borůvka.
dschult
approved these changes
Nov 24, 2025
Member
dschult
left a comment
There was a problem hiding this comment.
Looks good to me -- Thanks!
The diff makes it hard to see that the first change is in class MinimumSpanningTreeTestBase so it gets run on all algos. The second change is in the class TestBoruvka so it only gets run for the boruvka algo.
Thanks @Aka2210
amcandio
approved these changes
Nov 24, 2025
Contributor
amcandio
left a comment
There was a problem hiding this comment.
LGTM, thanks! You could also define a list of supported graphs in the base class and override that on the specific subclass
rossbar
approved these changes
Nov 24, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds tests to ensure that MST algorithms raise NetworkXNotImplemented on unsupported graph types.
Motivation
While reviewing the MST code in mst.py, I noticed that if the @not_implemented_for("directed") decorator is accidentally removed, the entire MST test suite still passes. In that situation, MST functions silently accept DiGraph (or MultiGraph for Borůvka) and return results, even though the documented behavior specifies that these graph types are not supported.
Although it is unlikely that the decorator will be removed intentionally—and such a change would typically be caught during code review—the lack of test coverage means this would not be detected by automated testing. To prevent this silent regression scenario, I added tests that verify:
All MST algorithms (Kruskal, Prim, and Borůvka) raise NetworkXNotImplemented on DiGraph.
Borůvka raises NetworkXNotImplemented on MultiGraph.
Kruskal and Prim continue to accept MultiGraph, as expected.
These tests ensure that the intended API contract is explicitly validated.
Notes
I am not entirely certain whether these tests are desirable or redundant, so I am submitting this PR to gather feedback. If the maintainers feel that these tests improve API contract coverage, they can be merged; otherwise, I am happy to revise or close the PR.
Thank you for reviewing!