summaryrefslogtreecommitdiff
path: root/networkx/conftest.py
blob: 0d39779c6ff6f2134d9fa518eb247300facbe143 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
import pytest
import networkx
import sys
import warnings


def pytest_addoption(parser):
    parser.addoption(
        "--runslow", action="store_true", default=False, help="run slow tests"
    )


def pytest_configure(config):
    config.addinivalue_line("markers", "slow: mark test as slow to run")


def pytest_collection_modifyitems(config, items):
    if config.getoption("--runslow"):
        # --runslow given in cli: do not skip slow tests
        return
    skip_slow = pytest.mark.skip(reason="need --runslow option to run")
    for item in items:
        if "slow" in item.keywords:
            item.add_marker(skip_slow)


# TODO: The warnings below need to be dealt with, but for now we silence them.
@pytest.fixture(autouse=True)
def set_warnings():
    warnings.filterwarnings(
        "ignore", category=DeprecationWarning, message=r"Ordered.* is deprecated"
    )
    warnings.filterwarnings(
        "ignore",
        category=DeprecationWarning,
        message="literal_stringizer is deprecated",
    )
    warnings.filterwarnings(
        "ignore",
        category=DeprecationWarning,
        message="literal_destringizer is deprecated",
    )
    warnings.filterwarnings(
        "ignore", category=DeprecationWarning, message="is_string_like is deprecated"
    )
    warnings.filterwarnings(
        "ignore", category=DeprecationWarning, message="\nauthority_matrix"
    )
    warnings.filterwarnings(
        "ignore", category=DeprecationWarning, message="\nhub_matrix"
    )
    warnings.filterwarnings(
        "ignore", category=DeprecationWarning, message="default_opener is deprecated"
    )
    warnings.filterwarnings(
        "ignore", category=DeprecationWarning, message="empty_generator is deprecated"
    )
    warnings.filterwarnings(
        "ignore", category=DeprecationWarning, message="make_str is deprecated"
    )
    warnings.filterwarnings(
        "ignore",
        category=DeprecationWarning,
        message="generate_unique_node is deprecated",
    )
    warnings.filterwarnings(
        "ignore",
        category=DeprecationWarning,
        message="context manager reversed is deprecated",
    )
    warnings.filterwarnings(
        "ignore",
        category=DeprecationWarning,
        message="This will return a generator in 3.0*",
    )
    warnings.filterwarnings(
        "ignore", category=DeprecationWarning, message="betweenness_centrality_source"
    )
    warnings.filterwarnings(
        "ignore", category=DeprecationWarning, message="edge_betweeness"
    )
    warnings.filterwarnings(
        "ignore", category=PendingDeprecationWarning, message="the matrix subclass"
    )
    warnings.filterwarnings(
        "ignore", category=DeprecationWarning, message="to_numpy_matrix"
    )
    warnings.filterwarnings(
        "ignore", category=DeprecationWarning, message="from_numpy_matrix"
    )
    warnings.filterwarnings(
        "ignore", category=DeprecationWarning, message="networkx.pagerank_numpy"
    )
    warnings.filterwarnings(
        "ignore", category=DeprecationWarning, message="networkx.pagerank_scipy"
    )
    warnings.filterwarnings(
        "ignore", category=DeprecationWarning, message="write_gpickle"
    )
    warnings.filterwarnings(
        "ignore", category=DeprecationWarning, message="read_gpickle"
    )
    warnings.filterwarnings("ignore", category=DeprecationWarning, message="write_shp")
    warnings.filterwarnings("ignore", category=DeprecationWarning, message="read_shp")
    warnings.filterwarnings(
        "ignore", category=DeprecationWarning, message="edges_from_line"
    )
    warnings.filterwarnings("ignore", category=DeprecationWarning, message="write_yaml")
    warnings.filterwarnings("ignore", category=DeprecationWarning, message="read_yaml")
    warnings.filterwarnings(
        "ignore", category=DeprecationWarning, message="FilterAtlas.copy"
    )
    warnings.filterwarnings(
        "ignore", category=DeprecationWarning, message="FilterAdjacency.copy"
    )
    warnings.filterwarnings(
        "ignore", category=DeprecationWarning, message="FilterMultiAdjacency.copy"
    )
    warnings.filterwarnings(
        "ignore", category=DeprecationWarning, message="FilterMultiInner.copy"
    )
    warnings.filterwarnings("ignore", category=DeprecationWarning, message="jit_data")
    warnings.filterwarnings("ignore", category=DeprecationWarning, message="jit_graph")
    warnings.filterwarnings("ignore", category=DeprecationWarning, message="consume")
    warnings.filterwarnings(
        "ignore", category=DeprecationWarning, message="iterable is deprecated"
    )
    warnings.filterwarnings(
        "ignore",
        category=FutureWarning,
        message="\nThe function signature for cytoscape",
    )
    warnings.filterwarnings(
        "ignore", category=DeprecationWarning, message="\nThe `attrs` keyword"
    )
    warnings.filterwarnings(
        "ignore", category=DeprecationWarning, message="preserve_random_state"
    )
    warnings.filterwarnings(
        "ignore", category=DeprecationWarning, message="`almost_equal`"
    )


@pytest.fixture(autouse=True)
def add_nx(doctest_namespace):
    doctest_namespace["nx"] = networkx


# What dependencies are installed?

try:
    import numpy

    has_numpy = True
except ImportError:
    has_numpy = False

try:
    import scipy

    has_scipy = True
except ImportError:
    has_scipy = False

try:
    import matplotlib

    has_matplotlib = True
except ImportError:
    has_matplotlib = False

try:
    import pandas

    has_pandas = True
except ImportError:
    has_pandas = False

try:
    import pygraphviz

    has_pygraphviz = True
except ImportError:
    has_pygraphviz = False

try:
    import yaml

    has_yaml = True
except ImportError:
    has_yaml = False

try:
    import pydot

    has_pydot = True
except ImportError:
    has_pydot = False

try:
    import ogr

    has_ogr = True
except ImportError:
    has_ogr = False


# List of files that pytest should ignore

collect_ignore = []

needs_numpy = [
    "algorithms/centrality/current_flow_closeness.py",
    "algorithms/node_classification/__init__.py",
    "algorithms/non_randomness.py",
    "algorithms/shortest_paths/dense.py",
    "linalg/bethehessianmatrix.py",
    "linalg/laplacianmatrix.py",
    "utils/misc.py",
]
needs_scipy = [
    "algorithms/assortativity/correlation.py",
    "algorithms/assortativity/mixing.py",
    "algorithms/assortativity/pairs.py",
    "algorithms/bipartite/matrix.py",
    "algorithms/bipartite/spectral.py",
    "algorithms/centrality/current_flow_betweenness.py",
    "algorithms/centrality/current_flow_betweenness_subset.py",
    "algorithms/centrality/eigenvector.py",
    "algorithms/centrality/katz.py",
    "algorithms/centrality/second_order.py",
    "algorithms/centrality/subgraph_alg.py",
    "algorithms/communicability_alg.py",
    "algorithms/link_analysis/hits_alg.py",
    "algorithms/link_analysis/pagerank_alg.py",
    "algorithms/node_classification/hmn.py",
    "algorithms/node_classification/lgc.py",
    "algorithms/similarity.py",
    "convert_matrix.py",
    "drawing/layout.py",
    "generators/spectral_graph_forge.py",
    "linalg/algebraicconnectivity.py",
    "linalg/attrmatrix.py",
    "linalg/graphmatrix.py",
    "linalg/modularitymatrix.py",
    "linalg/spectrum.py",
    "utils/rcm.py",
]
needs_matplotlib = ["drawing/nx_pylab.py"]
needs_pandas = ["convert_matrix.py"]
needs_yaml = ["readwrite/nx_yaml.py"]
needs_pygraphviz = ["drawing/nx_agraph.py"]
needs_pydot = ["drawing/nx_pydot.py"]
needs_ogr = ["readwrite/nx_shp.py"]

if not has_numpy:
    collect_ignore += needs_numpy
if not has_scipy:
    collect_ignore += needs_scipy
if not has_matplotlib:
    collect_ignore += needs_matplotlib
if not has_pandas:
    collect_ignore += needs_pandas
if not has_yaml:
    collect_ignore += needs_yaml
if not has_pygraphviz:
    collect_ignore += needs_pygraphviz
if not has_pydot:
    collect_ignore += needs_pydot
if not has_ogr:
    collect_ignore += needs_ogr

# FIXME:  This is to avoid errors on AppVeyor
if sys.platform.startswith("win"):
    collect_ignore += ["readwrite/graph6.py", "readwrite/sparse6.py"]