Skip to content

Minor refactor to cleanup/improve matching test suite - #8068

Merged
dschult merged 5 commits into
networkx:mainfrom
rossbar:matching-test-cleanup
May 26, 2025
Merged

dschult merged 5 commits into
networkx:mainfrom
rossbar:matching-test-cleanup

Conversation

@rossbar

@rossbar rossbar commented May 26, 2025 •

Copy link
Copy Markdown
Contributor

A few test suite improvements from having read the code while reviewing #8062.

This PR essentially contains 3 unrelated proposals, and might be easier to digest commit-by-commit:

  • 942193a is the big one: it removes a layer of indirection in the tests by getting rid of the consistent calls to matching_dict_to_set for munging the "expected" answers. IMO it's much more straightforward to compare to the expected edge sets explicitly. This is possible because nx.utils.edges_equal already handles arbitrary edge ordering, so there's no need to do so twice.
  • af4aef3 converts all the instances of pytest.raises from function calls to the context manager pattern, and adds the match= kwarg better ensure that the expected exception is being raised.
  • Finally, 2ba9698 and e01171d factor out all of the input-checking tests for the various functions into single parametrized tests. The main advantage of doing so is that, currently, all of the is_*matching functions have the same exception message for the input validation exceptions. By lumping them altogether in the test suite, it makes it less likely that individual function messages will diverge in the future.

@Peiffap Peiffap left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. Much more readable this way :).
Just a small typo!

@dschult dschult left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice -- This is much more readable. :)

@dschult
dschult merged commit 7c97a10 into networkx:main May 26, 2025
@jarrodmillman jarrodmillman added this to the 3.5 milestone May 29, 2025
@fei0319 fei0319 mentioned this pull request May 29, 2025
amcandio pushed a commit to amcandio/networkx that referenced this pull request Jul 20, 2025
* Factor out matching_dict_to_set for expected.

Removes layer of indirection that is not necessary because
edges_equal already handles arbitrary edge ordering.

* pytest.raises fn -> context w/ error msg checking.

* Factor out invalid input tests for is_\*matching fns.

* Consolidate not-implemented-for tests.

* Update networkx/algorithms/tests/test_matching.py

Co-authored-by: Gilles Peiffer <[email protected]>

---------

Co-authored-by: Gilles Peiffer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants