Skip to content

Commit

Permalink
Allow cugraph-nx to run networkx tests for nx versions 3.0, 3.1, and …
Browse files Browse the repository at this point in the history
…3.2 (#3808)

This is one step to support #3770 

Note that NetworkX version 3.2 is currently under development.

CC @rlratzel

Authors:
  - Erik Welch (https://github.com/eriknw)

Approvers:
  - Rick Ratzel (https://github.com/rlratzel)

URL: #3808
  • Loading branch information
eriknw authored Aug 22, 2023
1 parent 66d6c79 commit fa99e34
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 10 deletions.
117 changes: 109 additions & 8 deletions python/cugraph-nx/cugraph_nx/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class BackendInterface:
@staticmethod
def convert_from_nx(graph, *args, edge_attrs=None, weight=None, **kwargs):
if weight is not None:
# MAINT: networkx 3.0, 3.1
# For networkx 3.0 and 3.1 compatibility
if edge_attrs is not None:
raise TypeError(
Expand All @@ -38,6 +39,13 @@ def convert_to_nx(obj, *, name: str | None = None):

@staticmethod
def on_start_tests(items):
"""Modify pytest items after tests have been collected.
This is called during ``pytest_collection_modifyitems`` phase of pytest.
We use this to set `xfail` on tests we expect to fail. See:
https://docs.pytest.org/en/stable/reference/reference.html#std-hook-pytest_collection_modifyitems
"""
try:
import pytest
except ModuleNotFoundError:
Expand All @@ -51,17 +59,110 @@ def key(testpath):
return (testname, frozenset({classname, filename}))
return (testname, frozenset({filename}))

string_attribute = "unable to handle string attributes"
no_weights = "weighted implementation not currently supported"
no_multigraph = "multigraphs not currently supported"

xfail = {}

from packaging.version import parse

skip = {
key("test_pajek.py:TestPajek.test_ignored_attribute"): string_attribute,
key(
"test_agraph.py:TestAGraph.test_no_warnings_raised"
): "pytest.warn(None) deprecated",
}
nxver = parse(nx.__version__)
if nxver.major == 3 and nxver.minor in {0, 1}:
# MAINT: networkx 3.0, 3.1
xfail.update(
{
key(
"test_agraph.py:TestAGraph.test_no_warnings_raised"
): "pytest.warn(None) deprecated",
key(
"test_betweenness_centrality.py:"
"TestWeightedBetweennessCentrality.test_K5"
): no_weights,
key(
"test_betweenness_centrality.py:"
"TestWeightedBetweennessCentrality.test_P3_normalized"
): no_weights,
key(
"test_betweenness_centrality.py:"
"TestWeightedBetweennessCentrality.test_P3"
): no_weights,
key(
"test_betweenness_centrality.py:"
"TestWeightedBetweennessCentrality.test_krackhardt_kite_graph"
): no_weights,
key(
"test_betweenness_centrality.py:"
"TestWeightedBetweennessCentrality."
"test_krackhardt_kite_graph_normalized"
): no_weights,
key(
"test_betweenness_centrality.py:"
"TestWeightedBetweennessCentrality."
"test_florentine_families_graph"
): no_weights,
key(
"test_betweenness_centrality.py:"
"TestWeightedBetweennessCentrality.test_les_miserables_graph"
): no_weights,
key(
"test_betweenness_centrality.py:"
"TestWeightedBetweennessCentrality.test_ladder_graph"
): no_weights,
key(
"test_betweenness_centrality.py:"
"TestWeightedBetweennessCentrality.test_G"
): no_weights,
key(
"test_betweenness_centrality.py:"
"TestWeightedBetweennessCentrality.test_G2"
): no_weights,
key(
"test_betweenness_centrality.py:"
"TestWeightedBetweennessCentrality.test_G3"
): no_multigraph,
key(
"test_betweenness_centrality.py:"
"TestWeightedBetweennessCentrality.test_G4"
): no_multigraph,
key(
"test_betweenness_centrality.py:"
"TestWeightedEdgeBetweennessCentrality.test_K5"
): no_weights,
key(
"test_betweenness_centrality.py:"
"TestWeightedEdgeBetweennessCentrality.test_C4"
): no_weights,
key(
"test_betweenness_centrality.py:"
"TestWeightedEdgeBetweennessCentrality.test_P4"
): no_weights,
key(
"test_betweenness_centrality.py:"
"TestWeightedEdgeBetweennessCentrality.test_balanced_tree"
): no_weights,
key(
"test_betweenness_centrality.py:"
"TestWeightedEdgeBetweennessCentrality.test_weighted_graph"
): no_weights,
key(
"test_betweenness_centrality.py:"
"TestWeightedEdgeBetweennessCentrality."
"test_normalized_weighted_graph"
): no_weights,
key(
"test_betweenness_centrality.py:"
"TestWeightedEdgeBetweennessCentrality.test_weighted_multigraph"
): no_multigraph,
key(
"test_betweenness_centrality.py:"
"TestWeightedEdgeBetweennessCentrality."
"test_normalized_weighted_multigraph"
): no_multigraph,
}
)
for item in items:
kset = set(item.keywords)
for (test_name, keywords), reason in skip.items():
for (test_name, keywords), reason in xfail.items():
if item.name == test_name and keywords.issubset(kset):
item.add_marker(pytest.mark.xfail(reason=reason))

Expand Down
1 change: 1 addition & 0 deletions python/cugraph-nx/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ test = [
"pytest",
"pytest-benchmark",
"pytest-mpl",
"packaging >=21",
]

[project.urls]
Expand Down
8 changes: 6 additions & 2 deletions python/cugraph-nx/run_nx_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@
#
# Coverage of `cugraph_nx.algorithms` is reported and is a good sanity check that algorithms run.

# NETWORKX_GRAPH_CONVERT=cugraph NETWORKX_BACKEND_TEST_EXHAUSTIVE=True pytest --pyargs networkx "$@"
NETWORKX_TEST_BACKEND=cugraph NETWORKX_TEST_FALLBACK_TO_NX=True pytest --pyargs networkx --cov=cugraph_nx/algorithms --cov-report term-missing --no-cov-on-fail "$@"
NETWORKX_GRAPH_CONVERT=cugraph NETWORKX_BACKEND_TEST_EXHAUSTIVE=True \
NETWORKX_TEST_BACKEND=cugraph NETWORKX_TEST_FALLBACK_TO_NX=True \
pytest --pyargs networkx \
--cov=cugraph_nx/algorithms \
--cov-report term-missing --no-cov-on-fail \
"$@"

0 comments on commit fa99e34

Please sign in to comment.