summaryrefslogtreecommitdiff
path: root/networkx/tests
diff options
context:
space:
mode:
authorJarrod Millman <jarrod.millman@gmail.com>2019-10-08 22:18:40 -0700
committerJarrod Millman <jarrod.millman@gmail.com>2019-10-12 09:21:57 -0700
commit75e0c43bef21f764c669244fb57f658b4afc94e9 (patch)
tree7ecc0f885d8b80e60508a8b4960dd28e53c189f4 /networkx/tests
parent4093b6b22d681b701bd4dc5a201e7944cd50e268 (diff)
downloadnetworkx-75e0c43bef21f764c669244fb57f658b4afc94e9.tar.gz
Convert nose.tools.assert_* functions into asserts
Diffstat (limited to 'networkx/tests')
-rw-r--r--networkx/tests/test_all_random_functions.py8
-rw-r--r--networkx/tests/test_convert.py44
-rw-r--r--networkx/tests/test_convert_numpy.py88
-rw-r--r--networkx/tests/test_convert_scipy.py2
-rw-r--r--networkx/tests/test_relabel.py68
5 files changed, 105 insertions, 105 deletions
diff --git a/networkx/tests/test_all_random_functions.py b/networkx/tests/test_all_random_functions.py
index 87cd948e..4b4d66d1 100644
--- a/networkx/tests/test_all_random_functions.py
+++ b/networkx/tests/test_all_random_functions.py
@@ -31,13 +31,13 @@ def t(f, *args, **kwds):
after_np_rv = np.random.rand()
# if np_rv != after_np_rv:
# print(np_rv, after_np_rv, "don't match np!")
- assert_equal(np_rv, after_np_rv)
+ assert np_rv == after_np_rv
np.random.seed(42)
after_py_rv = random.random()
# if py_rv != after_py_rv:
# print(py_rv, after_py_rv, "don't match py!")
- assert_equal(py_rv, after_py_rv)
+ assert py_rv == after_py_rv
random.seed(42)
@@ -200,11 +200,11 @@ def test_rng_interface():
after_np_rv = np.random.rand()
# if np_rv != after_np_rv:
# print(np_rv, after_np_rv, "don't match np!")
- assert_equal(np_rv, after_np_rv)
+ assert np_rv == after_np_rv
after_py_rv = random.random()
# if py_rv != after_py_rv:
# print(py_rv, after_py_rv, "don't match py!")
- assert_equal(py_rv, after_py_rv)
+ assert py_rv == after_py_rv
# print("\nDone testing seed:", seed)
diff --git a/networkx/tests/test_convert.py b/networkx/tests/test_convert.py
index 21dc8173..2b272b7e 100644
--- a/networkx/tests/test_convert.py
+++ b/networkx/tests/test_convert.py
@@ -87,14 +87,14 @@ class TestConvert():
G = cycle_graph(10, create_using=nx.DiGraph)
dod = dest(G)
GG = source(dod, create_using=nx.DiGraph)
- assert_equal(sorted(G.nodes()), sorted(GG.nodes()))
- assert_equal(sorted(G.edges()), sorted(GG.edges()))
+ assert sorted(G.nodes()) == sorted(GG.nodes())
+ assert sorted(G.edges()) == sorted(GG.edges())
GW = to_networkx_graph(dod, create_using=nx.DiGraph)
- assert_equal(sorted(G.nodes()), sorted(GW.nodes()))
- assert_equal(sorted(G.edges()), sorted(GW.edges()))
+ assert sorted(G.nodes()) == sorted(GW.nodes())
+ assert sorted(G.edges()) == sorted(GW.edges())
GI = nx.DiGraph(dod)
- assert_equal(sorted(G.nodes()), sorted(GI.nodes()))
- assert_equal(sorted(G.edges()), sorted(GI.edges()))
+ assert sorted(G.nodes()) == sorted(GI.nodes())
+ assert sorted(G.edges()) == sorted(GI.edges())
def test_graph(self):
g = nx.cycle_graph(10)
@@ -111,8 +111,8 @@ class TestConvert():
assert_nodes_equal(sorted(G.nodes()), sorted(GW.nodes()))
assert_edges_equal(sorted(G.edges()), sorted(GW.edges()))
GI = nx.Graph(dod)
- assert_equal(sorted(G.nodes()), sorted(GI.nodes()))
- assert_equal(sorted(G.edges()), sorted(GI.edges()))
+ assert sorted(G.nodes()) == sorted(GI.nodes())
+ assert sorted(G.edges()) == sorted(GI.edges())
# Dict of lists
dol = to_dict_of_lists(G)
@@ -183,11 +183,11 @@ class TestConvert():
GI = nx.MultiGraph(dod) # convert can't tell whether to duplicate edges!
assert_nodes_equal(sorted(XGM.nodes()), sorted(GI.nodes()))
#assert_not_equal(sorted(XGM.edges()), sorted(GI.edges()))
- assert_false(sorted(XGM.edges()) == sorted(GI.edges()))
+ assert not sorted(XGM.edges()) == sorted(GI.edges())
GE = from_dict_of_dicts(dod, create_using=nx.MultiGraph,
multigraph_input=False)
assert_nodes_equal(sorted(XGM.nodes()), sorted(GE.nodes()))
- assert_not_equal(sorted(XGM.edges()), sorted(GE.edges()))
+ assert sorted(XGM.edges()) != sorted(GE.edges())
GI = nx.MultiGraph(XGM)
assert_nodes_equal(sorted(XGM.nodes()), sorted(GI.nodes()))
assert_edges_equal(sorted(XGM.edges()), sorted(GI.edges()))
@@ -232,27 +232,27 @@ class TestConvert():
def test_directed_to_undirected(self):
edges1 = [(0, 1), (1, 2), (2, 0)]
edges2 = [(0, 1), (1, 2), (0, 2)]
- assert_true(self.edgelists_equal(nx.Graph(nx.DiGraph(edges1)).edges(), edges1))
- assert_true(self.edgelists_equal(nx.Graph(nx.DiGraph(edges2)).edges(), edges1))
- assert_true(self.edgelists_equal(nx.MultiGraph(nx.DiGraph(edges1)).edges(), edges1))
- assert_true(self.edgelists_equal(nx.MultiGraph(nx.DiGraph(edges2)).edges(), edges1))
+ assert self.edgelists_equal(nx.Graph(nx.DiGraph(edges1)).edges(), edges1)
+ assert self.edgelists_equal(nx.Graph(nx.DiGraph(edges2)).edges(), edges1)
+ assert self.edgelists_equal(nx.MultiGraph(nx.DiGraph(edges1)).edges(), edges1)
+ assert self.edgelists_equal(nx.MultiGraph(nx.DiGraph(edges2)).edges(), edges1)
- assert_true(self.edgelists_equal(nx.MultiGraph(nx.MultiDiGraph(edges1)).edges(),
- edges1))
- assert_true(self.edgelists_equal(nx.MultiGraph(nx.MultiDiGraph(edges2)).edges(),
- edges1))
+ assert self.edgelists_equal(nx.MultiGraph(nx.MultiDiGraph(edges1)).edges(),
+ edges1)
+ assert self.edgelists_equal(nx.MultiGraph(nx.MultiDiGraph(edges2)).edges(),
+ edges1)
- assert_true(self.edgelists_equal(nx.Graph(nx.MultiDiGraph(edges1)).edges(), edges1))
- assert_true(self.edgelists_equal(nx.Graph(nx.MultiDiGraph(edges2)).edges(), edges1))
+ assert self.edgelists_equal(nx.Graph(nx.MultiDiGraph(edges1)).edges(), edges1)
+ assert self.edgelists_equal(nx.Graph(nx.MultiDiGraph(edges2)).edges(), edges1)
def test_attribute_dict_integrity(self):
# we must not replace dict-like graph data structures with dicts
G = nx.OrderedGraph()
G.add_nodes_from("abc")
H = to_networkx_graph(G, create_using=nx.OrderedGraph)
- assert_equal(list(H.nodes), list(G.nodes))
+ assert list(H.nodes) == list(G.nodes)
H = nx.OrderedDiGraph(G)
- assert_equal(list(H.nodes), list(G.nodes))
+ assert list(H.nodes) == list(G.nodes)
def test_to_edgelist(self):
G = nx.Graph([(1, 1)])
diff --git a/networkx/tests/test_convert_numpy.py b/networkx/tests/test_convert_numpy.py
index 6b4513ae..2525b3d1 100644
--- a/networkx/tests/test_convert_numpy.py
+++ b/networkx/tests/test_convert_numpy.py
@@ -37,8 +37,8 @@ class TestConvertNumpy(object):
return G
def assert_equal(self, G1, G2):
- assert_true(sorted(G1.nodes()) == sorted(G2.nodes()))
- assert_true(sorted(G1.edges()) == sorted(G2.edges()))
+ assert sorted(G1.nodes()) == sorted(G2.nodes())
+ assert sorted(G1.edges()) == sorted(G2.edges())
def identity_conversion(self, G, A, create_using):
assert(A.sum() > 0)
@@ -123,23 +123,23 @@ class TestConvertNumpy(object):
def test_from_numpy_matrix_type(self):
A = np.matrix([[1]])
G = nx.from_numpy_matrix(A)
- assert_equal(type(G[0][0]['weight']), int)
+ assert type(G[0][0]['weight']) == int
A = np.matrix([[1]]).astype(np.float)
G = nx.from_numpy_matrix(A)
- assert_equal(type(G[0][0]['weight']), float)
+ assert type(G[0][0]['weight']) == float
A = np.matrix([[1]]).astype(np.str)
G = nx.from_numpy_matrix(A)
- assert_equal(type(G[0][0]['weight']), str)
+ assert type(G[0][0]['weight']) == str
A = np.matrix([[1]]).astype(np.bool)
G = nx.from_numpy_matrix(A)
- assert_equal(type(G[0][0]['weight']), bool)
+ assert type(G[0][0]['weight']) == bool
A = np.matrix([[1]]).astype(np.complex)
G = nx.from_numpy_matrix(A)
- assert_equal(type(G[0][0]['weight']), complex)
+ assert type(G[0][0]['weight']) == complex
A = np.matrix([[1]]).astype(np.object)
assert_raises(TypeError, nx.from_numpy_matrix, A)
@@ -147,39 +147,39 @@ class TestConvertNumpy(object):
G = nx.cycle_graph(3)
A = nx.adj_matrix(G).todense()
H = nx.from_numpy_matrix(A)
- assert_true(all(type(m) == int and type(n) == int for m, n in H.edges()))
+ assert all(type(m) == int and type(n) == int for m, n in H.edges())
H = nx.from_numpy_array(A)
- assert_true(all(type(m) == int and type(n) == int for m, n in H.edges()))
+ assert all(type(m) == int and type(n) == int for m, n in H.edges())
def test_from_numpy_matrix_dtype(self):
dt = [('weight', float), ('cost', int)]
A = np.matrix([[(1.0, 2)]], dtype=dt)
G = nx.from_numpy_matrix(A)
- assert_equal(type(G[0][0]['weight']), float)
- assert_equal(type(G[0][0]['cost']), int)
- assert_equal(G[0][0]['cost'], 2)
- assert_equal(G[0][0]['weight'], 1.0)
+ assert type(G[0][0]['weight']) == float
+ assert type(G[0][0]['cost']) == int
+ assert G[0][0]['cost'] == 2
+ assert G[0][0]['weight'] == 1.0
def test_to_numpy_recarray(self):
G = nx.Graph()
G.add_edge(1, 2, weight=7.0, cost=5)
A = nx.to_numpy_recarray(G, dtype=[('weight', float), ('cost', int)])
- assert_equal(sorted(A.dtype.names), ['cost', 'weight'])
- assert_equal(A.weight[0, 1], 7.0)
- assert_equal(A.weight[0, 0], 0.0)
- assert_equal(A.cost[0, 1], 5)
- assert_equal(A.cost[0, 0], 0)
+ assert sorted(A.dtype.names) == ['cost', 'weight']
+ assert A.weight[0, 1] == 7.0
+ assert A.weight[0, 0] == 0.0
+ assert A.cost[0, 1] == 5
+ assert A.cost[0, 0] == 0
def test_numpy_multigraph(self):
G = nx.MultiGraph()
G.add_edge(1, 2, weight=7)
G.add_edge(1, 2, weight=70)
A = nx.to_numpy_matrix(G)
- assert_equal(A[1, 0], 77)
+ assert A[1, 0] == 77
A = nx.to_numpy_matrix(G, multigraph_weight=min)
- assert_equal(A[1, 0], 7)
+ assert A[1, 0] == 7
A = nx.to_numpy_matrix(G, multigraph_weight=max)
- assert_equal(A[1, 0], 70)
+ assert A[1, 0] == 70
def test_from_numpy_matrix_parallel_edges(self):
"""Tests that the :func:`networkx.from_numpy_matrix` function
@@ -236,7 +236,7 @@ class TestConvertNumpy(object):
"""
G = nx.complete_graph(3)
A = nx.to_numpy_matrix(G, dtype=int)
- assert_equal(A.dtype, int)
+ assert A.dtype == int
def test_dtype_int_multigraph(self):
"""Test that setting dtype int actually gives an integer matrix.
@@ -246,7 +246,7 @@ class TestConvertNumpy(object):
"""
G = nx.MultiGraph(nx.complete_graph(3))
A = nx.to_numpy_matrix(G, dtype=int)
- assert_equal(A.dtype, int)
+ assert A.dtype == int
class TestConvertNumpyArray(object):
@@ -276,8 +276,8 @@ class TestConvertNumpyArray(object):
return G
def assert_equal(self, G1, G2):
- assert_true(sorted(G1.nodes()) == sorted(G2.nodes()))
- assert_true(sorted(G1.edges()) == sorted(G2.edges()))
+ assert sorted(G1.nodes()) == sorted(G2.nodes())
+ assert sorted(G1.edges()) == sorted(G2.edges())
def identity_conversion(self, G, A, create_using):
assert(A.sum() > 0)
@@ -338,23 +338,23 @@ class TestConvertNumpyArray(object):
def test_from_numpy_array_type(self):
A = np.array([[1]])
G = nx.from_numpy_array(A)
- assert_equal(type(G[0][0]['weight']), int)
+ assert type(G[0][0]['weight']) == int
A = np.array([[1]]).astype(np.float)
G = nx.from_numpy_array(A)
- assert_equal(type(G[0][0]['weight']), float)
+ assert type(G[0][0]['weight']) == float
A = np.array([[1]]).astype(np.str)
G = nx.from_numpy_array(A)
- assert_equal(type(G[0][0]['weight']), str)
+ assert type(G[0][0]['weight']) == str
A = np.array([[1]]).astype(np.bool)
G = nx.from_numpy_array(A)
- assert_equal(type(G[0][0]['weight']), bool)
+ assert type(G[0][0]['weight']) == bool
A = np.array([[1]]).astype(np.complex)
G = nx.from_numpy_array(A)
- assert_equal(type(G[0][0]['weight']), complex)
+ assert type(G[0][0]['weight']) == complex
A = np.array([[1]]).astype(np.object)
assert_raises(TypeError, nx.from_numpy_array, A)
@@ -363,31 +363,31 @@ class TestConvertNumpyArray(object):
dt = [('weight', float), ('cost', int)]
A = np.array([[(1.0, 2)]], dtype=dt)
G = nx.from_numpy_array(A)
- assert_equal(type(G[0][0]['weight']), float)
- assert_equal(type(G[0][0]['cost']), int)
- assert_equal(G[0][0]['cost'], 2)
- assert_equal(G[0][0]['weight'], 1.0)
+ assert type(G[0][0]['weight']) == float
+ assert type(G[0][0]['cost']) == int
+ assert G[0][0]['cost'] == 2
+ assert G[0][0]['weight'] == 1.0
def test_to_numpy_recarray(self):
G = nx.Graph()
G.add_edge(1, 2, weight=7.0, cost=5)
A = nx.to_numpy_recarray(G, dtype=[('weight', float), ('cost', int)])
- assert_equal(sorted(A.dtype.names), ['cost', 'weight'])
- assert_equal(A.weight[0, 1], 7.0)
- assert_equal(A.weight[0, 0], 0.0)
- assert_equal(A.cost[0, 1], 5)
- assert_equal(A.cost[0, 0], 0)
+ assert sorted(A.dtype.names) == ['cost', 'weight']
+ assert A.weight[0, 1] == 7.0
+ assert A.weight[0, 0] == 0.0
+ assert A.cost[0, 1] == 5
+ assert A.cost[0, 0] == 0
def test_numpy_multigraph(self):
G = nx.MultiGraph()
G.add_edge(1, 2, weight=7)
G.add_edge(1, 2, weight=70)
A = nx.to_numpy_array(G)
- assert_equal(A[1, 0], 77)
+ assert A[1, 0] == 77
A = nx.to_numpy_array(G, multigraph_weight=min)
- assert_equal(A[1, 0], 7)
+ assert A[1, 0] == 7
A = nx.to_numpy_array(G, multigraph_weight=max)
- assert_equal(A[1, 0], 70)
+ assert A[1, 0] == 70
def test_from_numpy_array_parallel_edges(self):
"""Tests that the :func:`networkx.from_numpy_array` function
@@ -444,7 +444,7 @@ class TestConvertNumpyArray(object):
"""
G = nx.complete_graph(3)
A = nx.to_numpy_array(G, dtype=int)
- assert_equal(A.dtype, int)
+ assert A.dtype == int
def test_dtype_int_multigraph(self):
"""Test that setting dtype int actually gives an integer array.
@@ -454,4 +454,4 @@ class TestConvertNumpyArray(object):
"""
G = nx.MultiGraph(nx.complete_graph(3))
A = nx.to_numpy_array(G, dtype=int)
- assert_equal(A.dtype, int)
+ assert A.dtype == int
diff --git a/networkx/tests/test_convert_scipy.py b/networkx/tests/test_convert_scipy.py
index d9e67dd4..d15df56e 100644
--- a/networkx/tests/test_convert_scipy.py
+++ b/networkx/tests/test_convert_scipy.py
@@ -42,7 +42,7 @@ class TestConvertNumpy(object):
return G
def assert_isomorphic(self, G1, G2):
- assert_true(nx.is_isomorphic(G1, G2))
+ assert nx.is_isomorphic(G1, G2)
def identity_conversion(self, G, A, create_using):
GG = nx.from_scipy_sparse_matrix(A, create_using=create_using)
diff --git a/networkx/tests/test_relabel.py b/networkx/tests/test_relabel.py
index 01586562..43ce06c2 100644
--- a/networkx/tests/test_relabel.py
+++ b/networkx/tests/test_relabel.py
@@ -11,61 +11,61 @@ class TestRelabel():
# test that empty graph converts fine for all options
G = empty_graph()
H = nx.convert_node_labels_to_integers(G, 100)
- assert_equal(list(H.nodes()), [])
- assert_equal(list(H.edges()), [])
+ assert list(H.nodes()) == []
+ assert list(H.edges()) == []
for opt in ["default", "sorted", "increasing degree", "decreasing degree"]:
G = empty_graph()
H = nx.convert_node_labels_to_integers(G, 100, ordering=opt)
- assert_equal(list(H.nodes()), [])
- assert_equal(list(H.edges()), [])
+ assert list(H.nodes()) == []
+ assert list(H.edges()) == []
G = empty_graph()
G.add_edges_from([('A', 'B'), ('A', 'C'), ('B', 'C'), ('C', 'D')])
H = nx.convert_node_labels_to_integers(G)
degH = (d for n, d in H.degree())
degG = (d for n, d in G.degree())
- assert_equal(sorted(degH), sorted(degG))
+ assert sorted(degH) == sorted(degG)
H = nx.convert_node_labels_to_integers(G, 1000)
degH = (d for n, d in H.degree())
degG = (d for n, d in G.degree())
- assert_equal(sorted(degH), sorted(degG))
+ assert sorted(degH) == sorted(degG)
assert_nodes_equal(H.nodes(), [1000, 1001, 1002, 1003])
H = nx.convert_node_labels_to_integers(G, ordering="increasing degree")
degH = (d for n, d in H.degree())
degG = (d for n, d in G.degree())
- assert_equal(sorted(degH), sorted(degG))
- assert_equal(H.degree(0), 1)
- assert_equal(H.degree(1), 2)
- assert_equal(H.degree(2), 2)
- assert_equal(H.degree(3), 3)
+ assert sorted(degH) == sorted(degG)
+ assert H.degree(0) == 1
+ assert H.degree(1) == 2
+ assert H.degree(2) == 2
+ assert H.degree(3) == 3
H = nx.convert_node_labels_to_integers(G, ordering="decreasing degree")
degH = (d for n, d in H.degree())
degG = (d for n, d in G.degree())
- assert_equal(sorted(degH), sorted(degG))
- assert_equal(H.degree(0), 3)
- assert_equal(H.degree(1), 2)
- assert_equal(H.degree(2), 2)
- assert_equal(H.degree(3), 1)
+ assert sorted(degH) == sorted(degG)
+ assert H.degree(0) == 3
+ assert H.degree(1) == 2
+ assert H.degree(2) == 2
+ assert H.degree(3) == 1
H = nx.convert_node_labels_to_integers(G, ordering="increasing degree",
label_attribute='label')
degH = (d for n, d in H.degree())
degG = (d for n, d in G.degree())
- assert_equal(sorted(degH), sorted(degG))
- assert_equal(H.degree(0), 1)
- assert_equal(H.degree(1), 2)
- assert_equal(H.degree(2), 2)
- assert_equal(H.degree(3), 3)
+ assert sorted(degH) == sorted(degG)
+ assert H.degree(0) == 1
+ assert H.degree(1) == 2
+ assert H.degree(2) == 2
+ assert H.degree(3) == 3
# check mapping
- assert_equal(H.nodes[3]['label'], 'C')
- assert_equal(H.nodes[0]['label'], 'D')
- assert_true(H.nodes[1]['label'] == 'A' or H.nodes[2]['label'] == 'A')
- assert_true(H.nodes[1]['label'] == 'B' or H.nodes[2]['label'] == 'B')
+ assert H.nodes[3]['label'] == 'C'
+ assert H.nodes[0]['label'] == 'D'
+ assert H.nodes[1]['label'] == 'A' or H.nodes[2]['label'] == 'A'
+ assert H.nodes[1]['label'] == 'B' or H.nodes[2]['label'] == 'B'
def test_convert_to_integers2(self):
G = empty_graph()
@@ -73,14 +73,14 @@ class TestRelabel():
H = nx.convert_node_labels_to_integers(G, ordering="sorted")
degH = (d for n, d in H.degree())
degG = (d for n, d in G.degree())
- assert_equal(sorted(degH), sorted(degG))
+ assert sorted(degH) == sorted(degG)
H = nx.convert_node_labels_to_integers(G, ordering="sorted",
label_attribute='label')
- assert_equal(H.nodes[0]['label'], 'A')
- assert_equal(H.nodes[1]['label'], 'B')
- assert_equal(H.nodes[2]['label'], 'C')
- assert_equal(H.nodes[3]['label'], 'D')
+ assert H.nodes[0]['label'] == 'A'
+ assert H.nodes[1]['label'] == 'B'
+ assert H.nodes[2]['label'] == 'C'
+ assert H.nodes[3]['label'] == 'D'
@raises(nx.NetworkXError)
def test_convert_to_integers_raise(self):
@@ -154,14 +154,14 @@ class TestRelabel():
def test_relabel_copy_name(self):
G = nx.Graph()
H = nx.relabel_nodes(G, {}, copy=True)
- assert_equal(H.graph, G.graph)
+ assert H.graph == G.graph
H = nx.relabel_nodes(G, {}, copy=False)
- assert_equal(H.graph, G.graph)
+ assert H.graph == G.graph
G.name = "first"
H = nx.relabel_nodes(G, {}, copy=True)
- assert_equal(H.graph, G.graph)
+ assert H.graph == G.graph
H = nx.relabel_nodes(G, {}, copy=False)
- assert_equal(H.graph, G.graph)
+ assert H.graph == G.graph
def test_relabel_toposort(self):
K5 = nx.complete_graph(4)