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

Fix pydot tests when testing backends #7356

Merged
merged 1 commit into from Mar 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 14 additions & 6 deletions networkx/utils/backends.py
Expand Up @@ -924,7 +924,7 @@ def _convert_and_call_for_tests(

from collections.abc import Iterable, Iterator, Mapping
from copy import copy
from io import BufferedReader, BytesIO
from io import BufferedReader, BytesIO, StringIO, TextIOWrapper
from itertools import tee
from random import Random

Expand All @@ -941,9 +941,12 @@ def _convert_and_call_for_tests(
args1, args2 = zip(
*(
(arg, copy(arg))
if isinstance(arg, BytesIO | Random | Generator | RandomState)
if isinstance(
arg, BytesIO | StringIO | Random | Generator | RandomState
)
else tee(arg)
if isinstance(arg, Iterator) and not isinstance(arg, BufferedReader)
if isinstance(arg, Iterator)
and not isinstance(arg, BufferedReader | TextIOWrapper)
else (arg, arg)
for arg in args
)
Expand All @@ -954,9 +957,12 @@ def _convert_and_call_for_tests(
kwargs1, kwargs2 = zip(
*(
((k, v), (k, copy(v)))
if isinstance(v, BytesIO | Random | Generator | RandomState)
if isinstance(
v, BytesIO | StringIO | Random | Generator | RandomState
)
else ((k, (teed := tee(v))[0]), (k, teed[1]))
if isinstance(v, Iterator) and not isinstance(v, BufferedReader)
if isinstance(v, Iterator)
and not isinstance(v, BufferedReader | TextIOWrapper)
else ((k, v), (k, v))
for k, v in kwargs.items()
)
Expand Down Expand Up @@ -1121,13 +1127,15 @@ def check_iterator(it):
"read_gml",
"read_graph6",
"read_sparse6",
# We don't handle io.BufferedReader arguments
# We don't handle io.BufferedReader or io.TextIOWrapper arguments
"bipartite_read_edgelist",
"read_adjlist",
"read_edgelist",
"read_graphml",
"read_multiline_adjlist",
"read_pajek",
"from_pydot",
"pydot_read_dot",
# graph comparison fails b/c of nan values
"read_gexf",
}:
Expand Down