rm CondaPkg environment

This commit is contained in:
ton
2023-04-06 13:53:47 +07:00
parent 0a57ed7884
commit c43d949309
3329 changed files with 5725 additions and 447022 deletions

View File

@@ -0,0 +1,83 @@
# This file contains utilities for testing the dispatching feature
# A full test of all dispatchable algorithms is performed by
# modifying the pytest invocation and setting an environment variable
# NETWORKX_GRAPH_CONVERT=nx-loopback pytest
# This is comprehensive, but only tests the `test_override_dispatch`
# function in networkx.classes.backends.
# To test the `_dispatch` function directly, several tests scattered throughout
# NetworkX have been augmented to test normal and dispatch mode.
# Searching for `dispatch_interface` should locate the specific tests.
import networkx as nx
from networkx import DiGraph, Graph, MultiDiGraph, MultiGraph, PlanarEmbedding
class LoopbackGraph(Graph):
__networkx_plugin__ = "nx-loopback"
class LoopbackDiGraph(DiGraph):
__networkx_plugin__ = "nx-loopback"
class LoopbackMultiGraph(MultiGraph):
__networkx_plugin__ = "nx-loopback"
class LoopbackMultiDiGraph(MultiDiGraph):
__networkx_plugin__ = "nx-loopback"
class LoopbackPlanarEmbedding(PlanarEmbedding):
__networkx_plugin__ = "nx-loopback"
def convert(graph):
if isinstance(graph, PlanarEmbedding):
return LoopbackPlanarEmbedding(graph)
if isinstance(graph, MultiDiGraph):
return LoopbackMultiDiGraph(graph)
if isinstance(graph, MultiGraph):
return LoopbackMultiGraph(graph)
if isinstance(graph, DiGraph):
return LoopbackDiGraph(graph)
if isinstance(graph, Graph):
return LoopbackGraph(graph)
raise TypeError(f"Unsupported type of graph: {type(graph)}")
class LoopbackDispatcher:
non_toplevel = {
"inter_community_edges": nx.community.quality.inter_community_edges,
"is_tournament": nx.algorithms.tournament.is_tournament,
"mutual_weight": nx.algorithms.structuralholes.mutual_weight,
"score_sequence": nx.algorithms.tournament.score_sequence,
"tournament_matrix": nx.algorithms.tournament.tournament_matrix,
}
def __getattr__(self, item):
# Return the original, undecorated NetworkX algorithm
if hasattr(nx, item):
return getattr(nx, item)._orig_func
if item in self.non_toplevel:
return self.non_toplevel[item]._orig_func
raise AttributeError(item)
@staticmethod
def convert_from_nx(graph, weight=None, *, name=None):
return graph
@staticmethod
def convert_to_nx(obj, *, name=None):
return obj
@staticmethod
def on_start_tests(items):
# Verify that items can be xfailed
for item in items:
assert hasattr(item, "add_marker")
dispatcher = LoopbackDispatcher()

View File

@@ -70,8 +70,8 @@ class HistoricalTests:
G = self.G()
G.add_node("A")
assert "A" in G
assert not [] in G # never raise a Key or TypeError in this test
assert not {1: 1} in G
assert [] not in G # never raise a Key or TypeError in this test
assert {1: 1} not in G
def test_add_remove(self):
# Test add_node and remove_node acting for various nbunch

View File

@@ -0,0 +1,14 @@
import pytest
import networkx as nx
pytest.importorskip("scipy")
pytest.importorskip("numpy")
def test_dispatch_kwds_vs_args():
G = nx.path_graph(4)
nx.pagerank(G)
nx.pagerank(G=G)
with pytest.raises(TypeError):
nx.pagerank()

View File

@@ -155,7 +155,7 @@ class TestUnionAtlas:
assert view.__slots__ == pview.__slots__
def test_len(self):
assert len(self.av) == len(self.s) + len(self.p)
assert len(self.av) == len(self.s.keys() | self.p.keys()) == 5
def test_iter(self):
assert set(self.av) == set(self.s) | set(self.p)
@@ -257,7 +257,7 @@ class TestUnionMultiInner(TestUnionAdjacency):
self.adjview = nx.classes.coreviews.UnionMultiInner(self.s, self.p)
def test_len(self):
assert len(self.adjview) == len(self.s) + len(self.p)
assert len(self.adjview) == len(self.s.keys() | self.p.keys()) == 4
def test_getitem(self):
assert self.adjview[1] is not self.s[1]

View File

@@ -330,13 +330,13 @@ class TestFunction:
graph = nx.path_graph(4)
expected = [(0, 2), (0, 3), (1, 3)]
nedges = list(nx.non_edges(graph))
for (u, v) in expected:
for u, v in expected:
assert (u, v) in nedges or (v, u) in nedges
graph = nx.star_graph(4)
expected = [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]
nedges = list(nx.non_edges(graph))
for (u, v) in expected:
for u, v in expected:
assert (u, v) in nedges or (v, u) in nedges
# Directed graphs
@@ -738,9 +738,9 @@ def test_pathweight():
invalid_path = [1, 3, 2]
graphs = [nx.Graph(), nx.DiGraph(), nx.MultiGraph(), nx.MultiDiGraph()]
edges = [
(1, 2, dict(cost=5, dist=6)),
(2, 3, dict(cost=3, dist=4)),
(1, 2, dict(cost=1, dist=2)),
(1, 2, {"cost": 5, "dist": 6}),
(2, 3, {"cost": 3, "dist": 4}),
(1, 2, {"cost": 1, "dist": 2}),
]
for graph in graphs:
graph.add_edges_from(edges)

View File

@@ -1,6 +1,7 @@
import gc
import pickle
import platform
import weakref
import pytest
@@ -71,7 +72,19 @@ class BaseGraphTester:
G = self.Graph()
def count_objects_of_type(_type):
return sum(1 for obj in gc.get_objects() if isinstance(obj, _type))
# Iterating over all objects tracked by gc can include weak references
# whose weakly-referenced objects may no longer exist. Calling `isinstance`
# on such a weak reference will raise ReferenceError. There are at least
# three workarounds for this: one is to compare type names instead of using
# `isinstance` such as `type(obj).__name__ == typename`, another is to use
# `type(obj) == _type`, and the last is to ignore ProxyTypes as we do below.
# NOTE: even if this safeguard is deemed unnecessary to pass NetworkX tests,
# we should still keep it for maximum safety for other NetworkX backends.
return sum(
1
for obj in gc.get_objects()
if not isinstance(obj, weakref.ProxyTypes) and isinstance(obj, _type)
)
gc.collect()
before = count_objects_of_type(self.Graph)

View File

@@ -349,4 +349,4 @@ class TestChainsOfViews:
H = SG.copy()
assert SG.my_method() == "me"
assert H.my_method() == "me"
assert not 3 in H or 3 in SG
assert 3 not in H or 3 in SG

View File

@@ -421,13 +421,13 @@ class CustomDictClass(UserDict):
class MultiDiGraphSubClass(nx.MultiDiGraph):
node_dict_factory = CustomDictClass # type: ignore
node_attr_dict_factory = CustomDictClass # type: ignore
adjlist_outer_dict_factory = CustomDictClass # type: ignore
adjlist_inner_dict_factory = CustomDictClass # type: ignore
edge_key_dict_factory = CustomDictClass # type: ignore
edge_attr_dict_factory = CustomDictClass # type: ignore
graph_attr_dict_factory = CustomDictClass # type: ignore
node_dict_factory = CustomDictClass # type: ignore[assignment]
node_attr_dict_factory = CustomDictClass # type: ignore[assignment]
adjlist_outer_dict_factory = CustomDictClass # type: ignore[assignment]
adjlist_inner_dict_factory = CustomDictClass # type: ignore[assignment]
edge_key_dict_factory = CustomDictClass # type: ignore[assignment]
edge_attr_dict_factory = CustomDictClass # type: ignore[assignment]
graph_attr_dict_factory = CustomDictClass # type: ignore[assignment]
class TestMultiDiGraphSubclass(TestMultiDiGraph):

View File

@@ -202,8 +202,8 @@ class TestMultiGraph(BaseMultiGraphTester, _TestGraph):
def test_data_multigraph_input(self):
# standard case with edge keys and edge data
edata0 = dict(w=200, s="foo")
edata1 = dict(w=201, s="bar")
edata0 = {"w": 200, "s": "foo"}
edata1 = {"w": 201, "s": "bar"}
keydict = {0: edata0, 1: edata1}
dododod = {"a": {"b": keydict}}
@@ -235,7 +235,7 @@ class TestMultiGraph(BaseMultiGraphTester, _TestGraph):
dol = {"a": ["b"]}
multiple_edge = [("a", "b", "traits", etraits), ("a", "b", "graphics", egraphics)]
single_edge = [("a", "b", 0, {})] # type: ignore
single_edge = [("a", "b", 0, {})] # type: ignore[var-annotated]
single_edge1 = [("a", "b", 0, edata)]
single_edge2 = [("a", "b", 0, etraits)]
single_edge3 = [("a", "b", 0, {"traits": etraits, "s": "foo"})]
@@ -492,13 +492,13 @@ class CustomDictClass(UserDict):
class MultiGraphSubClass(nx.MultiGraph):
node_dict_factory = CustomDictClass # type: ignore
node_attr_dict_factory = CustomDictClass # type: ignore
adjlist_outer_dict_factory = CustomDictClass # type: ignore
adjlist_inner_dict_factory = CustomDictClass # type: ignore
edge_key_dict_factory = CustomDictClass # type: ignore
edge_attr_dict_factory = CustomDictClass # type: ignore
graph_attr_dict_factory = CustomDictClass # type: ignore
node_dict_factory = CustomDictClass # type: ignore[assignment]
node_attr_dict_factory = CustomDictClass # type: ignore[assignment]
adjlist_outer_dict_factory = CustomDictClass # type: ignore[assignment]
adjlist_inner_dict_factory = CustomDictClass # type: ignore[assignment]
edge_key_dict_factory = CustomDictClass # type: ignore[assignment]
edge_attr_dict_factory = CustomDictClass # type: ignore[assignment]
graph_attr_dict_factory = CustomDictClass # type: ignore[assignment]
class TestMultiGraphSubclass(TestMultiGraph):

View File

@@ -205,7 +205,7 @@ class TestNodeViewSetOps:
cls.nv = cls.G.nodes
def n_its(self, nodes):
return {node for node in nodes}
return set(nodes)
def test_len(self):
G = self.G.copy()
@@ -351,26 +351,26 @@ class TestEdgeDataView:
assert (1, 2) in ev and (2, 1) not in ev
else:
assert (1, 2) in ev and (2, 1) in ev
assert not (1, 4) in ev
assert not (1, 90) in ev
assert not (90, 1) in ev
assert (1, 4) not in ev
assert (1, 90) not in ev
assert (90, 1) not in ev
def test_contains_with_nbunch(self):
evr = self.eview(self.G)
ev = evr(nbunch=[0, 2])
if self.G.is_directed():
assert (0, 1) in ev
assert not (1, 2) in ev
assert (1, 2) not in ev
assert (2, 3) in ev
else:
assert (0, 1) in ev
assert (1, 2) in ev
assert (2, 3) in ev
assert not (3, 4) in ev
assert not (4, 5) in ev
assert not (5, 6) in ev
assert not (7, 8) in ev
assert not (8, 9) in ev
assert (3, 4) not in ev
assert (4, 5) not in ev
assert (5, 6) not in ev
assert (7, 8) not in ev
assert (8, 9) not in ev
def test_len(self):
evr = self.eview(self.G)
@@ -427,13 +427,13 @@ class TestOutEdgeDataView(TestEdgeDataView):
evr = self.eview(self.G)
ev = evr(nbunch=[0, 2])
assert (0, 1) in ev
assert not (1, 2) in ev
assert (1, 2) not in ev
assert (2, 3) in ev
assert not (3, 4) in ev
assert not (4, 5) in ev
assert not (5, 6) in ev
assert not (7, 8) in ev
assert not (8, 9) in ev
assert (3, 4) not in ev
assert (4, 5) not in ev
assert (5, 6) not in ev
assert (7, 8) not in ev
assert (8, 9) not in ev
class TestInEdgeDataView(TestOutEdgeDataView):
@@ -455,14 +455,14 @@ class TestInEdgeDataView(TestOutEdgeDataView):
def test_contains_with_nbunch(self):
evr = self.eview(self.G)
ev = evr(nbunch=[0, 2])
assert not (0, 1) in ev
assert (0, 1) not in ev
assert (1, 2) in ev
assert not (2, 3) in ev
assert not (3, 4) in ev
assert not (4, 5) in ev
assert not (5, 6) in ev
assert not (7, 8) in ev
assert not (8, 9) in ev
assert (2, 3) not in ev
assert (3, 4) not in ev
assert (4, 5) not in ev
assert (5, 6) not in ev
assert (7, 8) not in ev
assert (8, 9) not in ev
class TestMultiEdgeDataView(TestEdgeDataView):
@@ -490,11 +490,11 @@ class TestMultiEdgeDataView(TestEdgeDataView):
assert (0, 1) in ev
assert (1, 2) in ev
assert (2, 3) in ev
assert not (3, 4) in ev
assert not (4, 5) in ev
assert not (5, 6) in ev
assert not (7, 8) in ev
assert not (8, 9) in ev
assert (3, 4) not in ev
assert (4, 5) not in ev
assert (5, 6) not in ev
assert (7, 8) not in ev
assert (8, 9) not in ev
class TestOutMultiEdgeDataView(TestOutEdgeDataView):
@@ -520,13 +520,13 @@ class TestOutMultiEdgeDataView(TestOutEdgeDataView):
evr = self.eview(self.G)
ev = evr(nbunch=[0, 2])
assert (0, 1) in ev
assert not (1, 2) in ev
assert (1, 2) not in ev
assert (2, 3) in ev
assert not (3, 4) in ev
assert not (4, 5) in ev
assert not (5, 6) in ev
assert not (7, 8) in ev
assert not (8, 9) in ev
assert (3, 4) not in ev
assert (4, 5) not in ev
assert (5, 6) not in ev
assert (7, 8) not in ev
assert (8, 9) not in ev
class TestInMultiEdgeDataView(TestOutMultiEdgeDataView):
@@ -548,14 +548,14 @@ class TestInMultiEdgeDataView(TestOutMultiEdgeDataView):
def test_contains_with_nbunch(self):
evr = self.eview(self.G)
ev = evr(nbunch=[0, 2])
assert not (0, 1) in ev
assert (0, 1) not in ev
assert (1, 2) in ev
assert not (2, 3) in ev
assert not (3, 4) in ev
assert not (4, 5) in ev
assert not (5, 6) in ev
assert not (7, 8) in ev
assert not (8, 9) in ev
assert (2, 3) not in ev
assert (3, 4) not in ev
assert (4, 5) not in ev
assert (5, 6) not in ev
assert (7, 8) not in ev
assert (8, 9) not in ev
# Edge Views
@@ -631,13 +631,13 @@ class TestEdgeView:
else:
assert (1, 2) in ev and (2, 1) in ev
assert (1, 2) in edv and (2, 1) in edv
assert not (1, 4) in ev
assert not (1, 4) in edv
assert (1, 4) not in ev
assert (1, 4) not in edv
# edge not in graph
assert not (1, 90) in ev
assert not (90, 1) in ev
assert not (1, 90) in edv
assert not (90, 1) in edv
assert (1, 90) not in ev
assert (90, 1) not in ev
assert (1, 90) not in edv
assert (90, 1) not in edv
def test_contains_with_nbunch(self):
ev = self.eview(self.G)
@@ -645,11 +645,11 @@ class TestEdgeView:
assert (0, 1) in evn
assert (1, 2) in evn
assert (2, 3) in evn
assert not (3, 4) in evn
assert not (4, 5) in evn
assert not (5, 6) in evn
assert not (7, 8) in evn
assert not (8, 9) in evn
assert (3, 4) not in evn
assert (4, 5) not in evn
assert (5, 6) not in evn
assert (7, 8) not in evn
assert (8, 9) not in evn
def test_len(self):
ev = self.eview(self.G)
@@ -726,13 +726,13 @@ class TestOutEdgeView(TestEdgeView):
ev = self.eview(self.G)
evn = ev(nbunch=[0, 2])
assert (0, 1) in evn
assert not (1, 2) in evn
assert (1, 2) not in evn
assert (2, 3) in evn
assert not (3, 4) in evn
assert not (4, 5) in evn
assert not (5, 6) in evn
assert not (7, 8) in evn
assert not (8, 9) in evn
assert (3, 4) not in evn
assert (4, 5) not in evn
assert (5, 6) not in evn
assert (7, 8) not in evn
assert (8, 9) not in evn
class TestInEdgeView(TestEdgeView):
@@ -752,14 +752,14 @@ class TestInEdgeView(TestEdgeView):
def test_contains_with_nbunch(self):
ev = self.eview(self.G)
evn = ev(nbunch=[0, 2])
assert not (0, 1) in evn
assert (0, 1) not in evn
assert (1, 2) in evn
assert not (2, 3) in evn
assert not (3, 4) in evn
assert not (4, 5) in evn
assert not (5, 6) in evn
assert not (7, 8) in evn
assert not (8, 9) in evn
assert (2, 3) not in evn
assert (3, 4) not in evn
assert (4, 5) not in evn
assert (5, 6) not in evn
assert (7, 8) not in evn
assert (8, 9) not in evn
class TestMultiEdgeView(TestEdgeView):
@@ -871,7 +871,7 @@ class TestMultiEdgeView(TestEdgeView):
for e in ev:
assert len(e) == 3
elist = sorted([(i, i + 1, 0) for i in range(8)] + [(1, 2, 3)])
assert sorted(list(ev)) == elist
assert sorted(ev) == elist
# test order of arguments:graph, nbunch, data, keys, default
ev = evr((1, 2), "foo", True, 1)
for e in ev:
@@ -938,11 +938,11 @@ class TestMultiEdgeView(TestEdgeView):
assert (0, 1) in evn
assert (1, 2) in evn
assert (2, 3) in evn
assert not (3, 4) in evn
assert not (4, 5) in evn
assert not (5, 6) in evn
assert not (7, 8) in evn
assert not (8, 9) in evn
assert (3, 4) not in evn
assert (4, 5) not in evn
assert (5, 6) not in evn
assert (7, 8) not in evn
assert (8, 9) not in evn
class TestOutMultiEdgeView(TestMultiEdgeView):
@@ -969,13 +969,13 @@ class TestOutMultiEdgeView(TestMultiEdgeView):
ev = self.eview(self.G)
evn = ev(nbunch=[0, 2])
assert (0, 1) in evn
assert not (1, 2) in evn
assert (1, 2) not in evn
assert (2, 3) in evn
assert not (3, 4) in evn
assert not (4, 5) in evn
assert not (5, 6) in evn
assert not (7, 8) in evn
assert not (8, 9) in evn
assert (3, 4) not in evn
assert (4, 5) not in evn
assert (5, 6) not in evn
assert (7, 8) not in evn
assert (8, 9) not in evn
class TestInMultiEdgeView(TestMultiEdgeView):
@@ -1001,14 +1001,14 @@ class TestInMultiEdgeView(TestMultiEdgeView):
def test_contains_with_nbunch(self):
ev = self.eview(self.G)
evn = ev(nbunch=[0, 2])
assert not (0, 1) in evn
assert (0, 1) not in evn
assert (1, 2) in evn
assert not (2, 3) in evn
assert not (3, 4) in evn
assert not (4, 5) in evn
assert not (5, 6) in evn
assert not (7, 8) in evn
assert not (8, 9) in evn
assert (2, 3) not in evn
assert (3, 4) not in evn
assert (4, 5) not in evn
assert (5, 6) not in evn
assert (7, 8) not in evn
assert (8, 9) not in evn
# Degrees