diff options
author | Jarrod Millman <jarrod.millman@gmail.com> | 2019-10-08 22:18:40 -0700 |
---|---|---|
committer | Jarrod Millman <jarrod.millman@gmail.com> | 2019-10-12 09:21:57 -0700 |
commit | 75e0c43bef21f764c669244fb57f658b4afc94e9 (patch) | |
tree | 7ecc0f885d8b80e60508a8b4960dd28e53c189f4 /networkx/algorithms | |
parent | 4093b6b22d681b701bd4dc5a201e7944cd50e268 (diff) | |
download | networkx-75e0c43bef21f764c669244fb57f658b4afc94e9.tar.gz |
Convert nose.tools.assert_* functions into asserts
Diffstat (limited to 'networkx/algorithms')
130 files changed, 2683 insertions, 2800 deletions
diff --git a/networkx/algorithms/approximation/tests/test_approx_clust_coeff.py b/networkx/algorithms/approximation/tests/test_approx_clust_coeff.py index 629d3e75..a32eb18b 100644 --- a/networkx/algorithms/approximation/tests/test_approx_clust_coeff.py +++ b/networkx/algorithms/approximation/tests/test_approx_clust_coeff.py @@ -9,38 +9,38 @@ from networkx.algorithms.approximation import average_clustering def test_petersen(): # Actual coefficient is 0 G = nx.petersen_graph() - assert_equal(average_clustering(G, trials=int(len(G) / 2)), + assert (average_clustering(G, trials=int(len(G) / 2)) == nx.average_clustering(G)) def test_petersen_seed(): # Actual coefficient is 0 G = nx.petersen_graph() - assert_equal(average_clustering(G, trials=int(len(G) / 2), seed=1), + assert (average_clustering(G, trials=int(len(G) / 2), seed=1) == nx.average_clustering(G)) def test_tetrahedral(): # Actual coefficient is 1 G = nx.tetrahedral_graph() - assert_equal(average_clustering(G, trials=int(len(G) / 2)), + assert (average_clustering(G, trials=int(len(G) / 2)) == nx.average_clustering(G)) def test_dodecahedral(): # Actual coefficient is 0 G = nx.dodecahedral_graph() - assert_equal(average_clustering(G, trials=int(len(G) / 2)), + assert (average_clustering(G, trials=int(len(G) / 2)) == nx.average_clustering(G)) def test_empty(): G = nx.empty_graph(5) - assert_equal(average_clustering(G, trials=int(len(G) / 2)), 0) + assert average_clustering(G, trials=int(len(G) / 2)) == 0 def test_complete(): G = nx.complete_graph(5) - assert_equal(average_clustering(G, trials=int(len(G) / 2)), 1) + assert average_clustering(G, trials=int(len(G) / 2)) == 1 G = nx.complete_graph(7) - assert_equal(average_clustering(G, trials=int(len(G) / 2)), 1) + assert average_clustering(G, trials=int(len(G) / 2)) == 1 diff --git a/networkx/algorithms/approximation/tests/test_clique.py b/networkx/algorithms/approximation/tests/test_clique.py index d7d03a46..0737029b 100644 --- a/networkx/algorithms/approximation/tests/test_clique.py +++ b/networkx/algorithms/approximation/tests/test_clique.py @@ -53,22 +53,22 @@ class TestCliqueRemoval(object): def test_trivial_graph(self): G = nx.trivial_graph() independent_set, cliques = clique_removal(G) - assert_true(is_independent_set(G, independent_set)) - assert_true(all(is_clique(G, clique) for clique in cliques)) + assert is_independent_set(G, independent_set) + assert all(is_clique(G, clique) for clique in cliques) # In fact, we should only have 1-cliques, that is, singleton nodes. - assert_true(all(len(clique) == 1 for clique in cliques)) + assert all(len(clique) == 1 for clique in cliques) def test_complete_graph(self): G = nx.complete_graph(10) independent_set, cliques = clique_removal(G) - assert_true(is_independent_set(G, independent_set)) - assert_true(all(is_clique(G, clique) for clique in cliques)) + assert is_independent_set(G, independent_set) + assert all(is_clique(G, clique) for clique in cliques) def test_barbell_graph(self): G = nx.barbell_graph(10, 5) independent_set, cliques = clique_removal(G) - assert_true(is_independent_set(G, independent_set)) - assert_true(all(is_clique(G, clique) for clique in cliques)) + assert is_independent_set(G, independent_set) + assert all(is_clique(G, clique) for clique in cliques) class TestMaxClique(object): @@ -79,13 +79,13 @@ class TestMaxClique(object): def test_null_graph(self): G = nx.null_graph() - assert_equal(len(max_clique(G)), 0) + assert len(max_clique(G)) == 0 def test_complete_graph(self): graph = nx.complete_graph(30) # this should return the entire graph mc = max_clique(graph) - assert_equal(30, len(mc)) + assert 30 == len(mc) def test_maximal_by_cardinality(self): """Tests that the maximal clique is computed according to maximum @@ -97,11 +97,11 @@ class TestMaxClique(object): G = nx.complete_graph(5) G.add_edge(4, 5) clique = max_clique(G) - assert_greater(len(clique), 1) + assert len(clique) > 1 G = nx.lollipop_graph(30, 2) clique = max_clique(G) - assert_greater(len(clique), 2) + assert len(clique) > 2 def test_large_clique_size(): @@ -111,8 +111,8 @@ def test_large_clique_size(): G.add_edge(1, 12) G.add_node(13) - assert_equal(large_clique_size(G), 9) + assert large_clique_size(G) == 9 G.remove_node(5) - assert_equal(large_clique_size(G), 8) + assert large_clique_size(G) == 8 G.remove_edge(2, 3) - assert_equal(large_clique_size(G), 7) + assert large_clique_size(G) == 7 diff --git a/networkx/algorithms/approximation/tests/test_connectivity.py b/networkx/algorithms/approximation/tests/test_connectivity.py index cb3143bb..19bb010a 100644 --- a/networkx/algorithms/approximation/tests/test_connectivity.py +++ b/networkx/algorithms/approximation/tests/test_connectivity.py @@ -11,9 +11,9 @@ def test_global_node_connectivity(): G.add_edges_from([(1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 6), (3, 4), (3, 6), (4, 6), (4, 7), (5, 7), (6, 8), (6, 9), (7, 8), (7, 10), (8, 11), (9, 10), (9, 11), (10, 11)]) - assert_equal(2, approx.local_node_connectivity(G, 1, 11)) - assert_equal(2, approx.node_connectivity(G)) - assert_equal(2, approx.node_connectivity(G, 1, 11)) + assert 2 == approx.local_node_connectivity(G, 1, 11) + assert 2 == approx.node_connectivity(G) + assert 2 == approx.node_connectivity(G, 1, 11) def test_white_harary1(): @@ -28,27 +28,27 @@ def test_white_harary1(): G.remove_node(G.order() - 1) for i in range(7, 10): G.add_edge(0, i) - assert_equal(1, approx.node_connectivity(G)) + assert 1 == approx.node_connectivity(G) def test_complete_graphs(): for n in range(5, 25, 5): G = nx.complete_graph(n) - assert_equal(n - 1, approx.node_connectivity(G)) - assert_equal(n - 1, approx.node_connectivity(G, 0, 3)) + assert n - 1 == approx.node_connectivity(G) + assert n - 1 == approx.node_connectivity(G, 0, 3) def test_empty_graphs(): for k in range(5, 25, 5): G = nx.empty_graph(k) - assert_equal(0, approx.node_connectivity(G)) - assert_equal(0, approx.node_connectivity(G, 0, 3)) + assert 0 == approx.node_connectivity(G) + assert 0 == approx.node_connectivity(G, 0, 3) def test_petersen(): G = nx.petersen_graph() - assert_equal(3, approx.node_connectivity(G)) - assert_equal(3, approx.node_connectivity(G, 0, 5)) + assert 3 == approx.node_connectivity(G) + assert 3 == approx.node_connectivity(G, 0, 5) # Approximation fails with tutte graph # def test_tutte(): @@ -58,14 +58,14 @@ def test_petersen(): def test_dodecahedral(): G = nx.dodecahedral_graph() - assert_equal(3, approx.node_connectivity(G)) - assert_equal(3, approx.node_connectivity(G, 0, 5)) + assert 3 == approx.node_connectivity(G) + assert 3 == approx.node_connectivity(G, 0, 5) def test_octahedral(): G = nx.octahedral_graph() - assert_equal(4, approx.node_connectivity(G)) - assert_equal(4, approx.node_connectivity(G, 0, 5)) + assert 4 == approx.node_connectivity(G) + assert 4 == approx.node_connectivity(G, 0, 5) # Approximation can fail with icosahedral graph depending # on iteration order. @@ -103,10 +103,10 @@ def test_source_equals_target(): def test_directed_node_connectivity(): G = nx.cycle_graph(10, create_using=nx.DiGraph()) # only one direction D = nx.cycle_graph(10).to_directed() # 2 reciprocal edges - assert_equal(1, approx.node_connectivity(G)) - assert_equal(1, approx.node_connectivity(G, 1, 4)) - assert_equal(2, approx.node_connectivity(D)) - assert_equal(2, approx.node_connectivity(D, 1, 4)) + assert 1 == approx.node_connectivity(G) + assert 1 == approx.node_connectivity(G, 1, 4) + assert 2 == approx.node_connectivity(D) + assert 2 == approx.node_connectivity(D, 1, 4) class TestAllPairsNodeConnectivityApprox: @@ -130,31 +130,31 @@ class TestAllPairsNodeConnectivityApprox: K_undir = approx.all_pairs_node_connectivity(self.cycle) for source in K_undir: for target, k in K_undir[source].items(): - assert_true(k == 2) + assert k == 2 K_dir = approx.all_pairs_node_connectivity(self.directed_cycle) for source in K_dir: for target, k in K_dir[source].items(): - assert_true(k == 1) + assert k == 1 def test_complete(self): for G in [self.K10, self.K5, self.K20]: K = approx.all_pairs_node_connectivity(G) for source in K: for target, k in K[source].items(): - assert_true(k == len(G) - 1) + assert k == len(G) - 1 def test_paths(self): K_undir = approx.all_pairs_node_connectivity(self.path) for source in K_undir: for target, k in K_undir[source].items(): - assert_true(k == 1) + assert k == 1 K_dir = approx.all_pairs_node_connectivity(self.directed_path) for source in K_dir: for target, k in K_dir[source].items(): if source < target: - assert_true(k == 1) + assert k == 1 else: - assert_true(k == 0) + assert k == 0 def test_cutoff(self): for G in [self.K10, self.K5, self.K20]: @@ -162,10 +162,10 @@ class TestAllPairsNodeConnectivityApprox: paths = approx.all_pairs_node_connectivity(G, cutoff=mp) for source in paths: for target, K in paths[source].items(): - assert_true(K == mp) + assert K == mp def test_all_pairs_connectivity_nbunch(self): G = nx.complete_graph(5) nbunch = [0, 2, 3] C = approx.all_pairs_node_connectivity(G, nbunch=nbunch) - assert_equal(len(C), len(nbunch)) + assert len(C) == len(nbunch) diff --git a/networkx/algorithms/approximation/tests/test_independent_set.py b/networkx/algorithms/approximation/tests/test_independent_set.py index 199152dc..21edf2e3 100644 --- a/networkx/algorithms/approximation/tests/test_independent_set.py +++ b/networkx/algorithms/approximation/tests/test_independent_set.py @@ -6,4 +6,4 @@ import networkx.algorithms.approximation as a def test_independent_set(): # smoke test G = nx.Graph() - assert_equal(len(a.maximum_independent_set(G)), 0) + assert len(a.maximum_independent_set(G)) == 0 diff --git a/networkx/algorithms/approximation/tests/test_kcomponents.py b/networkx/algorithms/approximation/tests/test_kcomponents.py index d6eafd76..3413a98c 100644 --- a/networkx/algorithms/approximation/tests/test_kcomponents.py +++ b/networkx/algorithms/approximation/tests/test_kcomponents.py @@ -124,7 +124,7 @@ def _check_connectivity(G): for component in components: C = G.subgraph(component) K = nx.node_connectivity(C) - assert_greater_equal(K, k) + assert K >= k def test_torrents_and_ferraro_graph(): @@ -153,7 +153,7 @@ def test_karate_1(): G = nx.karate_club_graph() k_comps = k_components(G) k_num = build_k_number_dict(k_comps) - assert_in(k_num, (karate_k_num, approx_karate_k_num)) + assert k_num in (karate_k_num, approx_karate_k_num) def test_example_1_detail_3_and_4(): @@ -161,12 +161,12 @@ def test_example_1_detail_3_and_4(): result = k_components(G) # In this example graph there are 8 3-components, 4 with 15 nodes # and 4 with 5 nodes. - assert_equal(len(result[3]), 8) - assert_equal(len([c for c in result[3] if len(c) == 15]), 4) - assert_equal(len([c for c in result[3] if len(c) == 5]), 4) + assert len(result[3]) == 8 + assert len([c for c in result[3] if len(c) == 15]) == 4 + assert len([c for c in result[3] if len(c) == 5]) == 4 # There are also 8 4-components all with 5 nodes. - assert_equal(len(result[4]), 8) - assert_true(all(len(c) == 5 for c in result[4])) + assert len(result[4]) == 8 + assert all(len(c) == 5 for c in result[4]) # Finally check that the k-components detected have actually node # connectivity >= k. for k, components in result.items(): @@ -174,7 +174,7 @@ def test_example_1_detail_3_and_4(): continue for component in components: K = nx.node_connectivity(G.subgraph(component)) - assert_greater_equal(K, k) + assert K >= k @raises(nx.NetworkXNotImplemented) @@ -187,11 +187,11 @@ def test_same(): equal = {'A': 2, 'B': 2, 'C': 2} slightly_different = {'A': 2, 'B': 1, 'C': 2} different = {'A': 2, 'B': 8, 'C': 18} - assert_true(_same(equal)) - assert_false(_same(slightly_different)) - assert_true(_same(slightly_different, tol=1)) - assert_false(_same(different)) - assert_false(_same(different, tol=4)) + assert _same(equal) + assert not _same(slightly_different) + assert _same(slightly_different, tol=1) + assert not _same(different) + assert not _same(different, tol=4) class TestAntiGraph: @@ -211,40 +211,40 @@ class TestAntiGraph: for G, A in self.GA: n = G.order() s = len(list(G.edges())) + len(list(A.edges())) - assert_true(s == (n * (n - 1)) / 2) + assert s == (n * (n - 1)) / 2 def test_degree(self): for G, A in self.GA: - assert_equal(sorted(G.degree()), sorted(A.degree())) + assert sorted(G.degree()) == sorted(A.degree()) def test_core_number(self): for G, A in self.GA: - assert_equal(nx.core_number(G), nx.core_number(A)) + assert nx.core_number(G) == nx.core_number(A) def test_connected_components(self): for G, A in self.GA: gc = [set(c) for c in nx.connected_components(G)] ac = [set(c) for c in nx.connected_components(A)] for comp in ac: - assert_true(comp in gc) + assert comp in gc def test_adj(self): for G, A in self.GA: for n, nbrs in G.adj.items(): a_adj = sorted((n, sorted(ad)) for n, ad in A.adj.items()) g_adj = sorted((n, sorted(ad)) for n, ad in G.adj.items()) - assert_equal(a_adj, g_adj) + assert a_adj == g_adj def test_adjacency(self): for G, A in self.GA: a_adj = list(A.adjacency()) for n, nbrs in G.adjacency(): - assert_true((n, set(nbrs)) in a_adj) + assert (n, set(nbrs)) in a_adj def test_neighbors(self): for G, A in self.GA: node = list(G.nodes())[0] - assert_equal(set(G.neighbors(node)), set(A.neighbors(node))) + assert set(G.neighbors(node)) == set(A.neighbors(node)) def test_node_not_in_graph(self): for G, A in self.GA: @@ -256,10 +256,10 @@ class TestAntiGraph: for G, A in self.GA: node = list(G.nodes())[0] nodes = list(G.nodes())[1:4] - assert_equal(G.degree(node), A.degree(node)) - assert_equal(sum(d for n, d in G.degree()), sum(d for n, d in A.degree())) + assert G.degree(node) == A.degree(node) + assert sum(d for n, d in G.degree()) == sum(d for n, d in A.degree()) # AntiGraph is a ThinGraph, so all the weights are 1 - assert_equal(sum(d for n, d in A.degree()), + assert (sum(d for n, d in A.degree()) == sum(d for n, d in A.degree(weight='weight'))) - assert_equal(sum(d for n, d in G.degree(nodes)), + assert (sum(d for n, d in G.degree(nodes)) == sum(d for n, d in A.degree(nodes))) diff --git a/networkx/algorithms/approximation/tests/test_matching.py b/networkx/algorithms/approximation/tests/test_matching.py index 5286b313..d3b81c05 100644 --- a/networkx/algorithms/approximation/tests/test_matching.py +++ b/networkx/algorithms/approximation/tests/test_matching.py @@ -6,4 +6,4 @@ import networkx.algorithms.approximation as a def test_min_maximal_matching(): # smoke test G = nx.Graph() - assert_equal(len(a.min_maximal_matching(G)), 0) + assert len(a.min_maximal_matching(G)) == 0 diff --git a/networkx/algorithms/approximation/tests/test_treewidth.py b/networkx/algorithms/approximation/tests/test_treewidth.py index 9c41b038..a2c699ae 100644 --- a/networkx/algorithms/approximation/tests/test_treewidth.py +++ b/networkx/algorithms/approximation/tests/test_treewidth.py @@ -109,7 +109,7 @@ class TestTreewidthMinDegree(object): # (with [] denoting any order of the containing nodes) # resulting in treewidth 2 for the heuristic treewidth, _ = treewidth_min_fill_in(G) - assert_equals(treewidth, 2) + assert treewidth == 2 def test_heuristic_abort(self): """Test heuristic abort condition for fully connected graph""" @@ -138,7 +138,7 @@ class TestTreewidthMinDegree(object): G.add_node(1) G.add_node(2) treewidth, _ = treewidth_min_degree(G) - assert_equals(treewidth, 0) + assert treewidth == 0 def test_heuristic_first_steps(self): """Test first steps of min_degree heuristic""" @@ -167,7 +167,7 @@ class TestTreewidthMinDegree(object): elim_node = deg_heuristic.best_node(graph) # check only the first 5 elements for equality - assert_equals(steps[:5], [0, 1, 2, 3, 4]) + assert steps[:5] == [0, 1, 2, 3, 4] class TestTreewidthMinFillIn(object): @@ -214,7 +214,7 @@ class TestTreewidthMinFillIn(object): # (with [] denoting any order of the containing nodes) # resulting in treewidth 2 for the heuristic treewidth, _ = treewidth_min_fill_in(G) - assert_equals(treewidth, 2) + assert treewidth == 2 def test_heuristic_abort(self): """Test if min_fill_in returns None for fully connected graph""" @@ -241,7 +241,7 @@ class TestTreewidthMinFillIn(object): G.add_node(1) G.add_node(2) treewidth, _ = treewidth_min_fill_in(G) - assert_equals(treewidth, 0) + assert treewidth == 0 def test_heuristic_first_steps(self): """Test first steps of min_fill_in heuristic""" @@ -269,4 +269,4 @@ class TestTreewidthMinFillIn(object): elim_node = min_fill_in_heuristic(graph) # check only the first 2 elements for equality - assert_equals(steps[:2], [6, 5]) + assert steps[:2] == [6, 5] diff --git a/networkx/algorithms/approximation/tests/test_vertex_cover.py b/networkx/algorithms/approximation/tests/test_vertex_cover.py index b010ea87..ada17394 100644 --- a/networkx/algorithms/approximation/tests/test_vertex_cover.py +++ b/networkx/algorithms/approximation/tests/test_vertex_cover.py @@ -22,7 +22,7 @@ class TestMWVC(object): G.add_edges_from((0, v) for v in range(1, 26)) G.add_edges_from((v, 0) for v in range(26, 51)) cover = min_weighted_vertex_cover(G) - assert_equals(2, len(cover)) + assert 2 == len(cover) ok_(is_cover(G, cover)) def test_unweighted_undirected(self): @@ -30,7 +30,7 @@ class TestMWVC(object): size = 50 sg = nx.star_graph(size) cover = min_weighted_vertex_cover(sg) - assert_equals(2, len(cover)) + assert 2 == len(cover) ok_(is_cover(sg, cover)) def test_weighted(self): @@ -53,5 +53,5 @@ class TestMWVC(object): cover = min_weighted_vertex_cover(wg, weight="weight") csum = sum(wg.nodes[node]["weight"] for node in cover) - assert_equals(4, csum) + assert 4 == csum ok_(is_cover(wg, cover)) diff --git a/networkx/algorithms/assortativity/tests/test_connectivity.py b/networkx/algorithms/assortativity/tests/test_connectivity.py index 701d30f3..feeb1dbe 100644 --- a/networkx/algorithms/assortativity/tests/test_connectivity.py +++ b/networkx/algorithms/assortativity/tests/test_connectivity.py @@ -13,80 +13,80 @@ class TestNeighborConnectivity(object): G = nx.path_graph(4) answer = {1: 2.0, 2: 1.5} nd = nx.average_degree_connectivity(G) - assert_equal(nd, answer) + assert nd == answer D = G.to_directed() answer = {2: 2.0, 4: 1.5} nd = nx.average_degree_connectivity(D) - assert_equal(nd, answer) + assert nd == answer answer = {1: 2.0, 2: 1.5} D = G.to_directed() nd = nx.average_degree_connectivity(D, source='in', target='in') - assert_equal(nd, answer) + assert nd == answer D = G.to_directed() nd = nx.average_degree_connectivity(D, source='in', target='in') - assert_equal(nd, answer) + assert nd == answer def test_degree_p4_weighted(self): G = nx.path_graph(4) G[1][2]['weight'] = 4 answer = {1: 2.0, 2: 1.8} nd = nx.average_degree_connectivity(G, weight='weight') - assert_equal(nd, answer) + assert nd == answer answer = {1: 2.0, 2: 1.5} nd = nx.average_degree_connectivity(G) - assert_equal(nd, answer) + assert nd == answer D = G.to_directed() answer = {2: 2.0, 4: 1.8} nd = nx.average_degree_connectivity(D, weight='weight') - assert_equal(nd, answer) + assert nd == answer answer = {1: 2.0, 2: 1.8} D = G.to_directed() nd = nx.average_degree_connectivity(D, weight='weight', source='in', target='in') - assert_equal(nd, answer) + assert nd == answer D = G.to_directed() nd = nx.average_degree_connectivity(D, source='in', target='out', weight='weight') - assert_equal(nd, answer) + assert nd == answer def test_weight_keyword(self): G = nx.path_graph(4) G[1][2]['other'] = 4 answer = {1: 2.0, 2: 1.8} nd = nx.average_degree_connectivity(G, weight='other') - assert_equal(nd, answer) + assert nd == answer answer = {1: 2.0, 2: 1.5} nd = nx.average_degree_connectivity(G, weight=None) - assert_equal(nd, answer) + assert nd == answer D = G.to_directed() answer = {2: 2.0, 4: 1.8} nd = nx.average_degree_connectivity(D, weight='other') - assert_equal(nd, answer) + assert nd == answer answer = {1: 2.0, 2: 1.8} D = G.to_directed() nd = nx.average_degree_connectivity(D, weight='other', source='in', target='in') - assert_equal(nd, answer) + assert nd == answer D = G.to_directed() nd = nx.average_degree_connectivity(D, weight='other', source='in', target='in') - assert_equal(nd, answer) + assert nd == answer def test_degree_barrat(self): G = nx.star_graph(5) G.add_edges_from([(5, 6), (5, 7), (5, 8), (5, 9)]) G[0][5]['weight'] = 5 nd = nx.average_degree_connectivity(G)[5] - assert_equal(nd, 1.8) + assert nd == 1.8 nd = nx.average_degree_connectivity(G, weight='weight')[5] assert_almost_equal(nd, 3.222222, places=5) nd = nx.k_nearest_neighbors(G, weight='weight')[5] @@ -98,19 +98,19 @@ class TestNeighborConnectivity(object): G.add_edge(1, 3) G.add_edge(1, 4) c = nx.average_degree_connectivity(G) - assert_equal(c, {1: 0, 3: 1}) + assert c == {1: 0, 3: 1} c = nx.average_degree_connectivity(G, source='in', target='in') - assert_equal(c, {0: 0, 1: 0}) + assert c == {0: 0, 1: 0} c = nx.average_degree_connectivity(G, source='in', target='out') - assert_equal(c, {0: 0, 1: 3}) + assert c == {0: 0, 1: 3} c = nx.average_degree_connectivity(G, source='in', target='in+out') - assert_equal(c, {0: 0, 1: 3}) + assert c == {0: 0, 1: 3} c = nx.average_degree_connectivity(G, source='out', target='out') - assert_equal(c, {0: 0, 3: 0}) + assert c == {0: 0, 3: 0} c = nx.average_degree_connectivity(G, source='out', target='in') - assert_equal(c, {0: 0, 3: 1}) + assert c == {0: 0, 3: 1} c = nx.average_degree_connectivity(G, source='out', target='in+out') - assert_equal(c, {0: 0, 3: 1}) + assert c == {0: 0, 3: 1} def test_in_out_weight(self): G = nx.DiGraph() @@ -121,7 +121,7 @@ class TestNeighborConnectivity(object): c = nx.average_degree_connectivity(G, source=s, target=t) cw = nx.average_degree_connectivity(G, source=s, target=t, weight='weight') - assert_equal(c, cw) + assert c == cw @raises(ValueError) def test_invalid_source(self): @@ -139,4 +139,4 @@ class TestNeighborConnectivity(object): # just return the connectivity value itself? G = nx.trivial_graph() conn = nx.average_degree_connectivity(G, nodes=0) - assert_equal(conn, {0: 0}) + assert conn == {0: 0} diff --git a/networkx/algorithms/assortativity/tests/test_correlation.py b/networkx/algorithms/assortativity/tests/test_correlation.py index 2267bfeb..81b61482 100644 --- a/networkx/algorithms/assortativity/tests/test_correlation.py +++ b/networkx/algorithms/assortativity/tests/test_correlation.py @@ -65,15 +65,15 @@ class TestAttributeMixingCorrelation(BaseTestAttributeMixing): def test_attribute_assortativity_undirected(self): r = nx.attribute_assortativity_coefficient(self.G, 'fish') - assert_equal(r, 6.0 / 22.0) + assert r == 6.0 / 22.0 def test_attribute_assortativity_directed(self): r = nx.attribute_assortativity_coefficient(self.D, 'fish') - assert_equal(r, 1.0 / 3.0) + assert r == 1.0 / 3.0 def test_attribute_assortativity_multigraph(self): r = nx.attribute_assortativity_coefficient(self.M, 'fish') - assert_equal(r, 1.0) + assert r == 1.0 def test_attribute_assortativity_coefficient(self): # from "Mixing patterns in networks" diff --git a/networkx/algorithms/assortativity/tests/test_mixing.py b/networkx/algorithms/assortativity/tests/test_mixing.py index 9e135e3d..b6bba292 100644 --- a/networkx/algorithms/assortativity/tests/test_mixing.py +++ b/networkx/algorithms/assortativity/tests/test_mixing.py @@ -11,14 +11,14 @@ class TestDegreeMixingDict(BaseTestDegreeMixing): d_result = {1: {2: 2}, 2: {1: 2, 2: 2}, } - assert_equal(d, d_result) + assert d == d_result def test_degree_mixing_dict_undirected_normalized(self): d = nx.degree_mixing_dict(self.P4, normalized=True) d_result = {1: {2: 1.0 / 3}, 2: {1: 1.0 / 3, 2: 1.0 / 3}, } - assert_equal(d, d_result) + assert d == d_result def test_degree_mixing_dict_directed(self): d = nx.degree_mixing_dict(self.D) @@ -27,7 +27,7 @@ class TestDegreeMixingDict(BaseTestDegreeMixing): 2: {1: 1, 3: 1}, 3: {} } - assert_equal(d, d_result) + assert d == d_result def test_degree_mixing_dict_multigraph(self): d = nx.degree_mixing_dict(self.M) @@ -35,7 +35,7 @@ class TestDegreeMixingDict(BaseTestDegreeMixing): 2: {1: 1, 3: 3}, 3: {2: 3} } - assert_equal(d, d_result) + assert d == d_result class TestDegreeMixingMatrix(BaseTestDegreeMixing): @@ -105,7 +105,7 @@ class TestAttributeMixingDict(BaseTestAttributeMixing): 'red': {'one': 1}, 'blue': {'two': 1} } - assert_equal(d, d_result) + assert d == d_result def test_attribute_mixing_dict_directed(self): d = nx.attribute_mixing_dict(self.D, 'fish') @@ -114,14 +114,14 @@ class TestAttributeMixingDict(BaseTestAttributeMixing): 'red': {}, 'blue': {} } - assert_equal(d, d_result) + assert d == d_result def test_attribute_mixing_dict_multigraph(self): d = nx.attribute_mixing_dict(self.M, 'fish') d_result = {'one': {'one': 4}, 'two': {'two': 2}, } - assert_equal(d, d_result) + assert d == d_result class TestAttributeMixingMatrix(BaseTestAttributeMixing): diff --git a/networkx/algorithms/assortativity/tests/test_neighbor_degree.py b/networkx/algorithms/assortativity/tests/test_neighbor_degree.py index c294de48..b3b3cefd 100644 --- a/networkx/algorithms/assortativity/tests/test_neighbor_degree.py +++ b/networkx/algorithms/assortativity/tests/test_neighbor_degree.py @@ -9,72 +9,72 @@ class TestAverageNeighbor(object): G = nx.path_graph(4) answer = {0: 2, 1: 1.5, 2: 1.5, 3: 2} nd = nx.average_neighbor_degree(G) - assert_equal(nd, answer) + assert nd == answer D = G.to_directed() nd = nx.average_neighbor_degree(D) - assert_equal(nd, answer) + assert nd == answer D = G.to_directed() nd = nx.average_neighbor_degree(D) - assert_equal(nd, answer) + assert nd == answer D = G.to_directed() nd = nx.average_neighbor_degree(D, source='in', target='in') - assert_equal(nd, answer) + assert nd == answer def test_degree_p4_weighted(self): G = nx.path_graph(4) G[1][2]['weight'] = 4 answer = {0: 2, 1: 1.8, 2: 1.8, 3: 2} nd = nx.average_neighbor_degree(G, weight='weight') - assert_equal(nd, answer) + assert nd == answer D = G.to_directed() nd = nx.average_neighbor_degree(D, weight='weight') - assert_equal(nd, answer) + assert nd == answer D = G.to_directed() nd = nx.average_neighbor_degree(D, weight='weight') - assert_equal(nd, answer) + assert nd == answer nd = nx.average_neighbor_degree(D, source='out', target='out', weight='weight') - assert_equal(nd, answer) + assert nd == answer D = G.to_directed() nd = nx.average_neighbor_degree(D, source='in', target='in', weight='weight') - assert_equal(nd, answer) + assert nd == answer def test_degree_k4(self): G = nx.complete_graph(4) answer = {0: 3, 1: 3, 2: 3, 3: 3} nd = nx.average_neighbor_degree(G) - assert_equal(nd, answer) + assert nd == answer D = G.to_directed() nd = nx.average_neighbor_degree(D) - assert_equal(nd, answer) + assert nd == answer D = G.to_directed() nd = nx.average_neighbor_degree(D) - assert_equal(nd, answer) + assert nd == answer D = G.to_directed() nd = nx.average_neighbor_degree(D, source='in', target='in') - assert_equal(nd, answer) + assert nd == answer def test_degree_k4_nodes(self): G = nx.complete_graph(4) answer = {1: 3.0, 2: 3.0} nd = nx.average_neighbor_degree(G, nodes=[1, 2]) - assert_equal(nd, answer) + assert nd == answer def test_degree_barrat(self): G = nx.star_graph(5) G.add_edges_from([(5, 6), (5, 7), (5, 8), (5, 9)]) G[0][5]['weight'] = 5 nd = nx.average_neighbor_degree(G)[5] - assert_equal(nd, 1.8) + assert nd == 1.8 nd = nx.average_neighbor_degree(G, weight='weight')[5] assert_almost_equal(nd, 3.222222, places=5) diff --git a/networkx/algorithms/assortativity/tests/test_pairs.py b/networkx/algorithms/assortativity/tests/test_pairs.py index 0d5661f2..7fe4fa00 100644 --- a/networkx/algorithms/assortativity/tests/test_pairs.py +++ b/networkx/algorithms/assortativity/tests/test_pairs.py @@ -17,14 +17,14 @@ class TestAttributeMixingXY(BaseTestAttributeMixing): ('blue', 'two'), ('two', 'blue') ]) - assert_equal(attrxy, attrxy_result) + assert attrxy == attrxy_result def test_node_attribute_xy_undirected_nodes(self): attrxy = sorted(nx.node_attribute_xy(self.G, 'fish', nodes=['one', 'yellow'])) attrxy_result = sorted([ ]) - assert_equal(attrxy, attrxy_result) + assert attrxy == attrxy_result def test_node_attribute_xy_directed(self): attrxy = sorted(nx.node_attribute_xy(self.D, 'fish')) @@ -33,7 +33,7 @@ class TestAttributeMixingXY(BaseTestAttributeMixing): ('one', 'red'), ('two', 'blue') ]) - assert_equal(attrxy, attrxy_result) + assert attrxy == attrxy_result def test_node_attribute_xy_multigraph(self): attrxy = sorted(nx.node_attribute_xy(self.M, 'fish')) @@ -44,14 +44,14 @@ class TestAttributeMixingXY(BaseTestAttributeMixing): ('two', 'two'), ('two', 'two') ] - assert_equal(attrxy, attrxy_result) + assert attrxy == attrxy_result def test_node_attribute_xy_selfloop(self): attrxy = sorted(nx.node_attribute_xy(self.S, 'fish')) attrxy_result = [('one', 'one'), ('two', 'two') ] - assert_equal(attrxy, attrxy_result) + assert attrxy == attrxy_result class TestDegreeMixingXY(BaseTestDegreeMixing): @@ -64,13 +64,13 @@ class TestDegreeMixingXY(BaseTestDegreeMixing): (2, 2), (1, 2), (2, 1)]) - assert_equal(xy, xy_result) + assert xy == xy_result def test_node_degree_xy_undirected_nodes(self): xy = sorted(nx.node_degree_xy(self.P4, nodes=[0, 1, -1])) xy_result = sorted([(1, 2), (2, 1), ]) - assert_equal(xy, xy_result) + assert xy == xy_result def test_node_degree_xy_directed(self): xy = sorted(nx.node_degree_xy(self.D)) @@ -78,7 +78,7 @@ class TestDegreeMixingXY(BaseTestDegreeMixing): (2, 3), (1, 3), (1, 3)]) - assert_equal(xy, xy_result) + assert xy == xy_result def test_node_degree_xy_multigraph(self): xy = sorted(nx.node_degree_xy(self.M)) @@ -90,13 +90,13 @@ class TestDegreeMixingXY(BaseTestDegreeMixing): (3, 2), (1, 2), (2, 1)]) - assert_equal(xy, xy_result) + assert xy == xy_result def test_node_degree_xy_selfloop(self): xy = sorted(nx.node_degree_xy(self.S)) xy_result = sorted([(2, 2), (2, 2)]) - assert_equal(xy, xy_result) + assert xy == xy_result def test_node_degree_xy_weighted(self): G = nx.Graph() @@ -107,4 +107,4 @@ class TestDegreeMixingXY(BaseTestDegreeMixing): (17, 10), (17, 7), (10, 17)]) - assert_equal(xy, xy_result) + assert xy == xy_result diff --git a/networkx/algorithms/bipartite/tests/test_basic.py b/networkx/algorithms/bipartite/tests/test_basic.py index cbd0738e..f46c77d6 100644 --- a/networkx/algorithms/bipartite/tests/test_basic.py +++ b/networkx/algorithms/bipartite/tests/test_basic.py @@ -9,14 +9,14 @@ from networkx.algorithms import bipartite class TestBipartiteBasic: def test_is_bipartite(self): - assert_true(bipartite.is_bipartite(nx.path_graph(4))) - assert_true(bipartite.is_bipartite(nx.DiGraph([(1, 0)]))) - assert_false(bipartite.is_bipartite(nx.complete_graph(3))) + assert bipartite.is_bipartite(nx.path_graph(4)) + assert bipartite.is_bipartite(nx.DiGraph([(1, 0)])) + assert not bipartite.is_bipartite(nx.complete_graph(3)) def test_bipartite_color(self): G = nx.path_graph(4) c = bipartite.color(G) - assert_equal(c, {0: 1, 1: 0, 2: 1, 3: 0}) + assert c == {0: 1, 1: 0, 2: 1, 3: 0} @raises(nx.NetworkXError) def test_not_bipartite_color(self): @@ -24,27 +24,27 @@ class TestBipartiteBasic: def test_bipartite_directed(self): G = bipartite.random_graph(10, 10, 0.1, directed=True) - assert_true(bipartite.is_bipartite(G)) + assert bipartite.is_bipartite(G) def test_bipartite_sets(self): G = nx.path_graph(4) X, Y = bipartite.sets(G) - assert_equal(X, {0, 2}) - assert_equal(Y, {1, 3}) + assert X == {0, 2} + assert Y == {1, 3} def test_bipartite_sets_directed(self): G = nx.path_graph(4) D = G.to_directed() X, Y = bipartite.sets(D) - assert_equal(X, {0, 2}) - assert_equal(Y, {1, 3}) + assert X == {0, 2} + assert Y == {1, 3} def test_bipartite_sets_given_top_nodes(self): G = nx.path_graph(4) top_nodes = [0, 2] X, Y = bipartite.sets(G, top_nodes) - assert_equal(X, {0, 2}) - assert_equal(Y, {1, 3}) + assert X == {0, 2} + assert Y == {1, 3} @raises(nx.AmbiguousSolution) def test_bipartite_sets_disconnected(self): @@ -54,31 +54,31 @@ class TestBipartiteBasic: def test_is_bipartite_node_set(self): G = nx.path_graph(4) - assert_true(bipartite.is_bipartite_node_set(G, [0, 2])) - assert_true(bipartite.is_bipartite_node_set(G, [1, 3])) - assert_false(bipartite.is_bipartite_node_set(G, [1, 2])) + assert bipartite.is_bipartite_node_set(G, [0, 2]) + assert bipartite.is_bipartite_node_set(G, [1, 3]) + assert not bipartite.is_bipartite_node_set(G, [1, 2]) G.add_edge(10, 20) - assert_true(bipartite.is_bipartite_node_set(G, [0, 2, 10])) - assert_true(bipartite.is_bipartite_node_set(G, [0, 2, 20])) - assert_true(bipartite.is_bipartite_node_set(G, [1, 3, 10])) - assert_true(bipartite.is_bipartite_node_set(G, [1, 3, 20])) + assert bipartite.is_bipartite_node_set(G, [0, 2, 10]) + assert bipartite.is_bipartite_node_set(G, [0, 2, 20]) + assert bipartite.is_bipartite_node_set(G, [1, 3, 10]) + assert bipartite.is_bipartite_node_set(G, [1, 3, 20]) def test_bipartite_density(self): G = nx.path_graph(5) X, Y = bipartite.sets(G) density = float(len(list(G.edges()))) / (len(X) * len(Y)) - assert_equal(bipartite.density(G, X), density) + assert bipartite.density(G, X) == density D = nx.DiGraph(G.edges()) - assert_equal(bipartite.density(D, X), density / 2.0) - assert_equal(bipartite.density(nx.Graph(), {}), 0.0) + assert bipartite.density(D, X) == density / 2.0 + assert bipartite.density(nx.Graph(), {}) == 0.0 def test_bipartite_degrees(self): G = nx.path_graph(5) X = set([1, 3]) Y = set([0, 2, 4]) u, d = bipartite.degrees(G, Y) - assert_equal(dict(u), {1: 2, 3: 2}) - assert_equal(dict(d), {0: 1, 2: 2, 4: 1}) + assert dict(u) == {1: 2, 3: 2} + assert dict(d) == {0: 1, 2: 2, 4: 1} def test_bipartite_weighted_degrees(self): G = nx.path_graph(5) @@ -86,11 +86,11 @@ class TestBipartiteBasic: X = set([1, 3]) Y = set([0, 2, 4]) u, d = bipartite.degrees(G, Y, weight='weight') - assert_equal(dict(u), {1: 1.1, 3: 2}) - assert_equal(dict(d), {0: 0.1, 2: 2, 4: 1}) + assert dict(u) == {1: 1.1, 3: 2} + assert dict(d) == {0: 0.1, 2: 2, 4: 1} u, d = bipartite.degrees(G, Y, weight='other') - assert_equal(dict(u), {1: 1.2, 3: 2}) - assert_equal(dict(d), {0: 0.2, 2: 2, 4: 1}) + assert dict(u) == {1: 1.2, 3: 2} + assert dict(d) == {0: 0.2, 2: 2, 4: 1} @attr('numpy') def test_biadjacency_matrix_weight(self): @@ -103,9 +103,9 @@ class TestBipartiteBasic: X = [1, 3] Y = [0, 2, 4] M = bipartite.biadjacency_matrix(G, X, weight='weight') - assert_equal(M[0, 0], 2) + assert M[0, 0] == 2 M = bipartite.biadjacency_matrix(G, X, weight='other') - assert_equal(M[0, 0], 4) + assert M[0, 0] == 4 @attr('numpy') def test_biadjacency_matrix(self): @@ -119,8 +119,8 @@ class TestBipartiteBasic: G = bipartite.random_graph(tops[i], bots[i], 0.2) top = [n for n, d in G.nodes(data=True) if d['bipartite'] == 0] M = bipartite.biadjacency_matrix(G, top) - assert_equal(M.shape[0], tops[i]) - assert_equal(M.shape[1], bots[i]) + assert M.shape[0] == tops[i] + assert M.shape[1] == bots[i] @attr('numpy') def test_biadjacency_matrix_order(self): @@ -133,4 +133,4 @@ class TestBipartiteBasic: X = [3, 1] Y = [4, 2, 0] M = bipartite.biadjacency_matrix(G, X, Y, weight='weight') - assert_equal(M[1, 2], 2) + assert M[1, 2] == 2 diff --git a/networkx/algorithms/bipartite/tests/test_centrality.py b/networkx/algorithms/bipartite/tests/test_centrality.py index 740df0f8..577e6e60 100644 --- a/networkx/algorithms/bipartite/tests/test_centrality.py +++ b/networkx/algorithms/bipartite/tests/test_centrality.py @@ -17,42 +17,42 @@ class TestBipartiteCentrality(object): def test_degree_centrality(self): d = bipartite.degree_centrality(self.P4, [1, 3]) answer = {0: 0.5, 1: 1.0, 2: 1.0, 3: 0.5} - assert_equal(d, answer) + assert d == answer d = bipartite.degree_centrality(self.K3, [0, 1, 2]) answer = {0: 1.0, 1: 1.0, 2: 1.0, 3: 1.0, 4: 1.0, 5: 1.0} - assert_equal(d, answer) + assert d == answer d = bipartite.degree_centrality(self.C4, [0, 2]) answer = {0: 1.0, 1: 1.0, 2: 1.0, 3: 1.0} - assert_equal(d, answer) + assert d == answer def test_betweenness_centrality(self): c = bipartite.betweenness_centrality(self.P4, [1, 3]) answer = {0: 0.0, 1: 1.0, 2: 1.0, 3: 0.0} - assert_equal(c, answer) + assert c == answer c = bipartite.betweenness_centrality(self.K3, [0, 1, 2]) answer = {0: 0.125, 1: 0.125, 2: 0.125, 3: 0.125, 4: 0.125, 5: 0.125} - assert_equal(c, answer) + assert c == answer c = bipartite.betweenness_centrality(self.C4, [0, 2]) answer = {0: 0.25, 1: 0.25, 2: 0.25, 3: 0.25} - assert_equal(c, answer) + assert c == answer def test_closeness_centrality(self): c = bipartite.closeness_centrality(self.P4, [1, 3]) answer = {0: 2.0 / 3, 1: 1.0, 2: 1.0, 3: 2.0 / 3} - assert_equal(c, answer) + assert c == answer c = bipartite.closeness_centrality(self.K3, [0, 1, 2]) answer = {0: 1.0, 1: 1.0, 2: 1.0, 3: 1.0, 4: 1.0, 5: 1.0} - assert_equal(c, answer) + assert c == answer c = bipartite.closeness_centrality(self.C4, [0, 2]) answer = {0: 1.0, 1: 1.0, 2: 1.0, 3: 1.0} - assert_equal(c, answer) + assert c == answer G = nx.Graph() G.add_node(0) G.add_node(1) c = bipartite.closeness_centrality(G, [0]) - assert_equal(c, {1: 0.0}) + assert c == {1: 0.0} c = bipartite.closeness_centrality(G, [1]) - assert_equal(c, {1: 0.0}) + assert c == {1: 0.0} def test_davis_degree_centrality(self): G = self.davis diff --git a/networkx/algorithms/bipartite/tests/test_cluster.py b/networkx/algorithms/bipartite/tests/test_cluster.py index ce0c1e88..0965476a 100644 --- a/networkx/algorithms/bipartite/tests/test_cluster.py +++ b/networkx/algorithms/bipartite/tests/test_cluster.py @@ -25,9 +25,9 @@ def test_star_graph(): G = nx.star_graph(3) # all modes are the same answer = {0: 0, 1: 1, 2: 1, 3: 1} - assert_equal(bipartite.clustering(G, mode='dot'), answer) - assert_equal(bipartite.clustering(G, mode='min'), answer) - assert_equal(bipartite.clustering(G, mode='max'), answer) + assert bipartite.clustering(G, mode='dot') == answer + assert bipartite.clustering(G, mode='min') == answer + assert bipartite.clustering(G, mode='max') == answer @raises(nx.NetworkXError) @@ -43,37 +43,37 @@ def test_bad_mode(): def test_path_graph(): G = nx.path_graph(4) answer = {0: 0.5, 1: 0.5, 2: 0.5, 3: 0.5} - assert_equal(bipartite.clustering(G, mode='dot'), answer) - assert_equal(bipartite.clustering(G, mode='max'), answer) + assert bipartite.clustering(G, mode='dot') == answer + assert bipartite.clustering(G, mode='max') == answer answer = {0: 1, 1: 1, 2: 1, 3: 1} - assert_equal(bipartite.clustering(G, mode='min'), answer) + assert bipartite.clustering(G, mode='min') == answer def test_average_path_graph(): G = nx.path_graph(4) - assert_equal(bipartite.average_clustering(G, mode='dot'), 0.5) - assert_equal(bipartite.average_clustering(G, mode='max'), 0.5) - assert_equal(bipartite.average_clustering(G, mode='min'), 1) + assert bipartite.average_clustering(G, mode='dot') == 0.5 + assert bipartite.average_clustering(G, mode='max') == 0.5 + assert bipartite.average_clustering(G, mode='min') == 1 def test_ra_clustering_davis(): G = nx.davis_southern_women_graph() cc4 = round(bipartite.robins_alexander_clustering(G), 3) - assert_equal(cc4, 0.468) + assert cc4 == 0.468 def test_ra_clustering_square(): G = nx.path_graph(4) G.add_edge(0, 3) - assert_equal(bipartite.robins_alexander_clustering(G), 1.0) + assert bipartite.robins_alexander_clustering(G) == 1.0 def test_ra_clustering_zero(): G = nx.Graph() - assert_equal(bipartite.robins_alexander_clustering(G), 0) + assert bipartite.robins_alexander_clustering(G) == 0 G.add_nodes_from(range(4)) - assert_equal(bipartite.robins_alexander_clustering(G), 0) + assert bipartite.robins_alexander_clustering(G) == 0 G.add_edges_from([(0, 1), (2, 3), (3, 4)]) - assert_equal(bipartite.robins_alexander_clustering(G), 0) + assert bipartite.robins_alexander_clustering(G) == 0 G.add_edge(1, 2) - assert_equal(bipartite.robins_alexander_clustering(G), 0) + assert bipartite.robins_alexander_clustering(G) == 0 diff --git a/networkx/algorithms/bipartite/tests/test_covering.py b/networkx/algorithms/bipartite/tests/test_covering.py index 14611e7d..845ae1ac 100644 --- a/networkx/algorithms/bipartite/tests/test_covering.py +++ b/networkx/algorithms/bipartite/tests/test_covering.py @@ -14,12 +14,12 @@ class TestMinEdgeCover: def test_empty_graph(self): G = nx.Graph() - assert_equal(bipartite.min_edge_cover(G), set()) + assert bipartite.min_edge_cover(G) == set() def test_graph_single_edge(self): G = nx.Graph() G.add_edge(0, 1) - assert_equal(bipartite.min_edge_cover(G), + assert (bipartite.min_edge_cover(G) == {(0, 1), (1, 0)}) def test_bipartite_default(self): @@ -29,8 +29,8 @@ class TestMinEdgeCover: G.add_edges_from([(1, 'a'), (1, 'b'), (2, 'b'), (2, 'c'), (3, 'c'), (4, 'a')]) min_cover = bipartite.min_edge_cover(G) - assert_true(nx.is_edge_cover(G, min_cover)) - assert_equal(len(min_cover), 8) + assert nx.is_edge_cover(G, min_cover) + assert len(min_cover) == 8 def test_bipartite_explicit(self): G = nx.Graph() @@ -40,5 +40,5 @@ class TestMinEdgeCover: (2, 'c'), (3, 'c'), (4, 'a')]) min_cover = bipartite.min_edge_cover(G, bipartite.eppstein_matching) - assert_true(nx.is_edge_cover(G, min_cover)) - assert_equal(len(min_cover), 8) + assert nx.is_edge_cover(G, min_cover) + assert len(min_cover) == 8 diff --git a/networkx/algorithms/bipartite/tests/test_edgelist.py b/networkx/algorithms/bipartite/tests/test_edgelist.py index 20bbfe4a..99b97a88 100644 --- a/networkx/algorithms/bipartite/tests/test_edgelist.py +++ b/networkx/algorithms/bipartite/tests/test_edgelist.py @@ -64,7 +64,7 @@ class TestEdgelist: G.add_node(3, bipartite=0) bipartite.write_edgelist(G, fh, data=False) fh.seek(0) - assert_equal(fh.read(), b"1 2\n3 2\n") + assert fh.read() == b"1 2\n3 2\n" def test_write_edgelist_2(self): fh = io.BytesIO() @@ -75,7 +75,7 @@ class TestEdgelist: G.add_node(3, bipartite=0) bipartite.write_edgelist(G, fh, data=True) fh.seek(0) - assert_equal(fh.read(), b"1 2 {}\n3 2 {}\n") + assert fh.read() == b"1 2 {}\n3 2 {}\n" def test_write_edgelist_3(self): fh = io.BytesIO() @@ -87,7 +87,7 @@ class TestEdgelist: G.add_node(3, bipartite=0) bipartite.write_edgelist(G, fh, data=True) fh.seek(0) - assert_equal(fh.read(), b"1 2 {'weight': 2.0}\n3 2 {'weight': 3.0}\n") + assert fh.read() == b"1 2 {'weight': 2.0}\n3 2 {'weight': 3.0}\n" def test_write_edgelist_4(self): fh = io.BytesIO() @@ -99,7 +99,7 @@ class TestEdgelist: G.add_node(3, bipartite=0) bipartite.write_edgelist(G, fh, data=[('weight')]) fh.seek(0) - assert_equal(fh.read(), b"1 2 2.0\n3 2 3.0\n") + assert fh.read() == b"1 2 2.0\n3 2 3.0\n" def test_unicode(self): G = nx.Graph() @@ -162,7 +162,7 @@ class TestEdgelist: bipartite.write_edgelist(G, fname) H = bipartite.read_edgelist(fname) H2 = bipartite.read_edgelist(fname) - assert_not_equal(H, H2) # they should be different graphs + assert H != H2 # they should be different graphs G.remove_node('g') # isolated nodes are not written in edgelist assert_nodes_equal(list(H), list(G)) assert_edges_equal(list(H.edges()), list(G.edges())) @@ -187,7 +187,7 @@ class TestEdgelist: bipartite.write_edgelist(G, fname) H = bipartite.read_edgelist(fname, nodetype=int, create_using=nx.MultiGraph()) H2 = bipartite.read_edgelist(fname, nodetype=int, create_using=nx.MultiGraph()) - assert_not_equal(H, H2) # they should be different graphs + assert H != H2 # they should be different graphs assert_nodes_equal(list(H), list(G)) assert_edges_equal(list(H.edges()), list(G.edges())) os.close(fd) diff --git a/networkx/algorithms/bipartite/tests/test_generators.py b/networkx/algorithms/bipartite/tests/test_generators.py index 8062322c..9ba08304 100644 --- a/networkx/algorithms/bipartite/tests/test_generators.py +++ b/networkx/algorithms/bipartite/tests/test_generators.py @@ -12,29 +12,29 @@ from networkx.algorithms.bipartite.generators import * class TestGeneratorsBipartite(): def test_complete_bipartite_graph(self): G = complete_bipartite_graph(0, 0) - assert_true(nx.is_isomorphic(G, nx.null_graph())) + assert nx.is_isomorphic(G, nx.null_graph()) for i in [1, 5]: G = complete_bipartite_graph(i, 0) - assert_true(nx.is_isomorphic(G, nx.empty_graph(i))) + assert nx.is_isomorphic(G, nx.empty_graph(i)) G = complete_bipartite_graph(0, i) - assert_true(nx.is_isomorphic(G, nx.empty_graph(i))) + assert nx.is_isomorphic(G, nx.empty_graph(i)) G = complete_bipartite_graph(2, 2) - assert_true(nx.is_isomorphic(G, nx.cycle_graph(4))) + assert nx.is_isomorphic(G, nx.cycle_graph(4)) G = complete_bipartite_graph(1, 5) - assert_true(nx.is_isomorphic(G, nx.star_graph(5))) + assert nx.is_isomorphic(G, nx.star_graph(5)) G = complete_bipartite_graph(5, 1) - assert_true(nx.is_isomorphic(G, nx.star_graph(5))) + assert nx.is_isomorphic(G, nx.star_graph(5)) # complete_bipartite_graph(m1,m2) is a connected graph with # m1+m2 nodes and m1*m2 edges for m1, m2 in [(5, 11), (7, 3)]: G = complete_bipartite_graph(m1, m2) - assert_equal(nx.number_of_nodes(G), m1 + m2) - assert_equal(nx.number_of_edges(G), m1 * m2) + assert nx.number_of_nodes(G) == m1 + m2 + assert nx.number_of_edges(G) == m1 * m2 assert_raises(nx.NetworkXError, complete_bipartite_graph, 7, 3, create_using=nx.DiGraph) @@ -44,36 +44,36 @@ class TestGeneratorsBipartite(): 7, 3, create_using=nx.MultiDiGraph) mG = complete_bipartite_graph(7, 3, create_using=nx.MultiGraph) - assert_true(mG.is_multigraph()) - assert_equal(sorted(mG.edges()), sorted(G.edges())) + assert mG.is_multigraph() + assert sorted(mG.edges()) == sorted(G.edges()) mG = complete_bipartite_graph(7, 3, create_using=nx.MultiGraph) - assert_true(mG.is_multigraph()) - assert_equal(sorted(mG.edges()), sorted(G.edges())) + assert mG.is_multigraph() + assert sorted(mG.edges()) == sorted(G.edges()) mG = complete_bipartite_graph(7, 3) # default to Graph - assert_equal(sorted(mG.edges()), sorted(G.edges())) - assert_false(mG.is_multigraph()) - assert_false(mG.is_directed()) + assert sorted(mG.edges()) == sorted(G.edges()) + assert not mG.is_multigraph() + assert not mG.is_directed() # specify nodes rather than number of nodes G = complete_bipartite_graph([1, 2], ['a', 'b']) has_edges = G.has_edge(1, 'a') & G.has_edge(1, 'b') &\ G.has_edge(2, 'a') & G.has_edge(2, 'b') - assert_true(has_edges) - assert_equal(G.size(), 4) + assert has_edges + assert G.size() == 4 def test_configuration_model(self): aseq = [] bseq = [] G = configuration_model(aseq, bseq) - assert_equal(len(G), 0) + assert len(G) == 0 aseq = [0, 0] bseq = [0, 0] G = configuration_model(aseq, bseq) - assert_equal(len(G), 4) - assert_equal(G.number_of_edges(), 0) + assert len(G) == 4 + assert G.number_of_edges() == 0 aseq = [3, 3, 3, 3] bseq = [2, 2, 2, 2, 2] @@ -83,32 +83,32 @@ class TestGeneratorsBipartite(): aseq = [3, 3, 3, 3] bseq = [2, 2, 2, 2, 2, 2] G = configuration_model(aseq, bseq) - assert_equal(sorted(d for n, d in G.degree()), + assert (sorted(d for n, d in G.degree()) == [2, 2, 2, 2, 2, 2, 3, 3, 3, 3]) aseq = [2, 2, 2, 2, 2, 2] bseq = [3, 3, 3, 3] G = configuration_model(aseq, bseq) - assert_equal(sorted(d for n, d in G.degree()), + assert (sorted(d for n, d in G.degree()) == [2, 2, 2, 2, 2, 2, 3, 3, 3, 3]) aseq = [2, 2, 2, 1, 1, 1] bseq = [3, 3, 3] G = configuration_model(aseq, bseq) - assert_true(G.is_multigraph()) - assert_false(G.is_directed()) - assert_equal(sorted(d for n, d in G.degree()), + assert G.is_multigraph() + assert not G.is_directed() + assert (sorted(d for n, d in G.degree()) == [1, 1, 1, 2, 2, 2, 3, 3, 3]) GU = nx.project(nx.Graph(G), range(len(aseq))) - assert_equal(GU.number_of_nodes(), 6) + assert GU.number_of_nodes() == 6 GD = nx.project(nx.Graph(G), range(len(aseq), len(aseq) + len(bseq))) - assert_equal(GD.number_of_nodes(), 3) + assert GD.number_of_nodes() == 3 G = reverse_havel_hakimi_graph(aseq, bseq, create_using=nx.Graph) - assert_false(G.is_multigraph()) - assert_false(G.is_directed()) + assert not G.is_multigraph() + assert not G.is_directed() assert_raises(nx.NetworkXError, configuration_model, aseq, bseq, @@ -124,13 +124,13 @@ class TestGeneratorsBipartite(): aseq = [] bseq = [] G = havel_hakimi_graph(aseq, bseq) - assert_equal(len(G), 0) + assert len(G) == 0 aseq = [0, 0] bseq = [0, 0] G = havel_hakimi_graph(aseq, bseq) - assert_equal(len(G), 4) - assert_equal(G.number_of_edges(), 0) + assert len(G) == 4 + assert G.number_of_edges() == 0 aseq = [3, 3, 3, 3] bseq = [2, 2, 2, 2, 2] @@ -139,26 +139,26 @@ class TestGeneratorsBipartite(): bseq = [2, 2, 2, 2, 2, 2] G = havel_hakimi_graph(aseq, bseq) - assert_equal(sorted(d for n, d in G.degree()), + assert (sorted(d for n, d in G.degree()) == [2, 2, 2, 2, 2, 2, 3, 3, 3, 3]) aseq = [2, 2, 2, 2, 2, 2] bseq = [3, 3, 3, 3] G = havel_hakimi_graph(aseq, bseq) - assert_true(G.is_multigraph()) - assert_false(G.is_directed()) - assert_equal(sorted(d for n, d in G.degree()), + assert G.is_multigraph() + assert not G.is_directed() + assert (sorted(d for n, d in G.degree()) == [2, 2, 2, 2, 2, 2, 3, 3, 3, 3]) GU = nx.project(nx.Graph(G), range(len(aseq))) - assert_equal(GU.number_of_nodes(), 6) + assert GU.number_of_nodes() == 6 GD = nx.project(nx.Graph(G), range(len(aseq), len(aseq) + len(bseq))) - assert_equal(GD.number_of_nodes(), 4) + assert GD.number_of_nodes() == 4 G = reverse_havel_hakimi_graph(aseq, bseq, create_using=nx.Graph) - assert_false(G.is_multigraph()) - assert_false(G.is_directed()) + assert not G.is_multigraph() + assert not G.is_directed() assert_raises(nx.NetworkXError, havel_hakimi_graph, aseq, bseq, @@ -174,13 +174,13 @@ class TestGeneratorsBipartite(): aseq = [] bseq = [] G = reverse_havel_hakimi_graph(aseq, bseq) - assert_equal(len(G), 0) + assert len(G) == 0 aseq = [0, 0] bseq = [0, 0] G = reverse_havel_hakimi_graph(aseq, bseq) - assert_equal(len(G), 4) - assert_equal(G.number_of_edges(), 0) + assert len(G) == 4 + assert G.number_of_edges() == 0 aseq = [3, 3, 3, 3] bseq = [2, 2, 2, 2, 2] @@ -189,32 +189,32 @@ class TestGeneratorsBipartite(): bseq = [2, 2, 2, 2, 2, 2] G = reverse_havel_hakimi_graph(aseq, bseq) - assert_equal(sorted(d for n, d in G.degree()), + assert (sorted(d for n, d in G.degree()) == [2, 2, 2, 2, 2, 2, 3, 3, 3, 3]) aseq = [2, 2, 2, 2, 2, 2] bseq = [3, 3, 3, 3] G = reverse_havel_hakimi_graph(aseq, bseq) - assert_equal(sorted(d for n, d in G.degree()), + assert (sorted(d for n, d in G.degree()) == [2, 2, 2, 2, 2, 2, 3, 3, 3, 3]) aseq = [2, 2, 2, 1, 1, 1] bseq = [3, 3, 3] G = reverse_havel_hakimi_graph(aseq, bseq) - assert_true(G.is_multigraph()) - assert_false(G.is_directed()) - assert_equal(sorted(d for n, d in G.degree()), + assert G.is_multigraph() + assert not G.is_directed() + assert (sorted(d for n, d in G.degree()) == [1, 1, 1, 2, 2, 2, 3, 3, 3]) GU = nx.project(nx.Graph(G), range(len(aseq))) - assert_equal(GU.number_of_nodes(), 6) + assert GU.number_of_nodes() == 6 GD = nx.project(nx.Graph(G), range(len(aseq), len(aseq) + len(bseq))) - assert_equal(GD.number_of_nodes(), 3) + assert GD.number_of_nodes() == 3 G = reverse_havel_hakimi_graph(aseq, bseq, create_using=nx.Graph) - assert_false(G.is_multigraph()) - assert_false(G.is_directed()) + assert not G.is_multigraph() + assert not G.is_directed() assert_raises(nx.NetworkXError, reverse_havel_hakimi_graph, aseq, bseq, @@ -230,13 +230,13 @@ class TestGeneratorsBipartite(): aseq = [] bseq = [] G = alternating_havel_hakimi_graph(aseq, bseq) - assert_equal(len(G), 0) + assert len(G) == 0 aseq = [0, 0] bseq = [0, 0] G = alternating_havel_hakimi_graph(aseq, bseq) - assert_equal(len(G), 4) - assert_equal(G.number_of_edges(), 0) + assert len(G) == 4 + assert G.number_of_edges() == 0 aseq = [3, 3, 3, 3] bseq = [2, 2, 2, 2, 2] @@ -245,32 +245,32 @@ class TestGeneratorsBipartite(): bseq = [2, 2, 2, 2, 2, 2] G = alternating_havel_hakimi_graph(aseq, bseq) - assert_equal(sorted(d for n, d in G.degree()), + assert (sorted(d for n, d in G.degree()) == [2, 2, 2, 2, 2, 2, 3, 3, 3, 3]) aseq = [2, 2, 2, 2, 2, 2] bseq = [3, 3, 3, 3] G = alternating_havel_hakimi_graph(aseq, bseq) - assert_equal(sorted(d for n, d in G.degree()), + assert (sorted(d for n, d in G.degree()) == [2, 2, 2, 2, 2, 2, 3, 3, 3, 3]) aseq = [2, 2, 2, 1, 1, 1] bseq = [3, 3, 3] G = alternating_havel_hakimi_graph(aseq, bseq) - assert_true(G.is_multigraph()) - assert_false(G.is_directed()) - assert_equal(sorted(d for n, d in G.degree()), + assert G.is_multigraph() + assert not G.is_directed() + assert (sorted(d for n, d in G.degree()) == [1, 1, 1, 2, 2, 2, 3, 3, 3]) GU = nx.project(nx.Graph(G), range(len(aseq))) - assert_equal(GU.number_of_nodes(), 6) + assert GU.number_of_nodes() == 6 GD = nx.project(nx.Graph(G), range(len(aseq), len(aseq) + len(bseq))) - assert_equal(GD.number_of_nodes(), 3) + assert GD.number_of_nodes() == 3 G = reverse_havel_hakimi_graph(aseq, bseq, create_using=nx.Graph) - assert_false(G.is_multigraph()) - assert_false(G.is_directed()) + assert not G.is_multigraph() + assert not G.is_directed() assert_raises(nx.NetworkXError, alternating_havel_hakimi_graph, aseq, bseq, @@ -285,12 +285,12 @@ class TestGeneratorsBipartite(): def test_preferential_attachment(self): aseq = [3, 2, 1, 1] G = preferential_attachment_graph(aseq, 0.5) - assert_true(G.is_multigraph()) - assert_false(G.is_directed()) + assert G.is_multigraph() + assert not G.is_directed() G = preferential_attachment_graph(aseq, 0.5, create_using=nx.Graph) - assert_false(G.is_multigraph()) - assert_false(G.is_directed()) + assert not G.is_multigraph() + assert not G.is_directed() assert_raises(nx.NetworkXError, preferential_attachment_graph, aseq, 0.5, @@ -306,21 +306,21 @@ class TestGeneratorsBipartite(): n = 10 m = 20 G = random_graph(n, m, 0.9) - assert_equal(len(G), 30) - assert_true(nx.is_bipartite(G)) + assert len(G) == 30 + assert nx.is_bipartite(G) X, Y = nx.algorithms.bipartite.sets(G) - assert_equal(set(range(n)), X) - assert_equal(set(range(n, n + m)), Y) + assert set(range(n)) == X + assert set(range(n, n + m)) == Y def test_random_digraph(self): n = 10 m = 20 G = random_graph(n, m, 0.9, directed=True) - assert_equal(len(G), 30) - assert_true(nx.is_bipartite(G)) + assert len(G) == 30 + assert nx.is_bipartite(G) X, Y = nx.algorithms.bipartite.sets(G) - assert_equal(set(range(n)), X) - assert_equal(set(range(n, n + m)), Y) + assert set(range(n)) == X + assert set(range(n, n + m)) == Y def test_gnmk_random_graph(self): n = 10 @@ -329,23 +329,23 @@ class TestGeneratorsBipartite(): # set seed because sometimes it is not connected # which raises an error in bipartite.sets(G) below. G = gnmk_random_graph(n, m, edges, seed=1234) - assert_equal(len(G), n + m) - assert_true(nx.is_bipartite(G)) + assert len(G) == n + m + assert nx.is_bipartite(G) X, Y = nx.algorithms.bipartite.sets(G) #print(X) - assert_equal(set(range(n)), X) - assert_equal(set(range(n, n + m)), Y) - assert_equal(edges, len(list(G.edges()))) + assert set(range(n)) == X + assert set(range(n, n + m)) == Y + assert edges == len(list(G.edges())) def test_gnmk_random_graph_complete(self): n = 10 m = 20 edges = 200 G = gnmk_random_graph(n, m, edges) - assert_equal(len(G), n + m) - assert_true(nx.is_bipartite(G)) + assert len(G) == n + m + assert nx.is_bipartite(G) X, Y = nx.algorithms.bipartite.sets(G) #print(X) - assert_equal(set(range(n)), X) - assert_equal(set(range(n, n + m)), Y) - assert_equal(edges, len(list(G.edges()))) + assert set(range(n)) == X + assert set(range(n, n + m)) == Y + assert edges == len(list(G.edges())) diff --git a/networkx/algorithms/bipartite/tests/test_matching.py b/networkx/algorithms/bipartite/tests/test_matching.py index 2217f0b7..145e05da 100644 --- a/networkx/algorithms/bipartite/tests/test_matching.py +++ b/networkx/algorithms/bipartite/tests/test_matching.py @@ -125,11 +125,11 @@ class TestMatching(): def test_eppstein_matching_simple(self): match = eppstein_matching(self.simple_graph) - assert_equal(match, self.simple_solution) + assert match == self.simple_solution def test_hopcroft_karp_matching_simple(self): match = hopcroft_karp_matching(self.simple_graph) - assert_equal(match, self.simple_solution) + assert match == self.simple_solution @raises(nx.AmbiguousSolution) def test_eppstein_matching_disconnected(self): @@ -167,14 +167,14 @@ class TestMatching(): matching = hopcroft_karp_matching(btc, top_nodes) vertex_cover = to_vertex_cover(btc, matching, top_nodes) independent_set = set(G) - {v for _, v in vertex_cover} - assert_equal({'B', 'D', 'F', 'I', 'H'}, independent_set) + assert {'B', 'D', 'F', 'I', 'H'} == independent_set def test_vertex_cover_issue_2384(self): G = nx.Graph([(0, 3), (1, 3), (1, 4), (2, 3)]) matching = maximum_matching(G) vertex_cover = to_vertex_cover(G, matching) for u, v in G.edges(): - assert_true(u in vertex_cover or v in vertex_cover) + assert u in vertex_cover or v in vertex_cover def test_unorderable_nodes(self): a = object() @@ -186,7 +186,7 @@ class TestMatching(): matching = maximum_matching(G) vertex_cover = to_vertex_cover(G, matching) for u, v in G.edges(): - assert_true(u in vertex_cover or v in vertex_cover) + assert u in vertex_cover or v in vertex_cover def test_eppstein_matching(): @@ -197,7 +197,7 @@ def test_eppstein_matching(): G.add_edges_from([('a', 1), ('a', 'b'), (2, 'b'), (2, 'c'), (3, 'c'), (4, 1)]) matching = eppstein_matching(G) - assert_true(len(matching) == len(maximum_matching(G))) + assert len(matching) == len(maximum_matching(G)) assert all(x in set(matching.keys()) for x in set(matching.values())) @@ -223,7 +223,7 @@ class TestMinimumWeightFullMatching(object): G.add_edge(2, 4, weight=225) G.add_edge(2, 5, weight=300) matching = minimum_weight_full_matching(G) - assert_equal(matching, {0: 4, 1: 3, 2: 5, 4: 0, 3: 1, 5: 2}) + assert matching == {0: 4, 1: 3, 2: 5, 4: 0, 3: 1, 5: 2} def test_minimum_weight_full_matching_smaller_left(self): G = nx.complete_bipartite_graph(3, 4) @@ -240,7 +240,7 @@ class TestMinimumWeightFullMatching(object): G.add_edge(2, 5, weight=290) G.add_edge(2, 6, weight=3) matching = minimum_weight_full_matching(G) - assert_equal(matching, {0: 4, 1: 6, 2: 5, 4: 0, 5: 2, 6: 1}) + assert matching == {0: 4, 1: 6, 2: 5, 4: 0, 5: 2, 6: 1} def test_minimum_weight_full_matching_smaller_top_nodes_right(self): G = nx.complete_bipartite_graph(3, 4) @@ -257,7 +257,7 @@ class TestMinimumWeightFullMatching(object): G.add_edge(2, 5, weight=290) G.add_edge(2, 6, weight=3) matching = minimum_weight_full_matching(G, top_nodes=[3, 4, 5, 6]) - assert_equal(matching, {0: 4, 1: 6, 2: 5, 4: 0, 5: 2, 6: 1}) + assert matching == {0: 4, 1: 6, 2: 5, 4: 0, 5: 2, 6: 1} def test_minimum_weight_full_matching_smaller_right(self): G = nx.complete_bipartite_graph(4, 3) @@ -274,7 +274,7 @@ class TestMinimumWeightFullMatching(object): G.add_edge(3, 5, weight=2) G.add_edge(3, 6, weight=3) matching = minimum_weight_full_matching(G) - assert_equal(matching, {1: 4, 2: 6, 3: 5, 4: 1, 5: 3, 6: 2}) + assert matching == {1: 4, 2: 6, 3: 5, 4: 1, 5: 3, 6: 2} def test_minimum_weight_full_matching_negative_weights(self): G = nx.complete_bipartite_graph(2, 2) @@ -283,7 +283,7 @@ class TestMinimumWeightFullMatching(object): G.add_edge(1, 2, weight=-2) G.add_edge(1, 3, weight=0.3) matching = minimum_weight_full_matching(G) - assert_equal(matching, {0: 3, 1: 2, 2: 1, 3: 0}) + assert matching == {0: 3, 1: 2, 2: 1, 3: 0} def test_minimum_weight_full_matching_different_weight_key(self): G = nx.complete_bipartite_graph(2, 2) @@ -292,7 +292,7 @@ class TestMinimumWeightFullMatching(object): G.add_edge(1, 2, mass=1) G.add_edge(1, 3, mass=2) matching = minimum_weight_full_matching(G, weight='mass') - assert_equal(matching, {0: 3, 1: 2, 2: 1, 3: 0}) + assert matching == {0: 3, 1: 2, 2: 1, 3: 0} @raises(ValueError) def test_minimum_weight_full_matching_requires_complete_input(self): diff --git a/networkx/algorithms/bipartite/tests/test_matrix.py b/networkx/algorithms/bipartite/tests/test_matrix.py index e4626e06..b65f1ae6 100644 --- a/networkx/algorithms/bipartite/tests/test_matrix.py +++ b/networkx/algorithms/bipartite/tests/test_matrix.py @@ -24,9 +24,9 @@ class TestBiadjacencyMatrix: X = [1, 3] Y = [0, 2, 4] M = bipartite.biadjacency_matrix(G, X, weight='weight') - assert_equal(M[0, 0], 2) + assert M[0, 0] == 2 M = bipartite.biadjacency_matrix(G, X, weight='other') - assert_equal(M[0, 0], 4) + assert M[0, 0] == 4 def test_biadjacency_matrix(self): tops = [2, 5, 10] @@ -35,8 +35,8 @@ class TestBiadjacencyMatrix: G = bipartite.random_graph(tops[i], bots[i], 0.2) top = [n for n, d in G.nodes(data=True) if d['bipartite'] == 0] M = bipartite.biadjacency_matrix(G, top) - assert_equal(M.shape[0], tops[i]) - assert_equal(M.shape[1], bots[i]) + assert M.shape[0] == tops[i] + assert M.shape[1] == bots[i] def test_biadjacency_matrix_order(self): G = nx.path_graph(5) @@ -44,7 +44,7 @@ class TestBiadjacencyMatrix: X = [3, 1] Y = [4, 2, 0] M = bipartite.biadjacency_matrix(G, X, Y, weight='weight') - assert_equal(M[1, 2], 2) + assert M[1, 2] == 2 @raises(nx.NetworkXError) def test_null_graph(self): @@ -74,7 +74,7 @@ class TestBiadjacencyMatrix: B1 = nx.path_graph(5) M = bipartite.biadjacency_matrix(B1, [0, 2, 4]) B2 = bipartite.from_biadjacency_matrix(M) - assert_true(nx.is_isomorphic(B1, B2)) + assert nx.is_isomorphic(B1, B2) def test_from_biadjacency_weight(self): M = sparse.csc_matrix([[1, 2], [0, 3]]) diff --git a/networkx/algorithms/bipartite/tests/test_project.py b/networkx/algorithms/bipartite/tests/test_project.py index 4ad582b9..f636f67c 100644 --- a/networkx/algorithms/bipartite/tests/test_project.py +++ b/networkx/algorithms/bipartite/tests/test_project.py @@ -23,11 +23,11 @@ class TestBipartiteProject: P = bipartite.projected_graph(G, [1, 3]) assert_nodes_equal(list(P), [1, 3]) assert_edges_equal(list(P.edges()), [(1, 3)]) - assert_equal(P.nodes[1]['name'], G.nodes[1]['name']) + assert P.nodes[1]['name'] == G.nodes[1]['name'] P = bipartite.projected_graph(G, [0, 2]) assert_nodes_equal(list(P), [0, 2]) assert_edges_equal(list(P.edges()), [(0, 2)]) - assert_equal(P.nodes[2]['name'], G.nodes[2]['name']) + assert P.nodes[2]['name'] == G.nodes[2]['name'] def test_path_collaboration_projected_graph(self): G = nx.path_graph(4) @@ -111,8 +111,8 @@ class TestBipartiteProject: G.add_edge('c', 4) G.add_edge('b', 4) P = bipartite.collaboration_weighted_projected_graph(G, 'abc') - assert_equal(P['a']['b']['weight'], 1) - assert_equal(P['b']['c']['weight'], 2) + assert P['a']['b']['weight'] == 1 + assert P['b']['c']['weight'] == 2 def test_directed_projection(self): G = nx.DiGraph() @@ -124,7 +124,7 @@ class TestBipartiteProject: assert_edges_equal(list(P.edges()), [('A', 'B')]) P = bipartite.weighted_projected_graph(G, 'AB') assert_edges_equal(list(P.edges()), [('A', 'B')]) - assert_equal(P['A']['B']['weight'], 1) + assert P['A']['B']['weight'] == 1 P = bipartite.projected_graph(G, 'AB', multigraph=True) assert_edges_equal(list(P.edges()), [('A', 'B')]) @@ -138,7 +138,7 @@ class TestBipartiteProject: assert_edges_equal(list(P.edges()), [('A', 'B')]) P = bipartite.weighted_projected_graph(G, 'AB') assert_edges_equal(list(P.edges()), [('A', 'B')]) - assert_equal(P['A']['B']['weight'], 2) + assert P['A']['B']['weight'] == 2 P = bipartite.projected_graph(G, 'AB', multigraph=True) assert_edges_equal(list(P.edges()), [('A', 'B'), ('A', 'B')]) @@ -188,7 +188,7 @@ class TestBipartiteWeightedProjection: P = bipartite.weighted_projected_graph(self.G, 'ABCDEF') assert_edges_equal(list(P.edges()), Panswer.edges()) for u, v in list(P.edges()): - assert_equal(P[u][v]['weight'], Panswer[u][v]['weight']) + assert P[u][v]['weight'] == Panswer[u][v]['weight'] edges = [('A', 'B', 3), ('A', 'E', 1), @@ -203,7 +203,7 @@ class TestBipartiteWeightedProjection: P = bipartite.weighted_projected_graph(self.N, 'ABCDE') assert_edges_equal(list(P.edges()), Panswer.edges()) for u, v in list(P.edges()): - assert_equal(P[u][v]['weight'], Panswer[u][v]['weight']) + assert P[u][v]['weight'] == Panswer[u][v]['weight'] def test_project_weighted_newman(self): edges = [('A', 'B', 1.5), @@ -217,7 +217,7 @@ class TestBipartiteWeightedProjection: P = bipartite.collaboration_weighted_projected_graph(self.G, 'ABCDEF') assert_edges_equal(list(P.edges()), Panswer.edges()) for u, v in list(P.edges()): - assert_equal(P[u][v]['weight'], Panswer[u][v]['weight']) + assert P[u][v]['weight'] == Panswer[u][v]['weight'] edges = [('A', 'B', 11 / 6.0), ('A', 'E', 1 / 2.0), @@ -232,7 +232,7 @@ class TestBipartiteWeightedProjection: P = bipartite.collaboration_weighted_projected_graph(self.N, 'ABCDE') assert_edges_equal(list(P.edges()), Panswer.edges()) for u, v in list(P.edges()): - assert_equal(P[u][v]['weight'], Panswer[u][v]['weight']) + assert P[u][v]['weight'] == Panswer[u][v]['weight'] def test_project_weighted_ratio(self): edges = [('A', 'B', 2 / 6.0), @@ -246,7 +246,7 @@ class TestBipartiteWeightedProjection: P = bipartite.weighted_projected_graph(self.G, 'ABCDEF', ratio=True) assert_edges_equal(list(P.edges()), Panswer.edges()) for u, v in list(P.edges()): - assert_equal(P[u][v]['weight'], Panswer[u][v]['weight']) + assert P[u][v]['weight'] == Panswer[u][v]['weight'] edges = [('A', 'B', 3 / 3.0), ('A', 'E', 1 / 3.0), @@ -261,7 +261,7 @@ class TestBipartiteWeightedProjection: P = bipartite.weighted_projected_graph(self.N, 'ABCDE', ratio=True) assert_edges_equal(list(P.edges()), Panswer.edges()) for u, v in list(P.edges()): - assert_equal(P[u][v]['weight'], Panswer[u][v]['weight']) + assert P[u][v]['weight'] == Panswer[u][v]['weight'] def test_project_weighted_overlap(self): edges = [('A', 'B', 2 / 2.0), @@ -275,7 +275,7 @@ class TestBipartiteWeightedProjection: P = bipartite.overlap_weighted_projected_graph(self.G, 'ABCDEF', jaccard=False) assert_edges_equal(list(P.edges()), Panswer.edges()) for u, v in list(P.edges()): - assert_equal(P[u][v]['weight'], Panswer[u][v]['weight']) + assert P[u][v]['weight'] == Panswer[u][v]['weight'] edges = [('A', 'B', 3 / 3.0), ('A', 'E', 1 / 1.0), @@ -290,7 +290,7 @@ class TestBipartiteWeightedProjection: P = bipartite.overlap_weighted_projected_graph(self.N, 'ABCDE', jaccard=False) assert_edges_equal(list(P.edges()), Panswer.edges()) for u, v in list(P.edges()): - assert_equal(P[u][v]['weight'], Panswer[u][v]['weight']) + assert P[u][v]['weight'] == Panswer[u][v]['weight'] def test_project_weighted_jaccard(self): edges = [('A', 'B', 2 / 5.0), @@ -304,7 +304,7 @@ class TestBipartiteWeightedProjection: P = bipartite.overlap_weighted_projected_graph(self.G, 'ABCDEF') assert_edges_equal(list(P.edges()), Panswer.edges()) for u, v in list(P.edges()): - assert_equal(P[u][v]['weight'], Panswer[u][v]['weight']) + assert P[u][v]['weight'] == Panswer[u][v]['weight'] edges = [('A', 'B', 3 / 3.0), ('A', 'E', 1 / 3.0), @@ -319,7 +319,7 @@ class TestBipartiteWeightedProjection: P = bipartite.overlap_weighted_projected_graph(self.N, 'ABCDE') assert_edges_equal(list(P.edges()), Panswer.edges()) for u, v in P.edges(): - assert_equal(P[u][v]['weight'], Panswer[u][v]['weight']) + assert P[u][v]['weight'] == Panswer[u][v]['weight'] def test_generic_weighted_projected_graph_simple(self): def shared(G, u, v): diff --git a/networkx/algorithms/bipartite/tests/test_redundancy.py b/networkx/algorithms/bipartite/tests/test_redundancy.py index 2a5fa12a..beb5ba0e 100644 --- a/networkx/algorithms/bipartite/tests/test_redundancy.py +++ b/networkx/algorithms/bipartite/tests/test_redundancy.py @@ -23,7 +23,7 @@ from networkx.algorithms.bipartite import node_redundancy def test_no_redundant_nodes(): G = complete_bipartite_graph(2, 2) rc = node_redundancy(G) - assert_true(all(redundancy == 1 for redundancy in rc.values())) + assert all(redundancy == 1 for redundancy in rc.values()) def test_redundant_nodes(): @@ -32,9 +32,9 @@ def test_redundant_nodes(): G.add_edge(*edge) redundancy = node_redundancy(G) for v in edge: - assert_equal(redundancy[v], 2 / 3) + assert redundancy[v] == 2 / 3 for v in set(G) - edge: - assert_equal(redundancy[v], 1) + assert redundancy[v] == 1 @raises(NetworkXError) diff --git a/networkx/algorithms/centrality/tests/test_betweenness_centrality.py b/networkx/algorithms/centrality/tests/test_betweenness_centrality.py index 0721d86c..08b800d3 100644 --- a/networkx/algorithms/centrality/tests/test_betweenness_centrality.py +++ b/networkx/algorithms/centrality/tests/test_betweenness_centrality.py @@ -87,7 +87,7 @@ class TestBetweennessCentrality(object): b_approx1 = {0: 0.0, 1: 1.5, 2: 0.0} b_approx2 = {0: 0.0, 1: 0.75, 2: 0.0} for n in sorted(G): - assert_in(b[n], (b_approx1[n], b_approx2[n])) + assert b[n] in (b_approx1[n], b_approx2[n]) def test_P3_endpoints(self): """Betweenness centrality: P3 endpoints""" diff --git a/networkx/algorithms/centrality/tests/test_closeness_centrality.py b/networkx/algorithms/centrality/tests/test_closeness_centrality.py index a6e47a82..9550a11a 100644 --- a/networkx/algorithms/centrality/tests/test_closeness_centrality.py +++ b/networkx/algorithms/centrality/tests/test_closeness_centrality.py @@ -257,8 +257,8 @@ class TestClosenessCentrality: G.remove_edges_from([edge]) real_cc = nx.closeness_centrality(G) shared_items = set(test_cc.items()) & set(real_cc.items()) - assert_equals(len(shared_items), len(real_cc)) - assert_in(0, test_cc.values()) + assert len(shared_items) == len(real_cc) + assert 0 in test_cc.values() def test_incremental(self): # Check that incremental and regular give same output @@ -301,6 +301,6 @@ class TestClosenessCentrality: # incremental time: 0.00947 # regular time: 0.188 - assert_equals(set(test_cc.items()), set(real_cc.items())) + assert set(test_cc.items()) == set(real_cc.items()) prev_cc = test_cc diff --git a/networkx/algorithms/centrality/tests/test_degree_centrality.py b/networkx/algorithms/centrality/tests/test_degree_centrality.py index 7bbd61e2..bbcf5d40 100644 --- a/networkx/algorithms/centrality/tests/test_degree_centrality.py +++ b/networkx/algorithms/centrality/tests/test_degree_centrality.py @@ -92,11 +92,11 @@ class TestDegreeCentrality: def test_small_graph_centrality(self): G = nx.empty_graph(create_using=nx.DiGraph) - assert_equal({}, nx.degree_centrality(G)) - assert_equal({}, nx.out_degree_centrality(G)) - assert_equal({}, nx.in_degree_centrality(G)) + assert {} == nx.degree_centrality(G) + assert {} == nx.out_degree_centrality(G) + assert {} == nx.in_degree_centrality(G) G = nx.empty_graph(1, create_using=nx.DiGraph) - assert_equal({0: 1}, nx.degree_centrality(G)) - assert_equal({0: 1}, nx.out_degree_centrality(G)) - assert_equal({0: 1}, nx.in_degree_centrality(G)) + assert {0: 1} == nx.degree_centrality(G) + assert {0: 1} == nx.out_degree_centrality(G) + assert {0: 1} == nx.in_degree_centrality(G) diff --git a/networkx/algorithms/centrality/tests/test_group.py b/networkx/algorithms/centrality/tests/test_group.py index e64b3a38..4062f1d5 100644 --- a/networkx/algorithms/centrality/tests/test_group.py +++ b/networkx/algorithms/centrality/tests/test_group.py @@ -18,7 +18,7 @@ class TestGroupBetweennessCentrality: b = nx.group_betweenness_centrality(G, C, weight=None, normalized=False) b_answer = 3.0 - assert_equal(b, b_answer) + assert b == b_answer def test_group_betweenness_normalized(self): """ @@ -30,7 +30,7 @@ class TestGroupBetweennessCentrality: b = nx.group_betweenness_centrality(G, C, weight=None, normalized=True) b_answer = 1.0 - assert_equal(b, b_answer) + assert b == b_answer def test_group_betweenness_value_zero(self): """ @@ -40,7 +40,7 @@ class TestGroupBetweennessCentrality: C = [0, 1, 5] b = nx.group_betweenness_centrality(G, C, weight=None) b_answer = 0.0 - assert_equal(b, b_answer) + assert b == b_answer def test_group_betweenness_disconnected_graph(self): """ @@ -51,7 +51,7 @@ class TestGroupBetweennessCentrality: C = [1] b = nx.group_betweenness_centrality(G, C, weight=None) b_answer = 0.0 - assert_equal(b, b_answer) + assert b == b_answer @raises(nx.NodeNotFound) def test_group_betweenness_node_not_in_graph(self): @@ -70,7 +70,7 @@ class TestGroupClosenessCentrality: G = nx.path_graph(5) c = nx.group_closeness_centrality(G, [1]) c_answer = nx.closeness_centrality(G, 1) - assert_equal(c, c_answer) + assert c == c_answer def test_group_closeness_disconnected(self): """ @@ -80,7 +80,7 @@ class TestGroupClosenessCentrality: G.add_nodes_from([1, 2, 3, 4]) c = nx.group_closeness_centrality(G, [1, 2]) c_answer = 0 - assert_equal(c, c_answer) + assert c == c_answer def test_group_closeness_multiple_node(self): """ @@ -90,7 +90,7 @@ class TestGroupClosenessCentrality: G = nx.path_graph(4) c = nx.group_closeness_centrality(G, [1, 2]) c_answer = 1 - assert_equal(c, c_answer) + assert c == c_answer @raises(nx.NodeNotFound) def test_group_closeness_node_not_in_graph(self): @@ -109,7 +109,7 @@ class TestGroupDegreeCentrality: G = nx.path_graph(4) d = nx.group_degree_centrality(G, [1]) d_answer = nx.degree_centrality(G)[1] - assert_equal(d, d_answer) + assert d == d_answer def test_group_degree_centrality_multiple_node(self): """ @@ -122,7 +122,7 @@ class TestGroupDegreeCentrality: (2, 3), (2, 4), (2, 5)]) d = nx.group_degree_centrality(G, [1, 2]) d_answer = 1 - assert_equal(d, d_answer) + assert d == d_answer def test_group_in_degree_centrality(self): """ @@ -134,7 +134,7 @@ class TestGroupDegreeCentrality: (2, 3), (2, 4), (2, 5)]) d = nx.group_in_degree_centrality(G, [1, 2]) d_answer = 0 - assert_equal(d, d_answer) + assert d == d_answer def test_group_out_degree_centrality(self): """ @@ -146,7 +146,7 @@ class TestGroupDegreeCentrality: (2, 3), (2, 4), (2, 5)]) d = nx.group_out_degree_centrality(G, [1, 2]) d_answer = 1 - assert_equal(d, d_answer) + assert d == d_answer @raises(nx.NetworkXError) def test_group_degree_centrality_node_not_in_graph(self): diff --git a/networkx/algorithms/centrality/tests/test_harmonic_centrality.py b/networkx/algorithms/centrality/tests/test_harmonic_centrality.py index 495e6cfd..c32d5173 100644 --- a/networkx/algorithms/centrality/tests/test_harmonic_centrality.py +++ b/networkx/algorithms/centrality/tests/test_harmonic_centrality.py @@ -110,11 +110,11 @@ class TestClosenessCentrality: G = nx.DiGraph() c = harmonic_centrality(G, distance='weight') d = {} - assert_equal(c, d) + assert c == d def test_singleton(self): G = nx.DiGraph() G.add_node(0) c = harmonic_centrality(G, distance='weight') d = {0: 0} - assert_equal(c, d) + assert c == d diff --git a/networkx/algorithms/centrality/tests/test_katz_centrality.py b/networkx/algorithms/centrality/tests/test_katz_centrality.py index 3162120c..e599aa90 100644 --- a/networkx/algorithms/centrality/tests/test_katz_centrality.py +++ b/networkx/algorithms/centrality/tests/test_katz_centrality.py @@ -89,7 +89,7 @@ class TestKatzCentrality(object): def test_empty(self): e = nx.katz_centrality(nx.Graph(), 0.1) - assert_equal(e, {}) + assert e == {} @raises(nx.NetworkXException) def test_bad_beta(self): @@ -185,7 +185,7 @@ class TestKatzCentralityNumpy(object): def test_empty(self): e = nx.katz_centrality(nx.Graph(), 0.1) - assert_equal(e, {}) + assert e == {} @raises(nx.NetworkXException) def test_bad_beta(self): diff --git a/networkx/algorithms/centrality/tests/test_load_centrality.py b/networkx/algorithms/centrality/tests/test_load_centrality.py index 03dbcfa9..71a4fd1a 100644 --- a/networkx/algorithms/centrality/tests/test_load_centrality.py +++ b/networkx/algorithms/centrality/tests/test_load_centrality.py @@ -50,7 +50,7 @@ class TestLoadCentrality: def test_weighted_load(self): b = nx.load_centrality(self.G, weight='weight', normalized=False) for n in sorted(self.G): - assert_equal(b[n], self.exact_weighted[n]) + assert b[n] == self.exact_weighted[n] def test_k5_load(self): G = self.K5 diff --git a/networkx/algorithms/centrality/tests/test_reaching.py b/networkx/algorithms/centrality/tests/test_reaching.py index 223f7278..a2453c1f 100644 --- a/networkx/algorithms/centrality/tests/test_reaching.py +++ b/networkx/algorithms/centrality/tests/test_reaching.py @@ -29,41 +29,41 @@ class TestGlobalReachingCentrality(TestCase): G = nx.DiGraph() G.add_weighted_edges_from([(1, 2, 0.5), (1, 3, 0.5)]) grc = nx.global_reaching_centrality - assert_equal(grc(G, normalized=False, weight='weight'), 0.5) - assert_equal(grc(G), 1) + assert grc(G, normalized=False, weight='weight') == 0.5 + assert grc(G) == 1 def test_undirected_unweighted_star(self): G = nx.star_graph(2) grc = nx.global_reaching_centrality - assert_equal(grc(G, normalized=False, weight=None), 0.25) + assert grc(G, normalized=False, weight=None) == 0.25 def test_undirected_weighted_star(self): G = nx.Graph() G.add_weighted_edges_from([(1, 2, 1), (1, 3, 2)]) grc = nx.global_reaching_centrality - assert_equal(grc(G, normalized=False, weight='weight'), 0.375) + assert grc(G, normalized=False, weight='weight') == 0.375 def test_cycle_directed_unweighted(self): G = nx.DiGraph() G.add_edge(1, 2) G.add_edge(2, 1) - assert_equal(nx.global_reaching_centrality(G, weight=None), 0) + assert nx.global_reaching_centrality(G, weight=None) == 0 def test_cycle_undirected_unweighted(self): G = nx.Graph() G.add_edge(1, 2) - assert_equal(nx.global_reaching_centrality(G, weight=None), 0) + assert nx.global_reaching_centrality(G, weight=None) == 0 def test_cycle_directed_weighted(self): G = nx.DiGraph() G.add_weighted_edges_from([(1, 2, 1), (2, 1, 1)]) - assert_equal(nx.global_reaching_centrality(G), 0) + assert nx.global_reaching_centrality(G) == 0 def test_cycle_undirected_weighted(self): G = nx.Graph() G.add_edge(1, 2, weight=1) grc = nx.global_reaching_centrality - assert_equal(grc(G, normalized=False), 0) + assert grc(G, normalized=False) == 0 def test_directed_weighted(self): G = nx.DiGraph() @@ -105,10 +105,10 @@ class TestLocalReachingCentrality(TestCase): def test_undirected_unweighted_star(self): G = nx.star_graph(2) grc = nx.local_reaching_centrality - assert_equal(grc(G, 1, weight=None, normalized=False), 0.75) + assert grc(G, 1, weight=None, normalized=False) == 0.75 def test_undirected_weighted_star(self): G = nx.Graph() G.add_weighted_edges_from([(1, 2, 1), (1, 3, 2)]) centrality = nx.local_reaching_centrality(G, 1, normalized=False, weight='weight') - assert_equal(centrality, 1.5) + assert centrality == 1.5 diff --git a/networkx/algorithms/centrality/tests/test_voterank.py b/networkx/algorithms/centrality/tests/test_voterank.py index babd809b..8589a1e7 100644 --- a/networkx/algorithms/centrality/tests/test_voterank.py +++ b/networkx/algorithms/centrality/tests/test_voterank.py @@ -12,10 +12,10 @@ class TestVoteRankCentrality: G = nx.Graph() G.add_edges_from([(7, 8), (7, 5), (7, 9), (5, 0), (0, 1), (0, 2), (0, 3), (0, 4), (1, 6), (2, 6), (3, 6), (4, 6)]) - assert_equal([0, 7, 6], nx.voterank(G)) + assert [0, 7, 6] == nx.voterank(G) def test_voterank_centrality_2(self): G = nx.florentine_families_graph() d = nx.voterank(G, 4) exact = ['Medici', 'Strozzi', 'Guadagni', 'Castellani'] - assert_equal(exact, d) + assert exact == d diff --git a/networkx/algorithms/coloring/tests/test_coloring.py b/networkx/algorithms/coloring/tests/test_coloring.py index ee35a6a5..f8e31a53 100644 --- a/networkx/algorithms/coloring/tests/test_coloring.py +++ b/networkx/algorithms/coloring/tests/test_coloring.py @@ -44,8 +44,8 @@ class TestColoring: coloring = nx.coloring.greedy_color(graph, strategy=strategy, interchange=interchange) - assert_true(verify_length(coloring, n_nodes)) - assert_true(verify_coloring(graph, coloring)) + assert verify_length(coloring, n_nodes) + assert verify_coloring(graph, coloring) for graph_func, n_nodes in BASIC_TEST_CASES.items(): for interchange in [True, False]: @@ -63,9 +63,9 @@ class TestColoring: interchange=interchange) if not hasattr(colors, '__len__'): colors = [colors] - assert_true(any(verify_length(coloring, n_colors) - for n_colors in colors)) - assert_true(verify_coloring(graph, coloring)) + assert any(verify_length(coloring, n_colors) + for n_colors in colors) + assert verify_coloring(graph, coloring) for strategy, arglist in SPECIAL_TEST_CASES.items(): for args in arglist: @@ -93,14 +93,14 @@ class TestColoring: 'largest_first') colors_2 = nx.coloring.greedy_color(graph, nx.coloring.strategy_largest_first) - assert_equal(colors_1, colors_2) + assert colors_1 == colors_2 def test_seed_argument(self): graph = lf_shc() rs = nx.coloring.strategy_random_sequential c1 = nx.coloring.greedy_color(graph, lambda g, c: rs(g, c, seed=1)) for u, v in graph.edges: - assert_not_equal(c1[u], c1[v]) + assert c1[u] != c1[v] def test_is_coloring(self): G = nx.Graph() diff --git a/networkx/algorithms/community/tests/test_asyn_fluid.py b/networkx/algorithms/community/tests/test_asyn_fluid.py index 7ac19163..5c3a9be2 100644 --- a/networkx/algorithms/community/tests/test_asyn_fluid.py +++ b/networkx/algorithms/community/tests/test_asyn_fluid.py @@ -24,7 +24,7 @@ def test_single_node(): communities = asyn_fluidc(test, 1) result = {frozenset(c) for c in communities} - assert_equal(result, ground_truth) + assert result == ground_truth def test_two_nodes(): @@ -37,7 +37,7 @@ def test_two_nodes(): communities = asyn_fluidc(test, 2) result = {frozenset(c) for c in communities} - assert_equal(result, ground_truth) + assert result == ground_truth def test_two_clique_communities(): @@ -62,7 +62,7 @@ def test_two_clique_communities(): communities = asyn_fluidc(test, 2, seed=7) result = {frozenset(c) for c in communities} - assert_equal(result, ground_truth) + assert result == ground_truth def five_clique_ring(): @@ -127,4 +127,4 @@ def five_clique_ring(): communities = asyn_fluidc(test, 5, seed=9) result = {frozenset(c) for c in communities} - assert_equal(result, ground_truth) + assert result == ground_truth diff --git a/networkx/algorithms/community/tests/test_centrality.py b/networkx/algorithms/community/tests/test_centrality.py index 9be8140c..c2c42698 100644 --- a/networkx/algorithms/community/tests/test_centrality.py +++ b/networkx/algorithms/community/tests/test_centrality.py @@ -25,11 +25,11 @@ def set_of_sets(iterable): def validate_communities(result, expected): - assert_equal(set_of_sets(result), set_of_sets(expected)) + assert set_of_sets(result) == set_of_sets(expected) def validate_possible_communities(result, *expected): - assert_true(any(set_of_sets(result) == set_of_sets(p) for p in expected)) + assert any(set_of_sets(result) == set_of_sets(p) for p in expected) class TestGirvanNewman(object): @@ -42,14 +42,14 @@ class TestGirvanNewman(object): def test_no_edges(self): G = nx.empty_graph(3) communities = list(girvan_newman(G)) - assert_equal(len(communities), 1) + assert len(communities) == 1 validate_communities(communities[0], [{0}, {1}, {2}]) def test_undirected(self): # Start with the graph .-.-.-. G = nx.path_graph(4) communities = list(girvan_newman(G)) - assert_equal(len(communities), 3) + assert len(communities) == 3 # After one removal, we get the graph .-. .-. validate_communities(communities[0], [{0, 1}, {2, 3}]) # After the next, we get the graph .-. . ., but there are two @@ -62,7 +62,7 @@ class TestGirvanNewman(object): def test_directed(self): G = nx.DiGraph(nx.path_graph(4)) communities = list(girvan_newman(G)) - assert_equal(len(communities), 3) + assert len(communities) == 3 validate_communities(communities[0], [{0, 1}, {2, 3}]) validate_possible_communities(communities[1], [{0}, {1}, {2, 3}], [{0, 1}, {2}, {3}]) @@ -73,7 +73,7 @@ class TestGirvanNewman(object): G.add_edge(0, 0) G.add_edge(2, 2) communities = list(girvan_newman(G)) - assert_equal(len(communities), 3) + assert len(communities) == 3 validate_communities(communities[0], [{0, 1}, {2, 3}]) validate_possible_communities(communities[1], [{0}, {1}, {2, 3}], [{0, 1}, {2}, {3}]) @@ -86,7 +86,7 @@ class TestGirvanNewman(object): def heaviest(G): return max(G.edges(data='weight'), key=itemgetter(2))[:2] communities = list(girvan_newman(G, heaviest)) - assert_equal(len(communities), 3) + assert len(communities) == 3 validate_communities(communities[0], [{0}, {1, 2, 3}]) validate_communities(communities[1], [{0}, {1}, {2, 3}]) validate_communities(communities[2], [{0}, {1}, {2}, {3}]) diff --git a/networkx/algorithms/community/tests/test_kclique.py b/networkx/algorithms/community/tests/test_kclique.py index 056ce08d..cfeea73b 100644 --- a/networkx/algorithms/community/tests/test_kclique.py +++ b/networkx/algorithms/community/tests/test_kclique.py @@ -12,9 +12,9 @@ def test_overlapping_K5(): G.add_edges_from(combinations(range(5), 2)) # Add a five clique G.add_edges_from(combinations(range(2, 7), 2)) # Add another five clique c = list(k_clique_communities(G, 4)) - assert_equal(c, [frozenset(range(7))]) + assert c == [frozenset(range(7))] c = set(k_clique_communities(G, 5)) - assert_equal(c, {frozenset(range(5)), frozenset(range(2, 7))}) + assert c == {frozenset(range(5)), frozenset(range(2, 7))} def test_isolated_K5(): @@ -22,7 +22,7 @@ def test_isolated_K5(): G.add_edges_from(combinations(range(0, 5), 2)) # Add a five clique G.add_edges_from(combinations(range(5, 10), 2)) # Add another five clique c = set(k_clique_communities(G, 5)) - assert_equal(c, {frozenset(range(5)), frozenset(range(5, 10))}) + assert c == {frozenset(range(5)), frozenset(range(5, 10))} class TestZacharyKarateClub(object): @@ -32,7 +32,7 @@ class TestZacharyKarateClub(object): def _check_communities(self, k, expected): communities = set(k_clique_communities(self.G, k)) - assert_equal(communities, expected) + assert communities == expected def test_k2(self): # clique percolation with k=2 is just connected components diff --git a/networkx/algorithms/community/tests/test_kernighan_lin.py b/networkx/algorithms/community/tests/test_kernighan_lin.py index 6f2ff71e..b2956262 100644 --- a/networkx/algorithms/community/tests/test_kernighan_lin.py +++ b/networkx/algorithms/community/tests/test_kernighan_lin.py @@ -21,7 +21,7 @@ from networkx.algorithms.community import kernighan_lin_bisection def assert_partition_equal(x, y): - assert_equal(set(map(frozenset, x)), set(map(frozenset, y))) + assert set(map(frozenset, x)) == set(map(frozenset, y)) def test_partition(): diff --git a/networkx/algorithms/community/tests/test_label_propagation.py b/networkx/algorithms/community/tests/test_label_propagation.py index 20c62e25..d8e184a2 100644 --- a/networkx/algorithms/community/tests/test_label_propagation.py +++ b/networkx/algorithms/community/tests/test_label_propagation.py @@ -28,7 +28,7 @@ def test_one_node(): communities = label_propagation_communities(test) result = {frozenset(c) for c in communities} - assert_equal(result, ground_truth) + assert result == ground_truth def test_unconnected_communities(): @@ -48,7 +48,7 @@ def test_unconnected_communities(): communities = label_propagation_communities(test) result = {frozenset(c) for c in communities} - assert_equal(result, ground_truth) + assert result == ground_truth def test_connected_communities(): @@ -95,7 +95,7 @@ def test_connected_communities(): communities = label_propagation_communities(test) result = {frozenset(c) for c in communities} - assert_in(result, ground_truth) + assert result in ground_truth def test_termination(): @@ -120,7 +120,7 @@ class TestAsynLpaCommunities(object): """ communities = asyn_lpa_communities(G) result = {frozenset(c) for c in communities} - assert_equal(result, expected) + assert result == expected def test_null_graph(self): G = nx.null_graph() @@ -143,7 +143,7 @@ class TestAsynLpaCommunities(object): ground_truth = {frozenset('abc'), frozenset('def')} communities = asyn_lpa_communities(G, seed=1) result = {frozenset(c) for c in communities} - assert_equal(result, ground_truth) + assert result == ground_truth def test_several_communities(self): # This graph is the disjoint union of five triangles. diff --git a/networkx/algorithms/community/tests/test_modularity_max.py b/networkx/algorithms/community/tests/test_modularity_max.py index 16bc7354..3e3e0474 100644 --- a/networkx/algorithms/community/tests/test_modularity_max.py +++ b/networkx/algorithms/community/tests/test_modularity_max.py @@ -16,7 +16,7 @@ class TestCNM(object): def _check_communities(self, expected): communities = set(greedy_modularity_communities(self.G)) - assert_equal(communities, expected) + assert communities == expected def test_karate_club(self): john_a = frozenset([ @@ -33,7 +33,7 @@ class TestNaive(object): def _check_communities(self, expected): communities = set(_naive_greedy_modularity_communities(self.G)) - assert_equal(communities, expected) + assert communities == expected def test_karate_club(self): john_a = frozenset([ diff --git a/networkx/algorithms/community/tests/test_quality.py b/networkx/algorithms/community/tests/test_quality.py index edd98853..c7051b4b 100644 --- a/networkx/algorithms/community/tests/test_quality.py +++ b/networkx/algorithms/community/tests/test_quality.py @@ -67,12 +67,12 @@ def test_modularity(): def test_inter_community_edges_with_digraphs(): G = nx.complete_graph(2, create_using=nx.DiGraph()) partition = [{0}, {1}] - assert_equal(inter_community_edges(G, partition), 2) + assert inter_community_edges(G, partition) == 2 G = nx.complete_graph(10, create_using=nx.DiGraph()) partition = [{0}, {1, 2}, {3, 4, 5}, {6, 7, 8, 9}] - assert_equal(inter_community_edges(G, partition), 70) + assert inter_community_edges(G, partition) == 70 G = nx.cycle_graph(4, create_using=nx.DiGraph()) partition = [{0, 1}, {2, 3}] - assert_equal(inter_community_edges(G, partition), 2) + assert inter_community_edges(G, partition) == 2 diff --git a/networkx/algorithms/community/tests/test_utils.py b/networkx/algorithms/community/tests/test_utils.py index bfa01588..cdd94347 100644 --- a/networkx/algorithms/community/tests/test_utils.py +++ b/networkx/algorithms/community/tests/test_utils.py @@ -18,22 +18,22 @@ from networkx.algorithms.community import is_partition def test_is_partition(): G = nx.empty_graph(3) - assert_true(is_partition(G, [{0, 1}, {2}])) - assert_true(is_partition(G, ({0, 1}, {2}))) - assert_true(is_partition(G, ([0, 1], [2]))) - assert_true(is_partition(G, [[0, 1], [2]])) + assert is_partition(G, [{0, 1}, {2}]) + assert is_partition(G, ({0, 1}, {2})) + assert is_partition(G, ([0, 1], [2])) + assert is_partition(G, [[0, 1], [2]]) def test_not_covering(): G = nx.empty_graph(3) - assert_false(is_partition(G, [{0}, {1}])) + assert not is_partition(G, [{0}, {1}]) def test_not_disjoint(): G = nx.empty_graph(3) - assert_false(is_partition(G, [{0, 1}, {1, 2}])) + assert not is_partition(G, [{0, 1}, {1, 2}]) def test_not_node(): G = nx.empty_graph(3) - assert_false(is_partition(G, [{0, 1}, {3}])) + assert not is_partition(G, [{0, 1}, {3}]) diff --git a/networkx/algorithms/components/tests/test_attracting.py b/networkx/algorithms/components/tests/test_attracting.py index 568d81a8..55f78a51 100644 --- a/networkx/algorithms/components/tests/test_attracting.py +++ b/networkx/algorithms/components/tests/test_attracting.py @@ -20,36 +20,36 @@ class TestAttractingComponents(object): def test_attracting_components(self): ac = list(nx.attracting_components(self.G1)) - assert_true({2} in ac) - assert_true({9} in ac) - assert_true({10} in ac) + assert {2} in ac + assert {9} in ac + assert {10} in ac ac = list(nx.attracting_components(self.G2)) ac = [tuple(sorted(x)) for x in ac] - assert_true(ac == [(1, 2)]) + assert ac == [(1, 2)] ac = list(nx.attracting_components(self.G3)) ac = [tuple(sorted(x)) for x in ac] - assert_true((1, 2) in ac) - assert_true((3, 4) in ac) - assert_equal(len(ac), 2) + assert (1, 2) in ac + assert (3, 4) in ac + assert len(ac) == 2 ac = list(nx.attracting_components(self.G4)) - assert_equal(ac, []) + assert ac == [] def test_number_attacting_components(self): - assert_equal(nx.number_attracting_components(self.G1), 3) - assert_equal(nx.number_attracting_components(self.G2), 1) - assert_equal(nx.number_attracting_components(self.G3), 2) - assert_equal(nx.number_attracting_components(self.G4), 0) + assert nx.number_attracting_components(self.G1) == 3 + assert nx.number_attracting_components(self.G2) == 1 + assert nx.number_attracting_components(self.G3) == 2 + assert nx.number_attracting_components(self.G4) == 0 def test_is_attracting_component(self): - assert_false(nx.is_attracting_component(self.G1)) - assert_false(nx.is_attracting_component(self.G2)) - assert_false(nx.is_attracting_component(self.G3)) + assert not nx.is_attracting_component(self.G1) + assert not nx.is_attracting_component(self.G2) + assert not nx.is_attracting_component(self.G3) g2 = self.G3.subgraph([1, 2]) - assert_true(nx.is_attracting_component(g2)) - assert_false(nx.is_attracting_component(self.G4)) + assert nx.is_attracting_component(g2) + assert not nx.is_attracting_component(self.G4) def test_connected_raise(self): G = nx.Graph() diff --git a/networkx/algorithms/components/tests/test_biconnected.py b/networkx/algorithms/components/tests/test_biconnected.py index ae9e1039..0870203c 100644 --- a/networkx/algorithms/components/tests/test_biconnected.py +++ b/networkx/algorithms/components/tests/test_biconnected.py @@ -8,13 +8,13 @@ from networkx import NetworkXNotImplemented def assert_components_edges_equal(x, y): sx = {frozenset([frozenset(e) for e in c]) for c in x} sy = {frozenset([frozenset(e) for e in c]) for c in y} - assert_equal(sx, sy) + assert sx == sy def assert_components_equal(x, y): sx = {frozenset(c) for c in x} sy = {frozenset(c) for c in y} - assert_equal(sx, sy) + assert sx == sy def test_barbell(): @@ -22,7 +22,7 @@ def test_barbell(): nx.add_path(G, [7, 20, 21, 22]) nx.add_cycle(G, [22, 23, 24, 25]) pts = set(nx.articulation_points(G)) - assert_equal(pts, {7, 8, 9, 10, 11, 12, 20, 21, 22}) + assert pts == {7, 8, 9, 10, 11, 12, 20, 21, 22} answer = [ {12, 13, 14, 15, 16, 17, 18, 19}, @@ -41,34 +41,34 @@ def test_barbell(): G.add_edge(2, 17) pts = set(nx.articulation_points(G)) - assert_equal(pts, {7, 20, 21, 22}) + assert pts == {7, 20, 21, 22} def test_articulation_points_repetitions(): G = nx.Graph() G.add_edges_from([(0, 1), (1, 2), (1, 3)]) - assert_equal(list(nx.articulation_points(G)), [1]) + assert list(nx.articulation_points(G)) == [1] def test_articulation_points_cycle(): G = nx.cycle_graph(3) nx.add_cycle(G, [1, 3, 4]) pts = set(nx.articulation_points(G)) - assert_equal(pts, {1}) + assert pts == {1} def test_is_biconnected(): G = nx.cycle_graph(3) - assert_true(nx.is_biconnected(G)) + assert nx.is_biconnected(G) nx.add_cycle(G, [1, 3, 4]) - assert_false(nx.is_biconnected(G)) + assert not nx.is_biconnected(G) def test_empty_is_biconnected(): G = nx.empty_graph(5) - assert_false(nx.is_biconnected(G)) + assert not nx.is_biconnected(G) G.add_edge(0, 1) - assert_false(nx.is_biconnected(G)) + assert not nx.is_biconnected(G) def test_biconnected_components_cycle(): @@ -84,14 +84,14 @@ def test_biconnected_component_subgraphs_cycle(): G = nx.cycle_graph(3) nx.add_cycle(G, [1, 3, 4, 5]) Gc = set(nx.biconnected_component_subgraphs(G)) - assert_equal(len(Gc), 2) + assert len(Gc) == 2 g1, g2 = Gc if 0 in g1: - assert_true(nx.is_isomorphic(g1, nx.Graph([(0, 1), (0, 2), (1, 2)]))) - assert_true(nx.is_isomorphic(g2, nx.Graph([(1, 3), (1, 5), (3, 4), (4, 5)]))) + assert nx.is_isomorphic(g1, nx.Graph([(0, 1), (0, 2), (1, 2)])) + assert nx.is_isomorphic(g2, nx.Graph([(1, 3), (1, 5), (3, 4), (4, 5)])) else: - assert_true(nx.is_isomorphic(g1, nx.Graph([(1, 3), (1, 5), (3, 4), (4, 5)]))) - assert_true(nx.is_isomorphic(g2, nx.Graph([(0, 1), (0, 2), (1, 2)]))) + assert nx.is_isomorphic(g1, nx.Graph([(1, 3), (1, 5), (3, 4), (4, 5)])) + assert nx.is_isomorphic(g2, nx.Graph([(0, 1), (0, 2), (1, 2)])) def test_biconnected_components1(): @@ -104,7 +104,7 @@ def test_biconnected_components1(): ] G = nx.Graph(edges) pts = set(nx.articulation_points(G)) - assert_equal(pts, {4, 6, 7, 8, 9}) + assert pts == {4, 6, 7, 8, 9} comps = list(nx.biconnected_component_edges(G)) answer = [ [(3, 4), (15, 3), (10, 15), (10, 4), (2, 10), (4, 2)], @@ -139,9 +139,9 @@ def test_biconnected_components2(): def test_biconnected_davis(): D = nx.davis_southern_women_graph() bcc = list(nx.biconnected_components(D))[0] - assert_true(set(D) == bcc) # All nodes in a giant bicomponent + assert set(D) == bcc # All nodes in a giant bicomponent # So no articulation points - assert_equal(len(list(nx.articulation_points(D))), 0) + assert len(list(nx.articulation_points(D))) == 0 def test_biconnected_karate(): @@ -152,7 +152,7 @@ def test_biconnected_karate(): {0, 11}] bcc = list(nx.biconnected_components(K)) assert_components_equal(bcc, answer) - assert_equal(set(nx.articulation_points(K)), {0}) + assert set(nx.articulation_points(K)) == {0} def test_biconnected_eppstein(): @@ -177,8 +177,8 @@ def test_biconnected_eppstein(): 7: [4], 8: [1, 3, 6], }) - assert_true(nx.is_biconnected(G1)) - assert_false(nx.is_biconnected(G2)) + assert nx.is_biconnected(G1) + assert not nx.is_biconnected(G2) answer_G2 = [{1, 3, 6, 8}, {0, 2, 5}, {2, 3}, {4, 7}] bcc = list(nx.biconnected_components(G2)) assert_components_equal(bcc, answer_G2) @@ -186,10 +186,10 @@ def test_biconnected_eppstein(): def test_null_graph(): G = nx.Graph() - assert_false(nx.is_biconnected(G)) - assert_equal(list(nx.biconnected_components(G)), []) - assert_equal(list(nx.biconnected_component_edges(G)), []) - assert_equal(list(nx.articulation_points(G)), []) + assert not nx.is_biconnected(G) + assert list(nx.biconnected_components(G)) == [] + assert list(nx.biconnected_component_edges(G)) == [] + assert list(nx.articulation_points(G)) == [] def test_connected_raise(): diff --git a/networkx/algorithms/components/tests/test_connected.py b/networkx/algorithms/components/tests/test_connected.py index a9e5e2cb..4e94bfb2 100644 --- a/networkx/algorithms/components/tests/test_connected.py +++ b/networkx/algorithms/components/tests/test_connected.py @@ -55,27 +55,27 @@ class TestConnected: frozenset([4, 5, 6, 7, 8, 9]), frozenset([10, 11, 12, 13, 14]) } - assert_equal({frozenset(g) for g in cc(G)}, C) + assert {frozenset(g) for g in cc(G)} == C def test_number_connected_components(self): ncc = nx.number_connected_components - assert_equal(ncc(self.G), 3) + assert ncc(self.G) == 3 def test_number_connected_components2(self): ncc = nx.number_connected_components - assert_equal(ncc(self.grid), 1) + assert ncc(self.grid) == 1 def test_connected_components2(self): cc = nx.connected_components G = self.grid C = {frozenset([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])} - assert_equal({frozenset(g) for g in cc(G)}, C) + assert {frozenset(g) for g in cc(G)} == C def test_node_connected_components(self): ncc = nx.node_connected_component G = self.grid C = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} - assert_equal(ncc(G, 1), C) + assert ncc(G, 1) == C # deprecated def test_connected_component_subgraphs(self): @@ -85,13 +85,13 @@ class TestConnected: U = G.to_undirected() w = {frozenset(g) for g in wcc(G)} c = {frozenset(g) for g in cc(U)} - assert_equal(w, c) + assert w == c def test_is_connected(self): - assert_true(nx.is_connected(self.grid)) + assert nx.is_connected(self.grid) G = nx.Graph() G.add_nodes_from([1, 2]) - assert_false(nx.is_connected(G)) + assert not nx.is_connected(G) def test_connected_raise(self): assert_raises(NetworkXNotImplemented, nx.connected_components, self.DG) diff --git a/networkx/algorithms/components/tests/test_strongly_connected.py b/networkx/algorithms/components/tests/test_strongly_connected.py index e8da341c..fdd93884 100644 --- a/networkx/algorithms/components/tests/test_strongly_connected.py +++ b/networkx/algorithms/components/tests/test_strongly_connected.py @@ -46,35 +46,35 @@ class TestStronglyConnected: def test_tarjan(self): scc = nx.strongly_connected_components for G, C in self.gc: - assert_equal({frozenset(g) for g in scc(G)}, C) + assert {frozenset(g) for g in scc(G)} == C def test_tarjan_recursive(self): scc = nx.strongly_connected_components_recursive for G, C in self.gc: - assert_equal({frozenset(g) for g in scc(G)}, C) + assert {frozenset(g) for g in scc(G)} == C def test_kosaraju(self): scc = nx.kosaraju_strongly_connected_components for G, C in self.gc: - assert_equal({frozenset(g) for g in scc(G)}, C) + assert {frozenset(g) for g in scc(G)} == C def test_number_strongly_connected_components(self): ncc = nx.number_strongly_connected_components for G, C in self.gc: - assert_equal(ncc(G), len(C)) + assert ncc(G) == len(C) def test_is_strongly_connected(self): for G, C in self.gc: if len(C) == 1: - assert_true(nx.is_strongly_connected(G)) + assert nx.is_strongly_connected(G) else: - assert_false(nx.is_strongly_connected(G)) + assert not nx.is_strongly_connected(G) # deprecated def test_strongly_connected_component_subgraphs(self): scc = nx.strongly_connected_component_subgraphs for G, C in self.gc: - assert_equal({frozenset(g) for g in scc(G)}, C) + assert {frozenset(g) for g in scc(G)} == C def test_contract_scc1(self): G = nx.DiGraph() @@ -86,20 +86,20 @@ class TestStronglyConnected: scc = list(nx.strongly_connected_components(G)) cG = nx.condensation(G, scc) # DAG - assert_true(nx.is_directed_acyclic_graph(cG)) + assert nx.is_directed_acyclic_graph(cG) # nodes - assert_equal(sorted(cG.nodes()), [0, 1, 2, 3]) + assert sorted(cG.nodes()) == [0, 1, 2, 3] # edges mapping = {} for i, component in enumerate(scc): for n in component: mapping[n] = i edge = (mapping[2], mapping[3]) - assert_true(cG.has_edge(*edge)) + assert cG.has_edge(*edge) edge = (mapping[2], mapping[5]) - assert_true(cG.has_edge(*edge)) + assert cG.has_edge(*edge) edge = (mapping[3], mapping[5]) - assert_true(cG.has_edge(*edge)) + assert cG.has_edge(*edge) def test_contract_scc_isolate(self): # Bug found and fixed in [1687]. @@ -108,8 +108,8 @@ class TestStronglyConnected: G.add_edge(2, 1) scc = list(nx.strongly_connected_components(G)) cG = nx.condensation(G, scc) - assert_equal(list(cG.nodes()), [0]) - assert_equal(list(cG.edges()), []) + assert list(cG.nodes()) == [0] + assert list(cG.edges()) == [] def test_contract_scc_edge(self): G = nx.DiGraph() @@ -120,30 +120,30 @@ class TestStronglyConnected: G.add_edge(4, 3) scc = list(nx.strongly_connected_components(G)) cG = nx.condensation(G, scc) - assert_equal(sorted(cG.nodes()), [0, 1]) + assert sorted(cG.nodes()) == [0, 1] if 1 in scc[0]: edge = (0, 1) else: edge = (1, 0) - assert_equal(list(cG.edges()), [edge]) + assert list(cG.edges()) == [edge] def test_condensation_mapping_and_members(self): G, C = self.gc[1] C = sorted(C, key=len, reverse=True) cG = nx.condensation(G) mapping = cG.graph['mapping'] - assert_true(all(n in G for n in mapping)) - assert_true(all(0 == cN for n, cN in mapping.items() if n in C[0])) - assert_true(all(1 == cN for n, cN in mapping.items() if n in C[1])) + assert all(n in G for n in mapping) + assert all(0 == cN for n, cN in mapping.items() if n in C[0]) + assert all(1 == cN for n, cN in mapping.items() if n in C[1]) for n, d in cG.nodes(data=True): - assert_equal(set(C[n]), cG.nodes[n]['members']) + assert set(C[n]) == cG.nodes[n]['members'] def test_null_graph(self): G = nx.DiGraph() - assert_equal(list(nx.strongly_connected_components(G)), []) - assert_equal(list(nx.kosaraju_strongly_connected_components(G)), []) - assert_equal(list(nx.strongly_connected_components_recursive(G)), []) - assert_equal(len(nx.condensation(G)), 0) + assert list(nx.strongly_connected_components(G)) == [] + assert list(nx.kosaraju_strongly_connected_components(G)) == [] + assert list(nx.strongly_connected_components_recursive(G)) == [] + assert len(nx.condensation(G)) == 0 assert_raises(nx.NetworkXPointlessConcept, nx.is_strongly_connected, nx.DiGraph()) def test_connected_raise(self): diff --git a/networkx/algorithms/components/tests/test_subgraph_copies.py b/networkx/algorithms/components/tests/test_subgraph_copies.py index f61a0e82..8acf4753 100644 --- a/networkx/algorithms/components/tests/test_subgraph_copies.py +++ b/networkx/algorithms/components/tests/test_subgraph_copies.py @@ -39,50 +39,50 @@ class TestSubgraphAttributesDicts: for subgraph_func in self.subgraph_funcs: G = deepcopy(self.G if subgraph_func in self.undirected else self.D) SG = list(subgraph_func(G))[0] - assert_equal(SG[1][2]['eattr'], 'red') - assert_equal(SG.nodes[1]['nattr'], 'blue') - assert_equal(SG.graph['gattr'], 'green') + assert SG[1][2]['eattr'] == 'red' + assert SG.nodes[1]['nattr'] == 'blue' + assert SG.graph['gattr'] == 'green' SG[1][2]['eattr'] = 'foo' - assert_equal(G[1][2]['eattr'], 'red') - assert_equal(SG[1][2]['eattr'], 'foo') + assert G[1][2]['eattr'] == 'red' + assert SG[1][2]['eattr'] == 'foo' SG.nodes[1]['nattr'] = 'bar' - assert_equal(G.nodes[1]['nattr'], 'blue') - assert_equal(SG.nodes[1]['nattr'], 'bar') + assert G.nodes[1]['nattr'] == 'blue' + assert SG.nodes[1]['nattr'] == 'bar' SG.graph['gattr'] = 'baz' - assert_equal(G.graph['gattr'], 'green') - assert_equal(SG.graph['gattr'], 'baz') + assert G.graph['gattr'] == 'green' + assert SG.graph['gattr'] == 'baz' def test_subgraphs_copy(self): for subgraph_func in self.subgraph_funcs: test_graph = self.G if subgraph_func in self.undirected else self.D G = deepcopy(test_graph) SG = list(subgraph_func(G, copy=True))[0] - assert_equal(SG[1][2]['eattr'], 'red') - assert_equal(SG.nodes[1]['nattr'], 'blue') - assert_equal(SG.graph['gattr'], 'green') + assert SG[1][2]['eattr'] == 'red' + assert SG.nodes[1]['nattr'] == 'blue' + assert SG.graph['gattr'] == 'green' SG[1][2]['eattr'] = 'foo' - assert_equal(G[1][2]['eattr'], 'red') - assert_equal(SG[1][2]['eattr'], 'foo') + assert G[1][2]['eattr'] == 'red' + assert SG[1][2]['eattr'] == 'foo' SG.nodes[1]['nattr'] = 'bar' - assert_equal(G.nodes[1]['nattr'], 'blue') - assert_equal(SG.nodes[1]['nattr'], 'bar') + assert G.nodes[1]['nattr'] == 'blue' + assert SG.nodes[1]['nattr'] == 'bar' SG.graph['gattr'] = 'baz' - assert_equal(G.graph['gattr'], 'green') - assert_equal(SG.graph['gattr'], 'baz') + assert G.graph['gattr'] == 'green' + assert SG.graph['gattr'] == 'baz' def test_subgraphs_no_copy(self): for subgraph_func in self.subgraph_funcs: G = deepcopy(self.G if subgraph_func in self.undirected else self.D) SG = list(subgraph_func(G, copy=False))[0] - assert_equal(SG[1][2]['eattr'], 'red') - assert_equal(SG.nodes[1]['nattr'], 'blue') - assert_equal(SG.graph['gattr'], 'green') + assert SG[1][2]['eattr'] == 'red' + assert SG.nodes[1]['nattr'] == 'blue' + assert SG.graph['gattr'] == 'green' SG[1][2]['eattr'] = 'foo' - assert_equal(G[1][2]['eattr'], 'foo') - assert_equal(SG[1][2]['eattr'], 'foo') + assert G[1][2]['eattr'] == 'foo' + assert SG[1][2]['eattr'] == 'foo' SG.nodes[1]['nattr'] = 'bar' - assert_equal(G.nodes[1]['nattr'], 'bar') - assert_equal(SG.nodes[1]['nattr'], 'bar') + assert G.nodes[1]['nattr'] == 'bar' + assert SG.nodes[1]['nattr'] == 'bar' SG.graph['gattr'] = 'baz' - assert_equal(G.graph['gattr'], 'baz') - assert_equal(SG.graph['gattr'], 'baz') + assert G.graph['gattr'] == 'baz' + assert SG.graph['gattr'] == 'baz' diff --git a/networkx/algorithms/components/tests/test_weakly_connected.py b/networkx/algorithms/components/tests/test_weakly_connected.py index ac3bcf38..b7f4f3a5 100644 --- a/networkx/algorithms/components/tests/test_weakly_connected.py +++ b/networkx/algorithms/components/tests/test_weakly_connected.py @@ -39,14 +39,14 @@ class TestWeaklyConnected: U = G.to_undirected() w = {frozenset(g) for g in nx.weakly_connected_components(G)} c = {frozenset(g) for g in nx.connected_components(U)} - assert_equal(w, c) + assert w == c def test_number_weakly_connected_components(self): for G, C in self.gc: U = G.to_undirected() w = nx.number_weakly_connected_components(G) c = nx.number_connected_components(U) - assert_equal(w, c) + assert w == c # deprecated def test_weakly_connected_component_subgraphs(self): @@ -56,17 +56,17 @@ class TestWeaklyConnected: U = G.to_undirected() w = {frozenset(g) for g in wcc(G)} c = {frozenset(g) for g in cc(U)} - assert_equal(w, c) + assert w == c def test_is_weakly_connected(self): for G, C in self.gc: U = G.to_undirected() - assert_equal(nx.is_weakly_connected(G), nx.is_connected(U)) + assert nx.is_weakly_connected(G) == nx.is_connected(U) def test_null_graph(self): G = nx.DiGraph() - assert_equal(list(nx.weakly_connected_components(G)), []) - assert_equal(nx.number_weakly_connected_components(G), 0) + assert list(nx.weakly_connected_components(G)) == [] + assert nx.number_weakly_connected_components(G) == 0 assert_raises(nx.NetworkXPointlessConcept, nx.is_weakly_connected, G) def test_connected_raise(self): diff --git a/networkx/algorithms/connectivity/tests/test_connectivity.py b/networkx/algorithms/connectivity/tests/test_connectivity.py index bb4850f2..dc3f8437 100644 --- a/networkx/algorithms/connectivity/tests/test_connectivity.py +++ b/networkx/algorithms/connectivity/tests/test_connectivity.py @@ -47,19 +47,15 @@ def test_average_connectivity(): G3 = nx.Graph() for flow_func in flow_funcs: kwargs = dict(flow_func=flow_func) - assert_equal(nx.average_node_connectivity(G1, **kwargs), 1, - msg=msg.format(flow_func.__name__)) - assert_equal(nx.average_node_connectivity(G2, **kwargs), 2.2, - msg=msg.format(flow_func.__name__)) - assert_equal(nx.average_node_connectivity(G3, **kwargs), 0, - msg=msg.format(flow_func.__name__)) + assert nx.average_node_connectivity(G1, **kwargs) == 1, msg.format(flow_func.__name__) + assert nx.average_node_connectivity(G2, **kwargs) == 2.2, msg.format(flow_func.__name__) + assert nx.average_node_connectivity(G3, **kwargs) == 0, msg.format(flow_func.__name__) def test_average_connectivity_directed(): G = nx.DiGraph([(1, 3), (1, 4), (1, 5)]) for flow_func in flow_funcs: - assert_equal(nx.average_node_connectivity(G), 0.25, - msg=msg.format(flow_func.__name__)) + assert nx.average_node_connectivity(G) == 0.25, msg.format(flow_func.__name__) def test_articulation_points(): @@ -67,8 +63,7 @@ def test_articulation_points(): for flow_func in flow_funcs: for i in range(3): G = next(Ggen) - assert_equal(nx.node_connectivity(G, flow_func=flow_func), 1, - msg=msg.format(flow_func.__name__)) + assert nx.node_connectivity(G, flow_func=flow_func) == 1, msg.format(flow_func.__name__) def test_brandes_erlebach(): @@ -80,18 +75,12 @@ def test_brandes_erlebach(): (7, 10), (8, 11), (9, 10), (9, 11), (10, 11)]) for flow_func in flow_funcs: kwargs = dict(flow_func=flow_func) - assert_equal(3, local_edge_connectivity(G, 1, 11, **kwargs), - msg=msg.format(flow_func.__name__)) - assert_equal(3, nx.edge_connectivity(G, 1, 11, **kwargs), - msg=msg.format(flow_func.__name__)) - assert_equal(2, local_node_connectivity(G, 1, 11, **kwargs), - msg=msg.format(flow_func.__name__)) - assert_equal(2, nx.node_connectivity(G, 1, 11, **kwargs), - msg=msg.format(flow_func.__name__)) - assert_equal(2, nx.edge_connectivity(G, **kwargs), # node 5 has degree 2 - msg=msg.format(flow_func.__name__)) - assert_equal(2, nx.node_connectivity(G, **kwargs), - msg=msg.format(flow_func.__name__)) + assert 3 == local_edge_connectivity(G, 1, 11, **kwargs), msg.format(flow_func.__name__) + assert 3 == nx.edge_connectivity(G, 1, 11, **kwargs), msg.format(flow_func.__name__) + assert 2 == local_node_connectivity(G, 1, 11, **kwargs), msg.format(flow_func.__name__) + assert 2 == nx.node_connectivity(G, 1, 11, **kwargs), msg.format(flow_func.__name__) + assert 2 == nx.edge_connectivity(G, **kwargs), msg.format(flow_func.__name__) + assert 2 == nx.node_connectivity(G, **kwargs), msg.format(flow_func.__name__) def test_white_harary_1(): @@ -108,10 +97,8 @@ def test_white_harary_1(): for i in range(7, 10): G.add_edge(0, i) for flow_func in flow_funcs: - assert_equal(1, nx.node_connectivity(G, flow_func=flow_func), - msg=msg.format(flow_func.__name__)) - assert_equal(3, nx.edge_connectivity(G, flow_func=flow_func), - msg=msg.format(flow_func.__name__)) + assert 1 == nx.node_connectivity(G, flow_func=flow_func), msg.format(flow_func.__name__) + assert 3 == nx.edge_connectivity(G, flow_func=flow_func), msg.format(flow_func.__name__) def test_white_harary_2(): @@ -120,83 +107,65 @@ def test_white_harary_2(): G = nx.disjoint_union(nx.complete_graph(4), nx.complete_graph(4)) G.add_edge(0, 4) # kappa <= lambda <= delta - assert_equal(3, min(nx.core_number(G).values())) + assert 3 == min(nx.core_number(G).values()) for flow_func in flow_funcs: - assert_equal(1, nx.node_connectivity(G, flow_func=flow_func), - msg=msg.format(flow_func.__name__)) - assert_equal(1, nx.edge_connectivity(G, flow_func=flow_func), - msg=msg.format(flow_func.__name__)) + assert 1 == nx.node_connectivity(G, flow_func=flow_func), msg.format(flow_func.__name__) + assert 1 == nx.edge_connectivity(G, flow_func=flow_func), msg.format(flow_func.__name__) def test_complete_graphs(): for n in range(5, 20, 5): for flow_func in flow_funcs: G = nx.complete_graph(n) - assert_equal(n - 1, nx.node_connectivity(G, flow_func=flow_func), - msg=msg.format(flow_func.__name__)) - assert_equal(n - 1, nx.node_connectivity(G.to_directed(), - flow_func=flow_func), - msg=msg.format(flow_func.__name__)) - assert_equal(n - 1, nx.edge_connectivity(G, flow_func=flow_func), - msg=msg.format(flow_func.__name__)) - assert_equal(n - 1, nx.edge_connectivity(G.to_directed(), - flow_func=flow_func), - msg=msg.format(flow_func.__name__)) + assert n - 1 == nx.node_connectivity(G, flow_func=flow_func), msg.format(flow_func.__name__) + assert n - 1 == nx.node_connectivity(G.to_directed(), + flow_func=flow_func), msg.format(flow_func.__name__) + assert n - 1 == nx.edge_connectivity(G, flow_func=flow_func), msg.format(flow_func.__name__) + assert n - 1 == nx.edge_connectivity(G.to_directed(), + flow_func=flow_func), msg.format(flow_func.__name__) def test_empty_graphs(): for k in range(5, 25, 5): G = nx.empty_graph(k) for flow_func in flow_funcs: - assert_equal(0, nx.node_connectivity(G, flow_func=flow_func), - msg=msg.format(flow_func.__name__)) - assert_equal(0, nx.edge_connectivity(G, flow_func=flow_func), - msg=msg.format(flow_func.__name__)) + assert 0 == nx.node_connectivity(G, flow_func=flow_func), msg.format(flow_func.__name__) + assert 0 == nx.edge_connectivity(G, flow_func=flow_func), msg.format(flow_func.__name__) def test_petersen(): G = nx.petersen_graph() for flow_func in flow_funcs: - assert_equal(3, nx.node_connectivity(G, flow_func=flow_func), - msg=msg.format(flow_func.__name__)) - assert_equal(3, nx.edge_connectivity(G, flow_func=flow_func), - msg=msg.format(flow_func.__name__)) + assert 3 == nx.node_connectivity(G, flow_func=flow_func), msg.format(flow_func.__name__) + assert 3 == nx.edge_connectivity(G, flow_func=flow_func), msg.format(flow_func.__name__) def test_tutte(): G = nx.tutte_graph() for flow_func in flow_funcs: - assert_equal(3, nx.node_connectivity(G, flow_func=flow_func), - msg=msg.format(flow_func.__name__)) - assert_equal(3, nx.edge_connectivity(G, flow_func=flow_func), - msg=msg.format(flow_func.__name__)) + assert 3 == nx.node_connectivity(G, flow_func=flow_func), msg.format(flow_func.__name__) + assert 3 == nx.edge_connectivity(G, flow_func=flow_func), msg.format(flow_func.__name__) def test_dodecahedral(): G = nx.dodecahedral_graph() for flow_func in flow_funcs: - assert_equal(3, nx.node_connectivity(G, flow_func=flow_func), - msg=msg.format(flow_func.__name__)) - assert_equal(3, nx.edge_connectivity(G, flow_func=flow_func), - msg=msg.format(flow_func.__name__)) + assert 3 == nx.node_connectivity(G, flow_func=flow_func), msg.format(flow_func.__name__) + assert 3 == nx.edge_connectivity(G, flow_func=flow_func), msg.format(flow_func.__name__) def test_octahedral(): G = nx.octahedral_graph() for flow_func in flow_funcs: - assert_equal(4, nx.node_connectivity(G, flow_func=flow_func), - msg=msg.format(flow_func.__name__)) - assert_equal(4, nx.edge_connectivity(G, flow_func=flow_func), - msg=msg.format(flow_func.__name__)) + assert 4 == nx.node_connectivity(G, flow_func=flow_func), msg.format(flow_func.__name__) + assert 4 == nx.edge_connectivity(G, flow_func=flow_func), msg.format(flow_func.__name__) def test_icosahedral(): G = nx.icosahedral_graph() for flow_func in flow_funcs: - assert_equal(5, nx.node_connectivity(G, flow_func=flow_func), - msg=msg.format(flow_func.__name__)) - assert_equal(5, nx.edge_connectivity(G, flow_func=flow_func), - msg=msg.format(flow_func.__name__)) + assert 5 == nx.node_connectivity(G, flow_func=flow_func), msg.format(flow_func.__name__) + assert 5 == nx.edge_connectivity(G, flow_func=flow_func), msg.format(flow_func.__name__) def test_missing_source(): @@ -232,10 +201,8 @@ def test_not_weakly_connected(): nx.add_path(G, [1, 2, 3]) nx.add_path(G, [4, 5]) for flow_func in flow_funcs: - assert_equal(nx.node_connectivity(G), 0, - msg=msg.format(flow_func.__name__)) - assert_equal(nx.edge_connectivity(G), 0, - msg=msg.format(flow_func.__name__)) + assert nx.node_connectivity(G) == 0, msg.format(flow_func.__name__) + assert nx.edge_connectivity(G) == 0, msg.format(flow_func.__name__) def test_not_connected(): @@ -243,28 +210,20 @@ def test_not_connected(): nx.add_path(G, [1, 2, 3]) nx.add_path(G, [4, 5]) for flow_func in flow_funcs: - assert_equal(nx.node_connectivity(G), 0, - msg=msg.format(flow_func.__name__)) - assert_equal(nx.edge_connectivity(G), 0, - msg=msg.format(flow_func.__name__)) + assert nx.node_connectivity(G) == 0, msg.format(flow_func.__name__) + assert nx.edge_connectivity(G) == 0, msg.format(flow_func.__name__) def test_directed_edge_connectivity(): G = nx.cycle_graph(10, create_using=nx.DiGraph()) # only one direction D = nx.cycle_graph(10).to_directed() # 2 reciprocal edges for flow_func in flow_funcs: - assert_equal(1, nx.edge_connectivity(G, flow_func=flow_func), - msg=msg.format(flow_func.__name__)) - assert_equal(1, local_edge_connectivity(G, 1, 4, flow_func=flow_func), - msg=msg.format(flow_func.__name__)) - assert_equal(1, nx.edge_connectivity(G, 1, 4, flow_func=flow_func), - msg=msg.format(flow_func.__name__)) - assert_equal(2, nx.edge_connectivity(D, flow_func=flow_func), - msg=msg.format(flow_func.__name__)) - assert_equal(2, local_edge_connectivity(D, 1, 4, flow_func=flow_func), - msg=msg.format(flow_func.__name__)) - assert_equal(2, nx.edge_connectivity(D, 1, 4, flow_func=flow_func), - msg=msg.format(flow_func.__name__)) + assert 1 == nx.edge_connectivity(G, flow_func=flow_func), msg.format(flow_func.__name__) + assert 1 == local_edge_connectivity(G, 1, 4, flow_func=flow_func), msg.format(flow_func.__name__) + assert 1 == nx.edge_connectivity(G, 1, 4, flow_func=flow_func), msg.format(flow_func.__name__) + assert 2 == nx.edge_connectivity(D, flow_func=flow_func), msg.format(flow_func.__name__) + assert 2 == local_edge_connectivity(D, 1, 4, flow_func=flow_func), msg.format(flow_func.__name__) + assert 2 == nx.edge_connectivity(D, 1, 4, flow_func=flow_func), msg.format(flow_func.__name__) def test_cutoff(): @@ -276,8 +235,7 @@ def test_cutoff(): continue for cutoff in [3, 2, 1]: result = local_func(G, 0, 4, flow_func=flow_func, cutoff=cutoff) - assert_equal(cutoff, result, - msg="cutoff error in {0}".format(flow_func.__name__)) + assert cutoff == result, "cutoff error in {0}".format(flow_func.__name__) def test_invalid_auxiliary(): @@ -306,7 +264,7 @@ def test_edge_connectivity_flow_vs_stoer_wagner(): ] for graph_func in graph_funcs: G = graph_func() - assert_equal(nx.stoer_wagner(G)[0], nx.edge_connectivity(G)) + assert nx.stoer_wagner(G)[0] == nx.edge_connectivity(G) class TestAllPairsNodeConnectivity: @@ -330,42 +288,42 @@ class TestAllPairsNodeConnectivity: K_undir = nx.all_pairs_node_connectivity(self.cycle) for source in K_undir: for target, k in K_undir[source].items(): - assert_true(k == 2) + assert k == 2 K_dir = nx.all_pairs_node_connectivity(self.directed_cycle) for source in K_dir: for target, k in K_dir[source].items(): - assert_true(k == 1) + assert k == 1 def test_complete(self): for G in [self.K10, self.K5, self.K20]: K = nx.all_pairs_node_connectivity(G) for source in K: for target, k in K[source].items(): - assert_true(k == len(G) - 1) + assert k == len(G) - 1 def test_paths(self): K_undir = nx.all_pairs_node_connectivity(self.path) for source in K_undir: for target, k in K_undir[source].items(): - assert_true(k == 1) + assert k == 1 K_dir = nx.all_pairs_node_connectivity(self.directed_path) for source in K_dir: for target, k in K_dir[source].items(): if source < target: - assert_true(k == 1) + assert k == 1 else: - assert_true(k == 0) + assert k == 0 def test_all_pairs_connectivity_nbunch(self): G = nx.complete_graph(5) nbunch = [0, 2, 3] C = nx.all_pairs_node_connectivity(G, nbunch=nbunch) - assert_equal(len(C), len(nbunch)) + assert len(C) == len(nbunch) def test_all_pairs_connectivity_icosahedral(self): G = nx.icosahedral_graph() C = nx.all_pairs_node_connectivity(G) - assert_true(all(5 == C[u][v] for u, v in itertools.combinations(G, 2))) + assert all(5 == C[u][v] for u, v in itertools.combinations(G, 2)) def test_all_pairs_connectivity(self): G = nx.Graph() @@ -375,7 +333,7 @@ class TestAllPairsNodeConnectivity: for u, v in itertools.combinations(nodes, 2): A[u][v] = A[v][u] = nx.node_connectivity(G, u, v) C = nx.all_pairs_node_connectivity(G) - assert_equal(sorted((k, sorted(v)) for k, v in A.items()), + assert (sorted((k, sorted(v)) for k, v in A.items()) == sorted((k, sorted(v)) for k, v in C.items())) def test_all_pairs_connectivity_directed(self): @@ -386,7 +344,7 @@ class TestAllPairsNodeConnectivity: for u, v in itertools.permutations(nodes, 2): A[u][v] = nx.node_connectivity(G, u, v) C = nx.all_pairs_node_connectivity(G) - assert_equal(sorted((k, sorted(v)) for k, v in A.items()), + assert (sorted((k, sorted(v)) for k, v in A.items()) == sorted((k, sorted(v)) for k, v in C.items())) def test_all_pairs_connectivity_nbunch_combinations(self): @@ -396,7 +354,7 @@ class TestAllPairsNodeConnectivity: for u, v in itertools.combinations(nbunch, 2): A[u][v] = A[v][u] = nx.node_connectivity(G, u, v) C = nx.all_pairs_node_connectivity(G, nbunch=nbunch) - assert_equal(sorted((k, sorted(v)) for k, v in A.items()), + assert (sorted((k, sorted(v)) for k, v in A.items()) == sorted((k, sorted(v)) for k, v in C.items())) def test_all_pairs_connectivity_nbunch_iter(self): @@ -406,5 +364,5 @@ class TestAllPairsNodeConnectivity: for u, v in itertools.combinations(nbunch, 2): A[u][v] = A[v][u] = nx.node_connectivity(G, u, v) C = nx.all_pairs_node_connectivity(G, nbunch=iter(nbunch)) - assert_equal(sorted((k, sorted(v)) for k, v in A.items()), + assert (sorted((k, sorted(v)) for k, v in A.items()) == sorted((k, sorted(v)) for k, v in C.items())) diff --git a/networkx/algorithms/connectivity/tests/test_cuts.py b/networkx/algorithms/connectivity/tests/test_cuts.py index 0793e403..002f5a84 100644 --- a/networkx/algorithms/connectivity/tests/test_cuts.py +++ b/networkx/algorithms/connectivity/tests/test_cuts.py @@ -40,9 +40,8 @@ def test_articulation_points(): for i in range(1): # change 1 to 3 or more for more realizations. G = next(Ggen) cut = nx.minimum_node_cut(G, flow_func=flow_func) - assert_true(len(cut) == 1, msg=msg.format(flow_func.__name__)) - assert_true(cut.pop() in set(nx.articulation_points(G)), - msg=msg.format(flow_func.__name__)) + assert len(cut) == 1, msg.format(flow_func.__name__) + assert cut.pop() in set(nx.articulation_points(G)), msg.format(flow_func.__name__) def test_brandes_erlebach_book(): @@ -55,24 +54,21 @@ def test_brandes_erlebach_book(): for flow_func in flow_funcs: kwargs = dict(flow_func=flow_func) # edge cutsets - assert_equal(3, len(nx.minimum_edge_cut(G, 1, 11, **kwargs)), - msg=msg.format(flow_func.__name__)) + assert 3 == len(nx.minimum_edge_cut(G, 1, 11, **kwargs)), msg.format(flow_func.__name__) edge_cut = nx.minimum_edge_cut(G, **kwargs) # Node 5 has only two edges - assert_equal(2, len(edge_cut), msg=msg.format(flow_func.__name__)) + assert 2 == len(edge_cut), msg.format(flow_func.__name__) H = G.copy() H.remove_edges_from(edge_cut) - assert_false(nx.is_connected(H), msg=msg.format(flow_func.__name__)) + assert not nx.is_connected(H), msg.format(flow_func.__name__) # node cuts - assert_equal(set([6, 7]), minimum_st_node_cut(G, 1, 11, **kwargs), - msg=msg.format(flow_func.__name__)) - assert_equal(set([6, 7]), nx.minimum_node_cut(G, 1, 11, **kwargs), - msg=msg.format(flow_func.__name__)) + assert set([6, 7]) == minimum_st_node_cut(G, 1, 11, **kwargs), msg.format(flow_func.__name__) + assert set([6, 7]) == nx.minimum_node_cut(G, 1, 11, **kwargs), msg.format(flow_func.__name__) node_cut = nx.minimum_node_cut(G, **kwargs) - assert_equal(2, len(node_cut), msg=msg.format(flow_func.__name__)) + assert 2 == len(node_cut), msg.format(flow_func.__name__) H = G.copy() H.remove_nodes_from(node_cut) - assert_false(nx.is_connected(H), msg=msg.format(flow_func.__name__)) + assert not nx.is_connected(H), msg.format(flow_func.__name__) def test_white_harary_paper(): @@ -92,16 +88,16 @@ def test_white_harary_paper(): kwargs = dict(flow_func=flow_func) # edge cuts edge_cut = nx.minimum_edge_cut(G, **kwargs) - assert_equal(3, len(edge_cut), msg=msg.format(flow_func.__name__)) + assert 3 == len(edge_cut), msg.format(flow_func.__name__) H = G.copy() H.remove_edges_from(edge_cut) - assert_false(nx.is_connected(H), msg=msg.format(flow_func.__name__)) + assert not nx.is_connected(H), msg.format(flow_func.__name__) # node cuts node_cut = nx.minimum_node_cut(G, **kwargs) - assert_equal(set([0]), node_cut, msg=msg.format(flow_func.__name__)) + assert set([0]) == node_cut, msg.format(flow_func.__name__) H = G.copy() H.remove_nodes_from(node_cut) - assert_false(nx.is_connected(H), msg=msg.format(flow_func.__name__)) + assert not nx.is_connected(H), msg.format(flow_func.__name__) def test_petersen_cutset(): @@ -110,16 +106,16 @@ def test_petersen_cutset(): kwargs = dict(flow_func=flow_func) # edge cuts edge_cut = nx.minimum_edge_cut(G, **kwargs) - assert_equal(3, len(edge_cut), msg=msg.format(flow_func.__name__)) + assert 3 == len(edge_cut), msg.format(flow_func.__name__) H = G.copy() H.remove_edges_from(edge_cut) - assert_false(nx.is_connected(H), msg=msg.format(flow_func.__name__)) + assert not nx.is_connected(H), msg.format(flow_func.__name__) # node cuts node_cut = nx.minimum_node_cut(G, **kwargs) - assert_equal(3, len(node_cut), msg=msg.format(flow_func.__name__)) + assert 3 == len(node_cut), msg.format(flow_func.__name__) H = G.copy() H.remove_nodes_from(node_cut) - assert_false(nx.is_connected(H), msg=msg.format(flow_func.__name__)) + assert not nx.is_connected(H), msg.format(flow_func.__name__) def test_octahedral_cutset(): @@ -128,16 +124,16 @@ def test_octahedral_cutset(): kwargs = dict(flow_func=flow_func) # edge cuts edge_cut = nx.minimum_edge_cut(G, **kwargs) - assert_equal(4, len(edge_cut), msg=msg.format(flow_func.__name__)) + assert 4 == len(edge_cut), msg.format(flow_func.__name__) H = G.copy() H.remove_edges_from(edge_cut) - assert_false(nx.is_connected(H), msg=msg.format(flow_func.__name__)) + assert not nx.is_connected(H), msg.format(flow_func.__name__) # node cuts node_cut = nx.minimum_node_cut(G, **kwargs) - assert_equal(4, len(node_cut), msg=msg.format(flow_func.__name__)) + assert 4 == len(node_cut), msg.format(flow_func.__name__) H = G.copy() H.remove_nodes_from(node_cut) - assert_false(nx.is_connected(H), msg=msg.format(flow_func.__name__)) + assert not nx.is_connected(H), msg.format(flow_func.__name__) def test_icosahedral_cutset(): @@ -146,16 +142,16 @@ def test_icosahedral_cutset(): kwargs = dict(flow_func=flow_func) # edge cuts edge_cut = nx.minimum_edge_cut(G, **kwargs) - assert_equal(5, len(edge_cut), msg=msg.format(flow_func.__name__)) + assert 5 == len(edge_cut), msg.format(flow_func.__name__) H = G.copy() H.remove_edges_from(edge_cut) - assert_false(nx.is_connected(H), msg=msg.format(flow_func.__name__)) + assert not nx.is_connected(H), msg.format(flow_func.__name__) # node cuts node_cut = nx.minimum_node_cut(G, **kwargs) - assert_equal(5, len(node_cut), msg=msg.format(flow_func.__name__)) + assert 5 == len(node_cut), msg.format(flow_func.__name__) H = G.copy() H.remove_nodes_from(node_cut) - assert_false(nx.is_connected(H), msg=msg.format(flow_func.__name__)) + assert not nx.is_connected(H), msg.format(flow_func.__name__) def test_node_cutset_exception(): @@ -174,10 +170,9 @@ def test_node_cutset_random_graphs(): start = arbitrary_element(next(ccs)) G.add_edges_from((start, arbitrary_element(c)) for c in ccs) cutset = nx.minimum_node_cut(G, flow_func=flow_func) - assert_equal(nx.node_connectivity(G), len(cutset), - msg=msg.format(flow_func.__name__)) + assert nx.node_connectivity(G) == len(cutset), msg.format(flow_func.__name__) G.remove_nodes_from(cutset) - assert_false(nx.is_connected(G), msg=msg.format(flow_func.__name__)) + assert not nx.is_connected(G), msg.format(flow_func.__name__) def test_edge_cutset_random_graphs(): @@ -189,10 +184,9 @@ def test_edge_cutset_random_graphs(): start = arbitrary_element(next(ccs)) G.add_edges_from((start, arbitrary_element(c)) for c in ccs) cutset = nx.minimum_edge_cut(G, flow_func=flow_func) - assert_equal(nx.edge_connectivity(G), len(cutset), - msg=msg.format(flow_func.__name__)) + assert nx.edge_connectivity(G) == len(cutset), msg.format(flow_func.__name__) G.remove_edges_from(cutset) - assert_false(nx.is_connected(G), msg=msg.format(flow_func.__name__)) + assert not nx.is_connected(G), msg.format(flow_func.__name__) def test_empty_graphs(): @@ -209,7 +203,7 @@ def test_empty_graphs(): def test_unbounded(): G = nx.complete_graph(5) for flow_func in flow_funcs: - assert_equal(4, len(minimum_st_edge_cut(G, 1, 4, flow_func=flow_func))) + assert 4 == len(minimum_st_edge_cut(G, 1, 4, flow_func=flow_func)) def test_missing_source(): @@ -252,7 +246,7 @@ def tests_min_cut_complete(): G = nx.complete_graph(5) for interface_func in [nx.minimum_edge_cut, nx.minimum_node_cut]: for flow_func in flow_funcs: - assert_equal(4, len(interface_func(G, flow_func=flow_func))) + assert 4 == len(interface_func(G, flow_func=flow_func)) def tests_min_cut_complete_directed(): @@ -260,7 +254,7 @@ def tests_min_cut_complete_directed(): G = G.to_directed() for interface_func in [nx.minimum_edge_cut, nx.minimum_node_cut]: for flow_func in flow_funcs: - assert_equal(4, len(interface_func(G, flow_func=flow_func))) + assert 4 == len(interface_func(G, flow_func=flow_func)) def tests_minimum_st_node_cut(): diff --git a/networkx/algorithms/connectivity/tests/test_disjoint_paths.py b/networkx/algorithms/connectivity/tests/test_disjoint_paths.py index fd46ed00..895d11e7 100644 --- a/networkx/algorithms/connectivity/tests/test_disjoint_paths.py +++ b/networkx/algorithms/connectivity/tests/test_disjoint_paths.py @@ -31,7 +31,7 @@ def are_edge_disjoint_paths(G, paths): if not paths: return False for path in paths: - assert_true(is_path(G, path)) + assert is_path(G, path) paths_edges = [list(pairwise(p)) for p in paths] num_of_edges = sum(len(e) for e in paths_edges) num_unique_edges = len(set.union(*[set(es) for es in paths_edges])) @@ -44,7 +44,7 @@ def are_node_disjoint_paths(G, paths): if not paths: return False for path in paths: - assert_true(is_path(G, path)) + assert is_path(G, path) # first and last nodes are source and target st = {paths[0][0], paths[0][-1]} num_of_nodes = len([n for path in paths for n in path if n not in st]) @@ -65,20 +65,12 @@ def test_graph_from_pr_2053(): kwargs = dict(flow_func=flow_func) # edge disjoint paths edge_paths = list(nx.edge_disjoint_paths(G, 'A', 'Z', **kwargs)) - assert_true(are_edge_disjoint_paths(G, edge_paths), msg=msg.format(flow_func.__name__)) - assert_equal( - nx.edge_connectivity(G, 'A', 'Z'), - len(edge_paths), - msg=msg.format(flow_func.__name__), - ) + assert are_edge_disjoint_paths(G, edge_paths), msg.format(flow_func.__name__) + assert nx.edge_connectivity(G, 'A', 'Z') == len(edge_paths), msg.format(flow_func.__name__) # node disjoint paths node_paths = list(nx.node_disjoint_paths(G, 'A', 'Z', **kwargs)) - assert_true(are_node_disjoint_paths(G, node_paths), msg=msg.format(flow_func.__name__)) - assert_equal( - nx.node_connectivity(G, 'A', 'Z'), - len(node_paths), - msg=msg.format(flow_func.__name__), - ) + assert are_node_disjoint_paths(G, node_paths), msg.format(flow_func.__name__) + assert nx.node_connectivity(G, 'A', 'Z') == len(node_paths), msg.format(flow_func.__name__) def test_florentine_families(): @@ -87,20 +79,12 @@ def test_florentine_families(): kwargs = dict(flow_func=flow_func) # edge disjoint paths edge_dpaths = list(nx.edge_disjoint_paths(G, 'Medici', 'Strozzi', **kwargs)) - assert_true(are_edge_disjoint_paths(G, edge_dpaths), msg=msg.format(flow_func.__name__)) - assert_equal( - nx.edge_connectivity(G, 'Medici', 'Strozzi'), - len(edge_dpaths), - msg=msg.format(flow_func.__name__), - ) + assert are_edge_disjoint_paths(G, edge_dpaths), msg.format(flow_func.__name__) + assert nx.edge_connectivity(G, 'Medici', 'Strozzi') == len(edge_dpaths), msg.format(flow_func.__name__) # node disjoint paths node_dpaths = list(nx.node_disjoint_paths(G, 'Medici', 'Strozzi', **kwargs)) - assert_true(are_node_disjoint_paths(G, node_dpaths), msg=msg.format(flow_func.__name__)) - assert_equal( - nx.node_connectivity(G, 'Medici', 'Strozzi'), - len(node_dpaths), - msg=msg.format(flow_func.__name__), - ) + assert are_node_disjoint_paths(G, node_dpaths), msg.format(flow_func.__name__) + assert nx.node_connectivity(G, 'Medici', 'Strozzi') == len(node_dpaths), msg.format(flow_func.__name__) def test_karate(): @@ -109,20 +93,12 @@ def test_karate(): kwargs = dict(flow_func=flow_func) # edge disjoint paths edge_dpaths = list(nx.edge_disjoint_paths(G, 0, 33, **kwargs)) - assert_true(are_edge_disjoint_paths(G, edge_dpaths), msg=msg.format(flow_func.__name__)) - assert_equal( - nx.edge_connectivity(G, 0, 33), - len(edge_dpaths), - msg=msg.format(flow_func.__name__), - ) + assert are_edge_disjoint_paths(G, edge_dpaths), msg.format(flow_func.__name__) + assert nx.edge_connectivity(G, 0, 33) == len(edge_dpaths), msg.format(flow_func.__name__) # node disjoint paths node_dpaths = list(nx.node_disjoint_paths(G, 0, 33, **kwargs)) - assert_true(are_node_disjoint_paths(G, node_dpaths), msg=msg.format(flow_func.__name__)) - assert_equal( - nx.node_connectivity(G, 0, 33), - len(node_dpaths), - msg=msg.format(flow_func.__name__), - ) + assert are_node_disjoint_paths(G, node_dpaths), msg.format(flow_func.__name__) + assert nx.node_connectivity(G, 0, 33) == len(node_dpaths), msg.format(flow_func.__name__) def test_petersen_disjoint_paths(): @@ -131,12 +107,12 @@ def test_petersen_disjoint_paths(): kwargs = dict(flow_func=flow_func) # edge disjoint paths edge_dpaths = list(nx.edge_disjoint_paths(G, 0, 6, **kwargs)) - assert_true(are_edge_disjoint_paths(G, edge_dpaths), msg=msg.format(flow_func.__name__)) - assert_equal(3, len(edge_dpaths), msg=msg.format(flow_func.__name__)) + assert are_edge_disjoint_paths(G, edge_dpaths), msg.format(flow_func.__name__) + assert 3 == len(edge_dpaths), msg.format(flow_func.__name__) # node disjoint paths node_dpaths = list(nx.node_disjoint_paths(G, 0, 6, **kwargs)) - assert_true(are_node_disjoint_paths(G, node_dpaths), msg=msg.format(flow_func.__name__)) - assert_equal(3, len(node_dpaths), msg=msg.format(flow_func.__name__)) + assert are_node_disjoint_paths(G, node_dpaths), msg.format(flow_func.__name__) + assert 3 == len(node_dpaths), msg.format(flow_func.__name__) def test_octahedral_disjoint_paths(): @@ -145,12 +121,12 @@ def test_octahedral_disjoint_paths(): kwargs = dict(flow_func=flow_func) # edge disjoint paths edge_dpaths = list(nx.edge_disjoint_paths(G, 0, 5, **kwargs)) - assert_true(are_edge_disjoint_paths(G, edge_dpaths), msg=msg.format(flow_func.__name__)) - assert_equal(4, len(edge_dpaths), msg=msg.format(flow_func.__name__)) + assert are_edge_disjoint_paths(G, edge_dpaths), msg.format(flow_func.__name__) + assert 4 == len(edge_dpaths), msg.format(flow_func.__name__) # node disjoint paths node_dpaths = list(nx.node_disjoint_paths(G, 0, 5, **kwargs)) - assert_true(are_node_disjoint_paths(G, node_dpaths), msg=msg.format(flow_func.__name__)) - assert_equal(4, len(node_dpaths), msg=msg.format(flow_func.__name__)) + assert are_node_disjoint_paths(G, node_dpaths), msg.format(flow_func.__name__) + assert 4 == len(node_dpaths), msg.format(flow_func.__name__) def test_icosahedral_disjoint_paths(): @@ -159,12 +135,12 @@ def test_icosahedral_disjoint_paths(): kwargs = dict(flow_func=flow_func) # edge disjoint paths edge_dpaths = list(nx.edge_disjoint_paths(G, 0, 6, **kwargs)) - assert_true(are_edge_disjoint_paths(G, edge_dpaths), msg=msg.format(flow_func.__name__)) - assert_equal(5, len(edge_dpaths), msg=msg.format(flow_func.__name__)) + assert are_edge_disjoint_paths(G, edge_dpaths), msg.format(flow_func.__name__) + assert 5 == len(edge_dpaths), msg.format(flow_func.__name__) # node disjoint paths node_dpaths = list(nx.node_disjoint_paths(G, 0, 6, **kwargs)) - assert_true(are_node_disjoint_paths(G, node_dpaths), msg=msg.format(flow_func.__name__)) - assert_equal(5, len(node_dpaths), msg=msg.format(flow_func.__name__)) + assert are_node_disjoint_paths(G, node_dpaths), msg.format(flow_func.__name__) + assert 5 == len(node_dpaths), msg.format(flow_func.__name__) def test_cutoff_disjoint_paths(): @@ -175,12 +151,12 @@ def test_cutoff_disjoint_paths(): kwargs['cutoff'] = cutoff # edge disjoint paths edge_dpaths = list(nx.edge_disjoint_paths(G, 0, 6, **kwargs)) - assert_true(are_edge_disjoint_paths(G, edge_dpaths), msg=msg.format(flow_func.__name__)) - assert_equal(cutoff, len(edge_dpaths), msg=msg.format(flow_func.__name__)) + assert are_edge_disjoint_paths(G, edge_dpaths), msg.format(flow_func.__name__) + assert cutoff == len(edge_dpaths), msg.format(flow_func.__name__) # node disjoint paths node_dpaths = list(nx.node_disjoint_paths(G, 0, 6, **kwargs)) - assert_true(are_node_disjoint_paths(G, node_dpaths), msg=msg.format(flow_func.__name__)) - assert_equal(cutoff, len(node_dpaths), msg=msg.format(flow_func.__name__)) + assert are_node_disjoint_paths(G, node_dpaths), msg.format(flow_func.__name__) + assert cutoff == len(node_dpaths), msg.format(flow_func.__name__) @raises(nx.NetworkXError) diff --git a/networkx/algorithms/connectivity/tests/test_edge_augmentation.py b/networkx/algorithms/connectivity/tests/test_edge_augmentation.py index 2a0a1a6e..a9ecd5c2 100644 --- a/networkx/algorithms/connectivity/tests/test_edge_augmentation.py +++ b/networkx/algorithms/connectivity/tests/test_edge_augmentation.py @@ -65,19 +65,19 @@ def test_is_locally_k_edge_connected_exceptions(): def test_is_k_edge_connected(): G = nx.barbell_graph(10, 0) - assert_true(is_k_edge_connected(G, k=1)) - assert_false(is_k_edge_connected(G, k=2)) + assert is_k_edge_connected(G, k=1) + assert not is_k_edge_connected(G, k=2) G = nx.Graph() G.add_nodes_from([5, 15]) - assert_false(is_k_edge_connected(G, k=1)) - assert_false(is_k_edge_connected(G, k=2)) + assert not is_k_edge_connected(G, k=1) + assert not is_k_edge_connected(G, k=2) G = nx.complete_graph(5) - assert_true(is_k_edge_connected(G, k=1)) - assert_true(is_k_edge_connected(G, k=2)) - assert_true(is_k_edge_connected(G, k=3)) - assert_true(is_k_edge_connected(G, k=4)) + assert is_k_edge_connected(G, k=1) + assert is_k_edge_connected(G, k=2) + assert is_k_edge_connected(G, k=3) + assert is_k_edge_connected(G, k=4) def test_is_k_edge_connected_exceptions(): @@ -94,12 +94,12 @@ def test_is_k_edge_connected_exceptions(): def test_is_locally_k_edge_connected(): G = nx.barbell_graph(10, 0) - assert_true(is_locally_k_edge_connected(G, 5, 15, k=1)) - assert_false(is_locally_k_edge_connected(G, 5, 15, k=2)) + assert is_locally_k_edge_connected(G, 5, 15, k=1) + assert not is_locally_k_edge_connected(G, 5, 15, k=2) G = nx.Graph() G.add_nodes_from([5, 15]) - assert_false(is_locally_k_edge_connected(G, 5, 15, k=2)) + assert not is_locally_k_edge_connected(G, 5, 15, k=2) def test_null_graph(): @@ -151,7 +151,7 @@ def test_unfeasible(): # partial solutions should not error if real solutions are infeasible aug_edges = list(k_edge_augmentation(G, k=2, avail=[(7, 9)], partial=True)) - assert_equal(aug_edges, [(7, 9)]) + assert aug_edges == [(7, 9)] _check_augmentations(G, avail=[], max_k=MAX_EFFICIENT_K + 2) @@ -165,7 +165,7 @@ def test_tarjan(): print('aug_edges = {!r}'.format(aug_edges)) # can't assert edge exactly equality due to non-determinant edge order # but we do know the size of the solution must be 3 - assert_equal(len(aug_edges), 3) + assert len(aug_edges) == 3 avail = [(9, 7), (8, 5), (2, 10), (6, 13), (11, 18), (1, 17), (2, 3), (16, 17), (18, 14), (15, 14)] @@ -173,7 +173,7 @@ def test_tarjan(): # Can't assert exact length since approximation depends on the order of a # dict traversal. - assert_less_equal(len(aug_edges), 3 * 2) + assert len(aug_edges) <= 3 * 2 _check_augmentations(G, avail) @@ -245,19 +245,15 @@ def test_gnp_augmentation(): def _assert_solution_properties(G, aug_edges, avail_dict=None): """ Checks that aug_edges are consistently formatted """ if avail_dict is not None: - assert_true(all(e in avail_dict for e in aug_edges), - 'when avail is specified aug-edges should be in avail') + assert all(e in avail_dict for e in aug_edges), 'when avail is specified aug-edges should be in avail' unique_aug = set(map(tuple, map(sorted, aug_edges))) unique_aug = list(map(tuple, map(sorted, aug_edges))) - assert_true(len(aug_edges) == len(unique_aug), - 'edges should be unique') + assert len(aug_edges) == len(unique_aug), 'edges should be unique' - assert_false(any(u == v for u, v in unique_aug), - 'should be no self-edges') + assert not any(u == v for u, v in unique_aug), 'should be no self-edges' - assert_false(any(G.has_edge(u, v) for u, v in unique_aug), - 'aug edges and G.edges should be disjoint') + assert not any(G.has_edge(u, v) for u, v in unique_aug), 'aug edges and G.edges should be disjoint' def _augment_and_check(G, k, avail=None, weight=None, verbose=False, @@ -282,23 +278,21 @@ def _augment_and_check(G, k, avail=None, weight=None, verbose=False, # Find the augmentation if possible generator = nx.k_edge_augmentation(G, k=k, weight=weight, avail=avail) - assert_false(isinstance(generator, list), - 'should always return an iter') + assert not isinstance(generator, list), 'should always return an iter' aug_edges = [] for edge in generator: aug_edges.append(edge) except nx.NetworkXUnfeasible: infeasible = True info['infeasible'] = True - assert_equal(len(aug_edges), 0, - 'should not generate anything if unfeasible') + assert len(aug_edges) == 0, 'should not generate anything if unfeasible' if avail is None: n_nodes = G.number_of_nodes() - assert_less_equal(n_nodes, k, ( + assert n_nodes <= k, ( 'unconstrained cases are only unfeasible if |V| <= k. ' 'Got |V|={} and k={}'.format(n_nodes, k) - )) + ) else: if max_aug_k is None: G_aug_all = G.copy() @@ -308,9 +302,9 @@ def _augment_and_check(G, k, avail=None, weight=None, verbose=False, except nx.NetworkXPointlessConcept: max_aug_k = 0 - assert_less(max_aug_k, k, ( + assert max_aug_k < k, ( 'avail should only be unfeasible if using all edges ' - 'does not achieve k-edge-connectivity')) + 'does not achieve k-edge-connectivity') # Test for a partial solution partial_edges = list(nx.k_edge_augmentation( @@ -319,8 +313,8 @@ def _augment_and_check(G, k, avail=None, weight=None, verbose=False, info['n_partial_edges'] = len(partial_edges) if avail_dict is None: - assert_equal(set(partial_edges), set(complement_edges(G)), ( - 'unweighted partial solutions should be the complement')) + assert set(partial_edges) == set(complement_edges(G)), ( + 'unweighted partial solutions should be the complement') elif len(avail_dict) > 0: H = G.copy() @@ -333,8 +327,7 @@ def _augment_and_check(G, k, avail=None, weight=None, verbose=False, # Full connectivity should be no better than our partial # solution. - assert_equal(partial_conn, full_conn, - 'adding more edges should not increase k-conn') + assert partial_conn == full_conn, 'adding more edges should not increase k-conn' # Find the new edge-connectivity after adding the augmenting edges aug_edges = partial_edges @@ -362,11 +355,11 @@ def _augment_and_check(G, k, avail=None, weight=None, verbose=False, # Do checks if not infeasible and orig_k < k: - assert_greater_equal(info['aug_k'], k, ( - 'connectivity should increase to k={} or more'.format(k))) + assert info['aug_k'] >= k, ( + 'connectivity should increase to k={} or more'.format(k)) - assert_greater_equal(info['aug_k'], orig_k, ( - 'augmenting should never reduce connectivity')) + assert info['aug_k'] >= orig_k, ( + 'augmenting should never reduce connectivity') _assert_solution_properties(G, aug_edges, avail_dict) @@ -452,16 +445,16 @@ def _check_augmentations(G, avail=None, max_k=None, weight=None, # Check approximation ratios if k == 1: # when k=1, both solutions should be optimal - assert_equal(info2['total_weight'], info1['total_weight']) + assert info2['total_weight'] == info1['total_weight'] if k == 2: # when k=2, the weighted version is an approximation if orig_k == 0: # the approximation ratio is 3 if G is not connected - assert_less_equal(info2['total_weight'], + assert (info2['total_weight'] <= info1['total_weight'] * 3) else: # the approximation ratio is 2 if G is was connected - assert_less_equal(info2['total_weight'], + assert (info2['total_weight'] <= info1['total_weight'] * 2) _check_unconstrained_bridge_property(G, info1) @@ -478,5 +471,5 @@ def _check_unconstrained_bridge_property(G, info1): if p + q > 1: size_target = int(math.ceil(p / 2.0)) + q size_aug = info1['num_edges'] - assert_equal(size_aug, size_target, ( - 'augmentation size is different from what theory predicts')) + assert size_aug == size_target, ( + 'augmentation size is different from what theory predicts') diff --git a/networkx/algorithms/connectivity/tests/test_edge_kcomponents.py b/networkx/algorithms/connectivity/tests/test_edge_kcomponents.py index b4134b1d..6e20f04f 100644 --- a/networkx/algorithms/connectivity/tests/test_edge_kcomponents.py +++ b/networkx/algorithms/connectivity/tests/test_edge_kcomponents.py @@ -33,7 +33,7 @@ def _assert_subgraph_edge_connectivity(G, ccs_subgraph, k): C = G.subgraph(cc) if len(cc) > 1: connectivity = nx.edge_connectivity(C) - assert_greater_equal(connectivity, k) + assert connectivity >= k def _memo_connectivity(G, u, v, memo): @@ -55,7 +55,7 @@ def _all_pairs_connectivity(G, cc, k, memo): connectivity = _memo_connectivity(G, u, v, memo) if G.is_directed(): connectivity = min(connectivity, _memo_connectivity(G, v, u, memo)) - assert_greater_equal(connectivity, k) + assert connectivity >= k def _assert_local_cc_edge_connectivity(G, ccs_local, k, memo): @@ -100,33 +100,30 @@ def _check_edge_connectivity(G): _assert_subgraph_edge_connectivity(G, ccs_subgraph, k) if k == 1 or k == 2 and not G.is_directed(): - assert_equal(ccs_local, ccs_subgraph, - 'Subgraphs and components should be the same ' - 'when k == 1 or (k == 2 and not G.directed())') + assert ccs_local == ccs_subgraph, 'Subgraphs and components should be the same when k == 1 or (k == 2 and not G.directed())' if G.is_directed(): # Test special case methods are the same as the aux graph if k == 1: alt_sccs = fset(nx.strongly_connected_components(G)) - assert_equal(alt_sccs, ccs_local, 'k=1 failed alt') - assert_equal(alt_sccs, ccs_subgraph, 'k=1 failed alt') + assert alt_sccs == ccs_local, 'k=1 failed alt' + assert alt_sccs == ccs_subgraph, 'k=1 failed alt' else: # Test special case methods are the same as the aux graph if k == 1: alt_ccs = fset(nx.connected_components(G)) - assert_equal(alt_ccs, ccs_local, 'k=1 failed alt') - assert_equal(alt_ccs, ccs_subgraph, 'k=1 failed alt') + assert alt_ccs == ccs_local, 'k=1 failed alt' + assert alt_ccs == ccs_subgraph, 'k=1 failed alt' elif k == 2: alt_bridge_ccs = fset(bridge_components(G)) - assert_equal(alt_bridge_ccs, ccs_local, 'k=2 failed alt') - assert_equal(alt_bridge_ccs, ccs_subgraph, 'k=2 failed alt') + assert alt_bridge_ccs == ccs_local, 'k=2 failed alt' + assert alt_bridge_ccs == ccs_subgraph, 'k=2 failed alt' # if new methods for k == 3 or k == 4 are implemented add them here # Check the general subgraph method works by itself alt_subgraph_ccs = fset([set(C.nodes()) for C in general_k_edge_subgraphs(G, k=k)]) - assert_equal(alt_subgraph_ccs, ccs_subgraph, - 'alt subgraph method failed') + assert alt_subgraph_ccs == ccs_subgraph, 'alt subgraph method failed' # Stop once k is larger than all special case methods # and we cannot break down ccs any further. @@ -154,12 +151,12 @@ def test_zero_k_exception(): def test_empty_input(): G = nx.Graph() - assert_equal([], list(nx.k_edge_components(G, k=5))) - assert_equal([], list(nx.k_edge_subgraphs(G, k=5))) + assert [] == list(nx.k_edge_components(G, k=5)) + assert [] == list(nx.k_edge_subgraphs(G, k=5)) G = nx.DiGraph() - assert_equal([], list(nx.k_edge_components(G, k=5))) - assert_equal([], list(nx.k_edge_subgraphs(G, k=5))) + assert [] == list(nx.k_edge_components(G, k=5)) + assert [] == list(nx.k_edge_subgraphs(G, k=5)) def test_not_implemented(): @@ -176,15 +173,15 @@ def test_general_k_edge_subgraph_quick_return(): G = nx.Graph() G.add_node(0) subgraphs = list(general_k_edge_subgraphs(G, k=1)) - assert_equal(len(subgraphs), 1) + assert len(subgraphs) == 1 for subgraph in subgraphs: - assert_equal(subgraph.number_of_nodes(), 1) + assert subgraph.number_of_nodes() == 1 G.add_node(1) subgraphs = list(general_k_edge_subgraphs(G, k=1)) - assert_equal(len(subgraphs), 2) + assert len(subgraphs) == 2 for subgraph in subgraphs: - assert_equal(subgraph.number_of_nodes(), 1) + assert subgraph.number_of_nodes() == 1 # ---------------- @@ -247,7 +244,7 @@ def test_bridge_cc(): {1, 2, 3, 4}, {5}, {8, 9, 10}, {11, 12, 13}, {20}, {21}, {22}, {23}, {24} ]) - assert_equal(bridge_ccs, target_ccs) + assert bridge_ccs == target_ccs _check_edge_connectivity(G) @@ -268,27 +265,27 @@ def test_undirected_aux_graph(): components_1 = fset(aux_graph.k_edge_subgraphs(k=1)) target_1 = fset([{a, b, c, d, e, f, g}, {h, i}]) - assert_equal(target_1, components_1) + assert target_1 == components_1 # Check that the undirected case for k=1 agrees with CCs alt_1 = fset(nx.k_edge_subgraphs(G, k=1)) - assert_equal(alt_1, components_1) + assert alt_1 == components_1 components_2 = fset(aux_graph.k_edge_subgraphs(k=2)) target_2 = fset([{a, b, c, d, e, f, g}, {h}, {i}]) - assert_equal(target_2, components_2) + assert target_2 == components_2 # Check that the undirected case for k=2 agrees with bridge components alt_2 = fset(nx.k_edge_subgraphs(G, k=2)) - assert_equal(alt_2, components_2) + assert alt_2 == components_2 components_3 = fset(aux_graph.k_edge_subgraphs(k=3)) target_3 = fset([{a}, {b, c, f, g}, {d}, {e}, {h}, {i}]) - assert_equal(target_3, components_3) + assert target_3 == components_3 components_4 = fset(aux_graph.k_edge_subgraphs(k=4)) target_4 = fset([{a}, {b}, {c}, {d}, {e}, {f}, {g}, {h}, {i}]) - assert_equal(target_4, components_4) + assert target_4 == components_4 _check_edge_connectivity(G) @@ -310,14 +307,14 @@ def test_local_subgraph_difference(): subgraph_ccs = fset(aux_graph.k_edge_subgraphs(3)) subgraph_target = fset([{101}, {102}, {103}, {104}, {21, 22, 23, 24}, {11, 12, 13, 14}]) - assert_equal(subgraph_ccs, subgraph_target) + assert subgraph_ccs == subgraph_target # But in k-edge-ccs they are returned together # because they are locally 3-edge-connected local_ccs = fset(aux_graph.k_edge_components(3)) local_target = fset([{101}, {102}, {103}, {104}, {11, 12, 13, 14, 21, 22, 23, 24}]) - assert_equal(local_ccs, local_target) + assert local_ccs == local_target def test_local_subgraph_difference_directed(): @@ -327,23 +324,20 @@ def test_local_subgraph_difference_directed(): ] G = nx.DiGraph(it.chain(*[pairwise(path) for path in dipaths])) - assert_equal( - fset(nx.k_edge_components(G, k=1)), - fset(nx.k_edge_subgraphs(G, k=1)) - ) + assert ( + fset(nx.k_edge_components(G, k=1)) == + fset(nx.k_edge_subgraphs(G, k=1))) # Unlike undirected graphs, when k=2, for directed graphs there is a case # where the k-edge-ccs are not the same as the k-edge-subgraphs. # (in directed graphs ccs and subgraphs are the same when k=2) - assert_not_equal( - fset(nx.k_edge_components(G, k=2)), - fset(nx.k_edge_subgraphs(G, k=2)) - ) + assert ( + fset(nx.k_edge_components(G, k=2)) != + fset(nx.k_edge_subgraphs(G, k=2))) - assert_equal( - fset(nx.k_edge_components(G, k=3)), - fset(nx.k_edge_subgraphs(G, k=3)) - ) + assert ( + fset(nx.k_edge_components(G, k=3)) == + fset(nx.k_edge_subgraphs(G, k=3))) _check_edge_connectivity(G) @@ -357,20 +351,17 @@ def test_triangles(): G = nx.Graph(it.chain(*[pairwise(path) for path in paths])) # subgraph and ccs are the same in all cases here - assert_equal( - fset(nx.k_edge_components(G, k=1)), - fset(nx.k_edge_subgraphs(G, k=1)) - ) + assert ( + fset(nx.k_edge_components(G, k=1)) == + fset(nx.k_edge_subgraphs(G, k=1))) - assert_equal( - fset(nx.k_edge_components(G, k=2)), - fset(nx.k_edge_subgraphs(G, k=2)) - ) + assert ( + fset(nx.k_edge_components(G, k=2)) == + fset(nx.k_edge_subgraphs(G, k=2))) - assert_equal( - fset(nx.k_edge_components(G, k=3)), - fset(nx.k_edge_subgraphs(G, k=3)) - ) + assert ( + fset(nx.k_edge_components(G, k=3)) == + fset(nx.k_edge_subgraphs(G, k=3))) _check_edge_connectivity(G) @@ -392,18 +383,18 @@ def test_four_clique(): # The subgraphs and ccs are different for k=3 local_ccs = fset(nx.k_edge_components(G, k=3)) subgraphs = fset(nx.k_edge_subgraphs(G, k=3)) - assert_not_equal(local_ccs, subgraphs) + assert local_ccs != subgraphs # The cliques ares in the same cc clique1 = frozenset(paths[0]) clique2 = frozenset(paths[1]) - assert_in(clique1.union(clique2).union({100}), local_ccs) + assert clique1.union(clique2).union({100}) in local_ccs # but different subgraphs - assert_in(clique1, subgraphs) - assert_in(clique2, subgraphs) + assert clique1 in subgraphs + assert clique2 in subgraphs - assert_equal(G.degree(100), 3) + assert G.degree(100) == 3 _check_edge_connectivity(G) @@ -417,32 +408,28 @@ def test_five_clique(): (1, 100, 6), (2, 100, 7), (3, 200, 8), (4, 200, 100), ] G.add_edges_from(it.chain(*[pairwise(path) for path in paths])) - assert_equal(min(dict(nx.degree(G)).values()), 4) + assert min(dict(nx.degree(G)).values()) == 4 # For k=3 they are the same - assert_equal( - fset(nx.k_edge_components(G, k=3)), - fset(nx.k_edge_subgraphs(G, k=3)) - ) + assert ( + fset(nx.k_edge_components(G, k=3)) == + fset(nx.k_edge_subgraphs(G, k=3))) # For k=4 they are the different # the aux nodes are in the same CC as clique 1 but no the same subgraph - assert_not_equal( - fset(nx.k_edge_components(G, k=4)), - fset(nx.k_edge_subgraphs(G, k=4)) - ) + assert ( + fset(nx.k_edge_components(G, k=4)) != + fset(nx.k_edge_subgraphs(G, k=4))) # For k=5 they are not the same - assert_not_equal( - fset(nx.k_edge_components(G, k=5)), - fset(nx.k_edge_subgraphs(G, k=5)) - ) + assert ( + fset(nx.k_edge_components(G, k=5)) != + fset(nx.k_edge_subgraphs(G, k=5))) # For k=6 they are the same - assert_equal( - fset(nx.k_edge_components(G, k=6)), - fset(nx.k_edge_subgraphs(G, k=6)) - ) + assert ( + fset(nx.k_edge_components(G, k=6)) == + fset(nx.k_edge_subgraphs(G, k=6))) _check_edge_connectivity(G) @@ -467,19 +454,19 @@ def test_directed_aux_graph(): components_1 = fset(aux_graph.k_edge_subgraphs(k=1)) target_1 = fset([{a, b, c, d, e, f, g}, {h}, {i}]) - assert_equal(target_1, components_1) + assert target_1 == components_1 # Check that the directed case for k=1 agrees with SCCs alt_1 = fset(nx.strongly_connected_components(G)) - assert_equal(alt_1, components_1) + assert alt_1 == components_1 components_2 = fset(aux_graph.k_edge_subgraphs(k=2)) target_2 = fset([{i}, {e}, {d}, {b, c, f, g}, {h}, {a}]) - assert_equal(target_2, components_2) + assert target_2 == components_2 components_3 = fset(aux_graph.k_edge_subgraphs(k=3)) target_3 = fset([{a}, {b}, {c}, {d}, {e}, {f}, {g}, {h}, {i}]) - assert_equal(target_3, components_3) + assert target_3 == components_3 def test_random_gnp_directed(): diff --git a/networkx/algorithms/connectivity/tests/test_kcomponents.py b/networkx/algorithms/connectivity/tests/test_kcomponents.py index 0afe48c0..bbfe290f 100644 --- a/networkx/algorithms/connectivity/tests/test_kcomponents.py +++ b/networkx/algorithms/connectivity/tests/test_kcomponents.py @@ -90,7 +90,7 @@ def _check_connectivity(G, k_components): for component in components: C = G.subgraph(component) K = nx.node_connectivity(C) - assert_greater_equal(K, k) + assert K >= k def test_torrents_and_ferraro_graph(): @@ -100,12 +100,12 @@ def test_torrents_and_ferraro_graph(): # In this example graph there are 8 3-components, 4 with 15 nodes # and 4 with 5 nodes. - assert_equal(len(result[3]), 8) - assert_equal(len([c for c in result[3] if len(c) == 15]), 4) - assert_equal(len([c for c in result[3] if len(c) == 5]), 4) + assert len(result[3]) == 8 + assert len([c for c in result[3] if len(c) == 15]) == 4 + assert len([c for c in result[3] if len(c) == 5]) == 4 # There are also 8 4-components all with 5 nodes. - assert_equal(len(result[4]), 8) - assert_true(all(len(c) == 5 for c in result[4])) + assert len(result[4]) == 8 + assert all(len(c) == 5 for c in result[4]) def test_random_gnp(): @@ -145,7 +145,7 @@ def test_karate_component_number(): G = nx.karate_club_graph() k_components = nx.k_components(G) k_num = build_k_number_dict(k_components) - assert_equal(karate_k_num, k_num) + assert karate_k_num == k_num def test_davis_southern_women(): @@ -219,18 +219,17 @@ def test_davis_southern_women_detail_3_and_4(): for k, components in result.items(): if k < 3: continue - assert_true(len(components) == len(solution[k])) + assert len(components) == len(solution[k]) for component in components: - assert_true(component in solution[k]) + assert component in solution[k] def test_set_consolidation_rosettacode(): # Tests from http://rosettacode.org/wiki/Set_consolidation def list_of_sets_equal(result, solution): - assert_equal( - {frozenset(s) for s in result}, - {frozenset(s) for s in solution} - ) + assert ( + {frozenset(s) for s in result} == + {frozenset(s) for s in solution}) question = [{'A', 'B'}, {'C', 'D'}] solution = [{'A', 'B'}, {'C', 'D'}] list_of_sets_equal(_consolidate(question, 1), solution) diff --git a/networkx/algorithms/connectivity/tests/test_kcutsets.py b/networkx/algorithms/connectivity/tests/test_kcutsets.py index b2e78afd..3085bdfa 100644 --- a/networkx/algorithms/connectivity/tests/test_kcutsets.py +++ b/networkx/algorithms/connectivity/tests/test_kcutsets.py @@ -126,8 +126,8 @@ def _check_separating_sets(G): all_cuts = nx.all_node_cuts(Gc) # Only test a limited number of cut sets to reduce test time. for cut in itertools.islice(all_cuts, MAX_CUTSETS_TO_TEST): - assert_equal(node_conn, len(cut)) - assert_false(nx.is_connected(nx.restricted_view(G, cut, []))) + assert node_conn == len(cut) + assert not nx.is_connected(nx.restricted_view(G, cut, [])) def test_torrents_and_ferraro_graph(): @@ -184,7 +184,7 @@ def test_articulation_points(): G = next(Ggen) articulation_points = list({a} for a in nx.articulation_points(G)) for cut in nx.all_node_cuts(G): - assert_true(cut in articulation_points) + assert cut in articulation_points def test_grid_2d_graph(): @@ -199,7 +199,7 @@ def test_grid_2d_graph(): set([(0, 3), (1, 4)]), ] for cut in nx.all_node_cuts(G): - assert_true(cut in solution) + assert cut in solution def test_disconnected_graph(): @@ -217,20 +217,20 @@ def test_alternative_flow_functions(): all_cuts = nx.all_node_cuts(G, flow_func=flow_func) # Only test a limited number of cut sets to reduce test time. for cut in itertools.islice(all_cuts, MAX_CUTSETS_TO_TEST): - assert_equal(node_conn, len(cut)) - assert_false(nx.is_connected(nx.restricted_view(G, cut, []))) + assert node_conn == len(cut) + assert not nx.is_connected(nx.restricted_view(G, cut, [])) def test_is_separating_set_complete_graph(): G = nx.complete_graph(5) - assert_true(_is_separating_set(G, {0, 1, 2, 3})) + assert _is_separating_set(G, {0, 1, 2, 3}) def test_is_separating_set(): for i in [5, 10, 15]: G = nx.star_graph(i) max_degree_node = max(G, key=G.degree) - assert_true(_is_separating_set(G, {max_degree_node})) + assert _is_separating_set(G, {max_degree_node}) def test_non_repeated_cuts(): @@ -244,18 +244,18 @@ def test_non_repeated_cuts(): print(nx.info(G)) print("Solution: {}".format(solution)) print("Result: {}".format(cuts)) - assert_true(len(solution) == len(cuts)) + assert len(solution) == len(cuts) for cut in cuts: - assert_true(cut in solution) + assert cut in solution def test_cycle_graph(): G = nx.cycle_graph(5) solution = [{0, 2}, {0, 3}, {1, 3}, {1, 4}, {2, 4}] cuts = list(nx.all_node_cuts(G)) - assert_true(len(solution) == len(cuts)) + assert len(solution) == len(cuts) for cut in cuts: - assert_true(cut in solution) + assert cut in solution def test_complete_graph(): @@ -268,6 +268,6 @@ def test_complete_graph(): {1, 2, 3, 4}, ] cuts = list(nx.all_node_cuts(G)) - assert_true(len(solution) == len(cuts)) + assert len(solution) == len(cuts) for cut in cuts: - assert_true(cut in solution) + assert cut in solution diff --git a/networkx/algorithms/connectivity/tests/test_stoer_wagner.py b/networkx/algorithms/connectivity/tests/test_stoer_wagner.py index ee5d3ac2..7d1c7883 100644 --- a/networkx/algorithms/connectivity/tests/test_stoer_wagner.py +++ b/networkx/algorithms/connectivity/tests/test_stoer_wagner.py @@ -5,29 +5,29 @@ from nose.tools import * def _check_partition(G, cut_value, partition, weight): ok_(isinstance(partition, tuple)) - assert_equal(len(partition), 2) + assert len(partition) == 2 ok_(isinstance(partition[0], list)) ok_(isinstance(partition[1], list)) ok_(len(partition[0]) > 0) ok_(len(partition[1]) > 0) - assert_equal(sum(map(len, partition)), len(G)) - assert_equal(set(chain.from_iterable(partition)), set(G)) + assert sum(map(len, partition)) == len(G) + assert set(chain.from_iterable(partition)) == set(G) partition = tuple(map(set, partition)) w = 0 for u, v, e in G.edges(data=True): if (u in partition[0]) == (v in partition[1]): w += e.get(weight, 1) - assert_equal(w, cut_value) + assert w == cut_value def _test_stoer_wagner(G, answer, weight='weight'): cut_value, partition = nx.stoer_wagner(G, weight, heap=nx.utils.PairingHeap) - assert_equal(cut_value, answer) + assert cut_value == answer _check_partition(G, cut_value, partition, weight) cut_value, partition = nx.stoer_wagner(G, weight, heap=nx.utils.BinaryHeap) - assert_equal(cut_value, answer) + assert cut_value == answer _check_partition(G, cut_value, partition, weight) diff --git a/networkx/algorithms/flow/tests/test_gomory_hu.py b/networkx/algorithms/flow/tests/test_gomory_hu.py index 590a0519..d19a3f11 100644 --- a/networkx/algorithms/flow/tests/test_gomory_hu.py +++ b/networkx/algorithms/flow/tests/test_gomory_hu.py @@ -36,10 +36,10 @@ class TestGomoryHuTree: G = nx.karate_club_graph() nx.set_edge_attributes(G, 1, 'capacity') T = nx.gomory_hu_tree(G) - assert_true(nx.is_tree(T)) + assert nx.is_tree(T) for u, v in combinations(G, 2): cut_value, edge = self.minimum_edge_weight(T, u, v) - assert_equal(nx.minimum_cut_value(G, u, v), + assert (nx.minimum_cut_value(G, u, v) == cut_value) def test_karate_club_graph(self): @@ -47,10 +47,10 @@ class TestGomoryHuTree: nx.set_edge_attributes(G, 1, 'capacity') for flow_func in flow_funcs: T = nx.gomory_hu_tree(G, flow_func=flow_func) - assert_true(nx.is_tree(T)) + assert nx.is_tree(T) for u, v in combinations(G, 2): cut_value, edge = self.minimum_edge_weight(T, u, v) - assert_equal(nx.minimum_cut_value(G, u, v), + assert (nx.minimum_cut_value(G, u, v) == cut_value) def test_davis_southern_women_graph(self): @@ -58,10 +58,10 @@ class TestGomoryHuTree: nx.set_edge_attributes(G, 1, 'capacity') for flow_func in flow_funcs: T = nx.gomory_hu_tree(G, flow_func=flow_func) - assert_true(nx.is_tree(T)) + assert nx.is_tree(T) for u, v in combinations(G, 2): cut_value, edge = self.minimum_edge_weight(T, u, v) - assert_equal(nx.minimum_cut_value(G, u, v), + assert (nx.minimum_cut_value(G, u, v) == cut_value) def test_florentine_families_graph(self): @@ -69,10 +69,10 @@ class TestGomoryHuTree: nx.set_edge_attributes(G, 1, 'capacity') for flow_func in flow_funcs: T = nx.gomory_hu_tree(G, flow_func=flow_func) - assert_true(nx.is_tree(T)) + assert nx.is_tree(T) for u, v in combinations(G, 2): cut_value, edge = self.minimum_edge_weight(T, u, v) - assert_equal(nx.minimum_cut_value(G, u, v), + assert (nx.minimum_cut_value(G, u, v) == cut_value) def test_les_miserables_graph_cutset(self): @@ -80,21 +80,21 @@ class TestGomoryHuTree: nx.set_edge_attributes(G, 1, 'capacity') for flow_func in flow_funcs: T = nx.gomory_hu_tree(G, flow_func=flow_func) - assert_true(nx.is_tree(T)) + assert nx.is_tree(T) for u, v in combinations(G, 2): cut_value, edge = self.minimum_edge_weight(T, u, v) - assert_equal(nx.minimum_cut_value(G, u, v), + assert (nx.minimum_cut_value(G, u, v) == cut_value) def test_karate_club_graph_cutset(self): G = nx.karate_club_graph() nx.set_edge_attributes(G, 1, 'capacity') T = nx.gomory_hu_tree(G) - assert_true(nx.is_tree(T)) + assert nx.is_tree(T) u, v = 0, 33 cut_value, edge = self.minimum_edge_weight(T, u, v) cutset = self.compute_cutset(G, T, edge) - assert_equal(cut_value, len(cutset)) + assert cut_value == len(cutset) def test_wikipedia_example(self): # Example from https://en.wikipedia.org/wiki/Gomory%E2%80%93Hu_tree @@ -106,10 +106,10 @@ class TestGomoryHuTree: )) for flow_func in flow_funcs: T = nx.gomory_hu_tree(G, capacity='weight', flow_func=flow_func) - assert_true(nx.is_tree(T)) + assert nx.is_tree(T) for u, v in combinations(G, 2): cut_value, edge = self.minimum_edge_weight(T, u, v) - assert_equal(nx.minimum_cut_value(G, u, v, capacity='weight'), + assert (nx.minimum_cut_value(G, u, v, capacity='weight') == cut_value) @raises(nx.NetworkXNotImplemented) diff --git a/networkx/algorithms/flow/tests/test_maxflow.py b/networkx/algorithms/flow/tests/test_maxflow.py index 09df99fd..389c7593 100644 --- a/networkx/algorithms/flow/tests/test_maxflow.py +++ b/networkx/algorithms/flow/tests/test_maxflow.py @@ -30,10 +30,9 @@ def compute_cutset(G, partition): def validate_flows(G, s, t, flowDict, solnValue, capacity, flow_func): - assert_equal(set(G), set(flowDict), msg=msg.format(flow_func.__name__)) + assert set(G) == set(flowDict), msg.format(flow_func.__name__) for u in G: - assert_equal(set(G[u]), set(flowDict[u]), - msg=msg.format(flow_func.__name__)) + assert set(G[u]) == set(flowDict[u]), msg.format(flow_func.__name__) excess = {u: 0 for u in flowDict} for u in flowDict: for v, flow in flowDict[u].items(): @@ -44,30 +43,25 @@ def validate_flows(G, s, t, flowDict, solnValue, capacity, flow_func): excess[v] += flow for u, exc in excess.items(): if u == s: - assert_equal(exc, -solnValue, msg=msg.format(flow_func.__name__)) + assert exc == -solnValue, msg.format(flow_func.__name__) elif u == t: - assert_equal(exc, solnValue, msg=msg.format(flow_func.__name__)) + assert exc == solnValue, msg.format(flow_func.__name__) else: - assert_equal(exc, 0, msg=msg.format(flow_func.__name__)) + assert exc == 0, msg.format(flow_func.__name__) def validate_cuts(G, s, t, solnValue, partition, capacity, flow_func): - assert_true(all(n in G for n in partition[0]), - msg=msg.format(flow_func.__name__)) - assert_true(all(n in G for n in partition[1]), - msg=msg.format(flow_func.__name__)) + assert all(n in G for n in partition[0]), msg.format(flow_func.__name__) + assert all(n in G for n in partition[1]), msg.format(flow_func.__name__) cutset = compute_cutset(G, partition) - assert_true(all(G.has_edge(u, v) for (u, v) in cutset), - msg=msg.format(flow_func.__name__)) - assert_equal(solnValue, sum(G[u][v][capacity] for (u, v) in cutset), - msg=msg.format(flow_func.__name__)) + assert all(G.has_edge(u, v) for (u, v) in cutset), msg.format(flow_func.__name__) + assert solnValue == sum(G[u][v][capacity] for (u, v) in cutset), msg.format(flow_func.__name__) H = G.copy() H.remove_edges_from(cutset) if not G.is_directed(): - assert_false(nx.is_connected(H), msg=msg.format(flow_func.__name__)) + assert not nx.is_connected(H), msg.format(flow_func.__name__) else: - assert_false(nx.is_strongly_connected(H), - msg=msg.format(flow_func.__name__)) + assert not nx.is_strongly_connected(H), msg.format(flow_func.__name__) def compare_flows_and_cuts(G, s, t, solnFlows, solnValue, capacity='capacity'): @@ -76,7 +70,7 @@ def compare_flows_and_cuts(G, s, t, solnFlows, solnValue, capacity='capacity'): # Test both legacy and new implementations. flow_value = R.graph['flow_value'] flow_dict = build_flow_dict(G, R) - assert_equal(flow_value, solnValue, msg=msg.format(flow_func.__name__)) + assert flow_value == solnValue, msg.format(flow_func.__name__) validate_flows(G, s, t, flow_dict, solnValue, capacity, flow_func) # Minimum cut cut_value, partition = nx.minimum_cut(G, s, t, capacity=capacity, @@ -334,7 +328,7 @@ class TestMaxflowMinCutCommon: G = nx.Graph() G.add_weighted_edges_from([(0, 1, 1), (1, 2, 1), (2, 3, 1)], weight='capacity') G.remove_node(1) - assert_equal(nx.maximum_flow_value(G, 0, 3), 0) + assert nx.maximum_flow_value(G, 0, 3) == 0 flowSoln = {0: {}, 2: {3: 0}, 3: {2: 0}} compare_flows_and_cuts(G, 0, 3, flowSoln, 0) @@ -400,8 +394,8 @@ class TestMaxFlowMinCutInterface: result = interface_func(G, 'x', 'y', flow_func=flow_func) if interface_func in max_min_funcs: result = result[0] - assert_equal(fv, result, msg=msgi.format(flow_func.__name__, - interface_func.__name__)) + assert fv == result, msgi.format(flow_func.__name__, + interface_func.__name__) def test_minimum_cut_no_cutoff(self): G = self.G @@ -423,8 +417,8 @@ class TestMaxFlowMinCutInterface: result = interface_func(G, 0, 2, flow_func=flow_func, **kwargs) if interface_func in max_min_funcs: result = result[0] - assert_equal(fv, result, msg=msgi.format(flow_func.__name__, - interface_func.__name__)) + assert fv == result, msgi.format(flow_func.__name__, + interface_func.__name__) def test_kwargs_default_flow_func(self): G = self.H @@ -444,9 +438,8 @@ class TestMaxFlowMinCutInterface: residual=R) if interface_func in max_min_funcs: result = result[0] - assert_equal(fv, result, - msg=msgi.format(flow_func.__name__, - interface_func.__name__)) + assert fv == result, msgi.format(flow_func.__name__, + interface_func.__name__) # Tests specific to one algorithm @@ -454,7 +447,7 @@ def test_preflow_push_global_relabel_freq(): G = nx.DiGraph() G.add_edge(1, 2, capacity=1) R = preflow_push(G, 1, 2, global_relabel_freq=None) - assert_equal(R.graph['flow_value'], 1) + assert R.graph['flow_value'] == 1 assert_raises(nx.NetworkXError, preflow_push, G, 1, 2, global_relabel_freq=-1) @@ -465,7 +458,7 @@ def test_preflow_push_makes_enough_space(): nx.add_path(G, [0, 1, 3], capacity=1) nx.add_path(G, [1, 2, 3], capacity=1) R = preflow_push(G, 0, 3, value_only=False) - assert_equal(R.graph['flow_value'], 1) + assert R.graph['flow_value'] == 1 def test_shortest_augmenting_path_two_phase(): @@ -477,9 +470,9 @@ def test_shortest_augmenting_path_two_phase(): nx.add_path(G, ((i, j) for j in range(p)), capacity=1) G.add_edge((i, p - 1), 't', capacity=1) R = shortest_augmenting_path(G, 's', 't', two_phase=True) - assert_equal(R.graph['flow_value'], k) + assert R.graph['flow_value'] == k R = shortest_augmenting_path(G, 's', 't', two_phase=False) - assert_equal(R.graph['flow_value'], k) + assert R.graph['flow_value'] == k class TestCutoff: @@ -507,5 +500,4 @@ class TestCutoff: for cutoff in [3, 2, 1]: result = nx.maximum_flow_value(G, 0, 4, flow_func=flow_func, cutoff=cutoff) - assert_equal(cutoff, result, - msg="cutoff error in {0}".format(flow_func.__name__)) + assert cutoff == result, "cutoff error in {0}".format(flow_func.__name__) diff --git a/networkx/algorithms/flow/tests/test_maxflow_large_graph.py b/networkx/algorithms/flow/tests/test_maxflow_large_graph.py index 818a9e07..6cf1bb08 100644 --- a/networkx/algorithms/flow/tests/test_maxflow_large_graph.py +++ b/networkx/algorithms/flow/tests/test_maxflow_large_graph.py @@ -59,11 +59,10 @@ def read_graph(name): def validate_flows(G, s, t, soln_value, R, flow_func): flow_value = R.graph['flow_value'] flow_dict = build_flow_dict(G, R) - assert_equal(soln_value, flow_value, msg=msg.format(flow_func.__name__)) - assert_equal(set(G), set(flow_dict), msg=msg.format(flow_func.__name__)) + assert soln_value == flow_value, msg.format(flow_func.__name__) + assert set(G) == set(flow_dict), msg.format(flow_func.__name__) for u in G: - assert_equal(set(G[u]), set(flow_dict[u]), - msg=msg.format(flow_func.__name__)) + assert set(G[u]) == set(flow_dict[u]), msg.format(flow_func.__name__) excess = {u: 0 for u in flow_dict} for u in flow_dict: for v, flow in flow_dict[u].items(): @@ -74,11 +73,11 @@ def validate_flows(G, s, t, soln_value, R, flow_func): excess[v] += flow for u, exc in excess.items(): if u == s: - assert_equal(exc, -soln_value, msg=msg.format(flow_func.__name__)) + assert exc == -soln_value, msg.format(flow_func.__name__) elif u == t: - assert_equal(exc, soln_value, msg=msg.format(flow_func.__name__)) + assert exc ==soln_value, msg.format(flow_func.__name__) else: - assert_equal(exc, 0, msg=msg.format(flow_func.__name__)) + assert exc == 0, msg.format(flow_func.__name__) class TestMaxflowLargeGraph: @@ -93,8 +92,7 @@ class TestMaxflowLargeGraph: for flow_func in flow_funcs: kwargs['flow_func'] = flow_func flow_value = nx.maximum_flow_value(G, 1, 2, **kwargs) - assert_equal(flow_value, 5 * (N - 1), - msg=msg.format(flow_func.__name__)) + assert flow_value == 5 * (N - 1), msg.format(flow_func.__name__) def test_pyramid(self): N = 10 @@ -153,4 +151,4 @@ class TestMaxflowLargeGraph: def test_preflow_push_global_relabel(self): G = read_graph('gw1') R = preflow_push(G, 1, len(G), global_relabel_freq=50) - assert_equal(R.graph['flow_value'], 1202018) + assert R.graph['flow_value'] == 1202018 diff --git a/networkx/algorithms/flow/tests/test_mincost.py b/networkx/algorithms/flow/tests/test_mincost.py index 59681aff..5fa56b9a 100644 --- a/networkx/algorithms/flow/tests/test_mincost.py +++ b/networkx/algorithms/flow/tests/test_mincost.py @@ -19,16 +19,16 @@ class TestMinCostFlow: 'b': {'d': 4}, 'c': {'d': 1}, 'd': {}} - assert_equal(flowCost, 24) - assert_equal(nx.min_cost_flow_cost(G), 24) - assert_equal(H, soln) - assert_equal(nx.min_cost_flow(G), soln) - assert_equal(nx.cost_of_flow(G, H), 24) + assert flowCost == 24 + assert nx.min_cost_flow_cost(G) == 24 + assert H == soln + assert nx.min_cost_flow(G) == soln + assert nx.cost_of_flow(G, H) == 24 flowCost, H = nx.capacity_scaling(G) - assert_equal(flowCost, 24) - assert_equal(nx.cost_of_flow(G, H), 24) - assert_equal(H, soln) + assert flowCost == 24 + assert nx.cost_of_flow(G, H) == 24 + assert H == soln def test_negcycle_infcap(self): G = nx.DiGraph() @@ -104,16 +104,16 @@ class TestMinCostFlow: 'g': {'d': 0}, 'h': {'b': 0, 'g': 0}, 'r': {'a': 1, 'c': 1}} - assert_equal(flowCost, 41) - assert_equal(nx.min_cost_flow_cost(G), 41) - assert_equal(H, soln) - assert_equal(nx.min_cost_flow(G), soln) - assert_equal(nx.cost_of_flow(G, H), 41) + assert flowCost == 41 + assert nx.min_cost_flow_cost(G) == 41 + assert H == soln + assert nx.min_cost_flow(G) == soln + assert nx.cost_of_flow(G, H) == 41 flowCost, H = nx.capacity_scaling(G) - assert_equal(flowCost, 41) - assert_equal(nx.cost_of_flow(G, H), 41) - assert_equal(H, soln) + assert flowCost == 41 + assert nx.cost_of_flow(G, H) == 41 + assert H == soln def test_max_flow_min_cost(self): G = nx.DiGraph() @@ -131,18 +131,18 @@ class TestMinCostFlow: 't': {}} flow = nx.max_flow_min_cost(G, 's', 't', capacity='bandwidth', weight='cost') - assert_equal(flow, soln) - assert_equal(nx.cost_of_flow(G, flow, weight='cost'), 90) + assert flow == soln + assert nx.cost_of_flow(G, flow, weight='cost') == 90 G.add_edge('t', 's', cost=-100) flowCost, flow = nx.capacity_scaling(G, capacity='bandwidth', weight='cost') G.remove_edge('t', 's') - assert_equal(flowCost, -410) - assert_equal(flow['t']['s'], 5) + assert flowCost == -410 + assert flow['t']['s'] == 5 del flow['t']['s'] - assert_equal(flow, soln) - assert_equal(nx.cost_of_flow(G, flow, weight='cost'), 90) + assert flow == soln + assert nx.cost_of_flow(G, flow, weight='cost') == 90 def test_digraph1(self): # From Bradley, S. P., Hax, A. C. and Magnanti, T. L. Applied @@ -166,16 +166,16 @@ class TestMinCostFlow: 3: {4: 11, 5: 5}, 4: {5: 10}, 5: {3: 0}} - assert_equal(flowCost, 150) - assert_equal(nx.min_cost_flow_cost(G), 150) - assert_equal(H, soln) - assert_equal(nx.min_cost_flow(G), soln) - assert_equal(nx.cost_of_flow(G, H), 150) + assert flowCost == 150 + assert nx.min_cost_flow_cost(G) == 150 + assert H == soln + assert nx.min_cost_flow(G) == soln + assert nx.cost_of_flow(G, H) == 150 flowCost, H = nx.capacity_scaling(G) - assert_equal(flowCost, 150) - assert_equal(H, soln) - assert_equal(nx.cost_of_flow(G, H), 150) + assert flowCost == 150 + assert H == soln + assert nx.cost_of_flow(G, H) == 150 def test_digraph2(self): # Example from ticket #430 from mfrasca. Original source: @@ -205,16 +205,16 @@ class TestMinCostFlow: 6: {'t': 22}, 's': {1: 12, 2: 6, 3: 14}, 't': {}} - assert_equal(flow, soln) + assert flow == soln G.add_edge('t', 's', weight=-100) flowCost, flow = nx.capacity_scaling(G) G.remove_edge('t', 's') - assert_equal(flow['t']['s'], 32) - assert_equal(flowCost, -3007) + assert flow['t']['s'] == 32 + assert flowCost == -3007 del flow['t']['s'] - assert_equal(flow, soln) - assert_equal(nx.cost_of_flow(G, flow), 193) + assert flow == soln + assert nx.cost_of_flow(G, flow) == 193 def test_digraph3(self): """Combinatorial Optimization: Algorithms and Complexity, @@ -239,27 +239,27 @@ class TestMinCostFlow: "PS.ex.7.1: testing main function" sol = nx.max_flow_min_cost(G, 's', 't', capacity=0, weight=1) flow = sum(v for v in sol['s'].values()) - assert_equal(4, flow) - assert_equal(23, nx.cost_of_flow(G, sol, weight=1)) - assert_equal(sol['s'], {'a': 2, 'b': 2}) - assert_equal(sol['a'], {'b': 1, 't': 1}) - assert_equal(sol['b'], {'a': 0, 't': 3}) - assert_equal(sol['t'], {}) + assert 4 == flow + assert 23 == nx.cost_of_flow(G, sol, weight=1) + assert sol['s'] == {'a': 2, 'b': 2} + assert sol['a'] == {'b': 1, 't': 1} + assert sol['b'] == {'a': 0, 't': 3} + assert sol['t'] == {} G.add_edge('t', 's') G['t']['s'].update({1: -100}) flowCost, sol = nx.capacity_scaling(G, capacity=0, weight=1) G.remove_edge('t', 's') flow = sum(v for v in sol['s'].values()) - assert_equal(4, flow) - assert_equal(sol['t']['s'], 4) - assert_equal(flowCost, -377) + assert 4 == flow + assert sol['t']['s'] == 4 + assert flowCost == -377 del sol['t']['s'] - assert_equal(sol['s'], {'a': 2, 'b': 2}) - assert_equal(sol['a'], {'b': 1, 't': 1}) - assert_equal(sol['b'], {'a': 0, 't': 3}) - assert_equal(sol['t'], {}) - assert_equal(nx.cost_of_flow(G, sol, weight=1), 23) + assert sol['s'] == {'a': 2, 'b': 2} + assert sol['a'] == {'b': 1, 't': 1} + assert sol['b'] == {'a': 0, 't': 3} + assert sol['t'] == {} + assert nx.cost_of_flow(G, sol, weight=1) == 23 def test_zero_capacity_edges(self): """Address issue raised in ticket #617 by arv.""" @@ -281,16 +281,16 @@ class TestMinCostFlow: 3: {4: 2}, 4: {}, 5: {3: 2, 4: 0}} - assert_equal(flowCost, 6) - assert_equal(nx.min_cost_flow_cost(G), 6) - assert_equal(H, soln) - assert_equal(nx.min_cost_flow(G), soln) - assert_equal(nx.cost_of_flow(G, H), 6) + assert flowCost == 6 + assert nx.min_cost_flow_cost(G) == 6 + assert H == soln + assert nx.min_cost_flow(G) == soln + assert nx.cost_of_flow(G, H) == 6 flowCost, H = nx.capacity_scaling(G) - assert_equal(flowCost, 6) - assert_equal(H, soln) - assert_equal(nx.cost_of_flow(G, H), 6) + assert flowCost == 6 + assert H == soln + assert nx.cost_of_flow(G, H) == 6 def test_digon(self): """Check if digons are handled properly. Taken from ticket @@ -310,16 +310,16 @@ class TestMinCostFlow: soln = {1: {2: 0}, 2: {1: 0, 3: 4}, 3: {2: 0}} - assert_equal(flowCost, 2857140) - assert_equal(nx.min_cost_flow_cost(G), 2857140) - assert_equal(H, soln) - assert_equal(nx.min_cost_flow(G), soln) - assert_equal(nx.cost_of_flow(G, H), 2857140) + assert flowCost == 2857140 + assert nx.min_cost_flow_cost(G) == 2857140 + assert H == soln + assert nx.min_cost_flow(G) == soln + assert nx.cost_of_flow(G, H) == 2857140 flowCost, H = nx.capacity_scaling(G) - assert_equal(flowCost, 2857140) - assert_equal(H, soln) - assert_equal(nx.cost_of_flow(G, H), 2857140) + assert flowCost == 2857140 + assert H == soln + assert nx.cost_of_flow(G, H) == 2857140 def test_deadend(self): """Check if one-node cycles are handled properly. Taken from ticket @@ -357,24 +357,24 @@ class TestMinCostFlow: G.add_edge('a', 'b', capacity=1, weight=-1) G.add_edge('b', 'a', capacity=1, weight=-1) min_cost = -2 - assert_equal(nx.min_cost_flow_cost(G), min_cost) + assert nx.min_cost_flow_cost(G) == min_cost flowCost, H = nx.capacity_scaling(G) - assert_equal(flowCost, -2) - assert_equal(H, {'a': {'b': 1}, 'b': {'a': 1}}) - assert_equal(nx.cost_of_flow(G, H), -2) + assert flowCost == -2 + assert H == {'a': {'b': 1}, 'b': {'a': 1}} + assert nx.cost_of_flow(G, H) == -2 def test_multidigraph(self): """Multidigraphs are acceptable.""" G = nx.MultiDiGraph() G.add_weighted_edges_from([(1, 2, 1), (2, 3, 2)], weight='capacity') flowCost, H = nx.network_simplex(G) - assert_equal(flowCost, 0) - assert_equal(H, {1: {2: {0: 0}}, 2: {3: {0: 0}}, 3: {}}) + assert flowCost == 0 + assert H == {1: {2: {0: 0}}, 2: {3: {0: 0}}, 3: {}} flowCost, H = nx.capacity_scaling(G) - assert_equal(flowCost, 0) - assert_equal(H, {1: {2: {0: 0}}, 2: {3: {0: 0}}, 3: {}}) + assert flowCost == 0 + assert H == {1: {2: {0: 0}}, 2: {3: {0: 0}}, 3: {}} def test_negative_selfloops(self): """Negative selfloops should cause an exception if uncapacitated and @@ -386,11 +386,11 @@ class TestMinCostFlow: assert_raises(nx.NetworkXUnbounded, nx.capacity_scaling, G) G[1][1]['capacity'] = 2 flowCost, H = nx.network_simplex(G) - assert_equal(flowCost, -2) - assert_equal(H, {1: {1: 2}}) + assert flowCost == -2 + assert H == {1: {1: 2}} flowCost, H = nx.capacity_scaling(G) - assert_equal(flowCost, -2) - assert_equal(H, {1: {1: 2}}) + assert flowCost == -2 + assert H == {1: {1: 2}} G = nx.MultiDiGraph() G.add_edge(1, 1, 'x', weight=-1) @@ -399,11 +399,11 @@ class TestMinCostFlow: assert_raises(nx.NetworkXUnbounded, nx.capacity_scaling, G) G[1][1]['x']['capacity'] = 2 flowCost, H = nx.network_simplex(G) - assert_equal(flowCost, -2) - assert_equal(H, {1: {1: {'x': 2, 'y': 0}}}) + assert flowCost == -2 + assert H == {1: {1: {'x': 2, 'y': 0}}} flowCost, H = nx.capacity_scaling(G) - assert_equal(flowCost, -2) - assert_equal(H, {1: {1: {'x': 2, 'y': 0}}}) + assert flowCost == -2 + assert H == {1: {1: {'x': 2, 'y': 0}}} def test_bone_shaped(self): # From #1283 @@ -420,13 +420,13 @@ class TestMinCostFlow: G.add_edge(5, 3, capacity=4) G.add_edge(0, 3, capacity=0) flowCost, H = nx.network_simplex(G) - assert_equal(flowCost, 0) - assert_equal( - H, {0: {1: 2, 2: 2, 3: 0}, 1: {}, 2: {}, 3: {}, 4: {3: 2}, 5: {3: 2}}) + assert flowCost == 0 + assert ( + H == {0: {1: 2, 2: 2, 3: 0}, 1: {}, 2: {}, 3: {}, 4: {3: 2}, 5: {3: 2}}) flowCost, H = nx.capacity_scaling(G) - assert_equal(flowCost, 0) - assert_equal( - H, {0: {1: 2, 2: 2, 3: 0}, 1: {}, 2: {}, 3: {}, 4: {3: 2}, 5: {3: 2}}) + assert flowCost == 0 + assert ( + H == {0: {1: 2, 2: 2, 3: 0}, 1: {}, 2: {}, 3: {}, 4: {3: 2}, 5: {3: 2}}) def test_exceptions(self): G = nx.Graph() @@ -463,8 +463,8 @@ class TestMinCostFlow: fname = os.path.join(os.path.dirname(__file__), 'netgen-2.gpickle.bz2') G = nx.read_gpickle(fname) flowCost, flowDict = nx.network_simplex(G) - assert_equal(6749969302, flowCost) - assert_equal(6749969302, nx.cost_of_flow(G, flowDict)) + assert 6749969302 == flowCost + assert 6749969302 == nx.cost_of_flow(G, flowDict) flowCost, flowDict = nx.capacity_scaling(G) - assert_equal(6749969302, flowCost) - assert_equal(6749969302, nx.cost_of_flow(G, flowDict)) + assert 6749969302 == flowCost + assert 6749969302 == nx.cost_of_flow(G, flowDict) diff --git a/networkx/algorithms/isomorphism/tests/test_ismags.py b/networkx/algorithms/isomorphism/tests/test_ismags.py index e4a05662..d9130794 100644 --- a/networkx/algorithms/isomorphism/tests/test_ismags.py +++ b/networkx/algorithms/isomorphism/tests/test_ismags.py @@ -55,9 +55,9 @@ class TestSelfIsomorphism(object): graph.add_edges_from(edge_data) ismags = iso.ISMAGS(graph, graph, node_match=iso.categorical_node_match('name', None)) - assert_true(ismags.is_isomorphic()) - assert_true(ismags.subgraph_is_isomorphic()) - assert_equal(list(ismags.subgraph_isomorphisms_iter(symmetry=True)), + assert ismags.is_isomorphic() + assert ismags.subgraph_is_isomorphic() + assert (list(ismags.subgraph_isomorphisms_iter(symmetry=True)) == [{n: n for n in graph.nodes}]) def test_edgecase_self_isomorphism(self): @@ -91,9 +91,9 @@ class TestSelfIsomorphism(object): graph.add_edges_from(edge_data) ismags = iso.ISMAGS(graph, graph, node_match=iso.categorical_node_match('name', None)) - assert_true(ismags.is_isomorphic()) - assert_true(ismags.subgraph_is_isomorphic()) - assert_equal(list(ismags.subgraph_isomorphisms_iter(symmetry=True)), + assert ismags.is_isomorphic() + assert ismags.subgraph_is_isomorphic() + assert (list(ismags.subgraph_isomorphisms_iter(symmetry=True)) == [{n: n for n in graph.nodes}]) @@ -106,7 +106,7 @@ class TestSubgraphIsomorphism(object): g2.add_cycle(range(4)) g2.add_edges_from([(n, m) for n, m in zip(g2, range(4, 8))]) ismags = iso.ISMAGS(g2, g1) - assert_equal(list(ismags.subgraph_isomorphisms_iter(symmetry=True)), + assert (list(ismags.subgraph_isomorphisms_iter(symmetry=True)) == [{n: n for n in g1.nodes}]) def test_isomorphism2(self): @@ -121,14 +121,14 @@ class TestSubgraphIsomorphism(object): expected_symmetric = [{0: 0, 1: 1, 2: 2}, {0: 0, 1: 1, 3: 2}, {2: 0, 1: 1, 3: 2}] - assert_equal(_matches_to_sets(matches), + assert (_matches_to_sets(matches) == _matches_to_sets(expected_symmetric)) matches = ismags.subgraph_isomorphisms_iter(symmetry=False) expected_asymmetric = [{0: 2, 1: 1, 2: 0}, {0: 2, 1: 1, 3: 0}, {2: 2, 1: 1, 3: 0}] - assert_equal(_matches_to_sets(matches), + assert (_matches_to_sets(matches) == _matches_to_sets(expected_symmetric + expected_asymmetric)) def test_labeled_nodes(self): @@ -141,12 +141,12 @@ class TestSubgraphIsomorphism(object): ismags = iso.ISMAGS(g2, g1, node_match=lambda x, y: x == y) matches = ismags.subgraph_isomorphisms_iter(symmetry=True) expected_symmetric = [{0: 0, 1: 1, 2: 2}] - assert_equal(_matches_to_sets(matches), + assert (_matches_to_sets(matches) == _matches_to_sets(expected_symmetric)) matches = ismags.subgraph_isomorphisms_iter(symmetry=False) expected_asymmetric = [{0: 2, 1: 1, 2: 0}] - assert_equal(_matches_to_sets(matches), + assert (_matches_to_sets(matches) == _matches_to_sets(expected_symmetric + expected_asymmetric)) def test_labeled_edges(self): @@ -159,12 +159,12 @@ class TestSubgraphIsomorphism(object): ismags = iso.ISMAGS(g2, g1, edge_match=lambda x, y: x == y) matches = ismags.subgraph_isomorphisms_iter(symmetry=True) expected_symmetric = [{0: 0, 1: 1, 2: 2}] - assert_equal(_matches_to_sets(matches), + assert (_matches_to_sets(matches) == _matches_to_sets(expected_symmetric)) matches = ismags.subgraph_isomorphisms_iter(symmetry=False) expected_asymmetric = [{1: 2, 0: 0, 2: 1}] - assert_equal(_matches_to_sets(matches), + assert (_matches_to_sets(matches) == _matches_to_sets(expected_symmetric + expected_asymmetric)) @@ -188,7 +188,7 @@ class TestWikipediaExample(object): g1.add_edges_from(self.g1edges) g2.add_edges_from(self.g2edges) gm = iso.ISMAGS(g1, g2) - assert_true(gm.is_isomorphic()) + assert gm.is_isomorphic() class TestLargestCommonSubgraph(object): @@ -206,21 +206,21 @@ class TestLargestCommonSubgraph(object): graph2.nodes[7]['color'] = 2 ismags = iso.ISMAGS(graph1, graph2, node_match=iso.categorical_node_match('color', None)) - assert_equal(list(ismags.subgraph_isomorphisms_iter(True)), []) - assert_equal(list(ismags.subgraph_isomorphisms_iter(False)), []) + assert list(ismags.subgraph_isomorphisms_iter(True)) == [] + assert list(ismags.subgraph_isomorphisms_iter(False)) == [] found_mcis = _matches_to_sets(ismags.largest_common_subgraph()) expected = _matches_to_sets([{2: 2, 3: 4, 4: 3, 5: 5}, {2: 4, 3: 2, 4: 3, 5: 5}]) - assert_equal(expected, found_mcis) + assert expected == found_mcis ismags = iso.ISMAGS(graph2, graph1, node_match=iso.categorical_node_match('color', None)) - assert_equal(list(ismags.subgraph_isomorphisms_iter(True)), []) - assert_equal(list(ismags.subgraph_isomorphisms_iter(False)), []) + assert list(ismags.subgraph_isomorphisms_iter(True)) == [] + assert list(ismags.subgraph_isomorphisms_iter(False)) == [] found_mcis = _matches_to_sets(ismags.largest_common_subgraph()) # Same answer, but reversed. expected = _matches_to_sets([{2: 2, 3: 4, 4: 3, 5: 5}, {4: 2, 2: 3, 3: 4, 5: 5}]) - assert_equal(expected, found_mcis) + assert expected == found_mcis def test_symmetry_mcis(self): graph1 = nx.Graph() @@ -232,15 +232,15 @@ class TestLargestCommonSubgraph(object): # Only the symmetry of graph2 is taken into account here. ismags1 = iso.ISMAGS(graph1, graph2, node_match=iso.categorical_node_match('color', None)) - assert_equal(list(ismags1.subgraph_isomorphisms_iter(True)), []) + assert list(ismags1.subgraph_isomorphisms_iter(True)) == [] found_mcis = _matches_to_sets(ismags1.largest_common_subgraph()) expected = _matches_to_sets([{0: 0, 1: 1, 2: 2}, {1: 0, 3: 2, 2: 1}]) - assert_equal(expected, found_mcis) + assert expected == found_mcis # Only the symmetry of graph1 is taken into account here. ismags2 = iso.ISMAGS(graph2, graph1, node_match=iso.categorical_node_match('color', None)) - assert_equal(list(ismags2.subgraph_isomorphisms_iter(True)), []) + assert list(ismags2.subgraph_isomorphisms_iter(True)) == [] found_mcis = _matches_to_sets(ismags2.largest_common_subgraph()) expected = _matches_to_sets([{3: 2, 0: 0, 1: 1}, {2: 0, 0: 2, 1: 1}, @@ -249,7 +249,7 @@ class TestLargestCommonSubgraph(object): {0: 0, 1: 1, 2: 2}, {2: 0, 3: 2, 1: 1}]) - assert_equal(expected, found_mcis) + assert expected == found_mcis found_mcis1 = _matches_to_sets(ismags1.largest_common_subgraph(False)) found_mcis2 = ismags2.largest_common_subgraph(False) @@ -268,5 +268,5 @@ class TestLargestCommonSubgraph(object): {1: 0, 3: 2, 2: 1}, {0: 3, 1: 1, 2: 2}, {0: 0, 1: 1, 2: 2}]) - assert_equal(expected, found_mcis1) - assert_equal(expected, found_mcis2) + assert expected == found_mcis1 + assert expected == found_mcis2 diff --git a/networkx/algorithms/isomorphism/tests/test_isomorphism.py b/networkx/algorithms/isomorphism/tests/test_isomorphism.py index 1c357b7d..423d7a82 100644 --- a/networkx/algorithms/isomorphism/tests/test_isomorphism.py +++ b/networkx/algorithms/isomorphism/tests/test_isomorphism.py @@ -18,17 +18,17 @@ class TestIsomorph: cls.G4.add_edges_from([[1, 2], [1, 3], [1, 5], [2, 4]]) def test_could_be_isomorphic(self): - assert_true(iso.could_be_isomorphic(self.G1, self.G2)) - assert_true(iso.could_be_isomorphic(self.G1, self.G3)) - assert_false(iso.could_be_isomorphic(self.G1, self.G4)) - assert_true(iso.could_be_isomorphic(self.G3, self.G2)) + assert iso.could_be_isomorphic(self.G1, self.G2) + assert iso.could_be_isomorphic(self.G1, self.G3) + assert not iso.could_be_isomorphic(self.G1, self.G4) + assert iso.could_be_isomorphic(self.G3, self.G2) def test_fast_could_be_isomorphic(self): - assert_true(iso.fast_could_be_isomorphic(self.G3, self.G2)) + assert iso.fast_could_be_isomorphic(self.G3, self.G2) def test_faster_could_be_isomorphic(self): - assert_true(iso.faster_could_be_isomorphic(self.G3, self.G2)) + assert iso.faster_could_be_isomorphic(self.G3, self.G2) def test_is_isomorphic(self): - assert_true(iso.is_isomorphic(self.G1, self.G2)) - assert_false(iso.is_isomorphic(self.G1, self.G4)) + assert iso.is_isomorphic(self.G1, self.G2) + assert not iso.is_isomorphic(self.G1, self.G4) diff --git a/networkx/algorithms/isomorphism/tests/test_isomorphvf2.py b/networkx/algorithms/isomorphism/tests/test_isomorphvf2.py index e36c8c7d..4f1ce482 100644 --- a/networkx/algorithms/isomorphism/tests/test_isomorphvf2.py +++ b/networkx/algorithms/isomorphism/tests/test_isomorphvf2.py @@ -34,9 +34,9 @@ class TestWikipediaExample(object): g1.add_edges_from(self.g1edges) g2.add_edges_from(self.g2edges) gm = iso.GraphMatcher(g1, g2) - assert_true(gm.is_isomorphic()) + assert gm.is_isomorphic() #Just testing some cases - assert_true(gm.subgraph_is_monomorphic()) + assert gm.subgraph_is_monomorphic() mapping = sorted(gm.mapping.items()) # this mapping is only one of the possibilies @@ -52,7 +52,7 @@ class TestWikipediaExample(object): g2.add_edges_from(self.g2edges) g3 = g2.subgraph([1, 2, 3, 4]) gm = iso.GraphMatcher(g1, g3) - assert_true(gm.subgraph_is_isomorphic()) + assert gm.subgraph_is_isomorphic() def test_subgraph_mono(self): @@ -61,7 +61,7 @@ class TestWikipediaExample(object): g1.add_edges_from(self.g1edges) g2.add_edges_from([[1, 2], [2, 3], [3, 4]]) gm = iso.GraphMatcher(g1, g2) - assert_true(gm.subgraph_is_monomorphic()) + assert gm.subgraph_is_monomorphic() class TestVF2GraphDB(object): @@ -103,7 +103,7 @@ class TestVF2GraphDB(object): g1 = self.create_graph(os.path.join(head, 'iso_r01_s80.A99')) g2 = self.create_graph(os.path.join(head, 'iso_r01_s80.B99')) gm = iso.GraphMatcher(g1, g2) - assert_true(gm.is_isomorphic()) + assert gm.is_isomorphic() def test_subgraph(self): # A is the subgraph @@ -112,9 +112,9 @@ class TestVF2GraphDB(object): subgraph = self.create_graph(os.path.join(head, 'si2_b06_m200.A99')) graph = self.create_graph(os.path.join(head, 'si2_b06_m200.B99')) gm = iso.GraphMatcher(graph, subgraph) - assert_true(gm.subgraph_is_isomorphic()) + assert gm.subgraph_is_isomorphic() #Just testing some cases - assert_true(gm.subgraph_is_monomorphic()) + assert gm.subgraph_is_monomorphic() # There isn't a similar test implemented for subgraph monomorphism, # feel free to create one. @@ -143,7 +143,7 @@ class TestAtlas(object): d = dict(zip(nlist, labels)) relabel = nx.relabel_nodes(graph, d) gm = iso.GraphMatcher(graph, relabel) - assert_true(gm.is_isomorphic()) + assert gm.is_isomorphic() def test_multiedge(): @@ -169,9 +169,9 @@ def test_multiedge(): gm = iso.GraphMatcher(g1, g2) else: gm = iso.DiGraphMatcher(g1, g2) - assert_true(gm.is_isomorphic()) + assert gm.is_isomorphic() #Testing if monomorphism works in multigraphs - assert_true(gm.subgraph_is_monomorphic()) + assert gm.subgraph_is_monomorphic() def test_selfloop(): @@ -191,7 +191,7 @@ def test_selfloop(): gm = iso.GraphMatcher(g1, g2) else: gm = iso.DiGraphMatcher(g1, g2) - assert_true(gm.is_isomorphic()) + assert gm.is_isomorphic() def test_selfloop_mono(): @@ -213,7 +213,7 @@ def test_selfloop_mono(): gm = iso.GraphMatcher(g2, g1) else: gm = iso.DiGraphMatcher(g2, g1) - assert_true(not gm.subgraph_is_monomorphic()) + assert not gm.subgraph_is_monomorphic() def test_isomorphism_iter1(): @@ -230,12 +230,12 @@ def test_isomorphism_iter1(): gm13 = iso.DiGraphMatcher(g1, g3) x = list(gm12.subgraph_isomorphisms_iter()) y = list(gm13.subgraph_isomorphisms_iter()) - assert_true({'A': 'Y', 'B': 'Z'} in x) - assert_true({'B': 'Y', 'C': 'Z'} in x) - assert_true({'A': 'Z', 'B': 'Y'} in y) - assert_true({'B': 'Z', 'C': 'Y'} in y) - assert_equal(len(x), len(y)) - assert_equal(len(x), 2) + assert {'A': 'Y', 'B': 'Z'} in x + assert {'B': 'Y', 'C': 'Z'} in x + assert {'A': 'Z', 'B': 'Y'} in y + assert {'B': 'Z', 'C': 'Y'} in y + assert len(x) == len(y) + assert len(x) == 2 def test_monomorphism_iter1(): @@ -248,13 +248,13 @@ def test_monomorphism_iter1(): g2.add_edge('Y', 'Z') gm12 = iso.DiGraphMatcher(g1, g2) x = list(gm12.subgraph_monomorphisms_iter()) - assert_true({'A': 'X', 'B': 'Y', 'C': 'Z'} in x) - assert_true({'A': 'Y', 'B': 'Z', 'C': 'X'} in x) - assert_true({'A': 'Z', 'B': 'X', 'C': 'Y'} in x) - assert_equal(len(x), 3) + assert {'A': 'X', 'B': 'Y', 'C': 'Z'} in x + assert {'A': 'Y', 'B': 'Z', 'C': 'X'} in x + assert {'A': 'Z', 'B': 'X', 'C': 'Y'} in x + assert len(x) == 3 gm21 = iso.DiGraphMatcher(g2, g1) #Check if StopIteration exception returns False - assert_true(not gm21.subgraph_is_monomorphic()) + assert not gm21.subgraph_is_monomorphic() def test_isomorphism_iter2(): @@ -263,13 +263,13 @@ def test_isomorphism_iter2(): g1 = nx.path_graph(L) gm = iso.GraphMatcher(g1, g1) s = len(list(gm.isomorphisms_iter())) - assert_equal(s, 2) + assert s == 2 # Cycle for L in range(3, 10): g1 = nx.cycle_graph(L) gm = iso.GraphMatcher(g1, g1) s = len(list(gm.isomorphisms_iter())) - assert_equal(s, 2 * L) + assert s == 2 * L def test_multiple(): @@ -285,16 +285,16 @@ def test_multiple(): else: gmA = iso.DiGraphMatcher(g1, g2) gmB = iso.DiGraphMatcher(g1, g3) - assert_true(gmA.is_isomorphic()) + assert gmA.is_isomorphic() g2.remove_node('C') if not g1.is_directed(): gmA = iso.GraphMatcher(g1, g2) else: gmA = iso.DiGraphMatcher(g1, g2) - assert_true(gmA.subgraph_is_isomorphic()) - assert_true(gmB.subgraph_is_isomorphic()) - assert_true(gmA.subgraph_is_monomorphic()) - assert_true(gmB.subgraph_is_monomorphic()) + assert gmA.subgraph_is_isomorphic() + assert gmB.subgraph_is_isomorphic() + assert gmA.subgraph_is_monomorphic() + assert gmB.subgraph_is_monomorphic() # for m in [gmB.mapping, gmB.mapping]: # assert_true(m['A'] == 'A') # assert_true(m['B'] == 'B') @@ -308,14 +308,14 @@ def test_noncomparable_nodes(): # Graph G = nx.path_graph([node1, node2, node3]) gm = iso.GraphMatcher(G, G) - assert_true(gm.is_isomorphic()) + assert gm.is_isomorphic() #Just testing some cases - assert_true(gm.subgraph_is_monomorphic()) + assert gm.subgraph_is_monomorphic() # DiGraph G = nx.path_graph([node1, node2, node3], create_using=nx.DiGraph) H = nx.path_graph([node3, node2, node1], create_using=nx.DiGraph) dgm = iso.DiGraphMatcher(G, H) - assert_true(dgm.is_isomorphic()) + assert dgm.is_isomorphic() #Just testing some cases - assert_true(gm.subgraph_is_monomorphic()) + assert gm.subgraph_is_monomorphic() diff --git a/networkx/algorithms/isomorphism/tests/test_match_helpers.py b/networkx/algorithms/isomorphism/tests/test_match_helpers.py index 69d58e6c..a831783b 100644 --- a/networkx/algorithms/isomorphism/tests/test_match_helpers.py +++ b/networkx/algorithms/isomorphism/tests/test_match_helpers.py @@ -6,8 +6,8 @@ from networkx.algorithms import isomorphism as iso def test_categorical_node_match(): nm = iso.categorical_node_match(['x', 'y', 'z'], [None] * 3) - assert_true(nm(dict(x=1, y=2, z=3), dict(x=1, y=2, z=3))) - assert_true(not nm(dict(x=1, y=2, z=2), dict(x=1, y=2, z=1))) + assert nm(dict(x=1, y=2, z=3), dict(x=1, y=2, z=3)) + assert not nm(dict(x=1, y=2, z=2), dict(x=1, y=2, z=1)) class TestGenericMultiEdgeMatch: @@ -37,11 +37,11 @@ class TestGenericMultiEdgeMatch: flow_match = iso.generic_multiedge_match(['flowMin', 'flowMax'], [None] * 2, [eq] * 2) min_flow_match = iso.generic_multiedge_match('flowMin', None, eq) id_match = iso.generic_multiedge_match('id', None, eq) - assert_true(flow_match(self.G1[1][2], self.G2[2][3])) - assert_true(min_flow_match(self.G1[1][2], self.G2[2][3])) - assert_true(id_match(self.G1[1][2], self.G2[2][3])) - assert_true(full_match(self.G1[1][2], self.G2[2][3])) - assert_true(flow_match(self.G3[3][4], self.G4[4][5])) - assert_true(min_flow_match(self.G3[3][4], self.G4[4][5])) - assert_false(id_match(self.G3[3][4], self.G4[4][5])) - assert_false(full_match(self.G3[3][4], self.G4[4][5])) + assert flow_match(self.G1[1][2], self.G2[2][3]) + assert min_flow_match(self.G1[1][2], self.G2[2][3]) + assert id_match(self.G1[1][2], self.G2[2][3]) + assert full_match(self.G1[1][2], self.G2[2][3]) + assert flow_match(self.G3[3][4], self.G4[4][5]) + assert min_flow_match(self.G3[3][4], self.G4[4][5]) + assert not id_match(self.G3[3][4], self.G4[4][5]) + assert not full_match(self.G3[3][4], self.G4[4][5]) diff --git a/networkx/algorithms/isomorphism/tests/test_temporalisomorphvf2.py b/networkx/algorithms/isomorphism/tests/test_temporalisomorphvf2.py index 8257a8ae..adcbcd6e 100644 --- a/networkx/algorithms/isomorphism/tests/test_temporalisomorphvf2.py +++ b/networkx/algorithms/isomorphism/tests/test_temporalisomorphvf2.py @@ -86,7 +86,7 @@ class TestTimeRespectingGraphMatcher(object): G2 = self.provide_g2_path_3edges() d = timedelta() gm = iso.TimeRespectingGraphMatcher(G1, G2, temporal_name, d) - assert_true(gm.subgraph_is_isomorphic()) + assert gm.subgraph_is_isomorphic() def test_timdelta_zero_datetime_timeRespecting_returnsTrue(self): G1 = self.provide_g1_topology() @@ -95,7 +95,7 @@ class TestTimeRespectingGraphMatcher(object): G2 = self.provide_g2_path_3edges() d = timedelta() gm = iso.TimeRespectingGraphMatcher(G1, G2, temporal_name, d) - assert_true(gm.subgraph_is_isomorphic()) + assert gm.subgraph_is_isomorphic() def test_attNameStrange_timdelta_zero_timeRespecting_returnsTrue(self): G1 = self.provide_g1_topology() @@ -104,7 +104,7 @@ class TestTimeRespectingGraphMatcher(object): G2 = self.provide_g2_path_3edges() d = timedelta() gm = iso.TimeRespectingGraphMatcher(G1, G2, temporal_name, d) - assert_true(gm.subgraph_is_isomorphic()) + assert gm.subgraph_is_isomorphic() def test_notTimeRespecting_returnsFalse(self): G1 = self.provide_g1_topology() @@ -113,7 +113,7 @@ class TestTimeRespectingGraphMatcher(object): G2 = self.provide_g2_path_3edges() d = timedelta() gm = iso.TimeRespectingGraphMatcher(G1, G2, temporal_name, d) - assert_false(gm.subgraph_is_isomorphic()) + assert not gm.subgraph_is_isomorphic() def test_timdelta_one_config0_returns_no_embeddings(self): G1 = self.provide_g1_topology() @@ -123,7 +123,7 @@ class TestTimeRespectingGraphMatcher(object): d = timedelta(days=1) gm = iso.TimeRespectingGraphMatcher(G1, G2, temporal_name, d) count_match = len(list(gm.subgraph_isomorphisms_iter())) - assert_true(count_match == 0) + assert count_match == 0 def test_timdelta_one_config1_returns_four_embedding(self): G1 = self.provide_g1_topology() @@ -133,7 +133,7 @@ class TestTimeRespectingGraphMatcher(object): d = timedelta(days=1) gm = iso.TimeRespectingGraphMatcher(G1, G2, temporal_name, d) count_match = len(list(gm.subgraph_isomorphisms_iter())) - assert_true(count_match == 4) + assert count_match == 4 def test_timdelta_one_config2_returns_ten_embeddings(self): G1 = self.provide_g1_topology() @@ -144,7 +144,7 @@ class TestTimeRespectingGraphMatcher(object): gm = iso.TimeRespectingGraphMatcher(G1, G2, temporal_name, d) L = list(gm.subgraph_isomorphisms_iter()) count_match = len(list(gm.subgraph_isomorphisms_iter())) - assert_true(count_match == 10) + assert count_match == 10 class TestDiTimeRespectingGraphMatcher(object): @@ -169,7 +169,7 @@ class TestDiTimeRespectingGraphMatcher(object): G2 = self.provide_g2_path_3edges() d = timedelta() gm = iso.TimeRespectingDiGraphMatcher(G1, G2, temporal_name, d) - assert_true(gm.subgraph_is_isomorphic()) + assert gm.subgraph_is_isomorphic() def test_attNameStrange_timdelta_zero_same_dates_returns_true(self): G1 = self.provide_g1_topology() @@ -178,7 +178,7 @@ class TestDiTimeRespectingGraphMatcher(object): G2 = self.provide_g2_path_3edges() d = timedelta() gm = iso.TimeRespectingDiGraphMatcher(G1, G2, temporal_name, d) - assert_true(gm.subgraph_is_isomorphic()) + assert gm.subgraph_is_isomorphic() def test_timdelta_one_config0_returns_no_embeddings(self): G1 = self.provide_g1_topology() @@ -188,7 +188,7 @@ class TestDiTimeRespectingGraphMatcher(object): d = timedelta(days=1) gm = iso.TimeRespectingDiGraphMatcher(G1, G2, temporal_name, d) count_match = len(list(gm.subgraph_isomorphisms_iter())) - assert_true(count_match == 0) + assert count_match == 0 def test_timdelta_one_config1_returns_one_embedding(self): G1 = self.provide_g1_topology() @@ -198,7 +198,7 @@ class TestDiTimeRespectingGraphMatcher(object): d = timedelta(days=1) gm = iso.TimeRespectingDiGraphMatcher(G1, G2, temporal_name, d) count_match = len(list(gm.subgraph_isomorphisms_iter())) - assert_true(count_match == 1) + assert count_match == 1 def test_timdelta_one_config2_returns_two_embeddings(self): G1 = self.provide_g1_topology() @@ -208,4 +208,4 @@ class TestDiTimeRespectingGraphMatcher(object): d = timedelta(days=1) gm = iso.TimeRespectingDiGraphMatcher(G1, G2, temporal_name, d) count_match = len(list(gm.subgraph_isomorphisms_iter())) - assert_true(count_match == 2) + assert count_match == 2 diff --git a/networkx/algorithms/isomorphism/tests/test_vf2userfunc.py b/networkx/algorithms/isomorphism/tests/test_vf2userfunc.py index f704b204..39ddab59 100644 --- a/networkx/algorithms/isomorphism/tests/test_vf2userfunc.py +++ b/networkx/algorithms/isomorphism/tests/test_vf2userfunc.py @@ -25,7 +25,7 @@ def test_simple(): em = iso.numerical_multiedge_match('weight', 1) else: em = iso.numerical_edge_match('weight', 1) - assert_true(nx.is_isomorphic(g1, g2, edge_match=em)) + assert nx.is_isomorphic(g1, g2, edge_match=em) for mod1, mod2 in [(False, True), (True, False), (True, True)]: # mod1 tests a regular edge @@ -56,7 +56,7 @@ def test_simple(): g2._succ[0][0] = data2 g2._pred[0][0] = data2 - assert_false(nx.is_isomorphic(g1, g2, edge_match=em)) + assert not nx.is_isomorphic(g1, g2, edge_match=em) def test_weightkey(): @@ -66,15 +66,15 @@ def test_weightkey(): g1.add_edge('A', 'B', weight=1) g2.add_edge('C', 'D', weight=0) - assert_true(nx.is_isomorphic(g1, g2)) + assert nx.is_isomorphic(g1, g2) em = iso.numerical_edge_match('nonexistent attribute', 1) - assert_true(nx.is_isomorphic(g1, g2, edge_match=em)) + assert nx.is_isomorphic(g1, g2, edge_match=em) em = iso.numerical_edge_match('weight', 1) - assert_false(nx.is_isomorphic(g1, g2, edge_match=em)) + assert not nx.is_isomorphic(g1, g2, edge_match=em) g2 = nx.DiGraph() g2.add_edge('C', 'D') - assert_true(nx.is_isomorphic(g1, g2, edge_match=em)) + assert nx.is_isomorphic(g1, g2, edge_match=em) class TestNodeMatch_Graph(object): @@ -94,38 +94,38 @@ class TestNodeMatch_Graph(object): self.g2.add_edge('C', 'D', weight=1) def test_noweight_nocolor(self): - assert_true(nx.is_isomorphic(self.g1, self.g2)) + assert nx.is_isomorphic(self.g1, self.g2) def test_color1(self): - assert_false(nx.is_isomorphic(self.g1, self.g2, node_match=self.nm)) + assert not nx.is_isomorphic(self.g1, self.g2, node_match=self.nm) def test_color2(self): self.g1.nodes['A']['color'] = 'blue' - assert_true(nx.is_isomorphic(self.g1, self.g2, node_match=self.nm)) + assert nx.is_isomorphic(self.g1, self.g2, node_match=self.nm) def test_weight1(self): - assert_true(nx.is_isomorphic(self.g1, self.g2, edge_match=self.em)) + assert nx.is_isomorphic(self.g1, self.g2, edge_match=self.em) def test_weight2(self): self.g1.add_edge('A', 'B', weight=2) - assert_false(nx.is_isomorphic(self.g1, self.g2, edge_match=self.em)) + assert not nx.is_isomorphic(self.g1, self.g2, edge_match=self.em) def test_colorsandweights1(self): iso = nx.is_isomorphic(self.g1, self.g2, node_match=self.nm, edge_match=self.em) - assert_false(iso) + assert not iso def test_colorsandweights2(self): self.g1.nodes['A']['color'] = 'blue' iso = nx.is_isomorphic(self.g1, self.g2, node_match=self.nm, edge_match=self.em) - assert_true(iso) + assert iso def test_colorsandweights3(self): # make the weights disagree self.g1.add_edge('A', 'B', weight=2) - assert_false(nx.is_isomorphic(self.g1, self.g2, - node_match=self.nm, edge_match=self.em)) + assert not nx.is_isomorphic(self.g1, self.g2, + node_match=self.nm, edge_match=self.em) class TestEdgeMatch_MultiGraph(object): @@ -166,23 +166,23 @@ class TestEdgeMatch_MultiGraph(object): [eq, eq, iso.matchhelpers.close]) def test_weights_only(self): - assert_true(nx.is_isomorphic(self.g1, self.g2, edge_match=self.em)) + assert nx.is_isomorphic(self.g1, self.g2, edge_match=self.em) def test_colors_only(self): gm = self.GM(self.g1, self.g2, edge_match=self.emc) - assert_true(gm.is_isomorphic()) + assert gm.is_isomorphic() def test_colorsandweights(self): gm = self.GM(self.g1, self.g2, edge_match=self.emcm) - assert_false(gm.is_isomorphic()) + assert not gm.is_isomorphic() def test_generic1(self): gm = self.GM(self.g1, self.g2, edge_match=self.emg1) - assert_true(gm.is_isomorphic()) + assert gm.is_isomorphic() def test_generic2(self): gm = self.GM(self.g1, self.g2, edge_match=self.emg2) - assert_false(gm.is_isomorphic()) + assert not gm.is_isomorphic() class TestEdgeMatch_DiGraph(TestNodeMatch_Graph): diff --git a/networkx/algorithms/link_analysis/tests/test_hits.py b/networkx/algorithms/link_analysis/tests/test_hits.py index 8c584955..eb1de32f 100644 --- a/networkx/algorithms/link_analysis/tests/test_hits.py +++ b/networkx/algorithms/link_analysis/tests/test_hits.py @@ -76,10 +76,10 @@ class TestHITS: except ImportError: raise SkipTest('numpy not available.') G = networkx.Graph() - assert_equal(networkx.hits(G), ({}, {})) - assert_equal(networkx.hits_numpy(G), ({}, {})) - assert_equal(networkx.authority_matrix(G).shape, (0, 0)) - assert_equal(networkx.hub_matrix(G).shape, (0, 0)) + assert networkx.hits(G) == ({}, {}) + assert networkx.hits_numpy(G) == ({}, {}) + assert networkx.authority_matrix(G).shape == (0, 0) + assert networkx.hub_matrix(G).shape == (0, 0) def test_empty_scipy(self): try: @@ -87,7 +87,7 @@ class TestHITS: except ImportError: raise SkipTest('scipy not available.') G = networkx.Graph() - assert_equal(networkx.hits_scipy(G), ({}, {})) + assert networkx.hits_scipy(G) == ({}, {}) @raises(networkx.PowerIterationFailedConvergence) def test_hits_not_convergent(self): diff --git a/networkx/algorithms/link_analysis/tests/test_pagerank.py b/networkx/algorithms/link_analysis/tests/test_pagerank.py index 5b2f87ee..6875f36c 100644 --- a/networkx/algorithms/link_analysis/tests/test_pagerank.py +++ b/networkx/algorithms/link_analysis/tests/test_pagerank.py @@ -132,9 +132,9 @@ class TestPageRank(object): def test_empty(self): G = networkx.Graph() - assert_equal(networkx.pagerank(G), {}) - assert_equal(networkx.pagerank_numpy(G), {}) - assert_equal(networkx.google_matrix(G).shape, (0, 0)) + assert networkx.pagerank(G) == {} + assert networkx.pagerank_numpy(G) == {} + assert networkx.google_matrix(G).shape == (0, 0) class TestPageRankScipy(TestPageRank): @@ -172,4 +172,4 @@ class TestPageRankScipy(TestPageRank): def test_empty_scipy(self): G = networkx.Graph() - assert_equal(networkx.pagerank_scipy(G), {}) + assert networkx.pagerank_scipy(G) == {} diff --git a/networkx/algorithms/node_classification/tests/test_harmonic_function.py b/networkx/algorithms/node_classification/tests/test_harmonic_function.py index 5bdc083d..ca728e92 100644 --- a/networkx/algorithms/node_classification/tests/test_harmonic_function.py +++ b/networkx/algorithms/node_classification/tests/test_harmonic_function.py @@ -27,10 +27,10 @@ class TestHarmonicFunction: G.node[3][label_name] = 'B' predicted = node_classification.harmonic_function( G, label_name=label_name) - assert_equal(predicted[0], 'A') - assert_equal(predicted[1], 'A') - assert_equal(predicted[2], 'B') - assert_equal(predicted[3], 'B') + assert predicted[0] == 'A' + assert predicted[1] == 'A' + assert predicted[2] == 'B' + assert predicted[3] == 'B' @raises(nx.NetworkXError) def test_no_labels(self): @@ -66,10 +66,10 @@ class TestHarmonicFunction: G.node[0][label_name] = 'A' predicted = node_classification.harmonic_function( G, label_name=label_name) - assert_equal(predicted[0], 'A') - assert_equal(predicted[1], 'A') - assert_equal(predicted[2], 'A') - assert_equal(predicted[3], 'A') + assert predicted[0] == 'A' + assert predicted[1] == 'A' + assert predicted[2] == 'A' + assert predicted[3] == 'A' def test_nodes_all_labeled(self): G = nx.karate_club_graph() @@ -77,7 +77,7 @@ class TestHarmonicFunction: predicted = node_classification.harmonic_function( G, label_name=label_name) for i in range(len(G)): - assert_equal(predicted[i], G.node[i][label_name]) + assert predicted[i] == G.node[i][label_name] def test_labeled_nodes_are_not_changed(self): G = nx.karate_club_graph() @@ -89,4 +89,4 @@ class TestHarmonicFunction: G, label_name=label_name) label_not_removed = set(list(range(len(G)))) - label_removed for i in label_not_removed: - assert_equal(predicted[i], G.node[i][label_name]) + assert predicted[i] == G.node[i][label_name] diff --git a/networkx/algorithms/node_classification/tests/test_local_and_global_consistency.py b/networkx/algorithms/node_classification/tests/test_local_and_global_consistency.py index 84f1ca52..0402603d 100644 --- a/networkx/algorithms/node_classification/tests/test_local_and_global_consistency.py +++ b/networkx/algorithms/node_classification/tests/test_local_and_global_consistency.py @@ -27,10 +27,10 @@ class TestLocalAndGlobalConsistency: G.node[3][label_name] = 'B' predicted = node_classification.local_and_global_consistency( G, label_name=label_name) - assert_equal(predicted[0], 'A') - assert_equal(predicted[1], 'A') - assert_equal(predicted[2], 'B') - assert_equal(predicted[3], 'B') + assert predicted[0] == 'A' + assert predicted[1] == 'A' + assert predicted[2] == 'B' + assert predicted[3] == 'B' @raises(nx.NetworkXError) def test_no_labels(self): @@ -66,10 +66,10 @@ class TestLocalAndGlobalConsistency: G.node[0][label_name] = 'A' predicted = node_classification.local_and_global_consistency( G, label_name=label_name) - assert_equal(predicted[0], 'A') - assert_equal(predicted[1], 'A') - assert_equal(predicted[2], 'A') - assert_equal(predicted[3], 'A') + assert predicted[0] == 'A' + assert predicted[1] == 'A' + assert predicted[2] == 'A' + assert predicted[3] == 'A' def test_nodes_all_labeled(self): G = nx.karate_club_graph() @@ -77,4 +77,4 @@ class TestLocalAndGlobalConsistency: predicted = node_classification.local_and_global_consistency( G, alpha=0, label_name=label_name) for i in range(len(G)): - assert_equal(predicted[i], G.node[i][label_name]) + assert predicted[i] == G.node[i][label_name] diff --git a/networkx/algorithms/operators/tests/test_all.py b/networkx/algorithms/operators/tests/test_all.py index 58a99925..2e761e84 100644 --- a/networkx/algorithms/operators/tests/test_all.py +++ b/networkx/algorithms/operators/tests/test_all.py @@ -21,13 +21,13 @@ def test_union_all_attributes(): j.nodes[0]['x'] = 7 ghj = nx.union_all([g, h, j], rename=('g', 'h', 'j')) - assert_equal(set(ghj.nodes()), set(['h0', 'h1', 'g0', 'g1', 'j0', 'j1'])) + assert set(ghj.nodes()) == set(['h0', 'h1', 'g0', 'g1', 'j0', 'j1']) for n in ghj: graph, node = n - assert_equal(ghj.nodes[n], eval(graph).nodes[int(node)]) + assert ghj.nodes[n] == eval(graph).nodes[int(node)] - assert_equal(ghj.graph['attr'], 'attr') - assert_equal(ghj.graph['name'], 'j') # j graph attributes take precendent + assert ghj.graph['attr'] == 'attr' + assert ghj.graph['name'] == 'j' # j graph attributes take precendent def test_intersection_all(): @@ -44,8 +44,8 @@ def test_intersection_all(): R.add_edge(2, 3) R.add_edge(4, 1) I = nx.intersection_all([G, H, R]) - assert_equal(set(I.nodes()), set([1, 2, 3, 4])) - assert_equal(sorted(I.edges()), [(2, 3)]) + assert set(I.nodes()) == set([1, 2, 3, 4]) + assert sorted(I.edges()) == [(2, 3)] def test_intersection_all_attributes(): @@ -61,9 +61,9 @@ def test_intersection_all_attributes(): h.nodes[0]['x'] = 7 gh = nx.intersection_all([g, h]) - assert_equal(set(gh.nodes()), set(g.nodes())) - assert_equal(set(gh.nodes()), set(h.nodes())) - assert_equal(sorted(gh.edges()), sorted(g.edges())) + assert set(gh.nodes()) == set(g.nodes()) + assert set(gh.nodes()) == set(h.nodes()) + assert sorted(gh.edges()) == sorted(g.edges()) h.remove_node(0) assert_raises(nx.NetworkXError, nx.intersection, g, h) @@ -78,10 +78,10 @@ def test_intersection_all_multigraph_attributes(): h.add_edge(0, 1, key=0) h.add_edge(0, 1, key=3) gh = nx.intersection_all([g, h]) - assert_equal(set(gh.nodes()), set(g.nodes())) - assert_equal(set(gh.nodes()), set(h.nodes())) - assert_equal(sorted(gh.edges()), [(0, 1)]) - assert_equal(sorted(gh.edges(keys=True)), [(0, 1, 0)]) + assert set(gh.nodes()) == set(g.nodes()) + assert set(gh.nodes()) == set(h.nodes()) + assert sorted(gh.edges()) == [(0, 1)] + assert sorted(gh.edges(keys=True)) == [(0, 1, 0)] def test_union_all_and_compose_all(): @@ -100,38 +100,38 @@ def test_union_all_and_compose_all(): G = nx.union_all([G1, G2]) H = nx.compose_all([G1, G2]) assert_edges_equal(G.edges(), H.edges()) - assert_false(G.has_edge('A', '1')) + assert not G.has_edge('A', '1') assert_raises(nx.NetworkXError, nx.union, K3, P3) H1 = nx.union_all([H, G1], rename=('H', 'G1')) - assert_equal(sorted(H1.nodes()), + assert (sorted(H1.nodes()) == ['G1A', 'G1B', 'G1C', 'G1D', 'H1', 'H2', 'H3', 'H4', 'HA', 'HB', 'HC', 'HD']) H2 = nx.union_all([H, G2], rename=("H", "")) - assert_equal(sorted(H2.nodes()), + assert (sorted(H2.nodes()) == ['1', '2', '3', '4', 'H1', 'H2', 'H3', 'H4', 'HA', 'HB', 'HC', 'HD']) - assert_false(H1.has_edge('NB', 'NA')) + assert not H1.has_edge('NB', 'NA') G = nx.compose_all([G, G]) assert_edges_equal(G.edges(), H.edges()) G2 = nx.union_all([G2, G2], rename=('', 'copy')) - assert_equal(sorted(G2.nodes()), + assert (sorted(G2.nodes()) == ['1', '2', '3', '4', 'copy1', 'copy2', 'copy3', 'copy4']) - assert_equal(sorted(G2.neighbors('copy4')), []) - assert_equal(sorted(G2.neighbors('copy1')), ['copy2', 'copy3', 'copy4']) - assert_equal(len(G), 8) - assert_equal(nx.number_of_edges(G), 6) + assert sorted(G2.neighbors('copy4')) == [] + assert sorted(G2.neighbors('copy1')) == ['copy2', 'copy3', 'copy4'] + assert len(G) == 8 + assert nx.number_of_edges(G) == 6 E = nx.disjoint_union_all([G, G]) - assert_equal(len(E), 16) - assert_equal(nx.number_of_edges(E), 12) + assert len(E) == 16 + assert nx.number_of_edges(E) == 12 E = nx.disjoint_union_all([G1, G2]) - assert_equal(sorted(E.nodes()), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) + assert sorted(E.nodes()) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] G1 = nx.DiGraph() G1.add_edge('A', 'B') @@ -140,7 +140,7 @@ def test_union_all_and_compose_all(): G3 = nx.DiGraph() G3.add_edge(11, 22) G4 = nx.union_all([G1, G2, G3], rename=("G1", "G2", "G3")) - assert_equal(sorted(G4.nodes()), + assert (sorted(G4.nodes()) == ['G1A', 'G1B', 'G21', 'G22', 'G311', 'G322']) @@ -153,20 +153,20 @@ def test_union_all_multigraph(): H.add_edge(3, 4, key=0) H.add_edge(3, 4, key=1) GH = nx.union_all([G, H]) - assert_equal(set(GH), set(G) | set(H)) - assert_equal(set(GH.edges(keys=True)), + assert set(GH) == set(G) | set(H) + assert (set(GH.edges(keys=True)) == set(G.edges(keys=True)) | set(H.edges(keys=True))) def test_input_output(): l = [nx.Graph([(1, 2)]), nx.Graph([(3, 4)])] U = nx.disjoint_union_all(l) - assert_equal(len(l), 2) + assert len(l) == 2 C = nx.compose_all(l) - assert_equal(len(l), 2) + assert len(l) == 2 l = [nx.Graph([(1, 2)]), nx.Graph([(1, 2)])] R = nx.intersection_all(l) - assert_equal(len(l), 2) + assert len(l) == 2 @raises(nx.NetworkXError) diff --git a/networkx/algorithms/operators/tests/test_binary.py b/networkx/algorithms/operators/tests/test_binary.py index 263d9448..a4f0c5e8 100644 --- a/networkx/algorithms/operators/tests/test_binary.py +++ b/networkx/algorithms/operators/tests/test_binary.py @@ -16,13 +16,13 @@ def test_union_attributes(): h.nodes[0]['x'] = 7 gh = nx.union(g, h, rename=('g', 'h')) - assert_equal(set(gh.nodes()), set(['h0', 'h1', 'g0', 'g1'])) + assert set(gh.nodes()) == set(['h0', 'h1', 'g0', 'g1']) for n in gh: graph, node = n - assert_equal(gh.nodes[n], eval(graph).nodes[int(node)]) + assert gh.nodes[n] == eval(graph).nodes[int(node)] - assert_equal(gh.graph['attr'], 'attr') - assert_equal(gh.graph['name'], 'h') # h graph attributes take precendent + assert gh.graph['attr'] == 'attr' + assert gh.graph['name'] == 'h' # h graph attributes take precendent def test_intersection(): @@ -35,8 +35,8 @@ def test_intersection(): H.add_edge(2, 3) H.add_edge(3, 4) I = nx.intersection(G, H) - assert_equal(set(I.nodes()), set([1, 2, 3, 4])) - assert_equal(sorted(I.edges()), [(2, 3)]) + assert set(I.nodes()) == set([1, 2, 3, 4]) + assert sorted(I.edges()) == [(2, 3)] def test_intersection_attributes(): @@ -52,9 +52,9 @@ def test_intersection_attributes(): h.nodes[0]['x'] = 7 gh = nx.intersection(g, h) - assert_equal(set(gh.nodes()), set(g.nodes())) - assert_equal(set(gh.nodes()), set(h.nodes())) - assert_equal(sorted(gh.edges()), sorted(g.edges())) + assert set(gh.nodes()) == set(g.nodes()) + assert set(gh.nodes()) == set(h.nodes()) + assert sorted(gh.edges()) == sorted(g.edges()) h.remove_node(0) assert_raises(nx.NetworkXError, nx.intersection, g, h) @@ -69,10 +69,10 @@ def test_intersection_multigraph_attributes(): h.add_edge(0, 1, key=0) h.add_edge(0, 1, key=3) gh = nx.intersection(g, h) - assert_equal(set(gh.nodes()), set(g.nodes())) - assert_equal(set(gh.nodes()), set(h.nodes())) - assert_equal(sorted(gh.edges()), [(0, 1)]) - assert_equal(sorted(gh.edges(keys=True)), [(0, 1, 0)]) + assert set(gh.nodes()) == set(g.nodes()) + assert set(gh.nodes()) == set(h.nodes()) + assert sorted(gh.edges()) == [(0, 1)] + assert sorted(gh.edges(keys=True)) == [(0, 1, 0)] def test_difference(): @@ -85,14 +85,14 @@ def test_difference(): H.add_edge(2, 3) H.add_edge(3, 4) D = nx.difference(G, H) - assert_equal(set(D.nodes()), set([1, 2, 3, 4])) - assert_equal(sorted(D.edges()), [(1, 2)]) + assert set(D.nodes()) == set([1, 2, 3, 4]) + assert sorted(D.edges()) == [(1, 2)] D = nx.difference(H, G) - assert_equal(set(D.nodes()), set([1, 2, 3, 4])) - assert_equal(sorted(D.edges()), [(3, 4)]) + assert set(D.nodes()) == set([1, 2, 3, 4]) + assert sorted(D.edges()) == [(3, 4)] D = nx.symmetric_difference(G, H) - assert_equal(set(D.nodes()), set([1, 2, 3, 4])) - assert_equal(sorted(D.edges()), [(1, 2), (3, 4)]) + assert set(D.nodes()) == set([1, 2, 3, 4]) + assert sorted(D.edges()) == [(1, 2), (3, 4)] def test_difference2(): @@ -104,15 +104,15 @@ def test_difference2(): H.add_edge(1, 2) G.add_edge(2, 3) D = nx.difference(G, H) - assert_equal(set(D.nodes()), set([1, 2, 3, 4])) - assert_equal(sorted(D.edges()), [(2, 3)]) + assert set(D.nodes()) == set([1, 2, 3, 4]) + assert sorted(D.edges()) == [(2, 3)] D = nx.difference(H, G) - assert_equal(set(D.nodes()), set([1, 2, 3, 4])) - assert_equal(sorted(D.edges()), []) + assert set(D.nodes()) == set([1, 2, 3, 4]) + assert sorted(D.edges()) == [] H.add_edge(3, 4) D = nx.difference(H, G) - assert_equal(set(D.nodes()), set([1, 2, 3, 4])) - assert_equal(sorted(D.edges()), [(3, 4)]) + assert set(D.nodes()) == set([1, 2, 3, 4]) + assert sorted(D.edges()) == [(3, 4)] def test_difference_attributes(): @@ -128,9 +128,9 @@ def test_difference_attributes(): h.nodes[0]['x'] = 7 gh = nx.difference(g, h) - assert_equal(set(gh.nodes()), set(g.nodes())) - assert_equal(set(gh.nodes()), set(h.nodes())) - assert_equal(sorted(gh.edges()), []) + assert set(gh.nodes()) == set(g.nodes()) + assert set(gh.nodes()) == set(h.nodes()) + assert sorted(gh.edges()) == [] h.remove_node(0) assert_raises(nx.NetworkXError, nx.intersection, g, h) @@ -145,10 +145,10 @@ def test_difference_multigraph_attributes(): h.add_edge(0, 1, key=0) h.add_edge(0, 1, key=3) gh = nx.difference(g, h) - assert_equal(set(gh.nodes()), set(g.nodes())) - assert_equal(set(gh.nodes()), set(h.nodes())) - assert_equal(sorted(gh.edges()), [(0, 1), (0, 1)]) - assert_equal(sorted(gh.edges(keys=True)), [(0, 1, 1), (0, 1, 2)]) + assert set(gh.nodes()) == set(g.nodes()) + assert set(gh.nodes()) == set(h.nodes()) + assert sorted(gh.edges()) == [(0, 1), (0, 1)] + assert sorted(gh.edges(keys=True)) == [(0, 1, 1), (0, 1, 2)] def test_difference_raise(): @@ -167,10 +167,10 @@ def test_symmetric_difference_multigraph(): h.add_edge(0, 1, key=0) h.add_edge(0, 1, key=3) gh = nx.symmetric_difference(g, h) - assert_equal(set(gh.nodes()), set(g.nodes())) - assert_equal(set(gh.nodes()), set(h.nodes())) - assert_equal(sorted(gh.edges()), 3 * [(0, 1)]) - assert_equal(sorted(sorted(e) for e in gh.edges(keys=True)), + assert set(gh.nodes()) == set(g.nodes()) + assert set(gh.nodes()) == set(h.nodes()) + assert sorted(gh.edges()) == 3 * [(0, 1)] + assert (sorted(sorted(e) for e in gh.edges(keys=True)) == [[0, 1, 1], [0, 1, 2], [0, 1, 3]]) @@ -190,45 +190,45 @@ def test_union_and_compose(): G = nx.union(G1, G2) H = nx.compose(G1, G2) assert_edges_equal(G.edges(), H.edges()) - assert_false(G.has_edge('A', 1)) + assert not G.has_edge('A', 1) assert_raises(nx.NetworkXError, nx.union, K3, P3) H1 = nx.union(H, G1, rename=('H', 'G1')) - assert_equal(sorted(H1.nodes()), + assert (sorted(H1.nodes()) == ['G1A', 'G1B', 'G1C', 'G1D', 'H1', 'H2', 'H3', 'H4', 'HA', 'HB', 'HC', 'HD']) H2 = nx.union(H, G2, rename=("H", "")) - assert_equal(sorted(H2.nodes()), + assert (sorted(H2.nodes()) == ['1', '2', '3', '4', 'H1', 'H2', 'H3', 'H4', 'HA', 'HB', 'HC', 'HD']) - assert_false(H1.has_edge('NB', 'NA')) + assert not H1.has_edge('NB', 'NA') G = nx.compose(G, G) assert_edges_equal(G.edges(), H.edges()) G2 = nx.union(G2, G2, rename=('', 'copy')) - assert_equal(sorted(G2.nodes()), + assert (sorted(G2.nodes()) == ['1', '2', '3', '4', 'copy1', 'copy2', 'copy3', 'copy4']) - assert_equal(sorted(G2.neighbors('copy4')), []) - assert_equal(sorted(G2.neighbors('copy1')), ['copy2', 'copy3', 'copy4']) - assert_equal(len(G), 8) - assert_equal(nx.number_of_edges(G), 6) + assert sorted(G2.neighbors('copy4')) == [] + assert sorted(G2.neighbors('copy1')) == ['copy2', 'copy3', 'copy4'] + assert len(G) == 8 + assert nx.number_of_edges(G) == 6 E = nx.disjoint_union(G, G) - assert_equal(len(E), 16) - assert_equal(nx.number_of_edges(E), 12) + assert len(E) == 16 + assert nx.number_of_edges(E) == 12 E = nx.disjoint_union(G1, G2) - assert_equal(sorted(E.nodes()), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) + assert sorted(E.nodes()) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] G = nx.Graph() H = nx.Graph() G.add_nodes_from([(1, {'a1': 1})]) H.add_nodes_from([(1, {'b1': 1})]) R = nx.compose(G, H) - assert_equal(R.nodes, {1: {'a1': 1, 'b1': 1}}) + assert R.nodes == {1: {'a1': 1, 'b1': 1}} def test_union_multigraph(): @@ -239,8 +239,8 @@ def test_union_multigraph(): H.add_edge(3, 4, key=0) H.add_edge(3, 4, key=1) GH = nx.union(G, H) - assert_equal(set(GH), set(G) | set(H)) - assert_equal(set(GH.edges(keys=True)), + assert set(GH) == set(G) | set(H) + assert (set(GH.edges(keys=True)) == set(G.edges(keys=True)) | set(H.edges(keys=True))) @@ -252,8 +252,8 @@ def test_disjoint_union_multigraph(): H.add_edge(2, 3, key=0) H.add_edge(2, 3, key=1) GH = nx.disjoint_union(G, H) - assert_equal(set(GH), set(G) | set(H)) - assert_equal(set(GH.edges(keys=True)), + assert set(GH) == set(G) | set(H) + assert (set(GH.edges(keys=True)) == set(G.edges(keys=True)) | set(H.edges(keys=True))) @@ -265,13 +265,13 @@ def test_compose_multigraph(): H.add_edge(3, 4, key=0) H.add_edge(3, 4, key=1) GH = nx.compose(G, H) - assert_equal(set(GH), set(G) | set(H)) - assert_equal(set(GH.edges(keys=True)), + assert set(GH) == set(G) | set(H) + assert (set(GH.edges(keys=True)) == set(G.edges(keys=True)) | set(H.edges(keys=True))) H.add_edge(1, 2, key=2) GH = nx.compose(G, H) - assert_equal(set(GH), set(G) | set(H)) - assert_equal(set(GH.edges(keys=True)), + assert set(GH) == set(G) | set(H) + assert (set(GH.edges(keys=True)) == set(G.edges(keys=True)) | set(H.edges(keys=True))) @@ -284,19 +284,17 @@ def test_full_join_graph(): H.add_edge(3, 4) U = nx.full_join(G, H) - assert_equal(set(U), set(G) | set(H)) - assert_equal(len(U), len(G) + len(H)) - assert_equal(len(U.edges()), - len(G.edges()) + len(H.edges()) + len(G) * len(H) - ) + assert set(U) == set(G) | set(H) + assert len(U) == len(G) + len(H) + assert (len(U.edges()) == + len(G.edges()) + len(H.edges()) + len(G) * len(H)) # Rename U = nx.full_join(G, H, rename=('g', 'h')) - assert_equal(set(U), set(['g0', 'g1', 'g2', 'h3', 'h4'])) - assert_equal(len(U), len(G) + len(H)) - assert_equal(len(U.edges()), - len(G.edges()) + len(H.edges()) + len(G) * len(H) - ) + assert set(U) == set(['g0', 'g1', 'g2', 'h3', 'h4']) + assert len(U) == len(G) + len(H) + assert (len(U.edges()) == + len(G.edges()) + len(H.edges()) + len(G) * len(H)) # Rename graphs with string-like nodes G = nx.Graph() @@ -306,11 +304,10 @@ def test_full_join_graph(): H.add_edge("d", "e") U = nx.full_join(G, H, rename=('g', 'h')) - assert_equal(set(U), set(['ga', 'gb', 'gc', 'hd', 'he'])) - assert_equal(len(U), len(G) + len(H)) - assert_equal(len(U.edges()), - len(G.edges()) + len(H.edges()) + len(G) * len(H) - ) + assert set(U) == set(['ga', 'gb', 'gc', 'hd', 'he']) + assert len(U) == len(G) + len(H) + assert (len(U.edges()) == + len(G.edges()) + len(H.edges()) + len(G) * len(H)) # DiGraphs G = nx.DiGraph() @@ -320,19 +317,17 @@ def test_full_join_graph(): H.add_edge(3, 4) U = nx.full_join(G, H) - assert_equal(set(U), set(G) | set(H)) - assert_equal(len(U), len(G) + len(H)) - assert_equal(len(U.edges()), - len(G.edges()) + len(H.edges()) + len(G)*len(H) * 2 - ) + assert set(U) == set(G) | set(H) + assert len(U) == len(G) + len(H) + assert (len(U.edges()) == + len(G.edges()) + len(H.edges()) + len(G)*len(H) * 2) # DiGraphs Rename U = nx.full_join(G, H, rename=('g', 'h')) - assert_equal(set(U), set(['g0', 'g1', 'g2', 'h3', 'h4'])) - assert_equal(len(U), len(G) + len(H)) - assert_equal(len(U.edges()), - len(G.edges()) + len(H.edges()) + len(G) * len(H) * 2 - ) + assert set(U) == set(['g0', 'g1', 'g2', 'h3', 'h4']) + assert len(U) == len(G) + len(H) + assert (len(U.edges()) == + len(G.edges()) + len(H.edges()) + len(G) * len(H) * 2) def test_full_join_multigraph(): @@ -344,19 +339,17 @@ def test_full_join_multigraph(): H.add_edge(3, 4) U = nx.full_join(G, H) - assert_equal(set(U), set(G) | set(H)) - assert_equal(len(U), len(G) + len(H)) - assert_equal(len(U.edges()), - len(G.edges()) + len(H.edges()) + len(G) * len(H) - ) + assert set(U) == set(G) | set(H) + assert len(U) == len(G) + len(H) + assert (len(U.edges()) == + len(G.edges()) + len(H.edges()) + len(G) * len(H)) # MultiGraphs rename U = nx.full_join(G, H, rename=('g', 'h')) - assert_equal(set(U), set(['g0', 'g1', 'g2', 'h3', 'h4'])) - assert_equal(len(U), len(G) + len(H)) - assert_equal(len(U.edges()), - len(G.edges()) + len(H.edges()) + len(G) * len(H) - ) + assert set(U) == set(['g0', 'g1', 'g2', 'h3', 'h4']) + assert len(U) == len(G) + len(H) + assert (len(U.edges()) == + len(G.edges()) + len(H.edges()) + len(G) * len(H)) # MultiDiGraphs G = nx.MultiDiGraph() @@ -366,19 +359,17 @@ def test_full_join_multigraph(): H.add_edge(3, 4) U = nx.full_join(G, H) - assert_equal(set(U), set(G) | set(H)) - assert_equal(len(U), len(G) + len(H)) - assert_equal(len(U.edges()), - len(G.edges()) + len(H.edges()) + len(G) * len(H) * 2 - ) + assert set(U) == set(G) | set(H) + assert len(U) == len(G) + len(H) + assert (len(U.edges()) == + len(G.edges()) + len(H.edges()) + len(G) * len(H) * 2) # MultiDiGraphs rename U = nx.full_join(G, H, rename=('g', 'h')) - assert_equal(set(U), set(['g0', 'g1', 'g2', 'h3', 'h4'])) - assert_equal(len(U), len(G) + len(H)) - assert_equal(len(U.edges()), - len(G.edges()) + len(H.edges()) + len(G) * len(H) * 2 - ) + assert set(U) == set(['g0', 'g1', 'g2', 'h3', 'h4']) + assert len(U) == len(G) + len(H) + assert (len(U.edges()) == + len(G.edges()) + len(H.edges()) + len(G) * len(H) * 2) def test_mixed_type_union(): diff --git a/networkx/algorithms/operators/tests/test_product.py b/networkx/algorithms/operators/tests/test_product.py index 6ab5b504..f6a9e078 100644 --- a/networkx/algorithms/operators/tests/test_product.py +++ b/networkx/algorithms/operators/tests/test_product.py @@ -17,28 +17,28 @@ def test_tensor_product_null(): P10 = nx.path_graph(10) # null graph G = nx.tensor_product(null, null) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) # null_graph X anything = null_graph and v.v. G = nx.tensor_product(null, empty10) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.tensor_product(null, K3) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.tensor_product(null, K10) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.tensor_product(null, P3) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.tensor_product(null, P10) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.tensor_product(empty10, null) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.tensor_product(K3, null) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.tensor_product(K10, null) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.tensor_product(P3, null) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.tensor_product(P10, null) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) def test_tensor_product_size(): @@ -47,9 +47,9 @@ def test_tensor_product_size(): K5 = nx.complete_graph(5) G = nx.tensor_product(P5, K3) - assert_equal(nx.number_of_nodes(G), 5 * 3) + assert nx.number_of_nodes(G) == 5 * 3 G = nx.tensor_product(K3, K5) - assert_equal(nx.number_of_nodes(G), 3 * 5) + assert nx.number_of_nodes(G) == 3 * 5 def test_tensor_product_combinations(): @@ -57,31 +57,31 @@ def test_tensor_product_combinations(): P5 = nx.path_graph(5) K3 = nx.complete_graph(3) G = nx.tensor_product(P5, K3) - assert_equal(nx.number_of_nodes(G), 5 * 3) + assert nx.number_of_nodes(G) == 5 * 3 G = nx.tensor_product(P5, nx.MultiGraph(K3)) - assert_equal(nx.number_of_nodes(G), 5 * 3) + assert nx.number_of_nodes(G) == 5 * 3 G = nx.tensor_product(nx.MultiGraph(P5), K3) - assert_equal(nx.number_of_nodes(G), 5 * 3) + assert nx.number_of_nodes(G) == 5 * 3 G = nx.tensor_product(nx.MultiGraph(P5), nx.MultiGraph(K3)) - assert_equal(nx.number_of_nodes(G), 5 * 3) + assert nx.number_of_nodes(G) == 5 * 3 G = nx.tensor_product(nx.DiGraph(P5), nx.DiGraph(K3)) - assert_equal(nx.number_of_nodes(G), 5 * 3) + assert nx.number_of_nodes(G) == 5 * 3 def test_tensor_product_classic_result(): K2 = nx.complete_graph(2) G = nx.petersen_graph() G = nx.tensor_product(G, K2) - assert_true(nx.is_isomorphic(G, nx.desargues_graph())) + assert nx.is_isomorphic(G, nx.desargues_graph()) G = nx.cycle_graph(5) G = nx.tensor_product(G, K2) - assert_true(nx.is_isomorphic(G, nx.cycle_graph(10))) + assert nx.is_isomorphic(G, nx.cycle_graph(10)) G = nx.tetrahedral_graph() G = nx.tensor_product(G, K2) - assert_true(nx.is_isomorphic(G, nx.cubical_graph())) + assert nx.is_isomorphic(G, nx.cubical_graph()) def test_tensor_product_random(): @@ -92,9 +92,9 @@ def test_tensor_product_random(): for (u_G, u_H) in GH.nodes(): for (v_G, v_H) in GH.nodes(): if H.has_edge(u_H, v_H) and G.has_edge(u_G, v_G): - assert_true(GH.has_edge((u_G, u_H), (v_G, v_H))) + assert GH.has_edge((u_G, u_H), (v_G, v_H)) else: - assert_true(not GH.has_edge((u_G, u_H), (v_G, v_H))) + assert not GH.has_edge((u_G, u_H), (v_G, v_H)) def test_cartesian_product_multigraph(): @@ -105,8 +105,8 @@ def test_cartesian_product_multigraph(): H.add_edge(3, 4, key=0) H.add_edge(3, 4, key=1) GH = nx.cartesian_product(G, H) - assert_equal(set(GH), {(1, 3), (2, 3), (2, 4), (1, 4)}) - assert_equal({(frozenset([u, v]), k) for u, v, k in GH.edges(keys=True)}, + assert set(GH) == {(1, 3), (2, 3), (2, 4), (1, 4)} + assert ({(frozenset([u, v]), k) for u, v, k in GH.edges(keys=True)} == {(frozenset([u, v]), k) for u, v, k in [((1, 3), (2, 3), 0), ((1, 3), (2, 3), 1), ((1, 3), (1, 4), 0), ((1, 3), (1, 4), 1), @@ -128,28 +128,28 @@ def test_cartesian_product_null(): P10 = nx.path_graph(10) # null graph G = nx.cartesian_product(null, null) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) # null_graph X anything = null_graph and v.v. G = nx.cartesian_product(null, empty10) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.cartesian_product(null, K3) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.cartesian_product(null, K10) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.cartesian_product(null, P3) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.cartesian_product(null, P10) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.cartesian_product(empty10, null) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.cartesian_product(K3, null) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.cartesian_product(K10, null) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.cartesian_product(P3, null) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.cartesian_product(P10, null) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) def test_cartesian_product_size(): @@ -158,13 +158,13 @@ def test_cartesian_product_size(): P5 = nx.path_graph(5) K3 = nx.complete_graph(3) G = nx.cartesian_product(P5, K3) - assert_equal(nx.number_of_nodes(G), 5 * 3) - assert_equal(nx.number_of_edges(G), + assert nx.number_of_nodes(G) == 5 * 3 + assert (nx.number_of_edges(G) == nx.number_of_edges(P5) * nx.number_of_nodes(K3) + nx.number_of_edges(K3) * nx.number_of_nodes(P5)) G = nx.cartesian_product(K3, K5) - assert_equal(nx.number_of_nodes(G), 3 * 5) - assert_equal(nx.number_of_edges(G), + assert nx.number_of_nodes(G) == 3 * 5 + assert (nx.number_of_edges(G) == nx.number_of_edges(K5) * nx.number_of_nodes(K3) + nx.number_of_edges(K3) * nx.number_of_nodes(K5)) @@ -176,11 +176,11 @@ def test_cartesian_product_classic(): # cube = 2-path X 2-path G = nx.cartesian_product(P2, P2) G = nx.cartesian_product(P2, G) - assert_true(nx.is_isomorphic(G, nx.cubical_graph())) + assert nx.is_isomorphic(G, nx.cubical_graph()) # 3x3 grid G = nx.cartesian_product(P3, P3) - assert_true(nx.is_isomorphic(G, nx.grid_2d_graph(3, 3))) + assert nx.is_isomorphic(G, nx.grid_2d_graph(3, 3)) def test_cartesian_product_random(): @@ -192,9 +192,9 @@ def test_cartesian_product_random(): for (v_G, v_H) in GH.nodes(): if (u_G == v_G and H.has_edge(u_H, v_H)) or \ (u_H == v_H and G.has_edge(u_G, v_G)): - assert_true(GH.has_edge((u_G, u_H), (v_G, v_H))) + assert GH.has_edge((u_G, u_H), (v_G, v_H)) else: - assert_true(not GH.has_edge((u_G, u_H), (v_G, v_H))) + assert not GH.has_edge((u_G, u_H), (v_G, v_H)) @raises(nx.NetworkXError) @@ -211,28 +211,28 @@ def test_lexicographic_product_null(): P10 = nx.path_graph(10) # null graph G = nx.lexicographic_product(null, null) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) # null_graph X anything = null_graph and v.v. G = nx.lexicographic_product(null, empty10) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.lexicographic_product(null, K3) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.lexicographic_product(null, K10) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.lexicographic_product(null, P3) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.lexicographic_product(null, P10) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.lexicographic_product(empty10, null) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.lexicographic_product(K3, null) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.lexicographic_product(K10, null) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.lexicographic_product(P3, null) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.lexicographic_product(P10, null) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) def test_lexicographic_product_size(): @@ -240,22 +240,22 @@ def test_lexicographic_product_size(): P5 = nx.path_graph(5) K3 = nx.complete_graph(3) G = nx.lexicographic_product(P5, K3) - assert_equal(nx.number_of_nodes(G), 5 * 3) + assert nx.number_of_nodes(G) == 5 * 3 G = nx.lexicographic_product(K3, K5) - assert_equal(nx.number_of_nodes(G), 3 * 5) + assert nx.number_of_nodes(G) == 3 * 5 def test_lexicographic_product_combinations(): P5 = nx.path_graph(5) K3 = nx.complete_graph(3) G = nx.lexicographic_product(P5, K3) - assert_equal(nx.number_of_nodes(G), 5 * 3) + assert nx.number_of_nodes(G) == 5 * 3 G = nx.lexicographic_product(nx.MultiGraph(P5), K3) - assert_equal(nx.number_of_nodes(G), 5 * 3) + assert nx.number_of_nodes(G) == 5 * 3 G = nx.lexicographic_product(P5, nx.MultiGraph(K3)) - assert_equal(nx.number_of_nodes(G), 5 * 3) + assert nx.number_of_nodes(G) == 5 * 3 G = nx.lexicographic_product(nx.MultiGraph(P5), nx.MultiGraph(K3)) - assert_equal(nx.number_of_nodes(G), 5 * 3) + assert nx.number_of_nodes(G) == 5 * 3 # No classic easily found classic results for lexicographic product @@ -268,9 +268,9 @@ def test_lexicographic_product_random(): for (u_G, u_H) in GH.nodes(): for (v_G, v_H) in GH.nodes(): if G.has_edge(u_G, v_G) or (u_G == v_G and H.has_edge(u_H, v_H)): - assert_true(GH.has_edge((u_G, u_H), (v_G, v_H))) + assert GH.has_edge((u_G, u_H), (v_G, v_H)) else: - assert_true(not GH.has_edge((u_G, u_H), (v_G, v_H))) + assert not GH.has_edge((u_G, u_H), (v_G, v_H)) @raises(nx.NetworkXError) @@ -287,28 +287,28 @@ def test_strong_product_null(): P10 = nx.path_graph(10) # null graph G = nx.strong_product(null, null) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) # null_graph X anything = null_graph and v.v. G = nx.strong_product(null, empty10) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.strong_product(null, K3) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.strong_product(null, K10) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.strong_product(null, P3) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.strong_product(null, P10) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.strong_product(empty10, null) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.strong_product(K3, null) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.strong_product(K10, null) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.strong_product(P3, null) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) G = nx.strong_product(P10, null) - assert_true(nx.is_isomorphic(G, null)) + assert nx.is_isomorphic(G, null) def test_strong_product_size(): @@ -316,22 +316,22 @@ def test_strong_product_size(): P5 = nx.path_graph(5) K3 = nx.complete_graph(3) G = nx.strong_product(P5, K3) - assert_equal(nx.number_of_nodes(G), 5 * 3) + assert nx.number_of_nodes(G) == 5 * 3 G = nx.strong_product(K3, K5) - assert_equal(nx.number_of_nodes(G), 3 * 5) + assert nx.number_of_nodes(G) == 3 * 5 def test_strong_product_combinations(): P5 = nx.path_graph(5) K3 = nx.complete_graph(3) G = nx.strong_product(P5, K3) - assert_equal(nx.number_of_nodes(G), 5 * 3) + assert nx.number_of_nodes(G) == 5 * 3 G = nx.strong_product(nx.MultiGraph(P5), K3) - assert_equal(nx.number_of_nodes(G), 5 * 3) + assert nx.number_of_nodes(G) == 5 * 3 G = nx.strong_product(P5, nx.MultiGraph(K3)) - assert_equal(nx.number_of_nodes(G), 5 * 3) + assert nx.number_of_nodes(G) == 5 * 3 G = nx.strong_product(nx.MultiGraph(P5), nx.MultiGraph(K3)) - assert_equal(nx.number_of_nodes(G), 5 * 3) + assert nx.number_of_nodes(G) == 5 * 3 # No classic easily found classic results for strong product @@ -346,9 +346,9 @@ def test_strong_product_random(): if (u_G == v_G and H.has_edge(u_H, v_H)) or \ (u_H == v_H and G.has_edge(u_G, v_G)) or \ (G.has_edge(u_G, v_G) and H.has_edge(u_H, v_H)): - assert_true(GH.has_edge((u_G, u_H), (v_G, v_H))) + assert GH.has_edge((u_G, u_H), (v_G, v_H)) else: - assert_true(not GH.has_edge((u_G, u_H), (v_G, v_H))) + assert not GH.has_edge((u_G, u_H), (v_G, v_H)) @raises(nx.NetworkXNotImplemented) @@ -388,5 +388,5 @@ def test_rooted_product(): H = nx.Graph() H.add_edges_from([('a', 'b'), ('b', 'c'), ('b', 'd')]) R = nx.rooted_product(G, H, 'a') - assert_equal(len(R), len(G) * len(H)) - assert_equal(R.size(), G.size() + len(G) * H.size()) + assert len(R) == len(G) * len(H) + assert R.size() == G.size() + len(G) * H.size() diff --git a/networkx/algorithms/operators/tests/test_unary.py b/networkx/algorithms/operators/tests/test_unary.py index 68a59f64..a5e0f1c6 100644 --- a/networkx/algorithms/operators/tests/test_unary.py +++ b/networkx/algorithms/operators/tests/test_unary.py @@ -16,17 +16,17 @@ def test_complement(): # complement of the complete graph is empty G = nx.complement(K3) - assert_true(nx.is_isomorphic(G, nx.empty_graph(3))) + assert nx.is_isomorphic(G, nx.empty_graph(3)) G = nx.complement(K5) - assert_true(nx.is_isomorphic(G, nx.empty_graph(5))) + assert nx.is_isomorphic(G, nx.empty_graph(5)) # for any G, G=complement(complement(G)) P3cc = nx.complement(nx.complement(P3)) - assert_true(nx.is_isomorphic(P3, P3cc)) + assert nx.is_isomorphic(P3, P3cc) nullcc = nx.complement(nx.complement(null)) - assert_true(nx.is_isomorphic(null, nullcc)) + assert nx.is_isomorphic(null, nullcc) b = nx.bull_graph() bcc = nx.complement(nx.complement(b)) - assert_true(nx.is_isomorphic(b, bcc)) + assert nx.is_isomorphic(b, bcc) def test_complement_2(): @@ -35,7 +35,7 @@ def test_complement_2(): G1.add_edge('A', 'C') G1.add_edge('A', 'D') G1C = nx.complement(G1) - assert_equal(sorted(G1C.edges()), + assert (sorted(G1C.edges()) == [('B', 'A'), ('B', 'C'), ('B', 'D'), ('C', 'A'), ('C', 'B'), ('C', 'D'), ('D', 'A'), ('D', 'B'), ('D', 'C')]) diff --git a/networkx/algorithms/shortest_paths/tests/test_astar.py b/networkx/algorithms/shortest_paths/tests/test_astar.py index 484308fe..c38c98e0 100644 --- a/networkx/algorithms/shortest_paths/tests/test_astar.py +++ b/networkx/algorithms/shortest_paths/tests/test_astar.py @@ -40,11 +40,11 @@ class TestAStar: path1 = ["a", "c", "d"] path2 = ["a", "b", "c", "d"] - assert_in(nx.astar_path(graph, "a", "d", h), (path1, path2)) + assert nx.astar_path(graph, "a", "d", h) in (path1, path2) def test_astar_directed(self): - assert_equal(nx.astar_path(self.XG, 's', 'v'), ['s', 'x', 'u', 'v']) - assert_equal(nx.astar_path_length(self.XG, 's', 'v'), 9) + assert nx.astar_path(self.XG, 's', 'v') == ['s', 'x', 'u', 'v'] + assert nx.astar_path_length(self.XG, 's', 'v') == 9 def test_astar_multigraph(self): G = nx.MultiDiGraph(self.XG) @@ -58,31 +58,31 @@ class TestAStar: # to_undirected might choose either edge with weight 2 or weight 3 GG['u']['x']['weight'] = 2 GG['y']['v']['weight'] = 2 - assert_equal(nx.astar_path(GG, 's', 'v'), ['s', 'x', 'u', 'v']) - assert_equal(nx.astar_path_length(GG, 's', 'v'), 8) + assert nx.astar_path(GG, 's', 'v') == ['s', 'x', 'u', 'v'] + assert nx.astar_path_length(GG, 's', 'v') == 8 def test_astar_directed2(self): XG2 = nx.DiGraph() edges = [(1, 4, 1), (4, 5, 1), (5, 6, 1), (6, 3, 1), (1, 3, 50), (1, 2, 100), (2, 3, 100)] XG2.add_weighted_edges_from(edges) - assert_equal(nx.astar_path(XG2, 1, 3), [1, 4, 5, 6, 3]) + assert nx.astar_path(XG2, 1, 3) == [1, 4, 5, 6, 3] def test_astar_undirected2(self): XG3 = nx.Graph() edges = [(0, 1, 2), (1, 2, 12), (2, 3, 1), (3, 4, 5), (4, 5, 1), (5, 0, 10)] XG3.add_weighted_edges_from(edges) - assert_equal(nx.astar_path(XG3, 0, 3), [0, 1, 2, 3]) - assert_equal(nx.astar_path_length(XG3, 0, 3), 15) + assert nx.astar_path(XG3, 0, 3) == [0, 1, 2, 3] + assert nx.astar_path_length(XG3, 0, 3) == 15 def test_astar_undirected3(self): XG4 = nx.Graph() edges = [(0, 1, 2), (1, 2, 2), (2, 3, 1), (3, 4, 1), (4, 5, 1), (5, 6, 1), (6, 7, 1), (7, 0, 1)] XG4.add_weighted_edges_from(edges) - assert_equal(nx.astar_path(XG4, 0, 2), [0, 1, 2]) - assert_equal(nx.astar_path_length(XG4, 0, 2), 4) + assert nx.astar_path(XG4, 0, 2) == [0, 1, 2] + assert nx.astar_path_length(XG4, 0, 2) == 4 """ Tests that A* finds correct path when multiple paths exist and the best one is not expanded first (GH issue #3464) @@ -98,7 +98,7 @@ class TestAStar: graph = nx.DiGraph() graph.add_weighted_edges_from(edges) answer = ["n5", "n2", "n1", "n0"] - assert_equal(nx.astar_path(graph, "n5", "n0", h), answer) + assert nx.astar_path(graph, "n5", "n0", h) == answer """ Tests that that parent is not wrongly overridden when a node is re-explored multiple times. @@ -108,7 +108,7 @@ class TestAStar: ("c", "d", 1), ("d", "e", 1)] graph = nx.DiGraph() graph.add_weighted_edges_from(edges) - assert_equal(nx.astar_path(graph, "a", "e"), ["a", "c", "d", "e"]) + assert nx.astar_path(graph, "a", "e") == ["a", "c", "d", "e"] # >>> MXG4=NX.MultiGraph(XG4) # >>> MXG4.add_edge(0,1,3) @@ -120,8 +120,8 @@ class TestAStar: G.add_edges_from([('s', 'u'), ('s', 'x'), ('u', 'v'), ('u', 'x'), ('v', 'y'), ('x', 'u'), ('x', 'w'), ('w', 'v'), ('x', 'y'), ('y', 's'), ('y', 'v')]) - assert_equal(nx.astar_path(G, 's', 'v'), ['s', 'u', 'v']) - assert_equal(nx.astar_path_length(G, 's', 'v'), 2) + assert nx.astar_path(G, 's', 'v') == ['s', 'u', 'v'] + assert nx.astar_path_length(G, 's', 'v') == 2 @raises(nx.NodeNotFound) def test_astar_nopath(self): @@ -129,8 +129,8 @@ class TestAStar: def test_cycle(self): C = nx.cycle_graph(7) - assert_equal(nx.astar_path(C, 0, 3), [0, 1, 2, 3]) - assert_equal(nx.dijkstra_path(C, 0, 4), [0, 6, 5, 4]) + assert nx.astar_path(C, 0, 3) == [0, 1, 2, 3] + assert nx.dijkstra_path(C, 0, 4) == [0, 6, 5, 4] def test_unorderable_nodes(self): """Tests that A* accommodates nodes that are not orderable. @@ -158,4 +158,4 @@ class TestAStar: G = nx.Graph() G.add_edges_from(pairwise(nodes, cyclic=True)) path = nx.astar_path(G, nodes[0], nodes[2]) - assert_equal(len(path), 3) + assert len(path) == 3 diff --git a/networkx/algorithms/shortest_paths/tests/test_dense.py b/networkx/algorithms/shortest_paths/tests/test_dense.py index dbc57793..58eea01e 100644 --- a/networkx/algorithms/shortest_paths/tests/test_dense.py +++ b/networkx/algorithms/shortest_paths/tests/test_dense.py @@ -16,9 +16,9 @@ class TestFloyd: ('x', 'v', 5), ('x', 'y', 2), ('y', 's', 7), ('y', 'v', 6)]) path, dist = nx.floyd_warshall_predecessor_and_distance(XG) - assert_equal(dist['s']['v'], 9) - assert_equal(path['s']['v'], 'u') - assert_equal(dist, + assert dist['s']['v'] == 9 + assert path['s']['v'] == 'u' + assert (dist == {'y': {'y': 0, 'x': 12, 's': 7, 'u': 15, 'v': 6}, 'x': {'y': 2, 'x': 0, 's': 9, 'u': 3, 'v': 4}, 's': {'y': 7, 'x': 5, 's': 0, 'u': 8, 'v': 9}, @@ -30,7 +30,7 @@ class TestFloyd: # to_undirected might choose either edge with weight 2 or weight 3 GG['u']['x']['weight'] = 2 path, dist = nx.floyd_warshall_predecessor_and_distance(GG) - assert_equal(dist['s']['v'], 8) + assert dist['s']['v'] == 8 # skip this test, could be alternate path s-u-v # assert_equal(path['s']['v'],'y') @@ -41,13 +41,13 @@ class TestFloyd: ('x', 'v'), ('x', 'y'), ('y', 's'), ('y', 'v')]) path, dist = nx.floyd_warshall_predecessor_and_distance(G) - assert_equal(dist['s']['v'], 2) + assert dist['s']['v'] == 2 # skip this test, could be alternate path s-u-v # assert_equal(path['s']['v'],'x') # alternate interface dist = nx.floyd_warshall(G) - assert_equal(dist['s']['v'], 2) + assert dist['s']['v'] == 2 # floyd_warshall_predecessor_and_distance returns # dicts-of-defautdicts @@ -57,12 +57,12 @@ class TestFloyd: ('v', 'y', 6.0), ('x', 'u', 2.0)]) path, dist = nx.floyd_warshall_predecessor_and_distance(XG) inf = float("inf") - assert_equal(dist, + assert (dist == {'v': {'v': 0, 'x': 5.0, 'y': 6.0, 'u': 7.0}, 'x': {'x': 0, 'u': 2.0, 'v': inf, 'y': inf}, 'y': {'y': 0, 'x': 5.0, 'v': inf, 'u': 7.0}, 'u': {'u': 0, 'v': inf, 'x': inf, 'y': inf}}) - assert_equal(path, + assert (path == {'v': {'x': 'v', 'y': 'v', 'u': 'x'}, 'x': {'u': 'x'}, 'y': {'x': 'y', 'u': 'x'}}) @@ -78,10 +78,10 @@ class TestFloyd: predecessors, _ = nx.floyd_warshall_predecessor_and_distance(XG) path = nx.reconstruct_path('s', 'v', predecessors) - assert_equal(path, ['s', 'x', 'u', 'v']) + assert path == ['s', 'x', 'u', 'v'] path = nx.reconstruct_path('s', 's', predecessors) - assert_equal(path, []) + assert path == [] # this part raises the keyError nx.reconstruct_path('1', '2', predecessors) @@ -89,17 +89,17 @@ class TestFloyd: def test_cycle(self): path, dist = nx.floyd_warshall_predecessor_and_distance( nx.cycle_graph(7)) - assert_equal(dist[0][3], 3) - assert_equal(path[0][3], 2) - assert_equal(dist[0][4], 3) + assert dist[0][3] == 3 + assert path[0][3] == 2 + assert dist[0][4] == 3 def test_weighted(self): XG3 = nx.Graph() XG3.add_weighted_edges_from([[0, 1, 2], [1, 2, 12], [2, 3, 1], [3, 4, 5], [4, 5, 1], [5, 0, 10]]) path, dist = nx.floyd_warshall_predecessor_and_distance(XG3) - assert_equal(dist[0][3], 15) - assert_equal(path[0][3], 2) + assert dist[0][3] == 15 + assert path[0][3] == 2 def test_weighted2(self): XG4 = nx.Graph() @@ -107,8 +107,8 @@ class TestFloyd: [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1], [7, 0, 1]]) path, dist = nx.floyd_warshall_predecessor_and_distance(XG4) - assert_equal(dist[0][2], 4) - assert_equal(path[0][2], 1) + assert dist[0][2] == 4 + assert path[0][2] == 1 def test_weight_parameter(self): XG4 = nx.Graph() @@ -118,8 +118,8 @@ class TestFloyd: (6, 7, {'heavy': 1}), (7, 0, {'heavy': 1})]) path, dist = nx.floyd_warshall_predecessor_and_distance(XG4, weight='heavy') - assert_equal(dist[0][2], 4) - assert_equal(path[0][2], 1) + assert dist[0][2] == 4 + assert path[0][2] == 1 def test_zero_distance(self): XG = nx.DiGraph() @@ -131,7 +131,7 @@ class TestFloyd: path, dist = nx.floyd_warshall_predecessor_and_distance(XG) for u in XG: - assert_equal(dist[u][u], 0) + assert dist[u][u] == 0 GG = XG.to_undirected() # make sure we get lower weight @@ -148,10 +148,10 @@ class TestFloyd: (5, 4, 0), (4, 3, -5), (2, 5, -7)] G.add_weighted_edges_from(edges) dist = nx.floyd_warshall(G) - assert_equal(dist[1][3], -14) + assert dist[1][3] == -14 G = nx.MultiDiGraph() edges.append((2, 5, -7)) G.add_weighted_edges_from(edges) dist = nx.floyd_warshall(G) - assert_equal(dist[1][3], -14) + assert dist[1][3] == -14 diff --git a/networkx/algorithms/shortest_paths/tests/test_dense_numpy.py b/networkx/algorithms/shortest_paths/tests/test_dense_numpy.py index 34c1c0da..8a1dc77e 100644 --- a/networkx/algorithms/shortest_paths/tests/test_dense_numpy.py +++ b/networkx/algorithms/shortest_paths/tests/test_dense_numpy.py @@ -20,15 +20,15 @@ class TestFloydNumpy(object): def test_cycle_numpy(self): dist = nx.floyd_warshall_numpy(nx.cycle_graph(7)) - assert_equal(dist[0, 3], 3) - assert_equal(dist[0, 4], 3) + assert dist[0, 3] == 3 + assert dist[0, 4] == 3 def test_weighted_numpy_three_edges(self): XG3 = nx.Graph() XG3.add_weighted_edges_from([[0, 1, 2], [1, 2, 12], [2, 3, 1], [3, 4, 5], [4, 5, 1], [5, 0, 10]]) dist = nx.floyd_warshall_numpy(XG3) - assert_equal(dist[0, 3], 15) + assert dist[0, 3] == 15 def test_weighted_numpy_two_edges(self): XG4 = nx.Graph() @@ -36,7 +36,7 @@ class TestFloydNumpy(object): [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1], [7, 0, 1]]) dist = nx.floyd_warshall_numpy(XG4) - assert_equal(dist[0, 2], 4) + assert dist[0, 2] == 4 def test_weight_parameter_numpy(self): XG4 = nx.Graph() @@ -45,7 +45,7 @@ class TestFloydNumpy(object): (4, 5, {'heavy': 1}), (5, 6, {'heavy': 1}), (6, 7, {'heavy': 1}), (7, 0, {'heavy': 1})]) dist = nx.floyd_warshall_numpy(XG4, weight='heavy') - assert_equal(dist[0, 2], 4) + assert dist[0, 2] == 4 def test_directed_cycle_numpy(self): G = nx.DiGraph() @@ -59,10 +59,10 @@ class TestFloydNumpy(object): edges = [(1, 2, -2), (2, 3, -4), (1, 5, 1), (5, 4, 0), (4, 3, -5), (2, 5, -7)] G.add_weighted_edges_from(edges) dist = nx.floyd_warshall_numpy(G) - assert_equal(int(numpy.min(dist)), -14) + assert int(numpy.min(dist)) == -14 G = nx.MultiDiGraph() edges.append((2, 5, -7)) G.add_weighted_edges_from(edges) dist = nx.floyd_warshall_numpy(G) - assert_equal(int(numpy.min(dist)), -14) + assert int(numpy.min(dist)) == -14 diff --git a/networkx/algorithms/shortest_paths/tests/test_generic.py b/networkx/algorithms/shortest_paths/tests/test_generic.py index a2d6c870..87d473c3 100644 --- a/networkx/algorithms/shortest_paths/tests/test_generic.py +++ b/networkx/algorithms/shortest_paths/tests/test_generic.py @@ -14,11 +14,11 @@ import networkx as nx def validate_grid_path(r, c, s, t, p): ok_(isinstance(p, list)) - assert_equal(p[0], s) - assert_equal(p[-1], t) + assert p[0] == s + assert p[-1] == t s = ((s - 1) // c, (s - 1) % c) t = ((t - 1) // c, (t - 1) % c) - assert_equal(len(p), abs(t[0] - s[0]) + abs(t[1] - s[1]) + 1) + assert len(p) == abs(t[0] - s[0]) + abs(t[1] - s[1]) + 1 p = [((u - 1) // c, (u - 1) % c) for u in p] for u in p: ok_(0 <= u[0] < r) @@ -43,31 +43,31 @@ class TestGenericPath: cls.neg_weights.add_edge(2, 3, weight=-2) def test_shortest_path(self): - assert_equal(nx.shortest_path(self.cycle, 0, 3), [0, 1, 2, 3]) - assert_equal(nx.shortest_path(self.cycle, 0, 4), [0, 6, 5, 4]) + assert nx.shortest_path(self.cycle, 0, 3) == [0, 1, 2, 3] + assert nx.shortest_path(self.cycle, 0, 4) == [0, 6, 5, 4] validate_grid_path(4, 4, 1, 12, nx.shortest_path(self.grid, 1, 12)) - assert_equal(nx.shortest_path(self.directed_cycle, 0, 3), [0, 1, 2, 3]) + assert nx.shortest_path(self.directed_cycle, 0, 3) == [0, 1, 2, 3] # now with weights - assert_equal(nx.shortest_path(self.cycle, 0, 3, weight='weight'), + assert (nx.shortest_path(self.cycle, 0, 3, weight='weight') == [0, 1, 2, 3]) - assert_equal(nx.shortest_path(self.cycle, 0, 4, weight='weight'), + assert (nx.shortest_path(self.cycle, 0, 4, weight='weight') == [0, 6, 5, 4]) validate_grid_path(4, 4, 1, 12, nx.shortest_path(self.grid, 1, 12, weight='weight')) - assert_equal(nx.shortest_path(self.directed_cycle, 0, 3, - weight='weight'), + assert (nx.shortest_path(self.directed_cycle, 0, 3, + weight='weight') == [0, 1, 2, 3]) # weights and method specified - assert_equal(nx.shortest_path(self.directed_cycle, 0, 3, - weight='weight', method='dijkstra'), + assert (nx.shortest_path(self.directed_cycle, 0, 3, + weight='weight', method='dijkstra') == [0, 1, 2, 3]) - assert_equal(nx.shortest_path(self.directed_cycle, 0, 3, - weight='weight', method='bellman-ford'), + assert (nx.shortest_path(self.directed_cycle, 0, 3, + weight='weight', method='bellman-ford') == [0, 1, 2, 3]) # when Dijkstra's will probably (depending on precise implementation) # incorrectly return [0, 1, 3] instead - assert_equal(nx.shortest_path(self.neg_weights, 0, 3, weight='weight', - method='bellman-ford'), + assert (nx.shortest_path(self.neg_weights, 0, 3, weight='weight', + method='bellman-ford') == [0, 2, 3]) # confirm bad method rejection assert_raises(ValueError, nx.shortest_path, self.cycle, method='SPAM') @@ -77,38 +77,38 @@ class TestGenericPath: def test_shortest_path_target(self): answer = {0: [0, 1], 1: [1], 2: [2, 1]} sp = nx.shortest_path(nx.path_graph(3), target=1) - assert_equal(sp, answer) + assert sp == answer # with weights sp = nx.shortest_path(nx.path_graph(3), target=1, weight='weight') - assert_equal(sp, answer) + assert sp == answer # weights and method specified sp = nx.shortest_path(nx.path_graph(3), target=1, weight='weight', method='dijkstra') - assert_equal(sp, answer) + assert sp == answer sp = nx.shortest_path(nx.path_graph(3), target=1, weight='weight', method='bellman-ford') - assert_equal(sp, answer) + assert sp == answer def test_shortest_path_length(self): - assert_equal(nx.shortest_path_length(self.cycle, 0, 3), 3) - assert_equal(nx.shortest_path_length(self.grid, 1, 12), 5) - assert_equal(nx.shortest_path_length(self.directed_cycle, 0, 4), 4) + assert nx.shortest_path_length(self.cycle, 0, 3) == 3 + assert nx.shortest_path_length(self.grid, 1, 12) == 5 + assert nx.shortest_path_length(self.directed_cycle, 0, 4) == 4 # now with weights - assert_equal(nx.shortest_path_length(self.cycle, 0, 3, - weight='weight'), + assert (nx.shortest_path_length(self.cycle, 0, 3, + weight='weight') == 3) - assert_equal(nx.shortest_path_length(self.grid, 1, 12, - weight='weight'), + assert (nx.shortest_path_length(self.grid, 1, 12, + weight='weight') == 5) - assert_equal(nx.shortest_path_length(self.directed_cycle, 0, 4, - weight='weight'), + assert (nx.shortest_path_length(self.directed_cycle, 0, 4, + weight='weight') == 4) # weights and method specified - assert_equal(nx.shortest_path_length(self.cycle, 0, 3, weight='weight', - method='dijkstra'), + assert (nx.shortest_path_length(self.cycle, 0, 3, weight='weight', + method='dijkstra') == 3) - assert_equal(nx.shortest_path_length(self.cycle, 0, 3, weight='weight', - method='bellman-ford'), + assert (nx.shortest_path_length(self.cycle, 0, 3, weight='weight', + method='bellman-ford') == 3) # confirm bad method rejection assert_raises(ValueError, @@ -121,141 +121,141 @@ class TestGenericPath: def test_shortest_path_length_target(self): answer = {0: 1, 1: 0, 2: 1} sp = dict(nx.shortest_path_length(nx.path_graph(3), target=1)) - assert_equal(sp, answer) + assert sp == answer # with weights sp = nx.shortest_path_length(nx.path_graph(3), target=1, weight='weight') - assert_equal(sp, answer) + assert sp == answer # weights and method specified sp = nx.shortest_path_length(nx.path_graph(3), target=1, weight='weight', method='dijkstra') - assert_equal(sp, answer) + assert sp == answer sp = nx.shortest_path_length(nx.path_graph(3), target=1, weight='weight', method='bellman-ford') - assert_equal(sp, answer) + assert sp == answer def test_single_source_shortest_path(self): p = nx.shortest_path(self.cycle, 0) - assert_equal(p[3], [0, 1, 2, 3]) - assert_equal(p, nx.single_source_shortest_path(self.cycle, 0)) + assert p[3] == [0, 1, 2, 3] + assert p == nx.single_source_shortest_path(self.cycle, 0) p = nx.shortest_path(self.grid, 1) validate_grid_path(4, 4, 1, 12, p[12]) # now with weights p = nx.shortest_path(self.cycle, 0, weight='weight') - assert_equal(p[3], [0, 1, 2, 3]) - assert_equal(p, nx.single_source_dijkstra_path(self.cycle, 0)) + assert p[3] == [0, 1, 2, 3] + assert p == nx.single_source_dijkstra_path(self.cycle, 0) p = nx.shortest_path(self.grid, 1, weight='weight') validate_grid_path(4, 4, 1, 12, p[12]) # weights and method specified p = nx.shortest_path(self.cycle, 0, method='dijkstra', weight='weight') - assert_equal(p[3], [0, 1, 2, 3]) - assert_equal(p, nx.single_source_shortest_path(self.cycle, 0)) + assert p[3] == [0, 1, 2, 3] + assert p == nx.single_source_shortest_path(self.cycle, 0) p = nx.shortest_path(self.cycle, 0, method='bellman-ford', weight='weight') - assert_equal(p[3], [0, 1, 2, 3]) - assert_equal(p, nx.single_source_shortest_path(self.cycle, 0)) + assert p[3] == [0, 1, 2, 3] + assert p == nx.single_source_shortest_path(self.cycle, 0) def test_single_source_shortest_path_length(self): ans = dict(nx.shortest_path_length(self.cycle, 0)) - assert_equal(ans, {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1}) - assert_equal(ans, + assert ans == {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1} + assert (ans == dict(nx.single_source_shortest_path_length(self.cycle, 0))) ans = dict(nx.shortest_path_length(self.grid, 1)) - assert_equal(ans[16], 6) + assert ans[16] == 6 # now with weights ans = dict(nx.shortest_path_length(self.cycle, 0, weight='weight')) - assert_equal(ans, {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1}) - assert_equal(ans, dict(nx.single_source_dijkstra_path_length( - self.cycle, 0))) + assert ans == {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1} + assert ans == dict(nx.single_source_dijkstra_path_length( + self.cycle, 0)) ans = dict(nx.shortest_path_length(self.grid, 1, weight='weight')) - assert_equal(ans[16], 6) + assert ans[16] == 6 # weights and method specified ans = dict(nx.shortest_path_length(self.cycle, 0, weight='weight', method='dijkstra')) - assert_equal(ans, {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1}) - assert_equal(ans, dict(nx.single_source_dijkstra_path_length( - self.cycle, 0))) + assert ans == {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1} + assert ans == dict(nx.single_source_dijkstra_path_length( + self.cycle, 0)) ans = dict(nx.shortest_path_length(self.cycle, 0, weight='weight', method='bellman-ford')) - assert_equal(ans, {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1}) - assert_equal(ans, dict(nx.single_source_bellman_ford_path_length( - self.cycle, 0))) + assert ans == {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1} + assert ans == dict(nx.single_source_bellman_ford_path_length( + self.cycle, 0)) def test_all_pairs_shortest_path(self): p = nx.shortest_path(self.cycle) - assert_equal(p[0][3], [0, 1, 2, 3]) - assert_equal(p, dict(nx.all_pairs_shortest_path(self.cycle))) + assert p[0][3] == [0, 1, 2, 3] + assert p == dict(nx.all_pairs_shortest_path(self.cycle)) p = nx.shortest_path(self.grid) validate_grid_path(4, 4, 1, 12, p[1][12]) # now with weights p = nx.shortest_path(self.cycle, weight='weight') - assert_equal(p[0][3], [0, 1, 2, 3]) - assert_equal(p, dict(nx.all_pairs_dijkstra_path(self.cycle))) + assert p[0][3] == [0, 1, 2, 3] + assert p == dict(nx.all_pairs_dijkstra_path(self.cycle)) p = nx.shortest_path(self.grid, weight='weight') validate_grid_path(4, 4, 1, 12, p[1][12]) # weights and method specified p = nx.shortest_path(self.cycle, weight='weight', method='dijkstra') - assert_equal(p[0][3], [0, 1, 2, 3]) - assert_equal(p, dict(nx.all_pairs_dijkstra_path(self.cycle))) + assert p[0][3] == [0, 1, 2, 3] + assert p == dict(nx.all_pairs_dijkstra_path(self.cycle)) p = nx.shortest_path(self.cycle, weight='weight', method='bellman-ford') - assert_equal(p[0][3], [0, 1, 2, 3]) - assert_equal(p, dict(nx.all_pairs_bellman_ford_path(self.cycle))) + assert p[0][3] == [0, 1, 2, 3] + assert p == dict(nx.all_pairs_bellman_ford_path(self.cycle)) def test_all_pairs_shortest_path_length(self): ans = dict(nx.shortest_path_length(self.cycle)) - assert_equal(ans[0], {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1}) - assert_equal(ans, dict(nx.all_pairs_shortest_path_length(self.cycle))) + assert ans[0] == {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1} + assert ans == dict(nx.all_pairs_shortest_path_length(self.cycle)) ans = dict(nx.shortest_path_length(self.grid)) - assert_equal(ans[1][16], 6) + assert ans[1][16] == 6 # now with weights ans = dict(nx.shortest_path_length(self.cycle, weight='weight')) - assert_equal(ans[0], {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1}) - assert_equal(ans, dict(nx.all_pairs_dijkstra_path_length(self.cycle))) + assert ans[0] == {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1} + assert ans == dict(nx.all_pairs_dijkstra_path_length(self.cycle)) ans = dict(nx.shortest_path_length(self.grid, weight='weight')) - assert_equal(ans[1][16], 6) + assert ans[1][16] == 6 # weights and method specified ans = dict(nx.shortest_path_length(self.cycle, weight='weight', method='dijkstra')) - assert_equal(ans[0], {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1}) - assert_equal(ans, dict(nx.all_pairs_dijkstra_path_length(self.cycle))) + assert ans[0] == {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1} + assert ans == dict(nx.all_pairs_dijkstra_path_length(self.cycle)) ans = dict(nx.shortest_path_length(self.cycle, weight='weight', method='bellman-ford')) - assert_equal(ans[0], {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1}) - assert_equal(ans, + assert ans[0] == {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1} + assert (ans == dict(nx.all_pairs_bellman_ford_path_length(self.cycle))) def test_has_path(self): G = nx.Graph() nx.add_path(G, range(3)) nx.add_path(G, range(3, 5)) - assert_true(nx.has_path(G, 0, 2)) - assert_false(nx.has_path(G, 0, 4)) + assert nx.has_path(G, 0, 2) + assert not nx.has_path(G, 0, 4) def test_all_shortest_paths(self): G = nx.Graph() nx.add_path(G, [0, 1, 2, 3]) nx.add_path(G, [0, 10, 20, 3]) - assert_equal([[0, 1, 2, 3], [0, 10, 20, 3]], + assert ([[0, 1, 2, 3], [0, 10, 20, 3]] == sorted(nx.all_shortest_paths(G, 0, 3))) # with weights G = nx.Graph() nx.add_path(G, [0, 1, 2, 3]) nx.add_path(G, [0, 10, 20, 3]) - assert_equal([[0, 1, 2, 3], [0, 10, 20, 3]], + assert ([[0, 1, 2, 3], [0, 10, 20, 3]] == sorted(nx.all_shortest_paths(G, 0, 3, weight='weight'))) # weights and method specified G = nx.Graph() nx.add_path(G, [0, 1, 2, 3]) nx.add_path(G, [0, 10, 20, 3]) - assert_equal([[0, 1, 2, 3], [0, 10, 20, 3]], + assert ([[0, 1, 2, 3], [0, 10, 20, 3]] == sorted(nx.all_shortest_paths(G, 0, 3, weight='weight', method='dijkstra'))) G = nx.Graph() nx.add_path(G, [0, 1, 2, 3]) nx.add_path(G, [0, 10, 20, 3]) - assert_equal([[0, 1, 2, 3], [0, 10, 20, 3]], + assert ([[0, 1, 2, 3], [0, 10, 20, 3]] == sorted(nx.all_shortest_paths(G, 0, 3, weight='weight', method='bellman-ford'))) @@ -339,7 +339,7 @@ class TestAverageShortestPathLength(object): """ G = nx.trivial_graph() - assert_equal(nx.average_shortest_path_length(G), 0) + assert nx.average_shortest_path_length(G) == 0 @raises(nx.NetworkXPointlessConcept) def test_null_graph(self): diff --git a/networkx/algorithms/shortest_paths/tests/test_unweighted.py b/networkx/algorithms/shortest_paths/tests/test_unweighted.py index da9bf706..a659f904 100644 --- a/networkx/algorithms/shortest_paths/tests/test_unweighted.py +++ b/networkx/algorithms/shortest_paths/tests/test_unweighted.py @@ -5,11 +5,11 @@ import networkx as nx def validate_grid_path(r, c, s, t, p): ok_(isinstance(p, list)) - assert_equal(p[0], s) - assert_equal(p[-1], t) + assert p[0] == s + assert p[-1] == t s = ((s - 1) // c, (s - 1) % c) t = ((t - 1) // c, (t - 1) % c) - assert_equal(len(p), abs(t[0] - s[0]) + abs(t[1] - s[1]) + 1) + assert len(p) == abs(t[0] - s[0]) + abs(t[1] - s[1]) + 1 p = [((u - 1) // c, (u - 1) % c) for u in p] for u in p: ok_(0 <= u[0] < r) @@ -28,92 +28,92 @@ class TestUnweightedPath: cls.directed_cycle = nx.cycle_graph(7, create_using=nx.DiGraph()) def test_bidirectional_shortest_path(self): - assert_equal(nx.bidirectional_shortest_path(self.cycle, 0, 3), + assert (nx.bidirectional_shortest_path(self.cycle, 0, 3) == [0, 1, 2, 3]) - assert_equal(nx.bidirectional_shortest_path(self.cycle, 0, 4), + assert (nx.bidirectional_shortest_path(self.cycle, 0, 4) == [0, 6, 5, 4]) validate_grid_path(4, 4, 1, 12, nx.bidirectional_shortest_path(self.grid, 1, 12)) - assert_equal(nx.bidirectional_shortest_path(self.directed_cycle, 0, 3), + assert (nx.bidirectional_shortest_path(self.directed_cycle, 0, 3) == [0, 1, 2, 3]) def test_shortest_path_length(self): - assert_equal(nx.shortest_path_length(self.cycle, 0, 3), 3) - assert_equal(nx.shortest_path_length(self.grid, 1, 12), 5) - assert_equal(nx.shortest_path_length(self.directed_cycle, 0, 4), 4) + assert nx.shortest_path_length(self.cycle, 0, 3) == 3 + assert nx.shortest_path_length(self.grid, 1, 12) == 5 + assert nx.shortest_path_length(self.directed_cycle, 0, 4) == 4 # now with weights - assert_equal(nx.shortest_path_length(self.cycle, 0, 3, weight=True), 3) - assert_equal(nx.shortest_path_length(self.grid, 1, 12, weight=True), 5) - assert_equal(nx.shortest_path_length(self.directed_cycle, 0, 4, weight=True), 4) + assert nx.shortest_path_length(self.cycle, 0, 3, weight=True) == 3 + assert nx.shortest_path_length(self.grid, 1, 12, weight=True) == 5 + assert nx.shortest_path_length(self.directed_cycle, 0, 4, weight=True) == 4 def test_single_source_shortest_path(self): p = nx.single_source_shortest_path(self.directed_cycle, 3) - assert_equal(p[0], [3, 4, 5, 6, 0]) + assert p[0] == [3, 4, 5, 6, 0] p = nx.single_source_shortest_path(self.cycle, 0) - assert_equal(p[3], [0, 1, 2, 3]) + assert p[3] == [0, 1, 2, 3] p = nx.single_source_shortest_path(self.cycle, 0, cutoff=0) - assert_equal(p, {0: [0]}) + assert p == {0: [0]} def test_single_source_shortest_path_length(self): pl = nx.single_source_shortest_path_length lengths = {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1} - assert_equal(dict(pl(self.cycle, 0)), lengths) + assert dict(pl(self.cycle, 0)) == lengths lengths = {0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6} - assert_equal(dict(pl(self.directed_cycle, 0)), lengths) + assert dict(pl(self.directed_cycle, 0)) == lengths def test_single_target_shortest_path(self): p = nx.single_target_shortest_path(self.directed_cycle, 0) - assert_equal(p[3], [3, 4, 5, 6, 0]) + assert p[3] == [3, 4, 5, 6, 0] p = nx.single_target_shortest_path(self.cycle, 0) - assert_equal(p[3], [3, 2, 1, 0]) + assert p[3] == [3, 2, 1, 0] p = nx.single_target_shortest_path(self.cycle, 0, cutoff=0) - assert_equal(p, {0: [0]}) + assert p == {0: [0]} def test_single_target_shortest_path_length(self): pl = nx.single_target_shortest_path_length lengths = {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1} - assert_equal(dict(pl(self.cycle, 0)), lengths) + assert dict(pl(self.cycle, 0)) == lengths lengths = {0: 0, 1: 6, 2: 5, 3: 4, 4: 3, 5: 2, 6: 1} - assert_equal(dict(pl(self.directed_cycle, 0)), lengths) + assert dict(pl(self.directed_cycle, 0)) == lengths def test_all_pairs_shortest_path(self): p = dict(nx.all_pairs_shortest_path(self.cycle)) - assert_equal(p[0][3], [0, 1, 2, 3]) + assert p[0][3] == [0, 1, 2, 3] p = dict(nx.all_pairs_shortest_path(self.grid)) validate_grid_path(4, 4, 1, 12, p[1][12]) def test_all_pairs_shortest_path_length(self): l = dict(nx.all_pairs_shortest_path_length(self.cycle)) - assert_equal(l[0], {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1}) + assert l[0] == {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1} l = dict(nx.all_pairs_shortest_path_length(self.grid)) - assert_equal(l[1][16], 6) + assert l[1][16] == 6 def test_predecessor_path(self): G = nx.path_graph(4) - assert_equal(nx.predecessor(G, 0), {0: [], 1: [0], 2: [1], 3: [2]}) - assert_equal(nx.predecessor(G, 0, 3), [2]) + assert nx.predecessor(G, 0) == {0: [], 1: [0], 2: [1], 3: [2]} + assert nx.predecessor(G, 0, 3) == [2] def test_predecessor_cycle(self): G = nx.cycle_graph(4) pred = nx.predecessor(G, 0) - assert_equal(pred[0], []) - assert_equal(pred[1], [0]) - assert_true(pred[2] in [[1, 3], [3, 1]]) - assert_equal(pred[3], [0]) + assert pred[0] == [] + assert pred[1] == [0] + assert pred[2] in [[1, 3], [3, 1]] + assert pred[3] == [0] def test_predecessor_cutoff(self): G = nx.path_graph(4) p = nx.predecessor(G, 0, 3) - assert_false(4 in p) + assert not 4 in p def test_predecessor_target(self): G = nx.path_graph(4) p = nx.predecessor(G, 0, 3) - assert_equal(p, [2]) + assert p == [2] p = nx.predecessor(G, 0, 3, cutoff=2) - assert_equal(p, []) + assert p == [] p, s = nx.predecessor(G, 0, 3, return_seen=True) - assert_equal(p, [2]) - assert_equal(s, 3) + assert p == [2] + assert s == 3 p, s = nx.predecessor(G, 0, 3, cutoff=2, return_seen=True) - assert_equal(p, []) - assert_equal(s, -1) + assert p == [] + assert s == -1 diff --git a/networkx/algorithms/shortest_paths/tests/test_weighted.py b/networkx/algorithms/shortest_paths/tests/test_weighted.py index 3c0c13db..5b3e4d14 100644 --- a/networkx/algorithms/shortest_paths/tests/test_weighted.py +++ b/networkx/algorithms/shortest_paths/tests/test_weighted.py @@ -10,19 +10,19 @@ from networkx.utils import pairwise def validate_path(G, s, t, soln_len, path): - assert_equal(path[0], s) - assert_equal(path[-1], t) + assert path[0] == s + assert path[-1] == t if not G.is_multigraph(): computed = sum(G[u][v].get('weight', 1) for u, v in pairwise(path)) - assert_equal(soln_len, computed) + assert soln_len == computed else: computed = sum(min(e.get('weight', 1) for e in G[u][v].values()) for u, v in pairwise(path)) - assert_equal(soln_len, computed) + assert soln_len == computed def validate_length_path(G, s, t, soln_len, length, path): - assert_equal(soln_len, length) + assert soln_len == length validate_path(G, s, t, length, path) @@ -78,12 +78,12 @@ class TestWeightedPath(WeightedTestBase): def test_dijkstra(self): (D, P) = nx.single_source_dijkstra(self.XG, 's') validate_path(self.XG, 's', 'v', 9, P['v']) - assert_equal(D['v'], 9) + assert D['v'] == 9 validate_path( self.XG, 's', 'v', 9, nx.single_source_dijkstra_path(self.XG, 's')['v']) - assert_equal(dict( - nx.single_source_dijkstra_path_length(self.XG, 's'))['v'], 9) + assert dict( + nx.single_source_dijkstra_path_length(self.XG, 's'))['v'] == 9 validate_path( self.XG, 's', 'v', 9, nx.single_source_dijkstra(self.XG, 's')[1]['v']) @@ -96,15 +96,15 @@ class TestWeightedPath(WeightedTestBase): GG['u']['x']['weight'] = 2 (D, P) = nx.single_source_dijkstra(GG, 's') validate_path(GG, 's', 'v', 8, P['v']) - assert_equal(D['v'], 8) # uses lower weight of 2 on u<->x edge + assert D['v'] == 8 # uses lower weight of 2 on u<->x edge validate_path(GG, 's', 'v', 8, nx.dijkstra_path(GG, 's', 'v')) - assert_equal(nx.dijkstra_path_length(GG, 's', 'v'), 8) + assert nx.dijkstra_path_length(GG, 's', 'v') == 8 validate_path(self.XG2, 1, 3, 4, nx.dijkstra_path(self.XG2, 1, 3)) validate_path(self.XG3, 0, 3, 15, nx.dijkstra_path(self.XG3, 0, 3)) - assert_equal(nx.dijkstra_path_length(self.XG3, 0, 3), 15) + assert nx.dijkstra_path_length(self.XG3, 0, 3) == 15 validate_path(self.XG4, 0, 2, 4, nx.dijkstra_path(self.XG4, 0, 2)) - assert_equal(nx.dijkstra_path_length(self.XG4, 0, 2), 4) + assert nx.dijkstra_path_length(self.XG4, 0, 2) == 4 validate_path(self.MXG4, 0, 2, 4, nx.dijkstra_path(self.MXG4, 0, 2)) validate_path( self.G, 's', 'v', 2, nx.single_source_dijkstra(self.G, 's', 'v')[1]) @@ -112,7 +112,7 @@ class TestWeightedPath(WeightedTestBase): self.G, 's', 'v', 2, nx.single_source_dijkstra(self.G, 's')[1]['v']) validate_path(self.G, 's', 'v', 2, nx.dijkstra_path(self.G, 's', 'v')) - assert_equal(nx.dijkstra_path_length(self.G, 's', 'v'), 2) + assert nx.dijkstra_path_length(self.G, 's', 'v') == 2 # NetworkXError: node s not reachable from moon assert_raises(nx.NetworkXNoPath, nx.dijkstra_path, self.G, 's', 'moon') @@ -122,7 +122,7 @@ class TestWeightedPath(WeightedTestBase): validate_path(self.cycle, 0, 3, 3, nx.dijkstra_path(self.cycle, 0, 3)) validate_path(self.cycle, 0, 4, 3, nx.dijkstra_path(self.cycle, 0, 4)) - assert_equal(nx.single_source_dijkstra(self.cycle, 0, 0), (0, [0])) + assert nx.single_source_dijkstra(self.cycle, 0, 0) == (0, [0]) def test_bidirectional_dijkstra(self): validate_length_path( @@ -169,18 +169,18 @@ class TestWeightedPath(WeightedTestBase): def test_dijkstra_predecessor1(self): G = nx.path_graph(4) - assert_equal(nx.dijkstra_predecessor_and_distance(G, 0), + assert (nx.dijkstra_predecessor_and_distance(G, 0) == ({0: [], 1: [0], 2: [1], 3: [2]}, {0: 0, 1: 1, 2: 2, 3: 3})) def test_dijkstra_predecessor2(self): # 4-cycle G = nx.Graph([(0, 1), (1, 2), (2, 3), (3, 0)]) pred, dist = nx.dijkstra_predecessor_and_distance(G, (0)) - assert_equal(pred[0], []) - assert_equal(pred[1], [0]) - assert_true(pred[2] in [[1, 3], [3, 1]]) - assert_equal(pred[3], [0]) - assert_equal(dist, {0: 0, 1: 1, 2: 2, 3: 1}) + assert pred[0] == [] + assert pred[1] == [0] + assert pred[2] in [[1, 3], [3, 1]] + assert pred[3] == [0] + assert dist == {0: 0, 1: 1, 2: 2, 3: 1} def test_dijkstra_predecessor3(self): XG = nx.DiGraph() @@ -190,40 +190,40 @@ class TestWeightedPath(WeightedTestBase): ('x', 'v', 5), ('x', 'y', 2), ('y', 's', 7), ('y', 'v', 6)]) (P, D) = nx.dijkstra_predecessor_and_distance(XG, 's') - assert_equal(P['v'], ['u']) - assert_equal(D['v'], 9) + assert P['v'] == ['u'] + assert D['v'] == 9 (P, D) = nx.dijkstra_predecessor_and_distance(XG, 's', cutoff=8) - assert_false('v' in D) + assert not 'v' in D def test_single_source_dijkstra_path_length(self): pl = nx.single_source_dijkstra_path_length - assert_equal(dict(pl(self.MXG4, 0))[2], 4) + assert dict(pl(self.MXG4, 0))[2] == 4 spl = pl(self.MXG4, 0, cutoff=2) - assert_false(2 in spl) + assert not 2 in spl def test_bidirectional_dijkstra_multigraph(self): G = nx.MultiGraph() G.add_edge('a', 'b', weight=10) G.add_edge('a', 'b', weight=100) dp = nx.bidirectional_dijkstra(G, 'a', 'b') - assert_equal(dp, (10, ['a', 'b'])) + assert dp == (10, ['a', 'b']) def test_dijkstra_pred_distance_multigraph(self): G = nx.MultiGraph() G.add_edge('a', 'b', key='short', foo=5, weight=100) G.add_edge('a', 'b', key='long', bar=1, weight=110) p, d = nx.dijkstra_predecessor_and_distance(G, 'a') - assert_equal(p, {'a': [], 'b': ['a']}) - assert_equal(d, {'a': 0, 'b': 100}) + assert p == {'a': [], 'b': ['a']} + assert d == {'a': 0, 'b': 100} def test_negative_edge_cycle(self): G = nx.cycle_graph(5, create_using=nx.DiGraph()) - assert_equal(nx.negative_edge_cycle(G), False) + assert nx.negative_edge_cycle(G) == False G.add_edge(8, 9, weight=-7) G.add_edge(9, 8, weight=3) graph_size = len(G) - assert_equal(nx.negative_edge_cycle(G), True) - assert_equal(graph_size, len(G)) + assert nx.negative_edge_cycle(G) == True + assert graph_size == len(G) assert_raises(ValueError, nx.single_source_dijkstra_path_length, G, 8) assert_raises(ValueError, nx.single_source_dijkstra, G, 8) assert_raises(ValueError, nx.dijkstra_predecessor_and_distance, G, 8) @@ -249,42 +249,42 @@ class TestWeightedPath(WeightedTestBase): # The shortest path from 0 to 2 using the actual weights on the # edges should be [0, 1, 2]. distance, path = nx.single_source_dijkstra(G, 0, 2) - assert_equal(distance, 2) - assert_equal(path, [0, 1, 2]) + assert distance == 2 + assert path == [0, 1, 2] # However, with the above weight function, the shortest path # should be [0, 2], since that has a very small weight. distance, path = nx.single_source_dijkstra(G, 0, 2, weight=weight) - assert_equal(distance, 1 / 10) - assert_equal(path, [0, 2]) + assert distance == 1 / 10 + assert path == [0, 2] def test_all_pairs_dijkstra_path(self): cycle = nx.cycle_graph(7) p = dict(nx.all_pairs_dijkstra_path(cycle)) - assert_equal(p[0][3], [0, 1, 2, 3]) + assert p[0][3] == [0, 1, 2, 3] cycle[1][2]['weight'] = 10 p = dict(nx.all_pairs_dijkstra_path(cycle)) - assert_equal(p[0][3], [0, 6, 5, 4, 3]) + assert p[0][3] == [0, 6, 5, 4, 3] def test_all_pairs_dijkstra_path_length(self): cycle = nx.cycle_graph(7) pl = dict(nx.all_pairs_dijkstra_path_length(cycle)) - assert_equal(pl[0], {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1}) + assert pl[0] == {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1} cycle[1][2]['weight'] = 10 pl = dict(nx.all_pairs_dijkstra_path_length(cycle)) - assert_equal(pl[0], {0: 0, 1: 1, 2: 5, 3: 4, 4: 3, 5: 2, 6: 1}) + assert pl[0] == {0: 0, 1: 1, 2: 5, 3: 4, 4: 3, 5: 2, 6: 1} def test_all_pairs_dijkstra(self): cycle = nx.cycle_graph(7) out = dict(nx.all_pairs_dijkstra(cycle)) - assert_equal(out[0][0], {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1}) - assert_equal(out[0][1][3], [0, 1, 2, 3]) + assert out[0][0] == {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1} + assert out[0][1][3] == [0, 1, 2, 3] cycle[1][2]['weight'] = 10 out = dict(nx.all_pairs_dijkstra(cycle)) - assert_equal(out[0][0], {0: 0, 1: 1, 2: 5, 3: 4, 4: 3, 5: 2, 6: 1}) - assert_equal(out[0][1][3], [0, 6, 5, 4, 3]) + assert out[0][0] == {0: 0, 1: 1, 2: 5, 3: 4, 4: 3, 5: 2, 6: 1} + assert out[0][1][3] == [0, 6, 5, 4, 3] class TestDijkstraPathLength(object): @@ -314,7 +314,7 @@ class TestDijkstraPathLength(object): # function, the shortest path should be [0, 2], since that has a # very small weight. length = nx.dijkstra_path_length(G, 0, 2, weight=weight) - assert_equal(length, 1 / 10) + assert length == 1 / 10 class TestMultiSourceDijkstra(object): @@ -350,15 +350,15 @@ class TestMultiSourceDijkstra(object): distances, paths = nx.multi_source_dijkstra(G, sources) expected_distances = {0: 0, 1: 1, 2: 2, 3: 1, 4: 0} expected_paths = {0: [0], 1: [0, 1], 2: [0, 1, 2], 3: [4, 3], 4: [4]} - assert_equal(distances, expected_distances) - assert_equal(paths, expected_paths) + assert distances == expected_distances + assert paths == expected_paths def test_simple_paths(self): G = nx.path_graph(4) lengths = nx.multi_source_dijkstra_path_length(G, [0]) - assert_equal(lengths, {n: n for n in G}) + assert lengths == {n: n for n in G} paths = nx.multi_source_dijkstra_path(G, [0]) - assert_equal(paths, {n: list(range(n + 1)) for n in G}) + assert paths == {n: list(range(n + 1)) for n in G} class TestBellmanFordAndGoldbergRadzik(WeightedTestBase): @@ -366,11 +366,11 @@ class TestBellmanFordAndGoldbergRadzik(WeightedTestBase): def test_single_node_graph(self): G = nx.DiGraph() G.add_node(0) - assert_equal(nx.single_source_bellman_ford_path(G, 0), {0: [0]}) - assert_equal(nx.single_source_bellman_ford_path_length(G, 0), {0: 0}) - assert_equal(nx.single_source_bellman_ford(G, 0), ({0: 0}, {0: [0]})) - assert_equal(nx.bellman_ford_predecessor_and_distance(G, 0), ({0: []}, {0: 0})) - assert_equal(nx.goldberg_radzik(G, 0), ({0: None}, {0: 0})) + assert nx.single_source_bellman_ford_path(G, 0) == {0: [0]} + assert nx.single_source_bellman_ford_path_length(G, 0) == {0: 0} + assert nx.single_source_bellman_ford(G, 0) == ({0: 0}, {0: [0]}) + assert nx.bellman_ford_predecessor_and_distance(G, 0) == ({0: []}, {0: 0}) + assert nx.goldberg_radzik(G, 0) == ({0: None}, {0: 0}) def test_absent_source_bellman_ford(self): # the check is in _bellman_ford; this provides regression testing @@ -415,17 +415,17 @@ class TestBellmanFordAndGoldbergRadzik(WeightedTestBase): # no negative cycle but negative weight G = nx.cycle_graph(5, create_using=nx.DiGraph()) G.add_edge(1, 2, weight=-3) - assert_equal(nx.single_source_bellman_ford_path(G, 0), + assert (nx.single_source_bellman_ford_path(G, 0) == {0: [0], 1: [0, 1], 2: [0, 1, 2], 3: [0, 1, 2, 3], 4: [0, 1, 2, 3, 4]}) - assert_equal(nx.single_source_bellman_ford_path_length(G, 0), + assert (nx.single_source_bellman_ford_path_length(G, 0) == {0: 0, 1: 1, 2: -2, 3: -1, 4: 0}) - assert_equal(nx.single_source_bellman_ford(G, 0), + assert (nx.single_source_bellman_ford(G, 0) == ({0: 0, 1: 1, 2: -2, 3: -1, 4: 0}, {0: [0], 1: [0, 1], 2: [0, 1, 2], 3: [0, 1, 2, 3], 4: [0, 1, 2, 3, 4]})) - assert_equal(nx.bellman_ford_predecessor_and_distance(G, 0), + assert (nx.bellman_ford_predecessor_and_distance(G, 0) == ({0: [], 1: [0], 2: [1], 3: [2], 4: [3]}, {0: 0, 1: 1, 2: -2, 3: -1, 4: 0})) - assert_equal(nx.goldberg_radzik(G, 0), + assert (nx.goldberg_radzik(G, 0) == ({0: None, 1: 0, 2: 1, 3: 2, 4: 3}, {0: 0, 1: 1, 2: -2, 3: -1, 4: 0})) @@ -433,17 +433,17 @@ class TestBellmanFordAndGoldbergRadzik(WeightedTestBase): G = nx.complete_graph(6) G.add_edge(10, 11) G.add_edge(10, 12) - assert_equal(nx.single_source_bellman_ford_path(G, 0), + assert (nx.single_source_bellman_ford_path(G, 0) == {0: [0], 1: [0, 1], 2: [0, 2], 3: [0, 3], 4: [0, 4], 5: [0, 5]}) - assert_equal(nx.single_source_bellman_ford_path_length(G, 0), + assert (nx.single_source_bellman_ford_path_length(G, 0) == {0: 0, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1}) - assert_equal(nx.single_source_bellman_ford(G, 0), + assert (nx.single_source_bellman_ford(G, 0) == ({0: 0, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1}, {0: [0], 1: [0, 1], 2: [0, 2], 3: [0, 3], 4: [0, 4], 5: [0, 5]})) - assert_equal(nx.bellman_ford_predecessor_and_distance(G, 0), + assert (nx.bellman_ford_predecessor_and_distance(G, 0) == ({0: [], 1: [0], 2: [0], 3: [0], 4: [0], 5: [0]}, {0: 0, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1})) - assert_equal(nx.goldberg_radzik(G, 0), + assert (nx.goldberg_radzik(G, 0) == ({0: None, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0}, {0: 0, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1})) @@ -453,109 +453,109 @@ class TestBellmanFordAndGoldbergRadzik(WeightedTestBase): G.add_edges_from([('A', 'B', {'load': 3}), ('B', 'C', {'load': -10}), ('C', 'A', {'load': 2})]) - assert_equal(nx.single_source_bellman_ford_path(G, 0, weight='load'), + assert (nx.single_source_bellman_ford_path(G, 0, weight='load') == {0: [0], 1: [0, 1], 2: [0, 2], 3: [0, 3], 4: [0, 4], 5: [0, 5]}) - assert_equal(nx.single_source_bellman_ford_path_length(G, 0, weight='load'), + assert (nx.single_source_bellman_ford_path_length(G, 0, weight='load') == {0: 0, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1}) - assert_equal(nx.single_source_bellman_ford(G, 0, weight='load'), + assert (nx.single_source_bellman_ford(G, 0, weight='load') == ({0: 0, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1}, {0: [0], 1: [0, 1], 2: [0, 2], 3: [0, 3], 4: [0, 4], 5: [0, 5]})) - assert_equal(nx.bellman_ford_predecessor_and_distance(G, 0, weight='load'), + assert (nx.bellman_ford_predecessor_and_distance(G, 0, weight='load') == ({0: [], 1: [0], 2: [0], 3: [0], 4: [0], 5: [0]}, {0: 0, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1})) - assert_equal(nx.goldberg_radzik(G, 0, weight='load'), + assert (nx.goldberg_radzik(G, 0, weight='load') == ({0: None, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0}, {0: 0, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1})) def test_multigraph(self): - assert_equal(nx.bellman_ford_path(self.MXG, 's', 'v'), ['s', 'x', 'u', 'v']) - assert_equal(nx.bellman_ford_path_length(self.MXG, 's', 'v'), 9) - assert_equal(nx.single_source_bellman_ford_path(self.MXG, 's')['v'], ['s', 'x', 'u', 'v']) - assert_equal(nx.single_source_bellman_ford_path_length(self.MXG, 's')['v'], 9) + assert nx.bellman_ford_path(self.MXG, 's', 'v') == ['s', 'x', 'u', 'v'] + assert nx.bellman_ford_path_length(self.MXG, 's', 'v') == 9 + assert nx.single_source_bellman_ford_path(self.MXG, 's')['v'] == ['s', 'x', 'u', 'v'] + assert nx.single_source_bellman_ford_path_length(self.MXG, 's')['v'] == 9 D, P = nx.single_source_bellman_ford(self.MXG, 's', target='v') - assert_equal(D, 9) - assert_equal(P, ['s', 'x', 'u', 'v']) + assert D == 9 + assert P == ['s', 'x', 'u', 'v'] P, D = nx.bellman_ford_predecessor_and_distance(self.MXG, 's') - assert_equal(P['v'], ['u']) - assert_equal(D['v'], 9) + assert P['v'] == ['u'] + assert D['v'] == 9 P, D = nx.goldberg_radzik(self.MXG, 's') - assert_equal(P['v'], 'u') - assert_equal(D['v'], 9) - assert_equal(nx.bellman_ford_path(self.MXG4, 0, 2), [0, 1, 2]) - assert_equal(nx.bellman_ford_path_length(self.MXG4, 0, 2), 4) - assert_equal(nx.single_source_bellman_ford_path(self.MXG4, 0)[2], [0, 1, 2]) - assert_equal(nx.single_source_bellman_ford_path_length(self.MXG4, 0)[2], 4) + assert P['v'] == 'u' + assert D['v'] == 9 + assert nx.bellman_ford_path(self.MXG4, 0, 2) == [0, 1, 2] + assert nx.bellman_ford_path_length(self.MXG4, 0, 2) == 4 + assert nx.single_source_bellman_ford_path(self.MXG4, 0)[2] == [0, 1, 2] + assert nx.single_source_bellman_ford_path_length(self.MXG4, 0)[2] == 4 D, P = nx.single_source_bellman_ford(self.MXG4, 0, target=2) - assert_equal(D, 4) - assert_equal(P, [0, 1, 2]) + assert D == 4 + assert P == [0, 1, 2] P, D = nx.bellman_ford_predecessor_and_distance(self.MXG4, 0) - assert_equal(P[2], [1]) - assert_equal(D[2], 4) + assert P[2] == [1] + assert D[2] == 4 P, D = nx.goldberg_radzik(self.MXG4, 0) - assert_equal(P[2], 1) - assert_equal(D[2], 4) + assert P[2] == 1 + assert D[2] == 4 def test_others(self): - assert_equal(nx.bellman_ford_path(self.XG, 's', 'v'), ['s', 'x', 'u', 'v']) - assert_equal(nx.bellman_ford_path_length(self.XG, 's', 'v'), 9) - assert_equal(nx.single_source_bellman_ford_path(self.XG, 's')['v'], ['s', 'x', 'u', 'v']) - assert_equal(nx.single_source_bellman_ford_path_length(self.XG, 's')['v'], 9) + assert nx.bellman_ford_path(self.XG, 's', 'v') == ['s', 'x', 'u', 'v'] + assert nx.bellman_ford_path_length(self.XG, 's', 'v') == 9 + assert nx.single_source_bellman_ford_path(self.XG, 's')['v'] == ['s', 'x', 'u', 'v'] + assert nx.single_source_bellman_ford_path_length(self.XG, 's')['v'] == 9 D, P = nx.single_source_bellman_ford(self.XG, 's', target='v') - assert_equal(D, 9) - assert_equal(P, ['s', 'x', 'u', 'v']) + assert D == 9 + assert P == ['s', 'x', 'u', 'v'] (P, D) = nx.bellman_ford_predecessor_and_distance(self.XG, 's') - assert_equal(P['v'], ['u']) - assert_equal(D['v'], 9) + assert P['v'] == ['u'] + assert D['v'] == 9 (P, D) = nx.goldberg_radzik(self.XG, 's') - assert_equal(P['v'], 'u') - assert_equal(D['v'], 9) + assert P['v'] == 'u' + assert D['v'] == 9 def test_path_graph(self): G = nx.path_graph(4) - assert_equal(nx.single_source_bellman_ford_path(G, 0), + assert (nx.single_source_bellman_ford_path(G, 0) == {0: [0], 1: [0, 1], 2: [0, 1, 2], 3: [0, 1, 2, 3]}) - assert_equal(nx.single_source_bellman_ford_path_length(G, 0), + assert (nx.single_source_bellman_ford_path_length(G, 0) == {0: 0, 1: 1, 2: 2, 3: 3}) - assert_equal(nx.single_source_bellman_ford(G, 0), + assert (nx.single_source_bellman_ford(G, 0) == ({0: 0, 1: 1, 2: 2, 3: 3}, {0: [0], 1: [0, 1], 2: [0, 1, 2], 3: [0, 1, 2, 3]})) - assert_equal(nx.bellman_ford_predecessor_and_distance(G, 0), + assert (nx.bellman_ford_predecessor_and_distance(G, 0) == ({0: [], 1: [0], 2: [1], 3: [2]}, {0: 0, 1: 1, 2: 2, 3: 3})) - assert_equal(nx.goldberg_radzik(G, 0), + assert (nx.goldberg_radzik(G, 0) == ({0: None, 1: 0, 2: 1, 3: 2}, {0: 0, 1: 1, 2: 2, 3: 3})) - assert_equal(nx.single_source_bellman_ford_path(G, 3), + assert (nx.single_source_bellman_ford_path(G, 3) == {0: [3, 2, 1, 0], 1: [3, 2, 1], 2: [3, 2], 3: [3]}) - assert_equal(nx.single_source_bellman_ford_path_length(G, 3), + assert (nx.single_source_bellman_ford_path_length(G, 3) == {0: 3, 1: 2, 2: 1, 3: 0}) - assert_equal(nx.single_source_bellman_ford(G, 3), + assert (nx.single_source_bellman_ford(G, 3) == ({0: 3, 1: 2, 2: 1, 3: 0}, {0: [3, 2, 1, 0], 1: [3, 2, 1], 2: [3, 2], 3: [3]})) - assert_equal(nx.bellman_ford_predecessor_and_distance(G, 3), + assert (nx.bellman_ford_predecessor_and_distance(G, 3) == ({0: [1], 1: [2], 2: [3], 3: []}, {0: 3, 1: 2, 2: 1, 3: 0})) - assert_equal(nx.goldberg_radzik(G, 3), + assert (nx.goldberg_radzik(G, 3) == ({0: 1, 1: 2, 2: 3, 3: None}, {0: 3, 1: 2, 2: 1, 3: 0})) def test_4_cycle(self): # 4-cycle G = nx.Graph([(0, 1), (1, 2), (2, 3), (3, 0)]) dist, path = nx.single_source_bellman_ford(G, 0) - assert_equal(dist, {0: 0, 1: 1, 2: 2, 3: 1}) - assert_equal(path[0], [0]) - assert_equal(path[1], [0, 1]) - assert_true(path[2] in [[0, 1, 2], [0, 3, 2]]) - assert_equal(path[3], [0, 3]) + assert dist == {0: 0, 1: 1, 2: 2, 3: 1} + assert path[0] == [0] + assert path[1] == [0, 1] + assert path[2] in [[0, 1, 2], [0, 3, 2]] + assert path[3] == [0, 3] pred, dist = nx.bellman_ford_predecessor_and_distance(G, 0) - assert_equal(pred[0], []) - assert_equal(pred[1], [0]) - assert_true(pred[2] in [[1, 3], [3, 1]]) - assert_equal(pred[3], [0]) - assert_equal(dist, {0: 0, 1: 1, 2: 2, 3: 1}) + assert pred[0] == [] + assert pred[1] == [0] + assert pred[2] in [[1, 3], [3, 1]] + assert pred[3] == [0] + assert dist == {0: 0, 1: 1, 2: 2, 3: 1} pred, dist = nx.goldberg_radzik(G, 0) - assert_equal(pred[0], None) - assert_equal(pred[1], 0) - assert_true(pred[2] in [1, 3]) - assert_equal(pred[3], 0) - assert_equal(dist, {0: 0, 1: 1, 2: 2, 3: 1}) + assert pred[0] == None + assert pred[1] == 0 + assert pred[2] in [1, 3] + assert pred[3] == 0 + assert dist == {0: 0, 1: 1, 2: 2, 3: 1} def test_negative_weight(self): G = nx.DiGraph() @@ -565,8 +565,8 @@ class TestBellmanFordAndGoldbergRadzik(WeightedTestBase): G.add_edge('b','c', weight = -3) G.add_edge('c','d', weight = 1) - assert_equal(nx.bellman_ford_path(G, 'a', 'd'), ['a', 'b', 'c', 'd']) - assert_equal(nx.bellman_ford_path_length(G, 'a', 'd'), -1) + assert nx.bellman_ford_path(G, 'a', 'd') == ['a', 'b', 'c', 'd'] + assert nx.bellman_ford_path_length(G, 'a', 'd') == -1 class TestJohnsonAlgorithm(WeightedTestBase): @@ -595,11 +595,11 @@ class TestJohnsonAlgorithm(WeightedTestBase): ('0', '2', 2), ('1', '2', 4), ('2', '3', 1)]) paths = nx.johnson(G) - assert_equal(paths, {'1': {'1': ['1'], '3': ['1', '2', '3'], + assert paths == {'1': {'1': ['1'], '3': ['1', '2', '3'], '2': ['1', '2']}, '0': {'1': ['0', '1'], '0': ['0'], '3': ['0', '1', '2', '3'], '2': ['0', '1', '2']}, '3': {'3': ['3']}, - '2': {'3': ['2', '3'], '2': ['2']}}) + '2': {'3': ['2', '3'], '2': ['2']}} @raises(nx.NetworkXError) def test_unweighted_graph(self): diff --git a/networkx/algorithms/tests/test_asteroidal.py b/networkx/algorithms/tests/test_asteroidal.py index 330b51bc..a0ea4e15 100644 --- a/networkx/algorithms/tests/test_asteroidal.py +++ b/networkx/algorithms/tests/test_asteroidal.py @@ -9,19 +9,19 @@ def test_is_at_free(): is_at_free = nx.asteroidal.is_at_free cycle = nx.cycle_graph(6) - assert_false(is_at_free(cycle)) + assert not is_at_free(cycle) path = nx.path_graph(6) - assert_true(is_at_free(path)) + assert is_at_free(path) small_graph = nx.complete_graph(2) - assert_true(is_at_free(small_graph)) + assert is_at_free(small_graph) petersen = nx.petersen_graph() - assert_false(is_at_free(petersen)) + assert not is_at_free(petersen) clique = nx.complete_graph(6) - assert_true(is_at_free(clique)) + assert is_at_free(clique) line_clique = nx.line_graph(clique) - assert_false(is_at_free(line_clique)) + assert not is_at_free(line_clique) diff --git a/networkx/algorithms/tests/test_boundary.py b/networkx/algorithms/tests/test_boundary.py index bba22db3..8ce68d24 100644 --- a/networkx/algorithms/tests/test_boundary.py +++ b/networkx/algorithms/tests/test_boundary.py @@ -24,32 +24,32 @@ class TestNodeBoundary(object): def test_null_graph(self): """Tests that the null graph has empty node boundaries.""" null = nx.null_graph() - assert_equal(nx.node_boundary(null, []), set()) - assert_equal(nx.node_boundary(null, [], []), set()) - assert_equal(nx.node_boundary(null, [1, 2, 3]), set()) - assert_equal(nx.node_boundary(null, [1, 2, 3], [4, 5, 6]), set()) - assert_equal(nx.node_boundary(null, [1, 2, 3], [3, 4, 5]), set()) + assert nx.node_boundary(null, []) == set() + assert nx.node_boundary(null, [], []) == set() + assert nx.node_boundary(null, [1, 2, 3]) == set() + assert nx.node_boundary(null, [1, 2, 3], [4, 5, 6]) == set() + assert nx.node_boundary(null, [1, 2, 3], [3, 4, 5]) == set() def test_path_graph(self): P10 = cnlti(nx.path_graph(10), first_label=1) - assert_equal(nx.node_boundary(P10, []), set()) - assert_equal(nx.node_boundary(P10, [], []), set()) - assert_equal(nx.node_boundary(P10, [1, 2, 3]), {4}) - assert_equal(nx.node_boundary(P10, [4, 5, 6]), {3, 7}) - assert_equal(nx.node_boundary(P10, [3, 4, 5, 6, 7]), {2, 8}) - assert_equal(nx.node_boundary(P10, [8, 9, 10]), {7}) - assert_equal(nx.node_boundary(P10, [4, 5, 6], [9, 10]), set()) + assert nx.node_boundary(P10, []) == set() + assert nx.node_boundary(P10, [], []) == set() + assert nx.node_boundary(P10, [1, 2, 3]) == {4} + assert nx.node_boundary(P10, [4, 5, 6]) == {3, 7} + assert nx.node_boundary(P10, [3, 4, 5, 6, 7]) == {2, 8} + assert nx.node_boundary(P10, [8, 9, 10]) == {7} + assert nx.node_boundary(P10, [4, 5, 6], [9, 10]) == set() def test_complete_graph(self): K10 = cnlti(nx.complete_graph(10), first_label=1) - assert_equal(nx.node_boundary(K10, []), set()) - assert_equal(nx.node_boundary(K10, [], []), set()) - assert_equal(nx.node_boundary(K10, [1, 2, 3]), {4, 5, 6, 7, 8, 9, 10}) - assert_equal(nx.node_boundary(K10, [4, 5, 6]), {1, 2, 3, 7, 8, 9, 10}) - assert_equal(nx.node_boundary(K10, [3, 4, 5, 6, 7]), {1, 2, 8, 9, 10}) - assert_equal(nx.node_boundary(K10, [4, 5, 6], []), set()) - assert_equal(nx.node_boundary(K10, K10), set()) - assert_equal(nx.node_boundary(K10, [1, 2, 3], [3, 4, 5]), {4, 5}) + assert nx.node_boundary(K10, []) == set() + assert nx.node_boundary(K10, [], []) == set() + assert nx.node_boundary(K10, [1, 2, 3]) == {4, 5, 6, 7, 8, 9, 10} + assert nx.node_boundary(K10, [4, 5, 6]) == {1, 2, 3, 7, 8, 9, 10} + assert nx.node_boundary(K10, [3, 4, 5, 6, 7]) == {1, 2, 8, 9, 10} + assert nx.node_boundary(K10, [4, 5, 6], []) == set() + assert nx.node_boundary(K10, K10) == set() + assert nx.node_boundary(K10, [1, 2, 3], [3, 4, 5]) == {4, 5} def test_petersen(self): """Check boundaries in the petersen graph @@ -75,7 +75,7 @@ class TestNodeBoundary(object): S = {0, 1} boundary = nx.node_boundary(G, S) expected = {2} - assert_equal(boundary, expected) + assert boundary == expected def test_multigraph(self): """Tests the node boundary of a multigraph.""" @@ -83,7 +83,7 @@ class TestNodeBoundary(object): S = {0, 1} boundary = nx.node_boundary(G, S) expected = {2, 4} - assert_equal(boundary, expected) + assert boundary == expected def test_multidigraph(self): """Tests the edge boundary of a multdiigraph.""" @@ -92,7 +92,7 @@ class TestNodeBoundary(object): S = {0, 1} boundary = nx.node_boundary(G, S) expected = {2} - assert_equal(boundary, expected) + assert boundary == expected class TestEdgeBoundary(object): @@ -100,36 +100,36 @@ class TestEdgeBoundary(object): def test_null_graph(self): null = nx.null_graph() - assert_equal(list(nx.edge_boundary(null, [])), []) - assert_equal(list(nx.edge_boundary(null, [], [])), []) - assert_equal(list(nx.edge_boundary(null, [1, 2, 3])), []) - assert_equal(list(nx.edge_boundary(null, [1, 2, 3], [4, 5, 6])), []) - assert_equal(list(nx.edge_boundary(null, [1, 2, 3], [3, 4, 5])), []) + assert list(nx.edge_boundary(null, [])) == [] + assert list(nx.edge_boundary(null, [], [])) == [] + assert list(nx.edge_boundary(null, [1, 2, 3])) == [] + assert list(nx.edge_boundary(null, [1, 2, 3], [4, 5, 6])) == [] + assert list(nx.edge_boundary(null, [1, 2, 3], [3, 4, 5])) == [] def test_path_graph(self): P10 = cnlti(nx.path_graph(10), first_label=1) - assert_equal(list(nx.edge_boundary(P10, [])), []) - assert_equal(list(nx.edge_boundary(P10, [], [])), []) - assert_equal(list(nx.edge_boundary(P10, [1, 2, 3])), [(3, 4)]) - assert_equal(sorted(nx.edge_boundary(P10, [4, 5, 6])), + assert list(nx.edge_boundary(P10, [])) == [] + assert list(nx.edge_boundary(P10, [], [])) == [] + assert list(nx.edge_boundary(P10, [1, 2, 3])) == [(3, 4)] + assert (sorted(nx.edge_boundary(P10, [4, 5, 6])) == [(4, 3), (6, 7)]) - assert_equal(sorted(nx.edge_boundary(P10, [3, 4, 5, 6, 7])), + assert (sorted(nx.edge_boundary(P10, [3, 4, 5, 6, 7])) == [(3, 2), (7, 8)]) - assert_equal(list(nx.edge_boundary(P10, [8, 9, 10])), [(8, 7)]) - assert_equal(sorted(nx.edge_boundary(P10, [4, 5, 6], [9, 10])), []) - assert_equal(list(nx.edge_boundary(P10, [1, 2, 3], [3, 4, 5])), + assert list(nx.edge_boundary(P10, [8, 9, 10])) == [(8, 7)] + assert sorted(nx.edge_boundary(P10, [4, 5, 6], [9, 10])) == [] + assert (list(nx.edge_boundary(P10, [1, 2, 3], [3, 4, 5])) == [(2, 3), (3, 4)]) def test_complete_graph(self): K10 = cnlti(nx.complete_graph(10), first_label=1) def ilen(iterable): return sum(1 for i in iterable) - assert_equal(list(nx.edge_boundary(K10, [])), []) - assert_equal(list(nx.edge_boundary(K10, [], [])), []) - assert_equal(ilen(nx.edge_boundary(K10, [1, 2, 3])), 21) - assert_equal(ilen(nx.edge_boundary(K10, [4, 5, 6, 7])), 24) - assert_equal(ilen(nx.edge_boundary(K10, [3, 4, 5, 6, 7])), 25) - assert_equal(ilen(nx.edge_boundary(K10, [8, 9, 10])), 21) + assert list(nx.edge_boundary(K10, [])) == [] + assert list(nx.edge_boundary(K10, [], [])) == [] + assert ilen(nx.edge_boundary(K10, [1, 2, 3])) == 21 + assert ilen(nx.edge_boundary(K10, [4, 5, 6, 7])) == 24 + assert ilen(nx.edge_boundary(K10, [3, 4, 5, 6, 7])) == 25 + assert ilen(nx.edge_boundary(K10, [8, 9, 10])) == 21 assert_edges_equal(nx.edge_boundary(K10, [4, 5, 6], [9, 10]), [(4, 9), (4, 10), (5, 9), (5, 10), (6, 9), (6, 10)]) assert_edges_equal(nx.edge_boundary(K10, [1, 2, 3], [3, 4, 5]), @@ -142,7 +142,7 @@ class TestEdgeBoundary(object): S = {0, 1} boundary = list(nx.edge_boundary(G, S)) expected = [(1, 2)] - assert_equal(boundary, expected) + assert boundary == expected def test_multigraph(self): """Tests the edge boundary of a multigraph.""" @@ -150,7 +150,7 @@ class TestEdgeBoundary(object): S = {0, 1} boundary = list(nx.edge_boundary(G, S)) expected = [(0, 4), (0, 4), (1, 2), (1, 2)] - assert_equal(boundary, expected) + assert boundary == expected def test_multidigraph(self): """Tests the edge boundary of a multdiigraph.""" @@ -159,4 +159,4 @@ class TestEdgeBoundary(object): S = {0, 1} boundary = list(nx.edge_boundary(G, S)) expected = [(1, 2), (1, 2)] - assert_equal(boundary, expected) + assert boundary == expected diff --git a/networkx/algorithms/tests/test_bridges.py b/networkx/algorithms/tests/test_bridges.py index 0d377e9c..6751b126 100644 --- a/networkx/algorithms/tests/test_bridges.py +++ b/networkx/algorithms/tests/test_bridges.py @@ -48,17 +48,17 @@ class TestLocalBridges(TestCase): def test_nospan(self): expected = {(3, 4), (4, 3)} - assert_in(next(nx.local_bridges(self.BB, with_span=False)), expected) - assert_equal(set(nx.local_bridges(self.square, with_span=False)), self.square.edges) - assert_equal(list(nx.local_bridges(self.tri, with_span=False)), []) + assert next(nx.local_bridges(self.BB, with_span=False)) in expected + assert set(nx.local_bridges(self.square, with_span=False)) == self.square.edges + assert list(nx.local_bridges(self.tri, with_span=False)) == [] def test_no_weight(self): inf = float('inf') expected = {(3, 4, inf), (4, 3, inf)} - assert_in(next(nx.local_bridges(self.BB)), expected) + assert next(nx.local_bridges(self.BB)) in expected expected = {(u, v, 3) for u, v, in self.square.edges} - assert_equal(set(nx.local_bridges(self.square)), expected) - assert_equal(list(nx.local_bridges(self.tri)), []) + assert set(nx.local_bridges(self.square)) == expected + assert list(nx.local_bridges(self.tri)) == [] def test_weight(self): inf = float('inf') @@ -66,8 +66,8 @@ class TestLocalBridges(TestCase): G.edges[1, 2]['weight'] = 2 expected = {(u, v, 5 - wt) for u, v, wt in G.edges(data='weight', default=1)} - assert_equal(set(nx.local_bridges(G, weight='weight')), expected) + assert set(nx.local_bridges(G, weight='weight')) == expected expected = {(u, v, 6) for u, v in G.edges} lb = nx.local_bridges(G, weight=lambda u, v, d: 2) - assert_equal(set(lb), expected) + assert set(lb) == expected diff --git a/networkx/algorithms/tests/test_chordal.py b/networkx/algorithms/tests/test_chordal.py index f12870ba..75d021c0 100644 --- a/networkx/algorithms/tests/test_chordal.py +++ b/networkx/algorithms/tests/test_chordal.py @@ -27,41 +27,41 @@ class TestMCS: cls.non_chordal_G = non_chordal_G def test_is_chordal(self): - assert_false(nx.is_chordal(self.non_chordal_G)) - assert_true(nx.is_chordal(self.chordal_G)) - assert_true(nx.is_chordal(self.connected_chordal_G)) - assert_true(nx.is_chordal(nx.complete_graph(3))) - assert_true(nx.is_chordal(nx.cycle_graph(3))) - assert_false(nx.is_chordal(nx.cycle_graph(5))) + assert not nx.is_chordal(self.non_chordal_G) + assert nx.is_chordal(self.chordal_G) + assert nx.is_chordal(self.connected_chordal_G) + assert nx.is_chordal(nx.complete_graph(3)) + assert nx.is_chordal(nx.cycle_graph(3)) + assert not nx.is_chordal(nx.cycle_graph(5)) def test_induced_nodes(self): G = nx.generators.classic.path_graph(10) Induced_nodes = nx.find_induced_nodes(G, 1, 9, 2) - assert_equal(Induced_nodes, set([1, 2, 3, 4, 5, 6, 7, 8, 9])) + assert Induced_nodes == set([1, 2, 3, 4, 5, 6, 7, 8, 9]) assert_raises(nx.NetworkXTreewidthBoundExceeded, nx.find_induced_nodes, G, 1, 9, 1) Induced_nodes = nx.find_induced_nodes(self.chordal_G, 1, 6) - assert_equal(Induced_nodes, set([1, 2, 4, 6])) + assert Induced_nodes == set([1, 2, 4, 6]) assert_raises(nx.NetworkXError, nx.find_induced_nodes, self.non_chordal_G, 1, 5) def test_chordal_find_cliques(self): cliques = set([frozenset([9]), frozenset([7, 8]), frozenset([1, 2, 3]), frozenset([2, 3, 4]), frozenset([3, 4, 5, 6])]) - assert_equal(nx.chordal_graph_cliques(self.chordal_G), cliques) + assert nx.chordal_graph_cliques(self.chordal_G) == cliques def test_chordal_find_cliques_path(self): G = nx.path_graph(10) cliqueset = nx.chordal_graph_cliques(G) for (u, v) in G.edges(): - assert_true(frozenset([u, v]) in cliqueset + assert (frozenset([u, v]) in cliqueset or frozenset([v, u]) in cliqueset) def test_chordal_find_cliquesCC(self): cliques = set([frozenset([1, 2, 3]), frozenset([2, 3, 4]), frozenset([3, 4, 5, 6])]) cgc = nx.chordal_graph_cliques - assert_equal(cgc(self.connected_chordal_G), cliques) + assert cgc(self.connected_chordal_G) == cliques def test_complete_to_chordal_graph(self): fgrg = nx.fast_gnp_random_graph @@ -71,10 +71,10 @@ class TestMCS: nx.bull_graph(), fgrg(20, 0.3, seed=1)] for G in test_graphs: H, a = nx.complete_to_chordal_graph(G) - assert_true(nx.is_chordal(H)) - assert_equal(len(a), H.number_of_nodes()) + assert nx.is_chordal(H) + assert len(a) == H.number_of_nodes() if nx.is_chordal(G): - assert_equal(G.number_of_edges(), H.number_of_edges()) - assert_equal(set(a.values()), {0}) + assert G.number_of_edges() == H.number_of_edges() + assert set(a.values()) == {0} else: - assert_equal(len(set(a.values())), H.number_of_nodes()) + assert len(set(a.values())) == H.number_of_nodes() diff --git a/networkx/algorithms/tests/test_clique.py b/networkx/algorithms/tests/test_clique.py index ff200640..6eed0baf 100644 --- a/networkx/algorithms/tests/test_clique.py +++ b/networkx/algorithms/tests/test_clique.py @@ -19,111 +19,111 @@ class TestCliques: cl = list(nx.find_cliques(self.G)) rcl = nx.find_cliques_recursive(self.G) expected = [[2, 6, 1, 3], [2, 6, 4], [5, 4, 7], [8, 9], [10, 11]] - assert_equal(sorted(map(sorted, cl)), sorted(map(sorted, rcl))) - assert_equal(sorted(map(sorted, cl)), sorted(map(sorted, expected))) + assert sorted(map(sorted, cl)) == sorted(map(sorted, rcl)) + assert sorted(map(sorted, cl)) == sorted(map(sorted, expected)) def test_selfloops(self): self.G.add_edge(1, 1) cl = list(nx.find_cliques(self.G)) rcl = list(nx.find_cliques_recursive(self.G)) - assert_equal(set(map(frozenset, cl)), set(map(frozenset, rcl))) + assert set(map(frozenset, cl)) == set(map(frozenset, rcl)) answer = [{2, 6, 1, 3}, {2, 6, 4}, {5, 4, 7}, {8, 9}, {10, 11}] - assert_equal(len(answer), len(cl)) - assert_true(all(set(c) in answer for c in cl)) + assert len(answer) == len(cl) + assert all(set(c) in answer for c in cl) def test_find_cliques2(self): hcl = list(nx.find_cliques(self.H)) - assert_equal(sorted(map(sorted, hcl)), + assert (sorted(map(sorted, hcl)) == [[1, 2], [1, 4, 5, 6], [2, 3], [3, 4, 6]]) def test_clique_number(self): G = self.G - assert_equal(nx.graph_clique_number(G), 4) - assert_equal(nx.graph_clique_number(G, cliques=self.cl), 4) + assert nx.graph_clique_number(G) == 4 + assert nx.graph_clique_number(G, cliques=self.cl) == 4 def test_clique_number2(self): G = nx.Graph() G.add_nodes_from([1, 2, 3]) - assert_equal(nx.graph_clique_number(G), 1) + assert nx.graph_clique_number(G) == 1 def test_clique_number3(self): G = nx.Graph() - assert_equal(nx.graph_clique_number(G), 0) + assert nx.graph_clique_number(G) == 0 def test_number_of_cliques(self): G = self.G - assert_equal(nx.graph_number_of_cliques(G), 5) - assert_equal(nx.graph_number_of_cliques(G, cliques=self.cl), 5) - assert_equal(nx.number_of_cliques(G, 1), 1) - assert_equal(list(nx.number_of_cliques(G, [1]).values()), [1]) - assert_equal(list(nx.number_of_cliques(G, [1, 2]).values()), [1, 2]) - assert_equal(nx.number_of_cliques(G, [1, 2]), {1: 1, 2: 2}) - assert_equal(nx.number_of_cliques(G, 2), 2) - assert_equal(nx.number_of_cliques(G), + assert nx.graph_number_of_cliques(G) == 5 + assert nx.graph_number_of_cliques(G, cliques=self.cl) == 5 + assert nx.number_of_cliques(G, 1) == 1 + assert list(nx.number_of_cliques(G, [1]).values()) == [1] + assert list(nx.number_of_cliques(G, [1, 2]).values()) == [1, 2] + assert nx.number_of_cliques(G, [1, 2]) == {1: 1, 2: 2} + assert nx.number_of_cliques(G, 2) == 2 + assert (nx.number_of_cliques(G) == {1: 1, 2: 2, 3: 1, 4: 2, 5: 1, 6: 2, 7: 1, 8: 1, 9: 1, 10: 1, 11: 1}) - assert_equal(nx.number_of_cliques(G, nodes=list(G)), + assert (nx.number_of_cliques(G, nodes=list(G)) == {1: 1, 2: 2, 3: 1, 4: 2, 5: 1, 6: 2, 7: 1, 8: 1, 9: 1, 10: 1, 11: 1}) - assert_equal(nx.number_of_cliques(G, nodes=[2, 3, 4]), + assert (nx.number_of_cliques(G, nodes=[2, 3, 4]) == {2: 2, 3: 1, 4: 2}) - assert_equal(nx.number_of_cliques(G, cliques=self.cl), + assert (nx.number_of_cliques(G, cliques=self.cl) == {1: 1, 2: 2, 3: 1, 4: 2, 5: 1, 6: 2, 7: 1, 8: 1, 9: 1, 10: 1, 11: 1}) - assert_equal(nx.number_of_cliques(G, list(G), cliques=self.cl), + assert (nx.number_of_cliques(G, list(G), cliques=self.cl) == {1: 1, 2: 2, 3: 1, 4: 2, 5: 1, 6: 2, 7: 1, 8: 1, 9: 1, 10: 1, 11: 1}) def test_node_clique_number(self): G = self.G - assert_equal(nx.node_clique_number(G, 1), 4) - assert_equal(list(nx.node_clique_number(G, [1]).values()), [4]) - assert_equal(list(nx.node_clique_number(G, [1, 2]).values()), [4, 4]) - assert_equal(nx.node_clique_number(G, [1, 2]), {1: 4, 2: 4}) - assert_equal(nx.node_clique_number(G, 1), 4) - assert_equal(nx.node_clique_number(G), + assert nx.node_clique_number(G, 1) == 4 + assert list(nx.node_clique_number(G, [1]).values()) == [4] + assert list(nx.node_clique_number(G, [1, 2]).values()) == [4, 4] + assert nx.node_clique_number(G, [1, 2]) == {1: 4, 2: 4} + assert nx.node_clique_number(G, 1) == 4 + assert (nx.node_clique_number(G) == {1: 4, 2: 4, 3: 4, 4: 3, 5: 3, 6: 4, 7: 3, 8: 2, 9: 2, 10: 2, 11: 2}) - assert_equal(nx.node_clique_number(G, cliques=self.cl), + assert (nx.node_clique_number(G, cliques=self.cl) == {1: 4, 2: 4, 3: 4, 4: 3, 5: 3, 6: 4, 7: 3, 8: 2, 9: 2, 10: 2, 11: 2}) def test_cliques_containing_node(self): G = self.G - assert_equal(nx.cliques_containing_node(G, 1), + assert (nx.cliques_containing_node(G, 1) == [[2, 6, 1, 3]]) - assert_equal(list(nx.cliques_containing_node(G, [1]).values()), + assert (list(nx.cliques_containing_node(G, [1]).values()) == [[[2, 6, 1, 3]]]) - assert_equal([sorted(c) for c in list(nx.cliques_containing_node(G, [1, 2]).values())], + assert ([sorted(c) for c in list(nx.cliques_containing_node(G, [1, 2]).values())] == [[[2, 6, 1, 3]], [[2, 6, 1, 3], [2, 6, 4]]]) result = nx.cliques_containing_node(G, [1, 2]) for k, v in result.items(): result[k] = sorted(v) - assert_equal(result, + assert (result == {1: [[2, 6, 1, 3]], 2: [[2, 6, 1, 3], [2, 6, 4]]}) - assert_equal(nx.cliques_containing_node(G, 1), + assert (nx.cliques_containing_node(G, 1) == [[2, 6, 1, 3]]) expected = [{2, 6, 1, 3}, {2, 6, 4}] answer = [set(c) for c in nx.cliques_containing_node(G, 2)] - assert_in(answer, (expected, list(reversed(expected)))) + assert answer in (expected, list(reversed(expected))) answer = [set(c) for c in nx.cliques_containing_node(G, 2, cliques=self.cl)] - assert_in(answer, (expected, list(reversed(expected)))) - assert_equal(len(nx.cliques_containing_node(G)), 11) + assert answer in (expected, list(reversed(expected))) + assert len(nx.cliques_containing_node(G)) == 11 def test_make_clique_bipartite(self): G = self.G B = nx.make_clique_bipartite(G) - assert_equal(sorted(B), + assert (sorted(B) == [-5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) # Project onto the nodes of the original graph. H = nx.project(B, range(1, 12)) - assert_equal(H.adj, G.adj) + assert H.adj == G.adj # Project onto the nodes representing the cliques. H1 = nx.project(B, range(-5, 0)) # Relabel the negative numbers as positive ones. H1 = nx.relabel_nodes(H1, {-v: v for v in range(1, 6)}) - assert_equal(sorted(H1), [1, 2, 3, 4, 5]) + assert sorted(H1) == [1, 2, 3, 4, 5] def test_make_max_clique_graph(self): """Tests that the maximal clique graph is the same as the bipartite @@ -139,7 +139,7 @@ class TestCliques: # 0. H1 = nx.relabel_nodes(H1, {-v: v - 1 for v in range(1, 6)}) H2 = nx.make_max_clique_graph(G) - assert_equal(H1.adj, H2.adj) + assert H1.adj == H2.adj @raises(nx.NetworkXNotImplemented) def test_directed(self): @@ -163,7 +163,7 @@ class TestEnumerateAllCliques: cliques = list(nx.enumerate_all_cliques(G)) clique_sizes = list(map(len, cliques)) - assert_equal(sorted(clique_sizes), clique_sizes) + assert sorted(clique_sizes) == clique_sizes expected_cliques = [['a'], ['b'], @@ -211,5 +211,5 @@ class TestEnumerateAllCliques: ['a', 'b', 'c', 'd', 'e'], ['a', 'b', 'c', 'e']] - assert_equal(sorted(map(sorted, cliques)), + assert (sorted(map(sorted, cliques)) == sorted(map(sorted, expected_cliques))) diff --git a/networkx/algorithms/tests/test_cluster.py b/networkx/algorithms/tests/test_cluster.py index 7d9d2dd2..b728ebc5 100644 --- a/networkx/algorithms/tests/test_cluster.py +++ b/networkx/algorithms/tests/test_cluster.py @@ -7,197 +7,197 @@ class TestTriangles: def test_empty(self): G = nx.Graph() - assert_equal(list(nx.triangles(G).values()), []) + assert list(nx.triangles(G).values()) == [] def test_path(self): G = nx.path_graph(10) - assert_equal(list(nx.triangles(G).values()), + assert (list(nx.triangles(G).values()) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) - assert_equal(nx.triangles(G), + assert (nx.triangles(G) == {0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0}) def test_cubical(self): G = nx.cubical_graph() - assert_equal(list(nx.triangles(G).values()), + assert (list(nx.triangles(G).values()) == [0, 0, 0, 0, 0, 0, 0, 0]) - assert_equal(nx.triangles(G, 1), 0) - assert_equal(list(nx.triangles(G, [1, 2]).values()), [0, 0]) - assert_equal(nx.triangles(G, 1), 0) - assert_equal(nx.triangles(G, [1, 2]), {1: 0, 2: 0}) + assert nx.triangles(G, 1) == 0 + assert list(nx.triangles(G, [1, 2]).values()) == [0, 0] + assert nx.triangles(G, 1) == 0 + assert nx.triangles(G, [1, 2]) == {1: 0, 2: 0} def test_k5(self): G = nx.complete_graph(5) - assert_equal(list(nx.triangles(G).values()), [6, 6, 6, 6, 6]) - assert_equal(sum(nx.triangles(G).values()) / 3.0, 10) - assert_equal(nx.triangles(G, 1), 6) + assert list(nx.triangles(G).values()) == [6, 6, 6, 6, 6] + assert sum(nx.triangles(G).values()) / 3.0 == 10 + assert nx.triangles(G, 1) == 6 G.remove_edge(1, 2) - assert_equal(list(nx.triangles(G).values()), [5, 3, 3, 5, 5]) - assert_equal(nx.triangles(G, 1), 3) + assert list(nx.triangles(G).values()) == [5, 3, 3, 5, 5] + assert nx.triangles(G, 1) == 3 class TestDirectedClustering: def test_clustering(self): G = nx.DiGraph() - assert_equal(list(nx.clustering(G).values()), []) - assert_equal(nx.clustering(G), {}) + assert list(nx.clustering(G).values()) == [] + assert nx.clustering(G) == {} def test_path(self): G = nx.path_graph(10, create_using=nx.DiGraph()) - assert_equal(list(nx.clustering(G).values()), + assert (list(nx.clustering(G).values()) == [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) - assert_equal(nx.clustering(G), + assert (nx.clustering(G) == {0: 0.0, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 0.0, 6: 0.0, 7: 0.0, 8: 0.0, 9: 0.0}) def test_k5(self): G = nx.complete_graph(5, create_using=nx.DiGraph()) - assert_equal(list(nx.clustering(G).values()), [1, 1, 1, 1, 1]) - assert_equal(nx.average_clustering(G), 1) + assert list(nx.clustering(G).values()) == [1, 1, 1, 1, 1] + assert nx.average_clustering(G) == 1 G.remove_edge(1, 2) - assert_equal(list(nx.clustering(G).values()), + assert (list(nx.clustering(G).values()) == [11. / 12., 1.0, 1.0, 11. / 12., 11. / 12.]) - assert_equal(nx.clustering(G, [1, 4]), {1: 1.0, 4: 11. /12.}) + assert nx.clustering(G, [1, 4]) == {1: 1.0, 4: 11. /12.} G.remove_edge(2, 1) - assert_equal(list(nx.clustering(G).values()), + assert (list(nx.clustering(G).values()) == [5. / 6., 1.0, 1.0, 5. / 6., 5. / 6.]) - assert_equal(nx.clustering(G, [1, 4]), {1: 1.0, 4: 0.83333333333333337}) + assert nx.clustering(G, [1, 4]) == {1: 1.0, 4: 0.83333333333333337} def test_triangle_and_edge(self): G = nx.cycle_graph(3, create_using=nx.DiGraph()) G.add_edge(0, 4) - assert_equal(nx.clustering(G)[0], 1.0 / 6.0) + assert nx.clustering(G)[0] == 1.0 / 6.0 class TestDirectedWeightedClustering: def test_clustering(self): G = nx.DiGraph() - assert_equal(list(nx.clustering(G, weight='weight').values()), []) - assert_equal(nx.clustering(G), {}) + assert list(nx.clustering(G, weight='weight').values()) == [] + assert nx.clustering(G) == {} def test_path(self): G = nx.path_graph(10, create_using=nx.DiGraph()) - assert_equal(list(nx.clustering(G, weight='weight').values()), + assert (list(nx.clustering(G, weight='weight').values()) == [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) - assert_equal(nx.clustering(G, weight='weight'), + assert (nx.clustering(G, weight='weight') == {0: 0.0, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 0.0, 6: 0.0, 7: 0.0, 8: 0.0, 9: 0.0}) def test_k5(self): G = nx.complete_graph(5, create_using=nx.DiGraph()) - assert_equal(list(nx.clustering(G, weight='weight').values()), [1, 1, 1, 1, 1]) - assert_equal(nx.average_clustering(G, weight='weight'), 1) + assert list(nx.clustering(G, weight='weight').values()) == [1, 1, 1, 1, 1] + assert nx.average_clustering(G, weight='weight') == 1 G.remove_edge(1, 2) - assert_equal(list(nx.clustering(G, weight='weight').values()), + assert (list(nx.clustering(G, weight='weight').values()) == [11. / 12., 1.0, 1.0, 11. / 12., 11. / 12.]) - assert_equal(nx.clustering(G, [1, 4], weight='weight'), {1: 1.0, 4: 11. /12.}) + assert nx.clustering(G, [1, 4], weight='weight') == {1: 1.0, 4: 11. /12.} G.remove_edge(2, 1) - assert_equal(list(nx.clustering(G, weight='weight').values()), + assert (list(nx.clustering(G, weight='weight').values()) == [5. / 6., 1.0, 1.0, 5. / 6., 5. / 6.]) - assert_equal(nx.clustering(G, [1, 4], weight='weight'), {1: 1.0, 4: 0.83333333333333337}) + assert nx.clustering(G, [1, 4], weight='weight') == {1: 1.0, 4: 0.83333333333333337} def test_triangle_and_edge(self): G = nx.cycle_graph(3, create_using=nx.DiGraph()) G.add_edge(0, 4, weight=2) - assert_equal(nx.clustering(G)[0], 1.0 / 6.0) - assert_equal(nx.clustering(G, weight='weight')[0], 1.0 / 12.0) + assert nx.clustering(G)[0] == 1.0 / 6.0 + assert nx.clustering(G, weight='weight')[0] == 1.0 / 12.0 class TestWeightedClustering: def test_clustering(self): G = nx.Graph() - assert_equal(list(nx.clustering(G, weight='weight').values()), []) - assert_equal(nx.clustering(G), {}) + assert list(nx.clustering(G, weight='weight').values()) == [] + assert nx.clustering(G) == {} def test_path(self): G = nx.path_graph(10) - assert_equal(list(nx.clustering(G, weight='weight').values()), + assert (list(nx.clustering(G, weight='weight').values()) == [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) - assert_equal(nx.clustering(G, weight='weight'), + assert (nx.clustering(G, weight='weight') == {0: 0.0, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 0.0, 6: 0.0, 7: 0.0, 8: 0.0, 9: 0.0}) def test_cubical(self): G = nx.cubical_graph() - assert_equal(list(nx.clustering(G, weight='weight').values()), + assert (list(nx.clustering(G, weight='weight').values()) == [0, 0, 0, 0, 0, 0, 0, 0]) - assert_equal(nx.clustering(G, 1), 0) - assert_equal(list(nx.clustering(G, [1, 2], weight='weight').values()), [0, 0]) - assert_equal(nx.clustering(G, 1, weight='weight'), 0) - assert_equal(nx.clustering(G, [1, 2], weight='weight'), {1: 0, 2: 0}) + assert nx.clustering(G, 1) == 0 + assert list(nx.clustering(G, [1, 2], weight='weight').values()) == [0, 0] + assert nx.clustering(G, 1, weight='weight') == 0 + assert nx.clustering(G, [1, 2], weight='weight') == {1: 0, 2: 0} def test_k5(self): G = nx.complete_graph(5) - assert_equal(list(nx.clustering(G, weight='weight').values()), [1, 1, 1, 1, 1]) - assert_equal(nx.average_clustering(G, weight='weight'), 1) + assert list(nx.clustering(G, weight='weight').values()) == [1, 1, 1, 1, 1] + assert nx.average_clustering(G, weight='weight') == 1 G.remove_edge(1, 2) - assert_equal(list(nx.clustering(G, weight='weight').values()), + assert (list(nx.clustering(G, weight='weight').values()) == [5. / 6., 1.0, 1.0, 5. / 6., 5. / 6.]) - assert_equal(nx.clustering(G, [1, 4], weight='weight'), {1: 1.0, 4: 0.83333333333333337}) + assert nx.clustering(G, [1, 4], weight='weight') == {1: 1.0, 4: 0.83333333333333337} def test_triangle_and_edge(self): G = nx.cycle_graph(3) G.add_edge(0, 4, weight=2) - assert_equal(nx.clustering(G)[0], 1.0 / 3.0) - assert_equal(nx.clustering(G, weight='weight')[0], 1.0 / 6.0) + assert nx.clustering(G)[0] == 1.0 / 3.0 + assert nx.clustering(G, weight='weight')[0] == 1.0 / 6.0 class TestClustering: def test_clustering(self): G = nx.Graph() - assert_equal(list(nx.clustering(G).values()), []) - assert_equal(nx.clustering(G), {}) + assert list(nx.clustering(G).values()) == [] + assert nx.clustering(G) == {} def test_path(self): G = nx.path_graph(10) - assert_equal(list(nx.clustering(G).values()), + assert (list(nx.clustering(G).values()) == [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) - assert_equal(nx.clustering(G), + assert (nx.clustering(G) == {0: 0.0, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 0.0, 6: 0.0, 7: 0.0, 8: 0.0, 9: 0.0}) def test_cubical(self): G = nx.cubical_graph() - assert_equal(list(nx.clustering(G).values()), + assert (list(nx.clustering(G).values()) == [0, 0, 0, 0, 0, 0, 0, 0]) - assert_equal(nx.clustering(G, 1), 0) - assert_equal(list(nx.clustering(G, [1, 2]).values()), [0, 0]) - assert_equal(nx.clustering(G, 1), 0) - assert_equal(nx.clustering(G, [1, 2]), {1: 0, 2: 0}) + assert nx.clustering(G, 1) == 0 + assert list(nx.clustering(G, [1, 2]).values()) == [0, 0] + assert nx.clustering(G, 1) == 0 + assert nx.clustering(G, [1, 2]) == {1: 0, 2: 0} def test_k5(self): G = nx.complete_graph(5) - assert_equal(list(nx.clustering(G).values()), [1, 1, 1, 1, 1]) - assert_equal(nx.average_clustering(G), 1) + assert list(nx.clustering(G).values()) == [1, 1, 1, 1, 1] + assert nx.average_clustering(G) == 1 G.remove_edge(1, 2) - assert_equal(list(nx.clustering(G).values()), + assert (list(nx.clustering(G).values()) == [5. / 6., 1.0, 1.0, 5. / 6., 5. / 6.]) - assert_equal(nx.clustering(G, [1, 4]), {1: 1.0, 4: 0.83333333333333337}) + assert nx.clustering(G, [1, 4]) == {1: 1.0, 4: 0.83333333333333337} class TestTransitivity: def test_transitivity(self): G = nx.Graph() - assert_equal(nx.transitivity(G), 0.0) + assert nx.transitivity(G) == 0.0 def test_path(self): G = nx.path_graph(10) - assert_equal(nx.transitivity(G), 0.0) + assert nx.transitivity(G) == 0.0 def test_cubical(self): G = nx.cubical_graph() - assert_equal(nx.transitivity(G), 0.0) + assert nx.transitivity(G) == 0.0 def test_k5(self): G = nx.complete_graph(5) - assert_equal(nx.transitivity(G), 1.0) + assert nx.transitivity(G) == 1.0 G.remove_edge(1, 2) - assert_equal(nx.transitivity(G), 0.875) + assert nx.transitivity(G) == 0.875 # def test_clustering_transitivity(self): # # check that weighted average of clustering is transitivity @@ -216,32 +216,32 @@ class TestSquareClustering: def test_clustering(self): G = nx.Graph() - assert_equal(list(nx.square_clustering(G).values()), []) - assert_equal(nx.square_clustering(G), {}) + assert list(nx.square_clustering(G).values()) == [] + assert nx.square_clustering(G) == {} def test_path(self): G = nx.path_graph(10) - assert_equal(list(nx.square_clustering(G).values()), + assert (list(nx.square_clustering(G).values()) == [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) - assert_equal(nx.square_clustering(G), + assert (nx.square_clustering(G) == {0: 0.0, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 0.0, 6: 0.0, 7: 0.0, 8: 0.0, 9: 0.0}) def test_cubical(self): G = nx.cubical_graph() - assert_equal(list(nx.square_clustering(G).values()), + assert (list(nx.square_clustering(G).values()) == [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5]) - assert_equal(list(nx.square_clustering(G, [1, 2]).values()), [0.5, 0.5]) - assert_equal(nx.square_clustering(G, [1])[1], 0.5) - assert_equal(nx.square_clustering(G, [1, 2]), {1: 0.5, 2: 0.5}) + assert list(nx.square_clustering(G, [1, 2]).values()) == [0.5, 0.5] + assert nx.square_clustering(G, [1])[1] == 0.5 + assert nx.square_clustering(G, [1, 2]) == {1: 0.5, 2: 0.5} def test_k5(self): G = nx.complete_graph(5) - assert_equal(list(nx.square_clustering(G).values()), [1, 1, 1, 1, 1]) + assert list(nx.square_clustering(G).values()) == [1, 1, 1, 1, 1] def test_bipartite_k5(self): G = nx.complete_bipartite_graph(5, 5) - assert_equal(list(nx.square_clustering(G).values()), + assert (list(nx.square_clustering(G).values()) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) def test_lind_square_clustering(self): @@ -251,36 +251,36 @@ class TestSquareClustering: (7, 10), (6, 11), (6, 12), (2, 13), (2, 14), (3, 15), (3, 16)]) G1 = G.subgraph([1, 2, 3, 4, 5, 13, 14, 15, 16]) G2 = G.subgraph([1, 6, 7, 8, 9, 10, 11, 12]) - assert_equal(nx.square_clustering(G, [1])[1], 3 / 75.0) - assert_equal(nx.square_clustering(G1, [1])[1], 2 / 6.0) - assert_equal(nx.square_clustering(G2, [1])[1], 1 / 5.0) + assert nx.square_clustering(G, [1])[1] == 3 / 75.0 + assert nx.square_clustering(G1, [1])[1] == 2 / 6.0 + assert nx.square_clustering(G2, [1])[1] == 1 / 5.0 def test_average_clustering(): G = nx.cycle_graph(3) G.add_edge(2, 3) - assert_equal(nx.average_clustering(G), (1 + 1 + 1 / 3.0) / 4.0) - assert_equal(nx.average_clustering(G, count_zeros=True), (1 + 1 + 1 / 3.0) / 4.0) - assert_equal(nx.average_clustering(G, count_zeros=False), (1 + 1 + 1 / 3.0) / 3.0) + assert nx.average_clustering(G) == (1 + 1 + 1 / 3.0) / 4.0 + assert nx.average_clustering(G, count_zeros=True) == (1 + 1 + 1 / 3.0) / 4.0 + assert nx.average_clustering(G, count_zeros=False) == (1 + 1 + 1 / 3.0) / 3.0 class TestGeneralizedDegree: def test_generalized_degree(self): G = nx.Graph() - assert_equal(nx.generalized_degree(G), {}) + assert nx.generalized_degree(G) == {} def test_path(self): G = nx.path_graph(5) - assert_equal(nx.generalized_degree(G, 0), {0: 1}) - assert_equal(nx.generalized_degree(G, 1), {0: 2}) + assert nx.generalized_degree(G, 0) == {0: 1} + assert nx.generalized_degree(G, 1) == {0: 2} def test_cubical(self): G = nx.cubical_graph() - assert_equal(nx.generalized_degree(G, 0), {0: 3}) + assert nx.generalized_degree(G, 0) == {0: 3} def test_k5(self): G = nx.complete_graph(5) - assert_equal(nx.generalized_degree(G, 0), {3: 4}) + assert nx.generalized_degree(G, 0) == {3: 4} G.remove_edge(0, 1) - assert_equal(nx.generalized_degree(G, 0), {2: 3}) + assert nx.generalized_degree(G, 0) == {2: 3} diff --git a/networkx/algorithms/tests/test_core.py b/networkx/algorithms/tests/test_core.py index de466fa3..1b989f34 100644 --- a/networkx/algorithms/tests/test_core.py +++ b/networkx/algorithms/tests/test_core.py @@ -35,7 +35,7 @@ class TestCore: def test_trivial(self): """Empty graph""" G = nx.Graph() - assert_equal(nx.find_cores(G), {}) + assert nx.find_cores(G) == {} def test_find_cores(self): core = nx.find_cores(self.G) @@ -64,84 +64,84 @@ class TestCore: G = nx.DiGraph() edges = [(1, 2), (2, 1), (2, 3), (2, 4), (3, 4), (4, 3)] G.add_edges_from(edges) - assert_equal(nx.core_number(G), {1: 2, 2: 2, 3: 2, 4: 2}) + assert nx.core_number(G) == {1: 2, 2: 2, 3: 2, 4: 2} # small example where too aggressive edge removal can make cn[2] = 2 more_edges = [(1, 5), (3, 5), (4, 5), (3, 6), (4, 6), (5, 6)] G.add_edges_from(more_edges) - assert_equal(nx.core_number(G), {1: 3, 2: 3, 3: 3, 4: 3, 5: 3, 6: 3}) + assert nx.core_number(G) == {1: 3, 2: 3, 3: 3, 4: 3, 5: 3, 6: 3} def test_main_core(self): main_core_subgraph = nx.k_core(self.H) - assert_equal(sorted(main_core_subgraph.nodes()), [2, 4, 5, 6]) + assert sorted(main_core_subgraph.nodes()) == [2, 4, 5, 6] def test_k_core(self): # k=0 k_core_subgraph = nx.k_core(self.H, k=0) - assert_equal(sorted(k_core_subgraph.nodes()), sorted(self.H.nodes())) + assert sorted(k_core_subgraph.nodes()) == sorted(self.H.nodes()) # k=1 k_core_subgraph = nx.k_core(self.H, k=1) - assert_equal(sorted(k_core_subgraph.nodes()), [1, 2, 3, 4, 5, 6]) + assert sorted(k_core_subgraph.nodes()) == [1, 2, 3, 4, 5, 6] # k = 2 k_core_subgraph = nx.k_core(self.H, k=2) - assert_equal(sorted(k_core_subgraph.nodes()), [2, 4, 5, 6]) + assert sorted(k_core_subgraph.nodes()) == [2, 4, 5, 6] def test_main_crust(self): main_crust_subgraph = nx.k_crust(self.H) - assert_equal(sorted(main_crust_subgraph.nodes()), [0, 1, 3]) + assert sorted(main_crust_subgraph.nodes()) == [0, 1, 3] def test_k_crust(self): # k = 0 k_crust_subgraph = nx.k_crust(self.H, k=2) - assert_equal(sorted(k_crust_subgraph.nodes()), sorted(self.H.nodes())) + assert sorted(k_crust_subgraph.nodes()) == sorted(self.H.nodes()) # k=1 k_crust_subgraph = nx.k_crust(self.H, k=1) - assert_equal(sorted(k_crust_subgraph.nodes()), [0, 1, 3]) + assert sorted(k_crust_subgraph.nodes()) == [0, 1, 3] # k=2 k_crust_subgraph = nx.k_crust(self.H, k=0) - assert_equal(sorted(k_crust_subgraph.nodes()), [0]) + assert sorted(k_crust_subgraph.nodes()) == [0] def test_main_shell(self): main_shell_subgraph = nx.k_shell(self.H) - assert_equal(sorted(main_shell_subgraph.nodes()), [2, 4, 5, 6]) + assert sorted(main_shell_subgraph.nodes()) == [2, 4, 5, 6] def test_k_shell(self): # k=0 k_shell_subgraph = nx.k_shell(self.H, k=2) - assert_equal(sorted(k_shell_subgraph.nodes()), [2, 4, 5, 6]) + assert sorted(k_shell_subgraph.nodes()) == [2, 4, 5, 6] # k=1 k_shell_subgraph = nx.k_shell(self.H, k=1) - assert_equal(sorted(k_shell_subgraph.nodes()), [1, 3]) + assert sorted(k_shell_subgraph.nodes()) == [1, 3] # k=2 k_shell_subgraph = nx.k_shell(self.H, k=0) - assert_equal(sorted(k_shell_subgraph.nodes()), [0]) + assert sorted(k_shell_subgraph.nodes()) == [0] def test_k_corona(self): # k=0 k_corona_subgraph = nx.k_corona(self.H, k=2) - assert_equal(sorted(k_corona_subgraph.nodes()), [2, 4, 5, 6]) + assert sorted(k_corona_subgraph.nodes()) == [2, 4, 5, 6] # k=1 k_corona_subgraph = nx.k_corona(self.H, k=1) - assert_equal(sorted(k_corona_subgraph.nodes()), [1]) + assert sorted(k_corona_subgraph.nodes()) == [1] # k=2 k_corona_subgraph = nx.k_corona(self.H, k=0) - assert_equal(sorted(k_corona_subgraph.nodes()), [0]) + assert sorted(k_corona_subgraph.nodes()) == [0] def test_k_truss(self): # k=-1 k_truss_subgraph = nx.k_truss(self.G, -1) - assert_equal(sorted(k_truss_subgraph.nodes()), list(range(1,21))) + assert sorted(k_truss_subgraph.nodes()) == list(range(1,21)) # k=0 k_truss_subgraph = nx.k_truss(self.G, 0) - assert_equal(sorted(k_truss_subgraph.nodes()), list(range(1,21))) + assert sorted(k_truss_subgraph.nodes()) == list(range(1,21)) # k=1 k_truss_subgraph = nx.k_truss(self.G, 1) - assert_equal(sorted(k_truss_subgraph.nodes()), list(range(1,13))) + assert sorted(k_truss_subgraph.nodes()) == list(range(1,13)) # k=2 k_truss_subgraph = nx.k_truss(self.G, 2) - assert_equal(sorted(k_truss_subgraph.nodes()), list(range(1,9))) + assert sorted(k_truss_subgraph.nodes()) == list(range(1,9)) # k=3 k_truss_subgraph = nx.k_truss(self.G, 3) - assert_equal(sorted(k_truss_subgraph.nodes()), []) + assert sorted(k_truss_subgraph.nodes()) == [] def test_onion_layers(self): layers = nx.onion_layers(self.G) diff --git a/networkx/algorithms/tests/test_covering.py b/networkx/algorithms/tests/test_covering.py index 7539847f..a207dac6 100644 --- a/networkx/algorithms/tests/test_covering.py +++ b/networkx/algorithms/tests/test_covering.py @@ -13,17 +13,17 @@ class TestMinEdgeCover: def test_empty_graph(self): G = nx.Graph() - assert_equal(nx.min_edge_cover(G), set()) + assert nx.min_edge_cover(G) == set() def test_graph_with_loop(self): G = nx.Graph() G.add_edge(0, 0) - assert_equal(nx.min_edge_cover(G), {(0, 0)}) + assert nx.min_edge_cover(G) == {(0, 0)} def test_graph_single_edge(self): G = nx.Graph() G.add_edge(0, 1) - assert_in(nx.min_edge_cover(G), ({(0, 1)}, {(1, 0)})) + assert nx.min_edge_cover(G) in ({(0, 1)}, {(1, 0)}) def test_bipartite_explicit(self): G = nx.Graph() @@ -34,14 +34,14 @@ class TestMinEdgeCover: min_cover = nx.min_edge_cover(G, nx.algorithms.bipartite.matching. eppstein_matching) min_cover2 = nx.min_edge_cover(G) - assert_true(nx.is_edge_cover(G, min_cover)) - assert_equal(len(min_cover), 8) + assert nx.is_edge_cover(G, min_cover) + assert len(min_cover) == 8 def test_complete_graph(self): G = nx.complete_graph(10) min_cover = nx.min_edge_cover(G) - assert_true(nx.is_edge_cover(G, min_cover)) - assert_equal(len(min_cover), 5) + assert nx.is_edge_cover(G, min_cover) + assert len(min_cover) == 5 class TestIsEdgeCover: @@ -49,17 +49,17 @@ class TestIsEdgeCover: def test_empty_graph(self): G = nx.Graph() - assert_true(nx.is_edge_cover(G, set())) + assert nx.is_edge_cover(G, set()) def test_graph_with_loop(self): G = nx.Graph() G.add_edge(1, 1) - assert_true(nx.is_edge_cover(G, {(1, 1)})) + assert nx.is_edge_cover(G, {(1, 1)}) def test_graph_single_edge(self): G = nx.Graph() G.add_edge(0, 1) - assert_true(nx.is_edge_cover(G, {(0, 0), (1, 1)})) - assert_true(nx.is_edge_cover(G, {(0, 1), (1, 0)})) - assert_true(nx.is_edge_cover(G, {(0, 1)})) - assert_false(nx.is_edge_cover(G, {(0, 0)})) + assert nx.is_edge_cover(G, {(0, 0), (1, 1)}) + assert nx.is_edge_cover(G, {(0, 1), (1, 0)}) + assert nx.is_edge_cover(G, {(0, 1)}) + assert not nx.is_edge_cover(G, {(0, 0)}) diff --git a/networkx/algorithms/tests/test_cuts.py b/networkx/algorithms/tests/test_cuts.py index b3d151ee..52ed499f 100644 --- a/networkx/algorithms/tests/test_cuts.py +++ b/networkx/algorithms/tests/test_cuts.py @@ -21,37 +21,37 @@ class TestCutSize(object): G = nx.barbell_graph(3, 0) S = {0, 1, 4} T = {2, 3, 5} - assert_equal(nx.cut_size(G, S, T), 4) - assert_equal(nx.cut_size(G, T, S), 4) + assert nx.cut_size(G, S, T) == 4 + assert nx.cut_size(G, T, S) == 4 def test_single_edge(self): """Tests for a cut of a single edge.""" G = nx.barbell_graph(3, 0) S = {0, 1, 2} T = {3, 4, 5} - assert_equal(nx.cut_size(G, S, T), 1) - assert_equal(nx.cut_size(G, T, S), 1) + assert nx.cut_size(G, S, T) == 1 + assert nx.cut_size(G, T, S) == 1 def test_directed(self): """Tests that each directed edge is counted once in the cut.""" G = nx.barbell_graph(3, 0).to_directed() S = {0, 1, 2} T = {3, 4, 5} - assert_equal(nx.cut_size(G, S, T), 2) - assert_equal(nx.cut_size(G, T, S), 2) + assert nx.cut_size(G, S, T) == 2 + assert nx.cut_size(G, T, S) == 2 def test_directed_symmetric(self): """Tests that a cut in a directed graph is symmetric.""" G = nx.barbell_graph(3, 0).to_directed() S = {0, 1, 4} T = {2, 3, 5} - assert_equal(nx.cut_size(G, S, T), 8) - assert_equal(nx.cut_size(G, T, S), 8) + assert nx.cut_size(G, S, T) == 8 + assert nx.cut_size(G, T, S) == 8 def test_multigraph(self): """Tests that parallel edges are each counted for a cut.""" G = nx.MultiGraph(['ab', 'ab']) - assert_equal(nx.cut_size(G, {'a'}, {'b'}), 2) + assert nx.cut_size(G, {'a'}, {'b'}) == 2 class TestVolume(object): @@ -59,21 +59,21 @@ class TestVolume(object): def test_graph(self): G = nx.cycle_graph(4) - assert_equal(nx.volume(G, {0, 1}), 4) + assert nx.volume(G, {0, 1}) == 4 def test_digraph(self): G = nx.DiGraph([(0, 1), (1, 2), (2, 3), (3, 0)]) - assert_equal(nx.volume(G, {0, 1}), 2) + assert nx.volume(G, {0, 1}) == 2 def test_multigraph(self): edges = list(nx.cycle_graph(4).edges()) G = nx.MultiGraph(edges * 2) - assert_equal(nx.volume(G, {0, 1}), 8) + assert nx.volume(G, {0, 1}) == 8 def test_multidigraph(self): edges = [(0, 1), (1, 2), (2, 3), (3, 0)] G = nx.MultiDiGraph(edges * 2) - assert_equal(nx.volume(G, {0, 1}), 4) + assert nx.volume(G, {0, 1}) == 4 class TestNormalizedCutSize(object): @@ -89,7 +89,7 @@ class TestNormalizedCutSize(object): size = nx.normalized_cut_size(G, S, T) # The cut looks like this: o-{-o--o-}-o expected = 2 * ((1 / 4) + (1 / 2)) - assert_equal(expected, size) + assert expected == size def test_directed(self): G = nx.DiGraph([(0, 1), (1, 2), (2, 3)]) @@ -98,7 +98,7 @@ class TestNormalizedCutSize(object): size = nx.normalized_cut_size(G, S, T) # The cut looks like this: o-{->o-->o-}->o expected = 2 * ((1 / 2) + (1 / 1)) - assert_equal(expected, size) + assert expected == size class TestConductance(object): @@ -112,7 +112,7 @@ class TestConductance(object): T = {5} conductance = nx.conductance(G, S, T) expected = 1 / 5 - assert_equal(expected, conductance) + assert expected == conductance class TestEdgeExpansion(object): @@ -124,7 +124,7 @@ class TestEdgeExpansion(object): T = set(G) - S expansion = nx.edge_expansion(G, S, T) expected = 1 / 5 - assert_equal(expected, expansion) + assert expected == expansion class TestNodeExpansion(object): @@ -139,7 +139,7 @@ class TestNodeExpansion(object): # The neighborhood of S has cardinality five, and S has # cardinality three. expected = 5 / 3 - assert_equal(expected, expansion) + assert expected == expansion class TestBoundaryExpansion(object): @@ -154,7 +154,7 @@ class TestBoundaryExpansion(object): # The node boundary of S has cardinality six, and S has # cardinality three. expected = 6 / 4 - assert_equal(expected, expansion) + assert expected == expansion class TestMixingExpansion(object): @@ -171,4 +171,4 @@ class TestMixingExpansion(object): # graph is twice the total number of edges in a clique of size # five, plus one more for the bridge. expected = 1 / (2 * (5 * 4 + 1)) - assert_equal(expected, expansion) + assert expected == expansion diff --git a/networkx/algorithms/tests/test_cycles.py b/networkx/algorithms/tests/test_cycles.py index 9f22ee85..11eb6784 100644 --- a/networkx/algorithms/tests/test_cycles.py +++ b/networkx/algorithms/tests/test_cycles.py @@ -31,19 +31,19 @@ class TestCycles: G = self.G cy = networkx.cycle_basis(G, 0) sort_cy = sorted(sorted(c) for c in cy) - assert_equal(sort_cy, [[0, 1, 2, 3], [0, 1, 6, 7, 8], [0, 3, 4, 5]]) + assert sort_cy == [[0, 1, 2, 3], [0, 1, 6, 7, 8], [0, 3, 4, 5]] cy = networkx.cycle_basis(G, 1) sort_cy = sorted(sorted(c) for c in cy) - assert_equal(sort_cy, [[0, 1, 2, 3], [0, 1, 6, 7, 8], [0, 3, 4, 5]]) + assert sort_cy == [[0, 1, 2, 3], [0, 1, 6, 7, 8], [0, 3, 4, 5]] cy = networkx.cycle_basis(G, 9) sort_cy = sorted(sorted(c) for c in cy) - assert_equal(sort_cy, [[0, 1, 2, 3], [0, 1, 6, 7, 8], [0, 3, 4, 5]]) + assert sort_cy == [[0, 1, 2, 3], [0, 1, 6, 7, 8], [0, 3, 4, 5]] # test disconnected graphs nx.add_cycle(G, "ABC") cy = networkx.cycle_basis(G, 9) sort_cy = sorted(sorted(c) for c in cy[:-1]) + [sorted(cy[-1])] - assert_equal(sort_cy, [[0, 1, 2, 3], [0, 1, 6, 7, 8], [0, 3, 4, 5], - ['A', 'B', 'C']]) + assert sort_cy == [[0, 1, 2, 3], [0, 1, 6, 7, 8], [0, 3, 4, 5], + ['A', 'B', 'C']] @raises(nx.NetworkXNotImplemented) def test_cycle_basis(self): @@ -60,9 +60,9 @@ class TestCycles: G = nx.DiGraph(edges) cc = sorted(nx.simple_cycles(G)) ca = [[0], [0, 1, 2], [0, 2], [1, 2], [2]] - assert_equal(len(cc), len(ca)) + assert len(cc) == len(ca) for c in cc: - assert_true(any(self.is_cyclic_permutation(c, rc) for rc in ca)) + assert any(self.is_cyclic_permutation(c, rc) for rc in ca) @raises(nx.NetworkXNotImplemented) def test_simple_cycles_graph(self): @@ -79,25 +79,25 @@ class TestCycles: G = nx.DiGraph() nx.add_cycle(G, [1, 2, 3]) c = sorted(nx.simple_cycles(G)) - assert_equal(len(c), 1) - assert_true(self.is_cyclic_permutation(c[0], [1, 2, 3])) + assert len(c) == 1 + assert self.is_cyclic_permutation(c[0], [1, 2, 3]) nx.add_cycle(G, [10, 20, 30]) cc = sorted(nx.simple_cycles(G)) - assert_equal(len(cc), 2) + assert len(cc) == 2 ca = [[1, 2, 3], [10, 20, 30]] for c in cc: - assert_true(any(self.is_cyclic_permutation(c, rc) for rc in ca)) + assert any(self.is_cyclic_permutation(c, rc) for rc in ca) def test_simple_cycles_empty(self): G = nx.DiGraph() - assert_equal(list(nx.simple_cycles(G)), []) + assert list(nx.simple_cycles(G)) == [] def test_complete_directed_graph(self): # see table 2 in Johnson's paper ncircuits = [1, 5, 20, 84, 409, 2365, 16064] for n, c in zip(range(2, 9), ncircuits): G = nx.DiGraph(nx.complete_graph(n)) - assert_equal(len(list(nx.simple_cycles(G))), c) + assert len(list(nx.simple_cycles(G))) == c def worst_case_graph(self, k): # see figure 1 in Johnson's paper @@ -122,18 +122,18 @@ class TestCycles: for k in range(3, 10): G = self.worst_case_graph(k) l = len(list(nx.simple_cycles(G))) - assert_equal(l, 3 * k) + assert l == 3 * k def test_recursive_simple_and_not(self): for k in range(2, 10): G = self.worst_case_graph(k) cc = sorted(nx.simple_cycles(G)) rcc = sorted(nx.recursive_simple_cycles(G)) - assert_equal(len(cc), len(rcc)) + assert len(cc) == len(rcc) for c in cc: - assert_true(any(self.is_cyclic_permutation(c, r) for r in rcc)) + assert any(self.is_cyclic_permutation(c, r) for r in rcc) for rc in rcc: - assert_true(any(self.is_cyclic_permutation(rc, c) for c in cc)) + assert any(self.is_cyclic_permutation(rc, c) for c in cc) def test_simple_graph_with_reported_bug(self): G = nx.DiGraph() @@ -142,13 +142,13 @@ class TestCycles: (5, 1), (5, 2), (5, 3)] G.add_edges_from(edges) cc = sorted(nx.simple_cycles(G)) - assert_equal(len(cc), 26) + assert len(cc) == 26 rcc = sorted(nx.recursive_simple_cycles(G)) - assert_equal(len(cc), len(rcc)) + assert len(cc) == len(rcc) for c in cc: - assert_true(any(self.is_cyclic_permutation(c, rc) for rc in rcc)) + assert any(self.is_cyclic_permutation(c, rc) for rc in rcc) for rc in rcc: - assert_true(any(self.is_cyclic_permutation(rc, c) for c in cc)) + assert any(self.is_cyclic_permutation(rc, c) for c in cc) # These tests might fail with hash randomization since they depend on # edge_dfs. For more information, see the comments in: @@ -170,81 +170,81 @@ class TestFindCycle(object): G.add_edge(2, 0) x = list(find_cycle(G, self.nodes)) x_ = [(0, 1), (1, 2), (2, 0)] - assert_equal(x, x_) + assert x == x_ def test_graph_orientation_none(self): G = nx.Graph(self.edges) G.add_edge(2, 0) x = list(find_cycle(G, self.nodes, orientation=None)) x_ = [(0, 1), (1, 2), (2, 0)] - assert_equal(x, x_) + assert x == x_ def test_graph_orientation_original(self): G = nx.Graph(self.edges) G.add_edge(2, 0) x = list(find_cycle(G, self.nodes, orientation='original')) x_ = [(0, 1, FORWARD), (1, 2, FORWARD), (2, 0, FORWARD)] - assert_equal(x, x_) + assert x == x_ def test_digraph(self): G = nx.DiGraph(self.edges) x = list(find_cycle(G, self.nodes)) x_ = [(0, 1), (1, 0)] - assert_equal(x, x_) + assert x == x_ def test_digraph_orientation_none(self): G = nx.DiGraph(self.edges) x = list(find_cycle(G, self.nodes, orientation=None)) x_ = [(0, 1), (1, 0)] - assert_equal(x, x_) + assert x == x_ def test_digraph_orientation_original(self): G = nx.DiGraph(self.edges) x = list(find_cycle(G, self.nodes, orientation='original')) x_ = [(0, 1, FORWARD), (1, 0, FORWARD)] - assert_equal(x, x_) + assert x == x_ def test_multigraph(self): G = nx.MultiGraph(self.edges) x = list(find_cycle(G, self.nodes)) x_ = [(0, 1, 0), (1, 0, 1)] # or (1, 0, 2) # Hash randomization...could be any edge. - assert_equal(x[0], x_[0]) - assert_equal(x[1][:2], x_[1][:2]) + assert x[0] == x_[0] + assert x[1][:2] == x_[1][:2] def test_multidigraph(self): G = nx.MultiDiGraph(self.edges) x = list(find_cycle(G, self.nodes)) x_ = [(0, 1, 0), (1, 0, 0)] # (1, 0, 1) - assert_equal(x[0], x_[0]) - assert_equal(x[1][:2], x_[1][:2]) + assert x[0] == x_[0] + assert x[1][:2] == x_[1][:2] def test_digraph_ignore(self): G = nx.DiGraph(self.edges) x = list(find_cycle(G, self.nodes, orientation='ignore')) x_ = [(0, 1, FORWARD), (1, 0, FORWARD)] - assert_equal(x, x_) + assert x == x_ def test_digraph_reverse(self): G = nx.DiGraph(self.edges) x = list(find_cycle(G, self.nodes, orientation='reverse')) x_ = [(1, 0, REVERSE), (0, 1, REVERSE)] - assert_equal(x, x_) + assert x == x_ def test_multidigraph_ignore(self): G = nx.MultiDiGraph(self.edges) x = list(find_cycle(G, self.nodes, orientation='ignore')) x_ = [(0, 1, 0, FORWARD), (1, 0, 0, FORWARD)] # or (1, 0, 1, 1) - assert_equal(x[0], x_[0]) - assert_equal(x[1][:2], x_[1][:2]) - assert_equal(x[1][3], x_[1][3]) + assert x[0] == x_[0] + assert x[1][:2] == x_[1][:2] + assert x[1][3] == x_[1][3] def test_multidigraph_ignore2(self): # Loop traversed an edge while ignoring its orientation. G = nx.MultiDiGraph([(0, 1), (1, 2), (1, 2)]) x = list(find_cycle(G, [0, 1, 2], orientation='ignore')) x_ = [(1, 2, 0, FORWARD), (1, 2, 1, REVERSE)] - assert_equal(x, x_) + assert x == x_ def test_multidigraph_original(self): # Node 2 doesn't need to be searched again from visited from 4. @@ -260,7 +260,7 @@ class TestFindCycle(object): assert_raises(nx.exception.NetworkXNoCycle, find_cycle, G, orientation='original') x = list(find_cycle(G, orientation='ignore')) - assert_equal(x, [(0, 1, FORWARD), (1, 2, FORWARD), (0, 2, REVERSE)]) + assert x == [(0, 1, FORWARD), (1, 2, FORWARD), (0, 2, REVERSE)] def test_prev_explored(self): # https://github.com/networkx/networkx/issues/2323 @@ -270,15 +270,15 @@ class TestFindCycle(object): assert_raises(nx.NetworkXNoCycle, find_cycle, G, source=0) x = list(nx.find_cycle(G, 1)) x_ = [(1, 2), (2, 1)] - assert_equal(x, x_) + assert x == x_ x = list(nx.find_cycle(G, 2)) x_ = [(2, 1), (1, 2)] - assert_equal(x, x_) + assert x == x_ x = list(nx.find_cycle(G)) x_ = [(1, 2), (2, 1)] - assert_equal(x, x_) + assert x == x_ def test_no_cycle(self): # https://github.com/networkx/networkx/issues/2439 @@ -290,7 +290,7 @@ class TestFindCycle(object): def assert_basis_equal(a, b): - assert_list_equal(sorted(a), sorted(b)) + assert sorted(a) == sorted(b) class TestMinimumCycles(object): @@ -319,13 +319,13 @@ class TestMinimumCycles(object): ncomp = nx.number_connected_components(rg) dim_mcb = len(minimum_cycle_basis(rg)) - assert_equal(dim_mcb, nedges - nnodes + ncomp) + assert dim_mcb == nedges - nnodes + ncomp def test_complete_graph(self): cg = nx.complete_graph(5) mcb = minimum_cycle_basis(cg) - assert_true(all([len(cycle) == 3 for cycle in mcb])) + assert all([len(cycle) == 3 for cycle in mcb]) def test_tree_graph(self): tg = nx.balanced_tree(3, 3) - assert_false(minimum_cycle_basis(tg)) + assert not minimum_cycle_basis(tg) diff --git a/networkx/algorithms/tests/test_dag.py b/networkx/algorithms/tests/test_dag.py index f99d474c..73daec85 100644 --- a/networkx/algorithms/tests/test_dag.py +++ b/networkx/algorithms/tests/test_dag.py @@ -20,24 +20,24 @@ class TestDagLongestPath(object): def test_empty(self): G = nx.DiGraph() - assert_equal(nx.dag_longest_path(G), []) + assert nx.dag_longest_path(G) == [] def test_unweighted1(self): edges = [(1, 2), (2, 3), (2, 4), (3, 5), (5, 6), (3, 7)] G = nx.DiGraph(edges) - assert_equal(nx.dag_longest_path(G), [1, 2, 3, 5, 6]) + assert nx.dag_longest_path(G) == [1, 2, 3, 5, 6] def test_unweighted2(self): edges = [(1, 2), (2, 3), (3, 4), (4, 5), (1, 3), (1, 5), (3, 5)] G = nx.DiGraph(edges) - assert_equal(nx.dag_longest_path(G), [1, 2, 3, 4, 5]) + assert nx.dag_longest_path(G) == [1, 2, 3, 4, 5] def test_weighted(self): G = nx.DiGraph() edges = [(1, 2, -5), (2, 3, 1), (3, 4, 1), (4, 5, 0), (3, 5, 4), (1, 6, 2)] G.add_weighted_edges_from(edges) - assert_equal(nx.dag_longest_path(G), [2, 3, 5]) + assert nx.dag_longest_path(G) == [2, 3, 5] def test_undirected_not_implemented(self): G = nx.Graph() @@ -84,16 +84,16 @@ class TestDagLongestPathLength(object): def test_unweighted(self): edges = [(1, 2), (2, 3), (2, 4), (3, 5), (5, 6), (5, 7)] G = nx.DiGraph(edges) - assert_equal(nx.dag_longest_path_length(G), 4) + assert nx.dag_longest_path_length(G) == 4 edges = [(1, 2), (2, 3), (3, 4), (4, 5), (1, 3), (1, 5), (3, 5)] G = nx.DiGraph(edges) - assert_equal(nx.dag_longest_path_length(G), 4) + assert nx.dag_longest_path_length(G) == 4 # test degenerate graphs G = nx.DiGraph() G.add_node(1) - assert_equal(nx.dag_longest_path_length(G), 0) + assert nx.dag_longest_path_length(G) == 0 def test_undirected_not_implemented(self): G = nx.Graph() @@ -104,7 +104,7 @@ class TestDagLongestPathLength(object): (1, 6, 2)] G = nx.DiGraph() G.add_weighted_edges_from(edges) - assert_equal(nx.dag_longest_path_length(G), 5) + assert nx.dag_longest_path_length(G) == 5 class TestDAG: @@ -118,7 +118,7 @@ class TestDAG: for algorithm in [nx.topological_sort, nx.lexicographical_topological_sort]: - assert_equal(tuple(algorithm(DG)), (1, 2, 3)) + assert tuple(algorithm(DG)) == (1, 2, 3) DG.add_edge(3, 2) @@ -130,19 +130,19 @@ class TestDAG: for algorithm in [nx.topological_sort, nx.lexicographical_topological_sort]: - assert_equal(tuple(algorithm(DG)), (1, 3, 2)) + assert tuple(algorithm(DG)) == (1, 3, 2) DG.remove_edge(3, 2) - assert_in(tuple(nx.topological_sort(DG)), {(1, 2, 3), (1, 3, 2)}) - assert_equal(tuple(nx.lexicographical_topological_sort(DG)), (1, 2, 3)) + assert tuple(nx.topological_sort(DG)) in {(1, 2, 3), (1, 3, 2)} + assert tuple(nx.lexicographical_topological_sort(DG)) == (1, 2, 3) def test_is_directed_acyclic_graph(self): G = nx.generators.complete_graph(2) - assert_false(nx.is_directed_acyclic_graph(G)) - assert_false(nx.is_directed_acyclic_graph(G.to_directed())) - assert_false(nx.is_directed_acyclic_graph(nx.Graph([(3, 4), (4, 5)]))) - assert_true(nx.is_directed_acyclic_graph(nx.DiGraph([(3, 4), (4, 5)]))) + assert not nx.is_directed_acyclic_graph(G) + assert not nx.is_directed_acyclic_graph(G.to_directed()) + assert not nx.is_directed_acyclic_graph(nx.Graph([(3, 4), (4, 5)])) + assert nx.is_directed_acyclic_graph(nx.DiGraph([(3, 4), (4, 5)])) def test_topological_sort2(self): DG = nx.DiGraph({1: [2], 2: [3], 3: [4], @@ -150,11 +150,11 @@ class TestDAG: 12: [13], 13: [14], 14: [15]}) assert_raises(nx.NetworkXUnfeasible, consume, nx.topological_sort(DG)) - assert_false(nx.is_directed_acyclic_graph(DG)) + assert not nx.is_directed_acyclic_graph(DG) DG.remove_edge(1, 2) consume(nx.topological_sort(DG)) - assert_true(nx.is_directed_acyclic_graph(DG)) + assert nx.is_directed_acyclic_graph(DG) def test_topological_sort3(self): DG = nx.DiGraph() @@ -165,9 +165,9 @@ class TestDAG: def validate(order): ok_(isinstance(order, list)) - assert_equal(set(order), set(DG)) + assert set(order) == set(DG) for u, v in combinations(order, 2): - assert_false(nx.has_path(DG, v, u)) + assert not nx.has_path(DG, v, u) validate(list(nx.topological_sort(DG))) DG.add_edge(14, 1) @@ -182,7 +182,7 @@ class TestDAG: def test_topological_sort5(self): G = nx.DiGraph() G.add_edge(0, 1) - assert_equal(list(nx.topological_sort(G)), [0, 1]) + assert list(nx.topological_sort(G)) == [0, 1] def test_topological_sort6(self): for algorithm in [nx.topological_sort, @@ -217,11 +217,11 @@ class TestDAG: def test_all_topological_sorts_1(self): DG = nx.DiGraph([(1, 2), (2, 3), (3, 4), (4, 5)]) - assert_equal(list(nx.all_topological_sorts(DG)), [[1, 2, 3, 4, 5]]) + assert list(nx.all_topological_sorts(DG)) == [[1, 2, 3, 4, 5]] def test_all_topological_sorts_2(self): DG = nx.DiGraph([(1, 3), (2, 1), (2, 4), (4, 3), (4, 5)]) - assert_equal(sorted(nx.all_topological_sorts(DG)), + assert (sorted(nx.all_topological_sorts(DG)) == [[2, 1, 4, 3, 5], [2, 1, 4, 5, 3], [2, 4, 1, 3, 5], @@ -250,13 +250,13 @@ class TestDAG: DG = nx.DiGraph() for i in range(7): DG.add_node(i) - assert_equal(sorted(map(list, permutations(DG.nodes))), + assert (sorted(map(list, permutations(DG.nodes))) == sorted(nx.all_topological_sorts(DG))) def test_all_topological_sorts_multigraph_1(self): DG = nx.MultiDiGraph([(1, 2), (1, 2), (2, 3), (3, 4), (3, 5), (3, 5), (3, 5)]) - assert_equal(sorted(nx.all_topological_sorts(DG)), + assert (sorted(nx.all_topological_sorts(DG)) == sorted([[1, 2, 3, 4, 5], [1, 2, 3, 5, 4]])) @@ -266,7 +266,7 @@ class TestDAG: for i in range(1, N): edges.extend([(i, i+1)] * i) DG = nx.MultiDiGraph(edges) - assert_equal(list(nx.all_topological_sorts(DG)), + assert (list(nx.all_topological_sorts(DG)) == [list(range(1, N+1))]) def test_ancestors(self): @@ -274,9 +274,9 @@ class TestDAG: ancestors = nx.algorithms.dag.ancestors G.add_edges_from([ (1, 2), (1, 3), (4, 2), (4, 3), (4, 5), (2, 6), (5, 6)]) - assert_equal(ancestors(G, 6), set([1, 2, 4, 5])) - assert_equal(ancestors(G, 3), set([1, 4])) - assert_equal(ancestors(G, 1), set()) + assert ancestors(G, 6) == set([1, 2, 4, 5]) + assert ancestors(G, 3) == set([1, 4]) + assert ancestors(G, 1) == set() assert_raises(nx.NetworkXError, ancestors, G, 8) def test_descendants(self): @@ -284,9 +284,9 @@ class TestDAG: descendants = nx.algorithms.dag.descendants G.add_edges_from([ (1, 2), (1, 3), (4, 2), (4, 3), (4, 5), (2, 6), (5, 6)]) - assert_equal(descendants(G, 1), set([2, 3, 6])) - assert_equal(descendants(G, 4), set([2, 3, 5, 6])) - assert_equal(descendants(G, 3), set()) + assert descendants(G, 1) == set([2, 3, 6]) + assert descendants(G, 4) == set([2, 3, 5, 6]) + assert descendants(G, 3) == set() assert_raises(nx.NetworkXError, descendants, G, 8) def test_transitive_closure(self): @@ -307,13 +307,13 @@ class TestDAG: G = nx.DiGraph([(1, 2, {"a": 3}), (2, 3, {"b": 0}), (3, 4)]) H = nx.transitive_closure(G) for u, v in G.edges(): - assert_equal(G.get_edge_data(u, v), H.get_edge_data(u, v)) + assert G.get_edge_data(u, v) == H.get_edge_data(u, v) k = 10 G = nx.DiGraph((i, i + 1, {"f": "b", "weight": i}) for i in range(k)) H = nx.transitive_closure(G) for u, v in G.edges(): - assert_equal(G.get_edge_data(u, v), H.get_edge_data(u, v)) + assert G.get_edge_data(u, v) == H.get_edge_data(u, v) def test_reflexive_transitive_closure(self): G = nx.DiGraph([(1, 2), (2, 3), (3, 4)]) @@ -355,13 +355,13 @@ class TestDAG: G = nx.DiGraph([(1, 2, {"a": 3}), (2, 3, {"b": 0}), (3, 4)]) H = transitive_closure(G) for u, v in G.edges(): - assert_equal(G.get_edge_data(u, v), H.get_edge_data(u, v)) + assert G.get_edge_data(u, v) == H.get_edge_data(u, v) k = 10 G = nx.DiGraph((i, i + 1, {"foo": "bar", "weight": i}) for i in range(k)) H = transitive_closure(G) for u, v in G.edges(): - assert_equal(G.get_edge_data(u, v), H.get_edge_data(u, v)) + assert G.get_edge_data(u, v) == H.get_edge_data(u, v) def test_transitive_reduction(self): G = nx.DiGraph([(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]) @@ -378,7 +378,7 @@ class TestDAG: def _check_antichains(self, solution, result): sol = [frozenset(a) for a in solution] res = [frozenset(a) for a in result] - assert_true(set(sol) == set(res)) + assert set(sol) == set(res) def test_antichains(self): antichains = nx.algorithms.dag.antichains @@ -411,13 +411,13 @@ class TestDAG: def test_lexicographical_topological_sort(self): G = nx.DiGraph([(1, 2), (2, 3), (1, 4), (1, 5), (2, 6)]) - assert_equal(list(nx.lexicographical_topological_sort(G)), + assert (list(nx.lexicographical_topological_sort(G)) == [1, 2, 3, 4, 5, 6]) - assert_equal(list(nx.lexicographical_topological_sort( - G, key=lambda x: x)), + assert (list(nx.lexicographical_topological_sort( + G, key=lambda x: x)) == [1, 2, 3, 4, 5, 6]) - assert_equal(list(nx.lexicographical_topological_sort( - G, key=lambda x: -x)), + assert (list(nx.lexicographical_topological_sort( + G, key=lambda x: -x)) == [1, 5, 4, 2, 6, 3]) def test_lexicographical_topological_sort2(self): @@ -447,41 +447,41 @@ class TestDAG: # and that is not deterministic due to dicts not being ordered until v3.6 # after dropping NX support for 3.5 this can become: # assert_equal(sorting, test_nodes) - assert_equal(set(sorting), set(test_nodes)) + assert set(sorting) == set(test_nodes) def test_is_aperiodic_cycle(): G = nx.DiGraph() nx.add_cycle(G, [1, 2, 3, 4]) - assert_false(nx.is_aperiodic(G)) + assert not nx.is_aperiodic(G) def test_is_aperiodic_cycle2(): G = nx.DiGraph() nx.add_cycle(G, [1, 2, 3, 4]) nx.add_cycle(G, [3, 4, 5, 6, 7]) - assert_true(nx.is_aperiodic(G)) + assert nx.is_aperiodic(G) def test_is_aperiodic_cycle3(): G = nx.DiGraph() nx.add_cycle(G, [1, 2, 3, 4]) nx.add_cycle(G, [3, 4, 5, 6]) - assert_false(nx.is_aperiodic(G)) + assert not nx.is_aperiodic(G) def test_is_aperiodic_cycle4(): G = nx.DiGraph() nx.add_cycle(G, [1, 2, 3, 4]) G.add_edge(1, 3) - assert_true(nx.is_aperiodic(G)) + assert nx.is_aperiodic(G) def test_is_aperiodic_selfloop(): G = nx.DiGraph() nx.add_cycle(G, [1, 2, 3, 4]) G.add_edge(1, 1) - assert_true(nx.is_aperiodic(G)) + assert nx.is_aperiodic(G) def test_is_aperiodic_raise(): @@ -494,12 +494,12 @@ def test_is_aperiodic_raise(): def test_is_aperiodic_bipartite(): # Bipartite graph G = nx.DiGraph(nx.davis_southern_women_graph()) - assert_false(nx.is_aperiodic(G)) + assert not nx.is_aperiodic(G) def test_is_aperiodic_rary_tree(): G = nx.full_rary_tree(3, 27, create_using=nx.DiGraph()) - assert_false(nx.is_aperiodic(G)) + assert not nx.is_aperiodic(G) def test_is_aperiodic_disconnected(): @@ -507,17 +507,17 @@ def test_is_aperiodic_disconnected(): G = nx.DiGraph() nx.add_cycle(G, [1, 2, 3, 4]) nx.add_cycle(G, [5, 6, 7, 8]) - assert_false(nx.is_aperiodic(G)) + assert not nx.is_aperiodic(G) G.add_edge(1, 3) G.add_edge(5, 7) - assert_true(nx.is_aperiodic(G)) + assert nx.is_aperiodic(G) def test_is_aperiodic_disconnected2(): G = nx.DiGraph() nx.add_cycle(G, [0, 1, 2]) G.add_edge(3, 3) - assert_false(nx.is_aperiodic(G)) + assert not nx.is_aperiodic(G) class TestDagToBranching(object): @@ -531,8 +531,8 @@ class TestDagToBranching(object): G = nx.DiGraph([(0, 1), (0, 2), (1, 3), (2, 3)]) B = nx.dag_to_branching(G) expected = nx.DiGraph([(0, 1), (1, 3), (0, 2), (2, 4)]) - assert_true(nx.is_arborescence(B)) - assert_true(nx.is_isomorphic(B, expected)) + assert nx.is_arborescence(B) + assert nx.is_isomorphic(B, expected) def test_multiple_roots(self): """Tests that a directed acyclic graph with multiple degree zero @@ -543,9 +543,9 @@ class TestDagToBranching(object): G = nx.DiGraph([(0, 1), (0, 2), (1, 3), (2, 3), (5, 2)]) B = nx.dag_to_branching(G) expected = nx.DiGraph([(0, 1), (1, 3), (0, 2), (2, 4), (5, 6), (6, 7)]) - assert_true(nx.is_branching(B)) - assert_false(nx.is_arborescence(B)) - assert_true(nx.is_isomorphic(B, expected)) + assert nx.is_branching(B) + assert not nx.is_arborescence(B) + assert nx.is_isomorphic(B, expected) # # Attributes are not copied by this function. If they were, this would # # be a good test to uncomment. @@ -581,7 +581,7 @@ class TestDagToBranching(object): """ A = nx.balanced_tree(2, 2, create_using=nx.DiGraph()) B = nx.dag_to_branching(A) - assert_true(nx.is_isomorphic(A, B)) + assert nx.is_isomorphic(A, B) def test_already_branching(self): """Tests that a directed acyclic graph that is already a @@ -592,7 +592,7 @@ class TestDagToBranching(object): T2 = nx.balanced_tree(2, 2, create_using=nx.DiGraph()) G = nx.disjoint_union(T1, T2) B = nx.dag_to_branching(G) - assert_true(nx.is_isomorphic(G, B)) + assert nx.is_isomorphic(G, B) @raises(nx.HasACycle) def test_not_acyclic(self): diff --git a/networkx/algorithms/tests/test_distance_measures.py b/networkx/algorithms/tests/test_distance_measures.py index 87c49457..5b845f5d 100644 --- a/networkx/algorithms/tests/test_distance_measures.py +++ b/networkx/algorithms/tests/test_distance_measures.py @@ -15,61 +15,61 @@ class TestDistance: self.G = G def test_eccentricity(self): - assert_equal(nx.eccentricity(self.G, 1), 6) + assert nx.eccentricity(self.G, 1) == 6 e = nx.eccentricity(self.G) - assert_equal(e[1], 6) + assert e[1] == 6 sp = dict(nx.shortest_path_length(self.G)) e = nx.eccentricity(self.G, sp=sp) - assert_equal(e[1], 6) + assert e[1] == 6 e = nx.eccentricity(self.G, v=1) - assert_equal(e, 6) + assert e == 6 # This behavior changed in version 1.8 (ticket #739) e = nx.eccentricity(self.G, v=[1, 1]) - assert_equal(e[1], 6) + assert e[1] == 6 e = nx.eccentricity(self.G, v=[1, 2]) - assert_equal(e[1], 6) + assert e[1] == 6 # test against graph with one node G = nx.path_graph(1) e = nx.eccentricity(G) - assert_equal(e[0], 0) + assert e[0] == 0 e = nx.eccentricity(G, v=0) - assert_equal(e, 0) + assert e == 0 assert_raises(nx.NetworkXError, nx.eccentricity, G, 1) # test against empty graph G = nx.empty_graph() e = nx.eccentricity(G) - assert_equal(e, {}) + assert e == {} def test_diameter(self): - assert_equal(nx.diameter(self.G), 6) + assert nx.diameter(self.G) == 6 def test_radius(self): - assert_equal(nx.radius(self.G), 4) + assert nx.radius(self.G) == 4 def test_periphery(self): - assert_equal(set(nx.periphery(self.G)), set([1, 4, 13, 16])) + assert set(nx.periphery(self.G)) == set([1, 4, 13, 16]) def test_center(self): - assert_equal(set(nx.center(self.G)), set([6, 7, 10, 11])) + assert set(nx.center(self.G)) == set([6, 7, 10, 11]) def test_bound_diameter(self): - assert_equal(nx.diameter(self.G, usebounds=True), 6) + assert nx.diameter(self.G, usebounds=True) == 6 def test_bound_radius(self): - assert_equal(nx.radius(self.G, usebounds=True), 4) + assert nx.radius(self.G, usebounds=True) == 4 def test_bound_periphery(self): result = set([1, 4, 13, 16]) - assert_equal(set(nx.periphery(self.G, usebounds=True)), result) + assert set(nx.periphery(self.G, usebounds=True)) == result def test_bound_center(self): result = set([6, 7, 10, 11]) - assert_equal(set(nx.center(self.G, usebounds=True)), result) + assert set(nx.center(self.G, usebounds=True)) == result def test_radius_exception(self): G = nx.Graph() @@ -123,8 +123,8 @@ class TestResistanceDistance: N = sp_sparse.csr_matrix([[5, 6], [8, 9]], dtype=np.float32) Mn, Mn_nodelist = _laplacian_submatrix(1, M, [1, 2, 3]) - assert_equal(Mn_nodelist, [2, 3]) - assert_true(np.allclose(Mn.toarray(), N.toarray())) + assert Mn_nodelist == [2, 3] + assert np.allclose(Mn.toarray(), N.toarray()) @raises(nx.NetworkXError) def test_laplacian_submatrix_square(self): @@ -145,22 +145,22 @@ class TestResistanceDistance: def test_resistance_distance(self): rd = nx.resistance_distance(self.G, 1, 3, 'weight', True) test_data = 1/(1/(2+4) + 1/(1+3)) - assert_equal(round(rd, 5), round(test_data, 5)) + assert round(rd, 5) == round(test_data, 5) def test_resistance_distance_noinv(self): rd = nx.resistance_distance(self.G, 1, 3, 'weight', False) test_data = 1/(1/(1/2+1/4) + 1/(1/1+1/3)) - assert_equal(round(rd, 5), round(test_data, 5)) + assert round(rd, 5) == round(test_data, 5) def test_resistance_distance_no_weight(self): rd = nx.resistance_distance(self.G, 1, 3) - assert_equal(round(rd, 5), 1) + assert round(rd, 5) == 1 def test_resistance_distance_neg_weight(self): self.G[2][3]['weight'] = -4 rd = nx.resistance_distance(self.G, 1, 3, 'weight', True) test_data = 1/(1/(2+-4) + 1/(1+3)) - assert_equal(round(rd, 5), round(test_data, 5)) + assert round(rd, 5) == round(test_data, 5) def test_multigraph(self): G = nx.MultiGraph() @@ -169,7 +169,7 @@ class TestResistanceDistance: G.add_edge(3, 4, weight=1) G.add_edge(1, 4, weight=3) rd = nx.resistance_distance(G, 1, 3, 'weight', True) - assert_true(np.isclose(rd, 1/(1/(2+4) + 1/(1+3)))) + assert np.isclose(rd, 1/(1/(2+4) + 1/(1+3))) @raises(ZeroDivisionError) def test_resistance_distance_div0(self): @@ -199,8 +199,8 @@ class TestBarycenter(object): def barycenter_as_subgraph(self, g, **kwargs): """Return the subgraph induced on the barycenter of g""" b = nx.barycenter(g, **kwargs) - assert_is_instance(b, list) - assert_less_equal(set(b), set(g)) + assert isinstance(b, list) + assert set(b) <= set(g) return g.subgraph(b) def test_must_be_connected(self): @@ -210,7 +210,7 @@ class TestBarycenter(object): # Complete graph K_5. Normally it works... K_5 = nx.complete_graph(5) sp = dict(nx.shortest_path_length(K_5)) - assert_equal(nx.barycenter(K_5, sp=sp), list(K_5)) + assert nx.barycenter(K_5, sp=sp) == list(K_5) # ...but not with the weight argument for u, v, data in K_5.edges.data(): @@ -231,10 +231,10 @@ class TestBarycenter(object): RT = nx.random_tree(prng.randint(1, 75), prng) b = self.barycenter_as_subgraph(RT) if len(b) == 2: - assert_equal(b.size(), 1) + assert b.size() == 1 else: - assert_equal(len(b), 1) - assert_equal(b.size(), 0) + assert len(b) == 1 + assert b.size() == 0 def test_this_one_specific_tree(self): """Test the tree pictured at the bottom of [West01]_, p. 78.""" @@ -246,20 +246,20 @@ class TestBarycenter(object): 'z': ['y', 0, 1, 2, 3, 4], 0: ['z'], 1: ['z'], 2: ['z'], 3: ['z'], 4: ['z']}) b = self.barycenter_as_subgraph(g, attr='barycentricity') - assert_equal(list(b), ['z']) - assert_false(b.edges) + assert list(b) == ['z'] + assert not b.edges expected_barycentricity = {0: 23, 1: 23, 2: 23, 3: 23, 4: 23, 'a': 35, 'b': 27, 'x': 21, 'y': 17, 'z': 15 } for node, barycentricity in expected_barycentricity.items(): - assert_equal(g.nodes[node]['barycentricity'], barycentricity) + assert g.nodes[node]['barycentricity'] == barycentricity # Doubling weights should do nothing but double the barycentricities for edge in g.edges: g.edges[edge]['weight'] = 2 b = self.barycenter_as_subgraph(g, weight='weight', attr='barycentricity2') - assert_equal(list(b), ['z']) - assert_false(b.edges) + assert list(b) == ['z'] + assert not b.edges for node, barycentricity in expected_barycentricity.items(): - assert_equal(g.nodes[node]['barycentricity2'], barycentricity*2) + assert g.nodes[node]['barycentricity2'] == barycentricity*2 diff --git a/networkx/algorithms/tests/test_distance_regular.py b/networkx/algorithms/tests/test_distance_regular.py index 37a6aa05..108d0a9e 100644 --- a/networkx/algorithms/tests/test_distance_regular.py +++ b/networkx/algorithms/tests/test_distance_regular.py @@ -9,41 +9,41 @@ from networkx import is_strongly_regular class TestDistanceRegular(object): def test_is_distance_regular(self): - assert_true(nx.is_distance_regular(nx.icosahedral_graph())) - assert_true(nx.is_distance_regular(nx.petersen_graph())) - assert_true(nx.is_distance_regular(nx.cubical_graph())) - assert_true(nx.is_distance_regular(nx.complete_bipartite_graph(3, 3))) - assert_true(nx.is_distance_regular(nx.tetrahedral_graph())) - assert_true(nx.is_distance_regular(nx.dodecahedral_graph())) - assert_true(nx.is_distance_regular(nx.pappus_graph())) - assert_true(nx.is_distance_regular(nx.heawood_graph())) - assert_true(nx.is_distance_regular(nx.cycle_graph(3))) + assert nx.is_distance_regular(nx.icosahedral_graph()) + assert nx.is_distance_regular(nx.petersen_graph()) + assert nx.is_distance_regular(nx.cubical_graph()) + assert nx.is_distance_regular(nx.complete_bipartite_graph(3, 3)) + assert nx.is_distance_regular(nx.tetrahedral_graph()) + assert nx.is_distance_regular(nx.dodecahedral_graph()) + assert nx.is_distance_regular(nx.pappus_graph()) + assert nx.is_distance_regular(nx.heawood_graph()) + assert nx.is_distance_regular(nx.cycle_graph(3)) # no distance regular - assert_false(nx.is_distance_regular(nx.path_graph(4))) + assert not nx.is_distance_regular(nx.path_graph(4)) def test_not_connected(self): G = nx.cycle_graph(4) nx.add_cycle(G, [5, 6, 7]) - assert_false(nx.is_distance_regular(G)) + assert not nx.is_distance_regular(G) def test_global_parameters(self): b, c = nx.intersection_array(nx.cycle_graph(5)) g = nx.global_parameters(b, c) - assert_equal(list(g), [(0, 0, 2), (1, 0, 1), (1, 1, 0)]) + assert list(g) == [(0, 0, 2), (1, 0, 1), (1, 1, 0)] b, c = nx.intersection_array(nx.cycle_graph(3)) g = nx.global_parameters(b, c) - assert_equal(list(g), [(0, 0, 2), (1, 1, 0)]) + assert list(g) == [(0, 0, 2), (1, 1, 0)] def test_intersection_array(self): b, c = nx.intersection_array(nx.cycle_graph(5)) - assert_equal(b, [2, 1]) - assert_equal(c, [1, 1]) + assert b == [2, 1] + assert c == [1, 1] b, c = nx.intersection_array(nx.dodecahedral_graph()) - assert_equal(b, [3, 2, 1, 1, 1]) - assert_equal(c, [1, 1, 1, 2, 3]) + assert b == [3, 2, 1, 1, 1] + assert c == [1, 1, 1, 2, 3] b, c = nx.intersection_array(nx.icosahedral_graph()) - assert_equal(b, [5, 2, 1]) - assert_equal(c, [1, 2, 5]) + assert b == [5, 2, 1] + assert c == [1, 2, 5] class TestStronglyRegular(object): @@ -58,14 +58,14 @@ class TestStronglyRegular(object): """ G = nx.cycle_graph(5) - assert_true(is_strongly_regular(G)) + assert is_strongly_regular(G) def test_petersen_graph(self): """Tests that the Petersen graph is strongly regular.""" G = nx.petersen_graph() - assert_true(is_strongly_regular(G)) + assert is_strongly_regular(G) def test_path_graph(self): """Tests that the path graph is not strongly regular.""" G = nx.path_graph(4) - assert_false(is_strongly_regular(G)) + assert not is_strongly_regular(G) diff --git a/networkx/algorithms/tests/test_dominance.py b/networkx/algorithms/tests/test_dominance.py index 53d7f76b..e3df0c22 100644 --- a/networkx/algorithms/tests/test_dominance.py +++ b/networkx/algorithms/tests/test_dominance.py @@ -16,27 +16,27 @@ class TestImmediateDominators(object): def test_singleton(self): G = nx.DiGraph() G.add_node(0) - assert_equal(nx.immediate_dominators(G, 0), {0: 0}) + assert nx.immediate_dominators(G, 0) == {0: 0} G.add_edge(0, 0) - assert_equal(nx.immediate_dominators(G, 0), {0: 0}) + assert nx.immediate_dominators(G, 0) == {0: 0} def test_path(self): n = 5 G = nx.path_graph(n, create_using=nx.DiGraph()) - assert_equal(nx.immediate_dominators(G, 0), + assert (nx.immediate_dominators(G, 0) == {i: max(i - 1, 0) for i in range(n)}) def test_cycle(self): n = 5 G = nx.cycle_graph(n, create_using=nx.DiGraph()) - assert_equal(nx.immediate_dominators(G, 0), + assert (nx.immediate_dominators(G, 0) == {i: max(i - 1, 0) for i in range(n)}) def test_unreachable(self): n = 5 - assert_greater(n, 1) + assert n > 1 G = nx.path_graph(n, create_using=nx.DiGraph()) - assert_equal(nx.immediate_dominators(G, n // 2), + assert (nx.immediate_dominators(G, n // 2) == {i: max(i - 1, n // 2) for i in range(n // 2, n)}) def test_irreducible1(self): @@ -46,7 +46,7 @@ class TestImmediateDominators(object): # Software Practice & Experience, 4:110, 2001. edges = [(1, 2), (2, 1), (3, 2), (4, 1), (5, 3), (5, 4)] G = nx.DiGraph(edges) - assert_equal(nx.immediate_dominators(G, 5), + assert (nx.immediate_dominators(G, 5) == {i: 5 for i in range(1, 6)}) def test_irreducible2(self): @@ -57,18 +57,18 @@ class TestImmediateDominators(object): edges = [(1, 2), (2, 1), (2, 3), (3, 2), (4, 2), (4, 3), (5, 1), (6, 4), (6, 5)] G = nx.DiGraph(edges) - assert_equal(nx.immediate_dominators(G, 6), + assert (nx.immediate_dominators(G, 6) == {i: 6 for i in range(1, 7)}) def test_domrel_png(self): # Graph taken from https://commons.wikipedia.org/wiki/File:Domrel.png edges = [(1, 2), (2, 3), (2, 4), (2, 6), (3, 5), (4, 5), (5, 2)] G = nx.DiGraph(edges) - assert_equal(nx.immediate_dominators(G, 1), + assert (nx.immediate_dominators(G, 1) == {1: 1, 2: 1, 3: 2, 4: 2, 5: 2, 6: 2}) # Test postdominance. with nx.utils.reversed(G): - assert_equal(nx.immediate_dominators(G, 6), + assert (nx.immediate_dominators(G, 6) == {1: 2, 2: 6, 3: 5, 4: 5, 5: 2, 6: 6}) def test_boost_example(self): @@ -77,11 +77,11 @@ class TestImmediateDominators(object): edges = [(0, 1), (1, 2), (1, 3), (2, 7), (3, 4), (4, 5), (4, 6), (5, 7), (6, 4)] G = nx.DiGraph(edges) - assert_equal(nx.immediate_dominators(G, 0), + assert (nx.immediate_dominators(G, 0) == {0: 0, 1: 0, 2: 1, 3: 1, 4: 3, 5: 4, 6: 4, 7: 1}) # Test postdominance. with nx.utils.reversed(G): - assert_equal(nx.immediate_dominators(G, 7), + assert (nx.immediate_dominators(G, 7) == {0: 1, 1: 7, 2: 7, 3: 4, 4: 5, 5: 7, 6: 4, 7: 7}) @@ -99,27 +99,27 @@ class TestDominanceFrontiers(object): def test_singleton(self): G = nx.DiGraph() G.add_node(0) - assert_equal(nx.dominance_frontiers(G, 0), {0: set()}) + assert nx.dominance_frontiers(G, 0) == {0: set()} G.add_edge(0, 0) - assert_equal(nx.dominance_frontiers(G, 0), {0: set()}) + assert nx.dominance_frontiers(G, 0) == {0: set()} def test_path(self): n = 5 G = nx.path_graph(n, create_using=nx.DiGraph()) - assert_equal(nx.dominance_frontiers(G, 0), + assert (nx.dominance_frontiers(G, 0) == {i: set() for i in range(n)}) def test_cycle(self): n = 5 G = nx.cycle_graph(n, create_using=nx.DiGraph()) - assert_equal(nx.dominance_frontiers(G, 0), + assert (nx.dominance_frontiers(G, 0) == {i: set() for i in range(n)}) def test_unreachable(self): n = 5 - assert_greater(n, 1) + assert n > 1 G = nx.path_graph(n, create_using=nx.DiGraph()) - assert_equal(nx.dominance_frontiers(G, n // 2), + assert (nx.dominance_frontiers(G, n // 2) == {i: set() for i in range(n // 2, n)}) def test_irreducible1(self): @@ -129,8 +129,8 @@ class TestDominanceFrontiers(object): # Software Practice & Experience, 4:110, 2001. edges = [(1, 2), (2, 1), (3, 2), (4, 1), (5, 3), (5, 4)] G = nx.DiGraph(edges) - assert_equal({u: df - for u, df in nx.dominance_frontiers(G, 5).items()}, + assert ({u: df + for u, df in nx.dominance_frontiers(G, 5).items()} == {1: set([2]), 2: set([1]), 3: set([2]), 4: set([1]), 5: set()}) @@ -142,19 +142,19 @@ class TestDominanceFrontiers(object): edges = [(1, 2), (2, 1), (2, 3), (3, 2), (4, 2), (4, 3), (5, 1), (6, 4), (6, 5)] G = nx.DiGraph(edges) - assert_equal(nx.dominance_frontiers(G, 6), + assert (nx.dominance_frontiers(G, 6) == {1: set([2]), 2: set([1, 3]), 3: set([2]), 4: set([2, 3]), 5: set([1]), 6: set([])}) def test_domrel_png(self): # Graph taken from https://commons.wikipedia.org/wiki/File:Domrel.png edges = [(1, 2), (2, 3), (2, 4), (2, 6), (3, 5), (4, 5), (5, 2)] G = nx.DiGraph(edges) - assert_equal(nx.dominance_frontiers(G, 1), + assert (nx.dominance_frontiers(G, 1) == {1: set([]), 2: set([2]), 3: set([5]), 4: set([5]), 5: set([2]), 6: set()}) # Test postdominance. with nx.utils.reversed(G): - assert_equal(nx.dominance_frontiers(G, 6), + assert (nx.dominance_frontiers(G, 6) == {1: set(), 2: set([2]), 3: set([2]), 4: set([2]), 5: set([2]), 6: set()}) @@ -164,12 +164,12 @@ class TestDominanceFrontiers(object): edges = [(0, 1), (1, 2), (1, 3), (2, 7), (3, 4), (4, 5), (4, 6), (5, 7), (6, 4)] G = nx.DiGraph(edges) - assert_equal(nx.dominance_frontiers(G, 0), + assert (nx.dominance_frontiers(G, 0) == {0: set(), 1: set(), 2: set([7]), 3: set([7]), 4: set([4, 7]), 5: set([7]), 6: set([4]), 7: set()}) # Test postdominance. with nx.utils.reversed(G): - assert_equal(nx.dominance_frontiers(G, 7), + assert (nx.dominance_frontiers(G, 7) == {0: set(), 1: set(), 2: set([1]), 3: set([1]), 4: set([1, 4]), 5: set([1]), 6: set([4]), 7: set()}) @@ -191,16 +191,16 @@ class TestDominanceFrontiers(object): ] ) df = nx.dominance_frontiers(g, 'b0') - assert_equal(df, {'b4': set(), 'b5': set(['b3']), 'b6': set(['b7']), + assert df == {'b4': set(), 'b5': set(['b3']), 'b6': set(['b7']), 'b7': set(['b3']), 'b0': set(), 'b1': set(['b1']), 'b2': set(['b3']), - 'b3': set(['b1']), 'b8': set(['b7'])}) + 'b3': set(['b1']), 'b8': set(['b7'])} def test_loop(self): g = nx.DiGraph() g.add_edges_from([('a', 'b'), ('b', 'c'), ('b', 'a')]) df = nx.dominance_frontiers(g, 'a') - assert_equal(df, {'a': set(), 'b': set(), 'c': set()}) + assert df == {'a': set(), 'b': set(), 'c': set()} def test_missing_immediate_doms(self): # see https://github.com/networkx/networkx/issues/2070 @@ -257,4 +257,4 @@ class TestDominanceFrontiers(object): '6': set(['exit', '2']), 'exit': set()} for n in df: - assert_equal(set(df[n]), set(answer[n])) + assert set(df[n]) == set(answer[n]) diff --git a/networkx/algorithms/tests/test_dominating.py b/networkx/algorithms/tests/test_dominating.py index 7a49d162..5c617514 100644 --- a/networkx/algorithms/tests/test_dominating.py +++ b/networkx/algorithms/tests/test_dominating.py @@ -5,9 +5,9 @@ import networkx as nx def test_dominating_set(): G = nx.gnp_random_graph(100, 0.1) D = nx.dominating_set(G) - assert_true(nx.is_dominating_set(G, D)) + assert nx.is_dominating_set(G, D) D = nx.dominating_set(G, start_with=0) - assert_true(nx.is_dominating_set(G, D)) + assert nx.is_dominating_set(G, D) def test_complete(): @@ -15,9 +15,9 @@ def test_complete(): Thus the dominating set has to be of cardinality 1. """ K4 = nx.complete_graph(4) - assert_equal(len(nx.dominating_set(K4)), 1) + assert len(nx.dominating_set(K4)) == 1 K5 = nx.complete_graph(5) - assert_equal(len(nx.dominating_set(K5)), 1) + assert len(nx.dominating_set(K5)) == 1 @raises(nx.NetworkXError) @@ -29,11 +29,11 @@ def test_raise_dominating_set(): def test_is_dominating_set(): G = nx.path_graph(4) d = set([1, 3]) - assert_true(nx.is_dominating_set(G, d)) + assert nx.is_dominating_set(G, d) d = set([0, 2]) - assert_true(nx.is_dominating_set(G, d)) + assert nx.is_dominating_set(G, d) d = set([1]) - assert_false(nx.is_dominating_set(G, d)) + assert not nx.is_dominating_set(G, d) def test_wikipedia_is_dominating_set(): @@ -41,6 +41,6 @@ def test_wikipedia_is_dominating_set(): """ G = nx.cycle_graph(4) G.add_edges_from([(0, 4), (1, 4), (2, 5)]) - assert_true(nx.is_dominating_set(G, set([4, 3, 5]))) - assert_true(nx.is_dominating_set(G, set([0, 2]))) - assert_true(nx.is_dominating_set(G, set([1, 2]))) + assert nx.is_dominating_set(G, set([4, 3, 5])) + assert nx.is_dominating_set(G, set([0, 2])) + assert nx.is_dominating_set(G, set([1, 2])) diff --git a/networkx/algorithms/tests/test_efficiency.py b/networkx/algorithms/tests/test_efficiency.py index 597c076a..7202c0cf 100644 --- a/networkx/algorithms/tests/test_efficiency.py +++ b/networkx/algorithms/tests/test_efficiency.py @@ -27,20 +27,20 @@ class TestEfficiency: """ When nodes are disconnected, efficiency is 0 """ - assert_equal(nx.efficiency(self.G1, 1, 2), 0) + assert nx.efficiency(self.G1, 1, 2) == 0 def test_local_efficiency_disconnected_graph(self): """ In a disconnected graph the efficiency is 0 """ - assert_equal(nx.local_efficiency(self.G1), 0) + assert nx.local_efficiency(self.G1) == 0 def test_efficiency(self): - assert_equal(nx.efficiency(self.G2, 0, 1), 1) - assert_equal(nx.efficiency(self.G2, 0, 2), 1 / 2) + assert nx.efficiency(self.G2, 0, 1) == 1 + assert nx.efficiency(self.G2, 0, 2) == 1 / 2 def test_global_efficiency(self): - assert_equal(nx.global_efficiency(self.G2), 5 / 6) + assert nx.global_efficiency(self.G2) == 5 / 6 def test_global_efficiency_complete_graph(self): """ @@ -48,7 +48,7 @@ class TestEfficiency: """ for n in range(2, 10): G = nx.complete_graph(n) - assert_equal(nx.global_efficiency(G), 1) + assert nx.global_efficiency(G) == 1 def test_local_efficiency_complete_graph(self): """ @@ -58,11 +58,11 @@ class TestEfficiency: """ for n in range(3, 10): G = nx.complete_graph(n) - assert_equal(nx.local_efficiency(G), 1) + assert nx.local_efficiency(G) == 1 def test_using_ego_graph(self): """ Test that the ego graph is used when computing local efficiency. For more information, see GitHub issue #2710. """ - assert_equal(nx.local_efficiency(self.G3), 7 / 12) + assert nx.local_efficiency(self.G3) == 7 / 12 diff --git a/networkx/algorithms/tests/test_euler.py b/networkx/algorithms/tests/test_euler.py index ee17f847..6746203a 100644 --- a/networkx/algorithms/tests/test_euler.py +++ b/networkx/algorithms/tests/test_euler.py @@ -1,4 +1,5 @@ from unittest import TestCase +import collections from nose.tools import assert_equal from nose.tools import assert_false @@ -14,34 +15,34 @@ import networkx as nx class TestIsEulerian(TestCase): def test_is_eulerian(self): - assert_true(nx.is_eulerian(nx.complete_graph(5))) - assert_true(nx.is_eulerian(nx.complete_graph(7))) - assert_true(nx.is_eulerian(nx.hypercube_graph(4))) - assert_true(nx.is_eulerian(nx.hypercube_graph(6))) + assert nx.is_eulerian(nx.complete_graph(5)) + assert nx.is_eulerian(nx.complete_graph(7)) + assert nx.is_eulerian(nx.hypercube_graph(4)) + assert nx.is_eulerian(nx.hypercube_graph(6)) - assert_false(nx.is_eulerian(nx.complete_graph(4))) - assert_false(nx.is_eulerian(nx.complete_graph(6))) - assert_false(nx.is_eulerian(nx.hypercube_graph(3))) - assert_false(nx.is_eulerian(nx.hypercube_graph(5))) + assert not nx.is_eulerian(nx.complete_graph(4)) + assert not nx.is_eulerian(nx.complete_graph(6)) + assert not nx.is_eulerian(nx.hypercube_graph(3)) + assert not nx.is_eulerian(nx.hypercube_graph(5)) - assert_false(nx.is_eulerian(nx.petersen_graph())) - assert_false(nx.is_eulerian(nx.path_graph(4))) + assert not nx.is_eulerian(nx.petersen_graph()) + assert not nx.is_eulerian(nx.path_graph(4)) def test_is_eulerian2(self): # not connected G = nx.Graph() G.add_nodes_from([1, 2, 3]) - assert_false(nx.is_eulerian(G)) + assert not nx.is_eulerian(G) # not strongly connected G = nx.DiGraph() G.add_nodes_from([1, 2, 3]) - assert_false(nx.is_eulerian(G)) + assert not nx.is_eulerian(G) G = nx.MultiDiGraph() G.add_edge(1, 2) G.add_edge(2, 3) G.add_edge(2, 3) G.add_edge(3, 1) - assert_false(nx.is_eulerian(G)) + assert not nx.is_eulerian(G) class TestEulerianCircuit(TestCase): @@ -50,25 +51,25 @@ class TestEulerianCircuit(TestCase): edges = list(nx.eulerian_circuit(G, source=0)) nodes = [u for u, v in edges] - assert_equal(nodes, [0, 3, 2, 1]) - assert_equal(edges, [(0, 3), (3, 2), (2, 1), (1, 0)]) + assert nodes == [0, 3, 2, 1] + assert edges == [(0, 3), (3, 2), (2, 1), (1, 0)] edges = list(nx.eulerian_circuit(G, source=1)) nodes = [u for u, v in edges] - assert_equal(nodes, [1, 2, 3, 0]) - assert_equal(edges, [(1, 2), (2, 3), (3, 0), (0, 1)]) + assert nodes == [1, 2, 3, 0] + assert edges == [(1, 2), (2, 3), (3, 0), (0, 1)] G = nx.complete_graph(3) edges = list(nx.eulerian_circuit(G, source=0)) nodes = [u for u, v in edges] - assert_equal(nodes, [0, 2, 1]) - assert_equal(edges, [(0, 2), (2, 1), (1, 0)]) + assert nodes == [0, 2, 1] + assert edges == [(0, 2), (2, 1), (1, 0)] edges = list(nx.eulerian_circuit(G, source=1)) nodes = [u for u, v in edges] - assert_equal(nodes, [1, 2, 0]) - assert_equal(edges, [(1, 2), (2, 0), (0, 1)]) + assert nodes == [1, 2, 0] + assert edges == [(1, 2), (2, 0), (0, 1)] def test_eulerian_circuit_digraph(self): G = nx.DiGraph() @@ -76,13 +77,13 @@ class TestEulerianCircuit(TestCase): edges = list(nx.eulerian_circuit(G, source=0)) nodes = [u for u, v in edges] - assert_equal(nodes, [0, 1, 2, 3]) - assert_equal(edges, [(0, 1), (1, 2), (2, 3), (3, 0)]) + assert nodes == [0, 1, 2, 3] + assert edges == [(0, 1), (1, 2), (2, 3), (3, 0)] edges = list(nx.eulerian_circuit(G, source=1)) nodes = [u for u, v in edges] - assert_equal(nodes, [1, 2, 3, 0]) - assert_equal(edges, [(1, 2), (2, 3), (3, 0), (0, 1)]) + assert nodes == [1, 2, 3, 0] + assert edges == [(1, 2), (2, 3), (3, 0), (0, 1)] def test_multigraph(self): G = nx.MultiGraph() @@ -91,8 +92,8 @@ class TestEulerianCircuit(TestCase): G.add_edge(1, 2) edges = list(nx.eulerian_circuit(G, source=0)) nodes = [u for u, v in edges] - assert_equal(nodes, [0, 3, 2, 1, 2, 1]) - assert_equal(edges, [(0, 3), (3, 2), (2, 1), (1, 2), (2, 1), (1, 0)]) + assert nodes == [0, 3, 2, 1, 2, 1] + assert edges == [(0, 3), (3, 2), (2, 1), (1, 2), (2, 1), (1, 0)] def test_multigraph_with_keys(self): G = nx.MultiGraph() @@ -101,10 +102,10 @@ class TestEulerianCircuit(TestCase): G.add_edge(1, 2) edges = list(nx.eulerian_circuit(G, source=0, keys=True)) nodes = [u for u, v, k in edges] - assert_equal(nodes, [0, 3, 2, 1, 2, 1]) - assert_equal(edges[:2], [(0, 3, 0), (3, 2, 0)]) - assert_count_equal(edges[2:5], [(2, 1, 0), (1, 2, 1), (2, 1, 2)]) - assert_equal(edges[5:], [(1, 0, 0)]) + assert nodes == [0, 3, 2, 1, 2, 1] + assert edges[:2] == [(0, 3, 0), (3, 2, 0)] + assert collections.Counter(edges[2:5]) == collections.Counter([(2, 1, 0), (1, 2, 1), (2, 1, 2)]) + assert edges[5:] == [(1, 0, 0)] @raises(nx.NetworkXError) def test_not_eulerian(self): @@ -114,30 +115,30 @@ class TestEulerianCircuit(TestCase): class TestIsSemiEulerian(TestCase): def test_is_semieulerian(self): # Test graphs with Eulerian paths but no cycles return True. - assert_true(nx.is_semieulerian(nx.path_graph(4))) + assert nx.is_semieulerian(nx.path_graph(4)) G = nx.path_graph(6, create_using=nx.DiGraph) - assert_true(nx.is_semieulerian(G)) + assert nx.is_semieulerian(G) # Test graphs with Eulerian cycles return False. - assert_false(nx.is_semieulerian(nx.complete_graph(5))) - assert_false(nx.is_semieulerian(nx.complete_graph(7))) - assert_false(nx.is_semieulerian(nx.hypercube_graph(4))) - assert_false(nx.is_semieulerian(nx.hypercube_graph(6))) + assert not nx.is_semieulerian(nx.complete_graph(5)) + assert not nx.is_semieulerian(nx.complete_graph(7)) + assert not nx.is_semieulerian(nx.hypercube_graph(4)) + assert not nx.is_semieulerian(nx.hypercube_graph(6)) class TestHasEulerianPath(TestCase): def test_has_eulerian_path_cyclic(self): # Test graphs with Eulerian cycles return True. - assert_true(nx.has_eulerian_path(nx.complete_graph(5))) - assert_true(nx.has_eulerian_path(nx.complete_graph(7))) - assert_true(nx.has_eulerian_path(nx.hypercube_graph(4))) - assert_true(nx.has_eulerian_path(nx.hypercube_graph(6))) + assert nx.has_eulerian_path(nx.complete_graph(5)) + assert nx.has_eulerian_path(nx.complete_graph(7)) + assert nx.has_eulerian_path(nx.hypercube_graph(4)) + assert nx.has_eulerian_path(nx.hypercube_graph(6)) def test_has_eulerian_path_non_cyclic(self): # Test graphs with Eulerian paths but no cycles return True. - assert_true(nx.has_eulerian_path(nx.path_graph(4))) + assert nx.has_eulerian_path(nx.path_graph(4)) G = nx.path_graph(6, create_using=nx.DiGraph) - assert_true(nx.has_eulerian_path(G)) + assert nx.has_eulerian_path(G) class TestFindPathStart(TestCase): @@ -145,20 +146,20 @@ class TestFindPathStart(TestCase): find_path_start = nx.algorithms.euler._find_path_start # Test digraphs return correct starting node. G = nx.path_graph(6, create_using=nx.DiGraph) - assert_equal(find_path_start(G), 0) + assert find_path_start(G) == 0 edges = [(0, 1), (1, 2), (2, 0), (4, 0)] - assert_equal(find_path_start(nx.DiGraph(edges)), 4) + assert find_path_start(nx.DiGraph(edges)) == 4 # Test graph with no Eulerian path return None. edges = [(0, 1), (1, 2), (2, 3), (2, 4)] - assert_equal(find_path_start(nx.DiGraph(edges)), None) + assert find_path_start(nx.DiGraph(edges)) == None class TestEulerianPath(TestCase): def test_eulerian_path(self): x = [(4, 0), (0, 1), (1, 2), (2, 0)] for e1, e2 in zip(x, nx.eulerian_path(nx.DiGraph(x))): - assert_equal(e1, e2) + assert e1 == e2 class TestEulerize(TestCase): @@ -182,15 +183,15 @@ class TestEulerize(TestCase): def test_on_eulerian(self): G = nx.cycle_graph(3) H = nx.eulerize(G) - assert_true(nx.is_isomorphic(G, H)) + assert nx.is_isomorphic(G, H) def test_on_eulerian_multigraph(self): G = nx.MultiGraph(nx.cycle_graph(3)) G.add_edge(0, 1) H = nx.eulerize(G) - assert_true(nx.is_eulerian(H)) + assert nx.is_eulerian(H) def test_on_complete_graph(self): G = nx.complete_graph(4) - assert_true(nx.is_eulerian(nx.eulerize(G))) - assert_true(nx.is_eulerian(nx.eulerize(nx.MultiGraph(G)))) + assert nx.is_eulerian(nx.eulerize(G)) + assert nx.is_eulerian(nx.eulerize(nx.MultiGraph(G))) diff --git a/networkx/algorithms/tests/test_graphical.py b/networkx/algorithms/tests/test_graphical.py index 30276fdd..2d20adb5 100644 --- a/networkx/algorithms/tests/test_graphical.py +++ b/networkx/algorithms/tests/test_graphical.py @@ -10,8 +10,8 @@ def test_valid_degree_sequence1(): for i in range(10): G = nx.erdos_renyi_graph(n, p) deg = (d for n, d in G.degree()) - assert_true(nx.is_graphical(deg, method='eg')) - assert_true(nx.is_graphical(deg, method='hh')) + assert nx.is_graphical(deg, method='eg') + assert nx.is_graphical(deg, method='hh') def test_valid_degree_sequence2(): @@ -19,8 +19,8 @@ def test_valid_degree_sequence2(): for i in range(10): G = nx.barabasi_albert_graph(n, 1) deg = (d for n, d in G.degree()) - assert_true(nx.is_graphical(deg, method='eg')) - assert_true(nx.is_graphical(deg, method='hh')) + assert nx.is_graphical(deg, method='eg') + assert nx.is_graphical(deg, method='hh') def test_string_input(): @@ -35,8 +35,8 @@ def test_non_integer_input(): def test_negative_input(): - assert_false(nx.is_graphical([-1], 'hh')) - assert_false(nx.is_graphical([-1], 'eg')) + assert not nx.is_graphical([-1], 'hh') + assert not nx.is_graphical([-1], 'eg') class TestAtlas(object): @@ -53,32 +53,32 @@ class TestAtlas(object): def test_atlas(self): for graph in self.GAG: deg = (d for n, d in graph.degree()) - assert_true(nx.is_graphical(deg, method='eg')) - assert_true(nx.is_graphical(deg, method='hh')) + assert nx.is_graphical(deg, method='eg') + assert nx.is_graphical(deg, method='hh') def test_small_graph_true(): z = [5, 3, 3, 3, 3, 2, 2, 2, 1, 1, 1] - assert_true(nx.is_graphical(z, method='hh')) - assert_true(nx.is_graphical(z, method='eg')) + assert nx.is_graphical(z, method='hh') + assert nx.is_graphical(z, method='eg') z = [10, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2] - assert_true(nx.is_graphical(z, method='hh')) - assert_true(nx.is_graphical(z, method='eg')) + assert nx.is_graphical(z, method='hh') + assert nx.is_graphical(z, method='eg') z = [1, 1, 1, 1, 1, 2, 2, 2, 3, 4] - assert_true(nx.is_graphical(z, method='hh')) - assert_true(nx.is_graphical(z, method='eg')) + assert nx.is_graphical(z, method='hh') + assert nx.is_graphical(z, method='eg') def test_small_graph_false(): z = [1000, 3, 3, 3, 3, 2, 2, 2, 1, 1, 1] - assert_false(nx.is_graphical(z, method='hh')) - assert_false(nx.is_graphical(z, method='eg')) + assert not nx.is_graphical(z, method='hh') + assert not nx.is_graphical(z, method='eg') z = [6, 5, 4, 4, 2, 1, 1, 1] - assert_false(nx.is_graphical(z, method='hh')) - assert_false(nx.is_graphical(z, method='eg')) + assert not nx.is_graphical(z, method='hh') + assert not nx.is_graphical(z, method='eg') z = [1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 4] - assert_false(nx.is_graphical(z, method='hh')) - assert_false(nx.is_graphical(z, method='eg')) + assert not nx.is_graphical(z, method='hh') + assert not nx.is_graphical(z, method='eg') def test_directed_degree_sequence(): @@ -89,69 +89,69 @@ def test_directed_degree_sequence(): G = nx.erdos_renyi_graph(n, p * (i + 1), None, True) din = (d for n, d in G.in_degree()) dout = (d for n, d in G.out_degree()) - assert_true(nx.is_digraphical(din, dout)) + assert nx.is_digraphical(din, dout) def test_small_directed_sequences(): dout = [5, 3, 3, 3, 3, 2, 2, 2, 1, 1, 1] din = [3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1] - assert_true(nx.is_digraphical(din, dout)) + assert nx.is_digraphical(din, dout) # Test nongraphical directed sequence dout = [1000, 3, 3, 3, 3, 2, 2, 2, 1, 1, 1] din = [103, 102, 102, 102, 102, 102, 102, 102, 102, 102] - assert_false(nx.is_digraphical(din, dout)) + assert not nx.is_digraphical(din, dout) # Test digraphical small sequence dout = [1, 1, 1, 1, 1, 2, 2, 2, 3, 4] din = [2, 2, 2, 2, 2, 2, 2, 2, 1, 1] - assert_true(nx.is_digraphical(din, dout)) + assert nx.is_digraphical(din, dout) # Test nonmatching sum din = [2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1] - assert_false(nx.is_digraphical(din, dout)) + assert not nx.is_digraphical(din, dout) # Test for negative integer in sequence din = [2, 2, 2, -2, 2, 2, 2, 2, 1, 1, 4] - assert_false(nx.is_digraphical(din, dout)) + assert not nx.is_digraphical(din, dout) # Test for noninteger din = dout = [1, 1, 1.1, 1] - assert_false(nx.is_digraphical(din, dout)) + assert not nx.is_digraphical(din, dout) din = dout = [1, 1, "rer", 1] - assert_false(nx.is_digraphical(din, dout)) + assert not nx.is_digraphical(din, dout) def test_multi_sequence(): # Test nongraphical multi sequence seq = [1000, 3, 3, 3, 3, 2, 2, 2, 1, 1] - assert_false(nx.is_multigraphical(seq)) + assert not nx.is_multigraphical(seq) # Test small graphical multi sequence seq = [6, 5, 4, 4, 2, 1, 1, 1] - assert_true(nx.is_multigraphical(seq)) + assert nx.is_multigraphical(seq) # Test for negative integer in sequence seq = [6, 5, 4, -4, 2, 1, 1, 1] - assert_false(nx.is_multigraphical(seq)) + assert not nx.is_multigraphical(seq) # Test for sequence with odd sum seq = [1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 4] - assert_false(nx.is_multigraphical(seq)) + assert not nx.is_multigraphical(seq) # Test for noninteger seq = [1, 1, 1.1, 1] - assert_false(nx.is_multigraphical(seq)) + assert not nx.is_multigraphical(seq) seq = [1, 1, "rer", 1] - assert_false(nx.is_multigraphical(seq)) + assert not nx.is_multigraphical(seq) def test_pseudo_sequence(): # Test small valid pseudo sequence seq = [1000, 3, 3, 3, 3, 2, 2, 2, 1, 1] - assert_true(nx.is_pseudographical(seq)) + assert nx.is_pseudographical(seq) # Test for sequence with odd sum seq = [1000, 3, 3, 3, 3, 2, 2, 2, 1, 1, 1] - assert_false(nx.is_pseudographical(seq)) + assert not nx.is_pseudographical(seq) # Test for negative integer in sequence seq = [1000, 3, 3, 3, 3, 2, 2, -2, 1, 1] - assert_false(nx.is_pseudographical(seq)) + assert not nx.is_pseudographical(seq) # Test for noninteger seq = [1, 1, 1.1, 1] - assert_false(nx.is_pseudographical(seq)) + assert not nx.is_pseudographical(seq) seq = [1, 1, "rer", 1] - assert_false(nx.is_pseudographical(seq)) + assert not nx.is_pseudographical(seq) def test_numpy_degree_sequence(): @@ -160,11 +160,11 @@ def test_numpy_degree_sequence(): except ImportError: return ds = numpy.array([1, 2, 2, 2, 1], dtype=numpy.int64) - assert_true(nx.is_graphical(ds, 'eg')) - assert_true(nx.is_graphical(ds, 'hh')) + assert nx.is_graphical(ds, 'eg') + assert nx.is_graphical(ds, 'hh') ds = numpy.array([1, 2, 2, 2, 1], dtype=numpy.float64) - assert_true(nx.is_graphical(ds, 'eg')) - assert_true(nx.is_graphical(ds, 'hh')) + assert nx.is_graphical(ds, 'eg') + assert nx.is_graphical(ds, 'hh') ds = numpy.array([1.1, 2, 2, 2, 1], dtype=numpy.float64) assert_raises(nx.NetworkXException, nx.is_graphical, ds, 'eg') assert_raises(nx.NetworkXException, nx.is_graphical, ds, 'hh') diff --git a/networkx/algorithms/tests/test_hierarchy.py b/networkx/algorithms/tests/test_hierarchy.py index 5aa38d0b..91f3ac9a 100644 --- a/networkx/algorithms/tests/test_hierarchy.py +++ b/networkx/algorithms/tests/test_hierarchy.py @@ -10,18 +10,18 @@ def test_hierarchy_exception(): def test_hierarchy_cycle(): G = nx.cycle_graph(5, create_using=nx.DiGraph()) - assert_equal(nx.flow_hierarchy(G), 0.0) + assert nx.flow_hierarchy(G) == 0.0 def test_hierarchy_tree(): G = nx.full_rary_tree(2, 16, create_using=nx.DiGraph()) - assert_equal(nx.flow_hierarchy(G), 1.0) + assert nx.flow_hierarchy(G) == 1.0 def test_hierarchy_1(): G = nx.DiGraph() G.add_edges_from([(0, 1), (1, 2), (2, 3), (3, 1), (3, 4), (0, 4)]) - assert_equal(nx.flow_hierarchy(G), 0.5) + assert nx.flow_hierarchy(G) == 0.5 def test_hierarchy_weight(): @@ -32,4 +32,4 @@ def test_hierarchy_weight(): (3, 1, {'weight': .1}), (3, 4, {'weight': .3}), (0, 4, {'weight': .3})]) - assert_equal(nx.flow_hierarchy(G, weight='weight'), .75) + assert nx.flow_hierarchy(G, weight='weight') == .75 diff --git a/networkx/algorithms/tests/test_hybrid.py b/networkx/algorithms/tests/test_hybrid.py index 76137b87..6e64c880 100644 --- a/networkx/algorithms/tests/test_hybrid.py +++ b/networkx/algorithms/tests/test_hybrid.py @@ -6,10 +6,10 @@ def test_2d_grid_graph(): # FC article claims 2d grid graph of size n is (3,3)-connected # and (5,9)-connected, but I don't think it is (5,9)-connected G = nx.grid_2d_graph(8, 8, periodic=True) - assert_true(nx.is_kl_connected(G, 3, 3)) - assert_false(nx.is_kl_connected(G, 5, 9)) + assert nx.is_kl_connected(G, 3, 3) + assert not nx.is_kl_connected(G, 5, 9) (H, graphOK) = nx.kl_connected_subgraph(G, 5, 9, same_as_graph=True) - assert_false(graphOK) + assert not graphOK def test_small_graph(): @@ -17,9 +17,9 @@ def test_small_graph(): G.add_edge(1, 2) G.add_edge(1, 3) G.add_edge(2, 3) - assert_true(nx.is_kl_connected(G, 2, 2)) + assert nx.is_kl_connected(G, 2, 2) H = nx.kl_connected_subgraph(G, 2, 2) (H, graphOK) = nx.kl_connected_subgraph(G, 2, 2, low_memory=True, same_as_graph=True) - assert_true(graphOK) + assert graphOK diff --git a/networkx/algorithms/tests/test_isolate.py b/networkx/algorithms/tests/test_isolate.py index 369b730b..6dc2b1cf 100644 --- a/networkx/algorithms/tests/test_isolate.py +++ b/networkx/algorithms/tests/test_isolate.py @@ -18,20 +18,20 @@ def test_is_isolate(): G = nx.Graph() G.add_edge(0, 1) G.add_node(2) - assert_false(nx.is_isolate(G, 0)) - assert_false(nx.is_isolate(G, 1)) - assert_true(nx.is_isolate(G, 2)) + assert not nx.is_isolate(G, 0) + assert not nx.is_isolate(G, 1) + assert nx.is_isolate(G, 2) def test_isolates(): G = nx.Graph() G.add_edge(0, 1) G.add_nodes_from([2, 3]) - assert_equal(sorted(nx.isolates(G)), [2, 3]) + assert sorted(nx.isolates(G)) == [2, 3] def test_number_of_isolates(): G = nx.Graph() G.add_edge(0, 1) G.add_nodes_from([2, 3]) - assert_equal(nx.number_of_isolates(G), 2) + assert nx.number_of_isolates(G) == 2 diff --git a/networkx/algorithms/tests/test_link_prediction.py b/networkx/algorithms/tests/test_link_prediction.py index 4c73150b..46e3f8c4 100644 --- a/networkx/algorithms/tests/test_link_prediction.py +++ b/networkx/algorithms/tests/test_link_prediction.py @@ -11,7 +11,7 @@ def _test_func(G, ebunch, expected, predict_func, **kwargs): exp_dict = dict((tuple(sorted([u, v])), score) for u, v, score in expected) res_dict = dict((tuple(sorted([u, v])), score) for u, v, score in result) - assert_equal(len(exp_dict), len(res_dict)) + assert len(exp_dict) == len(res_dict) for p in exp_dict: assert_almost_equal(exp_dict[p], res_dict[p]) diff --git a/networkx/algorithms/tests/test_lowest_common_ancestors.py b/networkx/algorithms/tests/test_lowest_common_ancestors.py index a99f19f0..00f22f58 100644 --- a/networkx/algorithms/tests/test_lowest_common_ancestors.py +++ b/networkx/algorithms/tests/test_lowest_common_ancestors.py @@ -44,18 +44,18 @@ class TestTreeLCA(object): @staticmethod def assert_has_same_pairs(d1, d2): for (a, b) in ((min(pair), max(pair)) for pair in chain(d1, d2)): - assert_equal(get_pair(d1, a, b), get_pair(d2, a, b)) + assert get_pair(d1, a, b) == get_pair(d2, a, b) def test_tree_all_pairs_lowest_common_ancestor1(self): """Specifying the root is optional.""" - assert_equal(dict(tree_all_pairs_lca(self.DG)), self.ans) + assert dict(tree_all_pairs_lca(self.DG)) == self.ans def test_tree_all_pairs_lowest_common_ancestor2(self): """Specifying only some pairs gives only those pairs.""" test_pairs = [(0, 1), (0, 1), (1, 0)] ans = dict(tree_all_pairs_lca(self.DG, 0, test_pairs)) - assert_true((0, 1) in ans and (1, 0) in ans) - assert_equal(len(ans), 2) + assert (0, 1) in ans and (1, 0) in ans + assert len(ans) == 2 def test_tree_all_pairs_lowest_common_ancestor3(self): """Specifying no pairs same as specifying all.""" @@ -89,11 +89,11 @@ class TestTreeLCA(object): """Works on disconnected nodes.""" G = nx.DiGraph() G.add_node(1) - assert_equal({(1, 1): 1}, dict(tree_all_pairs_lca(G))) + assert {(1, 1): 1} == dict(tree_all_pairs_lca(G)) G.add_node(0) - assert_equal({(1, 1): 1}, dict(tree_all_pairs_lca(G, 1))) - assert_equal({(0, 0): 0}, dict(tree_all_pairs_lca(G, 0))) + assert {(1, 1): 1} == dict(tree_all_pairs_lca(G, 1)) + assert {(0, 0): 0} == dict(tree_all_pairs_lca(G, 0)) assert_raises(nx.NetworkXError, list, tree_all_pairs_lca(G)) @@ -110,8 +110,8 @@ class TestTreeLCA(object): """Test that pairs works correctly as a generator.""" pairs = iter([(0, 1), (0, 1), (1, 0)]) some_pairs = dict(tree_all_pairs_lca(self.DG, 0, pairs)) - assert_true((0, 1) in some_pairs and (1, 0) in some_pairs) - assert_equal(len(some_pairs), 2) + assert (0, 1) in some_pairs and (1, 0) in some_pairs + assert len(some_pairs) == 2 def test_tree_all_pairs_lowest_common_ancestor10(self): """Test that pairs not in the graph raises error.""" @@ -150,7 +150,7 @@ class TestTreeLCA(object): G = nx.DiGraph() G.add_node(3) ans = list(tree_all_pairs_lca(G)) - assert_equal(ans, [((3, 3), 3)]) + assert ans == [((3, 3), 3)] class TestDAGLCA: @@ -217,7 +217,7 @@ class TestDAGLCA: root_distance = nx.shortest_path_length(G, source=roots[0]) for a, b in ((min(pair), max(pair)) for pair in chain(d1, d2)): - assert_equal(root_distance[get_pair(d1, a, b)], + assert (root_distance[get_pair(d1, a, b)] == root_distance[get_pair(d2, a, b)]) def test_all_pairs_lowest_common_ancestor1(self): @@ -265,7 +265,7 @@ class TestDAGLCA: G = self.DG.copy() G.add_node(-1) gen = all_pairs_lca(G, [(-1, -1), (-1, 0)]) - assert_equal(dict(gen), {(-1, -1): -1}) + assert dict(gen) == {(-1, -1): -1} def test_all_pairs_lowest_common_ancestor7(self): """Test that LCA on null graph bails.""" @@ -283,7 +283,7 @@ class TestDAGLCA: G = nx.DiGraph() G.add_node(3) ans = list(all_pairs_lca(G)) - assert_equal(ans, [((3, 3), 3)]) + assert ans == [((3, 3), 3)] def test_all_pairs_lowest_common_ancestor10(self): """Test that it bails on None as a node.""" @@ -296,11 +296,11 @@ class TestDAGLCA: """Test that the one-pair function works on default.""" G = nx.DiGraph([(0, 1), (2, 1)]) sentinel = object() - assert_is(nx.lowest_common_ancestor(G, 0, 2, default=sentinel), + assert (nx.lowest_common_ancestor(G, 0, 2, default=sentinel) is sentinel) def test_lowest_common_ancestor2(self): """Test that the one-pair function works on identity.""" G = nx.DiGraph() G.add_node(3) - assert_equal(nx.lowest_common_ancestor(G, 3, 3), 3) + assert nx.lowest_common_ancestor(G, 3, 3) == 3 diff --git a/networkx/algorithms/tests/test_matching.py b/networkx/algorithms/tests/test_matching.py index 5eeec4f7..c31a2784 100644 --- a/networkx/algorithms/tests/test_matching.py +++ b/networkx/algorithms/tests/test_matching.py @@ -18,13 +18,13 @@ class TestMaxWeightMatching(object): def test_trivial1(self): """Empty graph""" G = nx.Graph() - assert_equal(nx.max_weight_matching(G), set()) + assert nx.max_weight_matching(G) == set() def test_trivial2(self): """Self loop""" G = nx.Graph() G.add_edge(0, 0, weight=100) - assert_equal(nx.max_weight_matching(G), set()) + assert nx.max_weight_matching(G) == set() def test_trivial3(self): """Single edge""" @@ -121,7 +121,7 @@ class TestMaxWeightMatching(object): dict_format = {1: 3, 2: 4, 3: 1, 4: 2, 5: 6, 6: 5} expected = {frozenset(e) for e in matching_dict_to_set(dict_format)} answer = {frozenset(e) for e in nx.max_weight_matching(G)} - assert_equal(answer, expected) + assert answer == expected def test_nested_s_blossom_relabel(self): """Create S-blossom, relabel as S, include in nested S-blossom:""" @@ -231,30 +231,30 @@ class TestIsMatching(object): def test_dict(self): G = nx.path_graph(4) - assert_true(nx.is_matching(G, {0: 1, 1: 0, 2: 3, 3: 2})) + assert nx.is_matching(G, {0: 1, 1: 0, 2: 3, 3: 2}) def test_empty_matching(self): G = nx.path_graph(4) - assert_true(nx.is_matching(G, set())) + assert nx.is_matching(G, set()) def test_single_edge(self): G = nx.path_graph(4) - assert_true(nx.is_matching(G, {(1, 2)})) + assert nx.is_matching(G, {(1, 2)}) def test_edge_order(self): G = nx.path_graph(4) - assert_true(nx.is_matching(G, {(0, 1), (2, 3)})) - assert_true(nx.is_matching(G, {(1, 0), (2, 3)})) - assert_true(nx.is_matching(G, {(0, 1), (3, 2)})) - assert_true(nx.is_matching(G, {(1, 0), (3, 2)})) + assert nx.is_matching(G, {(0, 1), (2, 3)}) + assert nx.is_matching(G, {(1, 0), (2, 3)}) + assert nx.is_matching(G, {(0, 1), (3, 2)}) + assert nx.is_matching(G, {(1, 0), (3, 2)}) def test_valid(self): G = nx.path_graph(4) - assert_true(nx.is_matching(G, {(0, 1), (2, 3)})) + assert nx.is_matching(G, {(0, 1), (2, 3)}) def test_invalid(self): G = nx.path_graph(4) - assert_false(nx.is_matching(G, {(0, 1), (1, 2), (2, 3)})) + assert not nx.is_matching(G, {(0, 1), (1, 2), (2, 3)}) class TestIsMaximalMatching(object): @@ -265,19 +265,19 @@ class TestIsMaximalMatching(object): def test_dict(self): G = nx.path_graph(4) - assert_true(nx.is_maximal_matching(G, {0: 1, 1: 0, 2: 3, 3: 2})) + assert nx.is_maximal_matching(G, {0: 1, 1: 0, 2: 3, 3: 2}) def test_valid(self): G = nx.path_graph(4) - assert_true(nx.is_maximal_matching(G, {(0, 1), (2, 3)})) + assert nx.is_maximal_matching(G, {(0, 1), (2, 3)}) def test_not_matching(self): G = nx.path_graph(4) - assert_false(nx.is_maximal_matching(G, {(0, 1), (1, 2), (2, 3)})) + assert not nx.is_maximal_matching(G, {(0, 1), (1, 2), (2, 3)}) def test_not_maximal(self): G = nx.path_graph(4) - assert_false(nx.is_maximal_matching(G, {(0, 1)})) + assert not nx.is_maximal_matching(G, {(0, 1)}) class TestIsPerfectMatching(object): @@ -288,11 +288,11 @@ class TestIsPerfectMatching(object): def test_dict(self): G = nx.path_graph(4) - assert_true(nx.is_perfect_matching(G, {0: 1, 1: 0, 2: 3, 3: 2})) + assert nx.is_perfect_matching(G, {0: 1, 1: 0, 2: 3, 3: 2}) def test_valid(self): G = nx.path_graph(4) - assert_true(nx.is_perfect_matching(G, {(0, 1), (2, 3)})) + assert nx.is_perfect_matching(G, {(0, 1), (2, 3)}) def test_valid_not_path(self): G = nx.cycle_graph(4) @@ -300,18 +300,18 @@ class TestIsPerfectMatching(object): G.add_edge(1, 4) G.add_edge(5, 2) - assert_true(nx.is_perfect_matching(G, {(1, 4), (0, 3), (5, 2)})) + assert nx.is_perfect_matching(G, {(1, 4), (0, 3), (5, 2)}) def test_not_matching(self): G = nx.path_graph(4) - assert_false(nx.is_perfect_matching(G, {(0, 1), (1, 2), (2, 3)})) + assert not nx.is_perfect_matching(G, {(0, 1), (1, 2), (2, 3)}) def test_maximal_but_not_perfect(self): G = nx.cycle_graph(4) G.add_edge(0, 4) G.add_edge(1, 4) - assert_false(nx.is_perfect_matching(G, {(1, 4), (0, 3)})) + assert not nx.is_perfect_matching(G, {(1, 4), (0, 3)}) class TestMaximalMatching(object): @@ -324,24 +324,24 @@ class TestMaximalMatching(object): edges = [(1, 2), (1, 5), (2, 3), (2, 5), (3, 4), (3, 6), (5, 6)] G = nx.Graph(edges) matching = nx.maximal_matching(G) - assert_true(nx.is_maximal_matching(G, matching)) + assert nx.is_maximal_matching(G, matching) def test_single_edge_matching(self): # In the star graph, any maximal matching has just one edge. G = nx.star_graph(5) matching = nx.maximal_matching(G) - assert_equal(1, len(matching)) - assert_true(nx.is_maximal_matching(G, matching)) + assert 1 == len(matching) + assert nx.is_maximal_matching(G, matching) def test_self_loops(self): # Create the path graph with two self-loops. G = nx.path_graph(3) G.add_edges_from([(0, 0), (1, 1)]) matching = nx.maximal_matching(G) - assert_equal(len(matching), 1) + assert len(matching) == 1 # The matching should never include self-loops. - assert_false(any(u == v for u, v in matching)) - assert_true(nx.is_maximal_matching(G, matching)) + assert not any(u == v for u, v in matching) + assert nx.is_maximal_matching(G, matching) def test_ordering(self): """Tests that a maximal matching is computed correctly @@ -353,5 +353,5 @@ class TestMaximalMatching(object): G.add_nodes_from(nodes) G.add_edges_from([(0, 1), (0, 2)]) matching = nx.maximal_matching(G) - assert_equal(len(matching), 1) - assert_true(nx.is_maximal_matching(G, matching)) + assert len(matching) == 1 + assert nx.is_maximal_matching(G, matching) diff --git a/networkx/algorithms/tests/test_minors.py b/networkx/algorithms/tests/test_minors.py index 812faf5e..3d35e4fb 100644 --- a/networkx/algorithms/tests/test_minors.py +++ b/networkx/algorithms/tests/test_minors.py @@ -36,7 +36,7 @@ class TestQuotient(object): actual = nx.quotient_graph(G, same_neighbors) # It won't take too long to run a graph isomorphism algorithm on such # small graphs. - assert_true(nx.is_isomorphic(expected, actual)) + assert nx.is_isomorphic(expected, actual) def test_quotient_graph_complete_bipartite(self): """Tests that the quotient graph of the complete bipartite graph under @@ -54,7 +54,7 @@ class TestQuotient(object): actual = nx.quotient_graph(G, same_neighbors) # It won't take too long to run a graph isomorphism algorithm on such # small graphs. - assert_true(nx.is_isomorphic(expected, actual)) + assert nx.is_isomorphic(expected, actual) def test_quotient_graph_edge_relation(self): """Tests for specifying an alternate edge relation for the quotient @@ -73,7 +73,7 @@ class TestQuotient(object): expected = nx.Graph() expected.add_edges_from([(0, 2), (0, 4), (2, 4)]) expected.add_edge(1, 3) - assert_true(nx.is_isomorphic(actual, expected)) + assert nx.is_isomorphic(actual, expected) def test_condensation_as_quotient(self): """This tests that the condensation of a graph can be viewed as the @@ -96,7 +96,7 @@ class TestQuotient(object): return component_of[u] == component_of[v] Q = nx.quotient_graph(G, same_component) - assert_true(nx.is_isomorphic(C, Q)) + assert nx.is_isomorphic(C, Q) def test_path(self): G = nx.path_graph(6) @@ -105,9 +105,9 @@ class TestQuotient(object): assert_nodes_equal(M, [0, 1, 2]) assert_edges_equal(M.edges(), [(0, 1), (1, 2)]) for n in M: - assert_equal(M.nodes[n]['nedges'], 1) - assert_equal(M.nodes[n]['nnodes'], 2) - assert_equal(M.nodes[n]['density'], 1) + assert M.nodes[n]['nedges'] == 1 + assert M.nodes[n]['nnodes'] == 2 + assert M.nodes[n]['density'] == 1 def test_multigraph_path(self): G = nx.MultiGraph(nx.path_graph(6)) @@ -116,9 +116,9 @@ class TestQuotient(object): assert_nodes_equal(M, [0, 1, 2]) assert_edges_equal(M.edges(), [(0, 1), (1, 2)]) for n in M: - assert_equal(M.nodes[n]['nedges'], 1) - assert_equal(M.nodes[n]['nnodes'], 2) - assert_equal(M.nodes[n]['density'], 1) + assert M.nodes[n]['nedges'] == 1 + assert M.nodes[n]['nnodes'] == 2 + assert M.nodes[n]['density'] == 1 def test_directed_path(self): G = nx.DiGraph() @@ -128,9 +128,9 @@ class TestQuotient(object): assert_nodes_equal(M, [0, 1, 2]) assert_edges_equal(M.edges(), [(0, 1), (1, 2)]) for n in M: - assert_equal(M.nodes[n]['nedges'], 1) - assert_equal(M.nodes[n]['nnodes'], 2) - assert_equal(M.nodes[n]['density'], 0.5) + assert M.nodes[n]['nedges'] == 1 + assert M.nodes[n]['nnodes'] == 2 + assert M.nodes[n]['density'] == 0.5 def test_directed_multigraph_path(self): G = nx.MultiDiGraph() @@ -140,9 +140,9 @@ class TestQuotient(object): assert_nodes_equal(M, [0, 1, 2]) assert_edges_equal(M.edges(), [(0, 1), (1, 2)]) for n in M: - assert_equal(M.nodes[n]['nedges'], 1) - assert_equal(M.nodes[n]['nnodes'], 2) - assert_equal(M.nodes[n]['density'], 0.5) + assert M.nodes[n]['nedges'] == 1 + assert M.nodes[n]['nnodes'] == 2 + assert M.nodes[n]['density'] == 0.5 @raises(nx.NetworkXException) def test_overlapping_blocks(self): @@ -158,12 +158,12 @@ class TestQuotient(object): M = nx.quotient_graph(G, partition, relabel=True) assert_nodes_equal(M, [0, 1, 2]) assert_edges_equal(M.edges(), [(0, 1), (1, 2)]) - assert_equal(M[0][1]['weight'], 2) - assert_equal(M[1][2]['weight'], 4) + assert M[0][1]['weight'] == 2 + assert M[1][2]['weight'] == 4 for n in M: - assert_equal(M.nodes[n]['nedges'], 1) - assert_equal(M.nodes[n]['nnodes'], 2) - assert_equal(M.nodes[n]['density'], 1) + assert M.nodes[n]['nedges'] == 1 + assert M.nodes[n]['nnodes'] == 2 + assert M.nodes[n]['density'] == 1 def test_barbell(self): G = nx.barbell_graph(3, 0) @@ -172,9 +172,9 @@ class TestQuotient(object): assert_nodes_equal(M, [0, 1]) assert_edges_equal(M.edges(), [(0, 1)]) for n in M: - assert_equal(M.nodes[n]['nedges'], 3) - assert_equal(M.nodes[n]['nnodes'], 3) - assert_equal(M.nodes[n]['density'], 1) + assert M.nodes[n]['nedges'] == 3 + assert M.nodes[n]['nnodes'] == 3 + assert M.nodes[n]['density'] == 1 def test_barbell_plus(self): G = nx.barbell_graph(3, 0) @@ -184,11 +184,11 @@ class TestQuotient(object): M = nx.quotient_graph(G, partition, relabel=True) assert_nodes_equal(M, [0, 1]) assert_edges_equal(M.edges(), [(0, 1)]) - assert_equal(M[0][1]['weight'], 2) + assert M[0][1]['weight'] == 2 for n in M: - assert_equal(M.nodes[n]['nedges'], 3) - assert_equal(M.nodes[n]['nnodes'], 3) - assert_equal(M.nodes[n]['density'], 1) + assert M.nodes[n]['nedges'] == 3 + assert M.nodes[n]['nnodes'] == 3 + assert M.nodes[n]['density'] == 1 def test_blockmodel(self): G = nx.path_graph(6) @@ -197,9 +197,9 @@ class TestQuotient(object): assert_nodes_equal(M.nodes(), [0, 1, 2]) assert_edges_equal(M.edges(), [(0, 1), (1, 2)]) for n in M.nodes(): - assert_equal(M.nodes[n]['nedges'], 1) - assert_equal(M.nodes[n]['nnodes'], 2) - assert_equal(M.nodes[n]['density'], 1.0) + assert M.nodes[n]['nedges'] == 1 + assert M.nodes[n]['nnodes'] == 2 + assert M.nodes[n]['density'] == 1.0 def test_multigraph_blockmodel(self): G = nx.MultiGraph(nx.path_graph(6)) @@ -209,9 +209,9 @@ class TestQuotient(object): assert_nodes_equal(M.nodes(), [0, 1, 2]) assert_edges_equal(M.edges(), [(0, 1), (1, 2)]) for n in M.nodes(): - assert_equal(M.nodes[n]['nedges'], 1) - assert_equal(M.nodes[n]['nnodes'], 2) - assert_equal(M.nodes[n]['density'], 1.0) + assert M.nodes[n]['nedges'] == 1 + assert M.nodes[n]['nnodes'] == 2 + assert M.nodes[n]['density'] == 1.0 def test_quotient_graph_incomplete_partition(self): G = nx.path_graph(6) @@ -235,7 +235,7 @@ class TestContraction(object): actual = nx.contracted_nodes(G, 0, 1) expected = nx.complete_graph(3) expected.add_edge(0, 0) - assert_true(nx.is_isomorphic(actual, expected)) + assert nx.is_isomorphic(actual, expected) def test_directed_node_contraction(self): """Tests for node contraction in a directed graph.""" @@ -244,7 +244,7 @@ class TestContraction(object): expected = nx.DiGraph(nx.complete_graph(3)) expected.add_edge(0, 0) expected.add_edge(0, 0) - assert_true(nx.is_isomorphic(actual, expected)) + assert nx.is_isomorphic(actual, expected) def test_create_multigraph(self): """Tests that using a MultiGraph creates multiple edges.""" @@ -290,15 +290,15 @@ class TestContraction(object): expected.add_edge(0, 0) cdict = {1: {'baz': 'xyzzy'}} expected.nodes[0].update(dict(foo='bar', contraction=cdict)) - assert_true(nx.is_isomorphic(actual, expected)) - assert_equal(actual.nodes, expected.nodes) + assert nx.is_isomorphic(actual, expected) + assert actual.nodes == expected.nodes def test_without_self_loops(self): """Tests for node contraction without preserving self-loops.""" G = nx.cycle_graph(4) actual = nx.contracted_nodes(G, 0, 1, self_loops=False) expected = nx.complete_graph(3) - assert_true(nx.is_isomorphic(actual, expected)) + assert nx.is_isomorphic(actual, expected) def test_contract_selfloop_graph(self): """Tests for node contraction when nodes have selfloops.""" @@ -321,7 +321,7 @@ class TestContraction(object): actual = nx.contracted_edge(G, (0, 1)) expected = nx.complete_graph(3) expected.add_edge(0, 0) - assert_true(nx.is_isomorphic(actual, expected)) + assert nx.is_isomorphic(actual, expected) @raises(ValueError) def test_nonexistent_edge(self): diff --git a/networkx/algorithms/tests/test_mis.py b/networkx/algorithms/tests/test_mis.py index 17a10404..efaf6d4f 100644 --- a/networkx/algorithms/tests/test_mis.py +++ b/networkx/algorithms/tests/test_mis.py @@ -47,19 +47,19 @@ class TestMaximalIndependantSet(object): def test_random_seed(self): G = nx.complete_graph(5) for node in G: - assert_equal(nx.maximal_independent_set(G, [node], seed=1), [node]) + assert nx.maximal_independent_set(G, [node], seed=1) == [node] def test_K5(self): """Maximal independent set: K5""" G = nx.complete_graph(5) for node in G: - assert_equal(nx.maximal_independent_set(G, [node]), [node]) + assert nx.maximal_independent_set(G, [node]) == [node] def test_K55(self): """Maximal independent set: K55""" G = nx.complete_graph(55) for node in G: - assert_equal(nx.maximal_independent_set(G, [node]), [node]) + assert nx.maximal_independent_set(G, [node]) == [node] def test_exception(self): """Bad input should raise exception.""" @@ -76,14 +76,14 @@ class TestMaximalIndependantSet(object): def test_florentine_family(self): G = self.florentine indep = nx.maximal_independent_set(G, ["Medici", "Bischeri"]) - assert_equal(sorted(indep), + assert (sorted(indep) == sorted(["Medici", "Bischeri", "Castellani", "Pazzi", "Ginori", "Lamberteschi"])) def test_bipartite(self): G = nx.complete_bipartite_graph(12, 34) indep = nx.maximal_independent_set(G, [4, 5, 9, 10]) - assert_equal(sorted(indep), list(range(12))) + assert sorted(indep) == list(range(12)) def test_random_graphs(self): """Generate 50 random graphs of different types and sizes and @@ -91,7 +91,7 @@ class TestMaximalIndependantSet(object): for i in range(0, 50, 10): G = nx.random_graphs.erdos_renyi_graph(i * 10 + 1, random.random()) IS = nx.maximal_independent_set(G) - assert_false(list(G.subgraph(IS).edges())) + assert not list(G.subgraph(IS).edges()) neighbors_of_MIS = set.union(*(set(G.neighbors(v)) for v in IS)) for v in set(G.nodes()).difference(IS): - assert_true(v in neighbors_of_MIS) + assert v in neighbors_of_MIS diff --git a/networkx/algorithms/tests/test_moral.py b/networkx/algorithms/tests/test_moral.py index 81268c21..dccba37b 100644 --- a/networkx/algorithms/tests/test_moral.py +++ b/networkx/algorithms/tests/test_moral.py @@ -10,9 +10,9 @@ def test_get_moral_graph(): graph.add_nodes_from([1, 2, 3, 4, 5, 6, 7]) graph.add_edges_from([(1, 2), (3, 2), (4, 1), (4, 5), (6, 5), (7, 5)]) H = moral_graph(graph) - assert_true(not H.is_directed()) - assert_true(H.has_edge(1, 3)) - assert_true(H.has_edge(4, 6)) - assert_true(H.has_edge(6, 7)) - assert_true(H.has_edge(4, 7)) - assert_true(not H.has_edge(1, 5)) + assert not H.is_directed() + assert H.has_edge(1, 3) + assert H.has_edge(4, 6) + assert H.has_edge(6, 7) + assert H.has_edge(4, 7) + assert not H.has_edge(1, 5) diff --git a/networkx/algorithms/tests/test_planar_drawing.py b/networkx/algorithms/tests/test_planar_drawing.py index 8a4c1168..6ed918d3 100644 --- a/networkx/algorithms/tests/test_planar_drawing.py +++ b/networkx/algorithms/tests/test_planar_drawing.py @@ -89,11 +89,9 @@ def test_triangulate_embedding2(): def check_triangulation(embedding, expected_embedding): res_embedding, _ = triangulate_embedding(embedding, True) - assert_equals(res_embedding.get_data(), expected_embedding, - "Expected embedding incorrect") + assert res_embedding.get_data() == expected_embedding, "Expected embedding incorrect" res_embedding, _ = triangulate_embedding(embedding, False) - assert_equals(res_embedding.get_data(), expected_embedding, - "Expected embedding incorrect") + assert res_embedding.get_data() == expected_embedding, "Expected embedding incorrect" def check_embedding_data(embedding_data): @@ -103,15 +101,13 @@ def check_embedding_data(embedding_data): pos_fully = nx.combinatorial_embedding_to_pos(embedding, False) msg = "Planar drawing does not conform to the embedding (fully " \ "triangulation)" - assert_true(planar_drawing_conforms_to_embedding(embedding, pos_fully), - msg) + assert planar_drawing_conforms_to_embedding(embedding, pos_fully), msg check_edge_intersections(embedding, pos_fully) pos_internally = nx.combinatorial_embedding_to_pos(embedding, True) msg = "Planar drawing does not conform to the embedding (internal " \ "triangulation)" - assert_true(planar_drawing_conforms_to_embedding(embedding, - pos_internally), - msg) + assert planar_drawing_conforms_to_embedding(embedding, + pos_internally), msg check_edge_intersections(embedding, pos_internally) diff --git a/networkx/algorithms/tests/test_planarity.py b/networkx/algorithms/tests/test_planarity.py index 6fbc9f71..2e5f8583 100644 --- a/networkx/algorithms/tests/test_planarity.py +++ b/networkx/algorithms/tests/test_planarity.py @@ -40,8 +40,8 @@ class TestLRPlanarity: msg = "Wrong planarity check result. Should be non-planar." # check if the result is as expected - assert_equals(is_planar, is_planar_lr, msg) - assert_equals(is_planar, is_planar_lr_rec, msg) + assert is_planar == is_planar_lr, msg + assert is_planar == is_planar_lr_rec, msg if is_planar_lr: # check embedding @@ -208,8 +208,7 @@ def check_embedding(G, embedding): # Check that graphs are equivalent - assert_equals(set(G.nodes), set(embedding.nodes), - "Bad embedding. Nodes don't match the original graph.") + assert set(G.nodes) == set(embedding.nodes), "Bad embedding. Nodes don't match the original graph." # Check that the edges are equal g_edges = set() @@ -217,8 +216,7 @@ def check_embedding(G, embedding): if edge[0] != edge[1]: g_edges.add((edge[0], edge[1])) g_edges.add((edge[1], edge[0])) - assert_equals(g_edges, set(embedding.edges), - "Bad embedding. Edges don't match the original graph.") + assert g_edges == set(embedding.edges), "Bad embedding. Edges don't match the original graph." def check_counterexample(G, sub_graph): @@ -277,7 +275,7 @@ class TestPlanarEmbeddingClass: embedding = self.get_star_embedding(3) data = embedding.get_data() data_cmp = {0: [2, 1], 1: [0], 2: [0]} - assert_equals(data, data_cmp) + assert data == data_cmp @raises(nx.NetworkXException) def test_missing_edge_orientation(self): @@ -325,7 +323,7 @@ class TestPlanarEmbeddingClass: embedding.add_half_edge_first(1, 2) embedding.add_half_edge_first(2, 1) face = embedding.traverse_face(1, 2) - assert_equals(face, [1, 2]) + assert face == [1, 2] @raises(nx.NetworkXException) def test_unsuccessful_face_traversal(self): diff --git a/networkx/algorithms/tests/test_richclub.py b/networkx/algorithms/tests/test_richclub.py index d2055570..ae6fe88b 100644 --- a/networkx/algorithms/tests/test_richclub.py +++ b/networkx/algorithms/tests/test_richclub.py @@ -5,38 +5,38 @@ from nose.tools import * def test_richclub(): G = nx.Graph([(0, 1), (0, 2), (1, 2), (1, 3), (1, 4), (4, 5)]) rc = nx.richclub.rich_club_coefficient(G, normalized=False) - assert_equal(rc, {0: 12.0 / 30, 1: 8.0 / 12}) + assert rc == {0: 12.0 / 30, 1: 8.0 / 12} # test single value rc0 = nx.richclub.rich_club_coefficient(G, normalized=False)[0] - assert_equal(rc0, 12.0 / 30.0) + assert rc0 == 12.0 / 30.0 def test_richclub_seed(): G = nx.Graph([(0, 1), (0, 2), (1, 2), (1, 3), (1, 4), (4, 5)]) rcNorm = nx.richclub.rich_club_coefficient(G, Q=2, seed=1) - assert_equal(rcNorm, {0: 1.0, 1: 1.0}) + assert rcNorm == {0: 1.0, 1: 1.0} def test_richclub_normalized(): G = nx.Graph([(0, 1), (0, 2), (1, 2), (1, 3), (1, 4), (4, 5)]) rcNorm = nx.richclub.rich_club_coefficient(G, Q=2) - assert_equal(rcNorm, {0: 1.0, 1: 1.0}) + assert rcNorm == {0: 1.0, 1: 1.0} def test_richclub2(): T = nx.balanced_tree(2, 10) rc = nx.richclub.rich_club_coefficient(T, normalized=False) - assert_equal(rc, {0: 4092 / (2047 * 2046.0), + assert rc == {0: 4092 / (2047 * 2046.0), 1: (2044.0 / (1023 * 1022)), - 2: (2040.0 / (1022 * 1021))}) + 2: (2040.0 / (1022 * 1021))} def test_richclub3(): # tests edgecase G = nx.karate_club_graph() rc = nx.rich_club_coefficient(G, normalized=False) - assert_equal(rc, {0: 156.0 / 1122, + assert rc == {0: 156.0 / 1122, 1: 154.0 / 1056, 2: 110.0 / 462, 3: 78.0 / 240, @@ -51,17 +51,17 @@ def test_richclub3(): 12: 0.0, 13: 0.0, 14: 0.0, - 15: 0.0, }) + 15: 0.0, } def test_richclub4(): G = nx.Graph() G.add_edges_from([(0, 1), (0, 2), (0, 3), (0, 4), (4, 5), (5, 9), (6, 9), (7, 9), (8, 9)]) rc = nx.rich_club_coefficient(G, normalized=False) - assert_equal(rc, {0: 18 / 90.0, + assert rc == {0: 18 / 90.0, 1: 6 / 12.0, 2: 0.0, - 3: 0.0}) + 3: 0.0} @raises(nx.NetworkXNotImplemented) diff --git a/networkx/algorithms/tests/test_similarity.py b/networkx/algorithms/tests/test_similarity.py index 8fceb734..c08f7344 100644 --- a/networkx/algorithms/tests/test_similarity.py +++ b/networkx/algorithms/tests/test_similarity.py @@ -45,25 +45,25 @@ class TestSimilarity: G2 = cycle_graph(6) G3 = wheel_graph(7) - assert_equal(graph_edit_distance(G0, G0), 0) - assert_equal(graph_edit_distance(G0, G1), 11) - assert_equal(graph_edit_distance(G1, G0), 11) - assert_equal(graph_edit_distance(G0, G2), 12) - assert_equal(graph_edit_distance(G2, G0), 12) - assert_equal(graph_edit_distance(G0, G3), 19) - assert_equal(graph_edit_distance(G3, G0), 19) - - assert_equal(graph_edit_distance(G1, G1), 0) - assert_equal(graph_edit_distance(G1, G2), 1) - assert_equal(graph_edit_distance(G2, G1), 1) - assert_equal(graph_edit_distance(G1, G3), 8) - assert_equal(graph_edit_distance(G3, G1), 8) - - assert_equal(graph_edit_distance(G2, G2), 0) - assert_equal(graph_edit_distance(G2, G3), 7) - assert_equal(graph_edit_distance(G3, G2), 7) - - assert_equal(graph_edit_distance(G3, G3), 0) + assert graph_edit_distance(G0, G0) == 0 + assert graph_edit_distance(G0, G1) == 11 + assert graph_edit_distance(G1, G0) == 11 + assert graph_edit_distance(G0, G2) == 12 + assert graph_edit_distance(G2, G0) == 12 + assert graph_edit_distance(G0, G3) == 19 + assert graph_edit_distance(G3, G0) == 19 + + assert graph_edit_distance(G1, G1) == 0 + assert graph_edit_distance(G1, G2) == 1 + assert graph_edit_distance(G2, G1) == 1 + assert graph_edit_distance(G1, G3) == 8 + assert graph_edit_distance(G3, G1) == 8 + + assert graph_edit_distance(G2, G2) == 0 + assert graph_edit_distance(G2, G3) == 7 + assert graph_edit_distance(G3, G2) == 7 + + assert graph_edit_distance(G3, G3) == 0 def test_graph_edit_distance_node_match(self): G1 = cycle_graph(5) @@ -72,8 +72,8 @@ class TestSimilarity: attr['color'] = 'red' if n % 2 == 0 else 'blue' for n, attr in G2.nodes.items(): attr['color'] = 'red' if n % 2 == 1 else 'blue' - assert_equal(graph_edit_distance(G1, G2), 0) - assert_equal(graph_edit_distance(G1, G2, node_match=lambda n1, n2: n1['color'] == n2['color']), 1) + assert graph_edit_distance(G1, G2) == 0 + assert graph_edit_distance(G1, G2, node_match=lambda n1, n2: n1['color'] == n2['color']) == 1 def test_graph_edit_distance_edge_match(self): G1 = path_graph(6) @@ -82,8 +82,8 @@ class TestSimilarity: attr['color'] = 'red' if min(e) % 2 == 0 else 'blue' for e, attr in G2.edges.items(): attr['color'] = 'red' if min(e) // 3 == 0 else 'blue' - assert_equal(graph_edit_distance(G1, G2), 0) - assert_equal(graph_edit_distance(G1, G2, edge_match=lambda e1, e2: e1['color'] == e2['color']), 2) + assert graph_edit_distance(G1, G2) == 0 + assert graph_edit_distance(G1, G2, edge_match=lambda e1, e2: e1['color'] == e2['color']) == 2 def test_graph_edit_distance_node_cost(self): G1 = path_graph(6) @@ -111,10 +111,10 @@ class TestSimilarity: else: return 100 - assert_equal(graph_edit_distance(G1, G2, + assert graph_edit_distance(G1, G2, node_subst_cost=node_subst_cost, node_del_cost=node_del_cost, - node_ins_cost=node_ins_cost), 6) + node_ins_cost=node_ins_cost) == 6 def test_graph_edit_distance_edge_cost(self): G1 = path_graph(6) @@ -142,24 +142,24 @@ class TestSimilarity: else: return 1.0 - assert_equal(graph_edit_distance(G1, G2, + assert graph_edit_distance(G1, G2, edge_subst_cost=edge_subst_cost, edge_del_cost=edge_del_cost, - edge_ins_cost=edge_ins_cost), 0.23) + edge_ins_cost=edge_ins_cost) == 0.23 def test_graph_edit_distance_upper_bound(self): G1 = circular_ladder_graph(2) G2 = circular_ladder_graph(6) - assert_equal(graph_edit_distance(G1, G2, upper_bound=5), None) - assert_equal(graph_edit_distance(G1, G2, upper_bound=24), 22) - assert_equal(graph_edit_distance(G1, G2), 22) + assert graph_edit_distance(G1, G2, upper_bound=5) == None + assert graph_edit_distance(G1, G2, upper_bound=24) == 22 + assert graph_edit_distance(G1, G2) == 22 def test_optimal_edit_paths(self): G1 = path_graph(3) G2 = cycle_graph(3) paths, cost = optimal_edit_paths(G1, G2) - assert_equal(cost, 1) - assert_equal(len(paths), 6) + assert cost == 1 + assert len(paths) == 6 def canonical(vertex_path, edge_path): return tuple(sorted(vertex_path)), tuple(sorted(edge_path, key=lambda x: (None in x, x))) @@ -170,7 +170,7 @@ class TestSimilarity: ([(0, 1), (1, 2), (2, 0)], [((0, 1), (1, 2)), ((1, 2), (0, 2)), (None, (0, 1))]), ([(0, 2), (1, 0), (2, 1)], [((0, 1), (0, 2)), ((1, 2), (0, 1)), (None, (1, 2))]), ([(0, 2), (1, 1), (2, 0)], [((0, 1), (1, 2)), ((1, 2), (0, 1)), (None, (0, 2))])] - assert_equal(set(canonical(*p) for p in paths), + assert (set(canonical(*p) for p in paths) == set(canonical(*p) for p in expected_paths)) def test_optimize_graph_edit_distance(self): @@ -178,9 +178,9 @@ class TestSimilarity: G2 = circular_ladder_graph(6) bestcost = 1000 for cost in optimize_graph_edit_distance(G1, G2): - assert_less(cost, bestcost) + assert cost < bestcost bestcost = cost - assert_equal(bestcost, 22) + assert bestcost == 22 # def test_graph_edit_distance_bigger(self): # G1 = circular_ladder_graph(12) @@ -196,25 +196,25 @@ class TestSimilarity: G3 = nx.Graph() G3.add_edges_from((('A', 'A'), ('A', 'B'), ('B', 'B'))) - assert_equal(graph_edit_distance(G0, G0), 0) - assert_equal(graph_edit_distance(G0, G1), 4) - assert_equal(graph_edit_distance(G1, G0), 4) - assert_equal(graph_edit_distance(G0, G2), 4) - assert_equal(graph_edit_distance(G2, G0), 4) - assert_equal(graph_edit_distance(G0, G3), 5) - assert_equal(graph_edit_distance(G3, G0), 5) + assert graph_edit_distance(G0, G0) == 0 + assert graph_edit_distance(G0, G1) == 4 + assert graph_edit_distance(G1, G0) == 4 + assert graph_edit_distance(G0, G2) == 4 + assert graph_edit_distance(G2, G0) == 4 + assert graph_edit_distance(G0, G3) == 5 + assert graph_edit_distance(G3, G0) == 5 - assert_equal(graph_edit_distance(G1, G1), 0) - assert_equal(graph_edit_distance(G1, G2), 0) - assert_equal(graph_edit_distance(G2, G1), 0) - assert_equal(graph_edit_distance(G1, G3), 1) - assert_equal(graph_edit_distance(G3, G1), 1) + assert graph_edit_distance(G1, G1) == 0 + assert graph_edit_distance(G1, G2) == 0 + assert graph_edit_distance(G2, G1) == 0 + assert graph_edit_distance(G1, G3) == 1 + assert graph_edit_distance(G3, G1) == 1 - assert_equal(graph_edit_distance(G2, G2), 0) - assert_equal(graph_edit_distance(G2, G3), 1) - assert_equal(graph_edit_distance(G3, G2), 1) + assert graph_edit_distance(G2, G2) == 0 + assert graph_edit_distance(G2, G3) == 1 + assert graph_edit_distance(G3, G2) == 1 - assert_equal(graph_edit_distance(G3, G3), 0) + assert graph_edit_distance(G3, G3) == 0 def test_digraph(self): G0 = nx.DiGraph() @@ -225,25 +225,25 @@ class TestSimilarity: G3 = nx.DiGraph() G3.add_edges_from((('A', 'B'), ('A', 'C'), ('B', 'D'), ('C', 'D'))) - assert_equal(graph_edit_distance(G0, G0), 0) - assert_equal(graph_edit_distance(G0, G1), 8) - assert_equal(graph_edit_distance(G1, G0), 8) - assert_equal(graph_edit_distance(G0, G2), 8) - assert_equal(graph_edit_distance(G2, G0), 8) - assert_equal(graph_edit_distance(G0, G3), 8) - assert_equal(graph_edit_distance(G3, G0), 8) + assert graph_edit_distance(G0, G0) == 0 + assert graph_edit_distance(G0, G1) == 8 + assert graph_edit_distance(G1, G0) == 8 + assert graph_edit_distance(G0, G2) == 8 + assert graph_edit_distance(G2, G0) == 8 + assert graph_edit_distance(G0, G3) == 8 + assert graph_edit_distance(G3, G0) == 8 - assert_equal(graph_edit_distance(G1, G1), 0) - assert_equal(graph_edit_distance(G1, G2), 2) - assert_equal(graph_edit_distance(G2, G1), 2) - assert_equal(graph_edit_distance(G1, G3), 4) - assert_equal(graph_edit_distance(G3, G1), 4) + assert graph_edit_distance(G1, G1) == 0 + assert graph_edit_distance(G1, G2) == 2 + assert graph_edit_distance(G2, G1) == 2 + assert graph_edit_distance(G1, G3) == 4 + assert graph_edit_distance(G3, G1) == 4 - assert_equal(graph_edit_distance(G2, G2), 0) - assert_equal(graph_edit_distance(G2, G3), 2) - assert_equal(graph_edit_distance(G3, G2), 2) + assert graph_edit_distance(G2, G2) == 0 + assert graph_edit_distance(G2, G3) == 2 + assert graph_edit_distance(G3, G2) == 2 - assert_equal(graph_edit_distance(G3, G3), 0) + assert graph_edit_distance(G3, G3) == 0 def test_multigraph(self): G0 = nx.MultiGraph() @@ -254,25 +254,25 @@ class TestSimilarity: G3 = nx.MultiGraph() G3.add_edges_from((('A', 'B'), ('B', 'C'), ('A', 'C'), ('A', 'C'), ('A', 'C'))) - assert_equal(graph_edit_distance(G0, G0), 0) - assert_equal(graph_edit_distance(G0, G1), 6) - assert_equal(graph_edit_distance(G1, G0), 6) - assert_equal(graph_edit_distance(G0, G2), 7) - assert_equal(graph_edit_distance(G2, G0), 7) - assert_equal(graph_edit_distance(G0, G3), 8) - assert_equal(graph_edit_distance(G3, G0), 8) + assert graph_edit_distance(G0, G0) == 0 + assert graph_edit_distance(G0, G1) == 6 + assert graph_edit_distance(G1, G0) == 6 + assert graph_edit_distance(G0, G2) == 7 + assert graph_edit_distance(G2, G0) == 7 + assert graph_edit_distance(G0, G3) == 8 + assert graph_edit_distance(G3, G0) == 8 - assert_equal(graph_edit_distance(G1, G1), 0) - assert_equal(graph_edit_distance(G1, G2), 1) - assert_equal(graph_edit_distance(G2, G1), 1) - assert_equal(graph_edit_distance(G1, G3), 2) - assert_equal(graph_edit_distance(G3, G1), 2) + assert graph_edit_distance(G1, G1) == 0 + assert graph_edit_distance(G1, G2) == 1 + assert graph_edit_distance(G2, G1) == 1 + assert graph_edit_distance(G1, G3) == 2 + assert graph_edit_distance(G3, G1) == 2 - assert_equal(graph_edit_distance(G2, G2), 0) - assert_equal(graph_edit_distance(G2, G3), 1) - assert_equal(graph_edit_distance(G3, G2), 1) + assert graph_edit_distance(G2, G2) == 0 + assert graph_edit_distance(G2, G3) == 1 + assert graph_edit_distance(G3, G2) == 1 - assert_equal(graph_edit_distance(G3, G3), 0) + assert graph_edit_distance(G3, G3) == 0 def test_multidigraph(self): G1 = nx.MultiDiGraph() @@ -280,8 +280,8 @@ class TestSimilarity: G2 = nx.MultiDiGraph() G2.add_edges_from((('winter', 'spring'), ('spring', 'summer'), ('summer', 'autumn'), ('autumn', 'winter'))) - assert_equal(graph_edit_distance(G1, G2), 5) - assert_equal(graph_edit_distance(G2, G1), 5) + assert graph_edit_distance(G1, G2) == 5 + assert graph_edit_distance(G2, G1) == 5 # by https://github.com/jfbeaumont def testCopy(self): @@ -289,7 +289,7 @@ class TestSimilarity: G.add_node('A', label='A') G.add_node('B', label='B') G.add_edge('A', 'B', label='a-b') - assert_equal(graph_edit_distance(G, G.copy(), node_match=nmatch, edge_match=ematch), 0) + assert graph_edit_distance(G, G.copy(), node_match=nmatch, edge_match=ematch) == 0 def testSame(self): G1 = nx.Graph() @@ -300,7 +300,7 @@ class TestSimilarity: G2.add_node('A', label='A') G2.add_node('B', label='B') G2.add_edge('A', 'B', label='a-b') - assert_equal(graph_edit_distance(G1, G2, node_match=nmatch, edge_match=ematch), 0) + assert graph_edit_distance(G1, G2, node_match=nmatch, edge_match=ematch) == 0 def testOneEdgeLabelDiff(self): G1 = nx.Graph() @@ -311,7 +311,7 @@ class TestSimilarity: G2.add_node('A', label='A') G2.add_node('B', label='B') G2.add_edge('A', 'B', label='bad') - assert_equal(graph_edit_distance(G1, G2, node_match=nmatch, edge_match=ematch), 1) + assert graph_edit_distance(G1, G2, node_match=nmatch, edge_match=ematch) == 1 def testOneNodeLabelDiff(self): G1 = nx.Graph() @@ -322,7 +322,7 @@ class TestSimilarity: G2.add_node('A', label='Z') G2.add_node('B', label='B') G2.add_edge('A', 'B', label='a-b') - assert_equal(graph_edit_distance(G1, G2, node_match=nmatch, edge_match=ematch), 1) + assert graph_edit_distance(G1, G2, node_match=nmatch, edge_match=ematch) == 1 def testOneExtraNode(self): G1 = nx.Graph() @@ -334,7 +334,7 @@ class TestSimilarity: G2.add_node('B', label='B') G2.add_edge('A', 'B', label='a-b') G2.add_node('C', label='C') - assert_equal(graph_edit_distance(G1, G2, node_match=nmatch, edge_match=ematch), 1) + assert graph_edit_distance(G1, G2, node_match=nmatch, edge_match=ematch) == 1 def testOneExtraEdge(self): G1 = nx.Graph() @@ -349,7 +349,7 @@ class TestSimilarity: G2.add_node('C', label='C') G2.add_edge('A', 'B', label='a-b') G2.add_edge('A', 'C', label='a-c') - assert_equal(graph_edit_distance(G1, G2, node_match=nmatch, edge_match=ematch), 1) + assert graph_edit_distance(G1, G2, node_match=nmatch, edge_match=ematch) == 1 def testOneExtraNodeAndEdge(self): G1 = nx.Graph() @@ -362,7 +362,7 @@ class TestSimilarity: G2.add_node('C', label='C') G2.add_edge('A', 'B', label='a-b') G2.add_edge('A', 'C', label='a-c') - assert_equal(graph_edit_distance(G1, G2, node_match=nmatch, edge_match=ematch), 2) + assert graph_edit_distance(G1, G2, node_match=nmatch, edge_match=ematch) == 2 def testGraph1(self): G1 = getCanonical() @@ -374,7 +374,7 @@ class TestSimilarity: G2.add_edge('A', 'B', label='a-b') G2.add_edge('B', 'D', label='b-d') G2.add_edge('D', 'E', label='d-e') - assert_equal(graph_edit_distance(G1, G2, node_match=nmatch, edge_match=ematch), 3) + assert graph_edit_distance(G1, G2, node_match=nmatch, edge_match=ematch) == 3 def testGraph2(self): G1 = getCanonical() @@ -388,7 +388,7 @@ class TestSimilarity: G2.add_edge('B', 'C', label='b-c') G2.add_edge('C', 'D', label='c-d') G2.add_edge('C', 'E', label='c-e') - assert_equal(graph_edit_distance(G1, G2, node_match=nmatch, edge_match=ematch), 4) + assert graph_edit_distance(G1, G2, node_match=nmatch, edge_match=ematch) == 4 def testGraph3(self): G1 = getCanonical() @@ -406,7 +406,7 @@ class TestSimilarity: G2.add_edge('D', 'F', label='d-f') G2.add_edge('D', 'G', label='d-g') G2.add_edge('E', 'B', label='e-b') - assert_equal(graph_edit_distance(G1, G2, node_match=nmatch, edge_match=ematch), 12) + assert graph_edit_distance(G1, G2, node_match=nmatch, edge_match=ematch) == 12 def testGraph4(self): G1 = getCanonical() @@ -418,7 +418,7 @@ class TestSimilarity: G2.add_edge('A', 'B', label='a-b') G2.add_edge('B', 'C', label='b-c') G2.add_edge('C', 'D', label='c-d') - assert_equal(graph_edit_distance(G1, G2, node_match=nmatch, edge_match=ematch), 2) + assert graph_edit_distance(G1, G2, node_match=nmatch, edge_match=ematch) == 2 def testGraph4_a(self): G1 = getCanonical() @@ -430,7 +430,7 @@ class TestSimilarity: G2.add_edge('A', 'B', label='a-b') G2.add_edge('B', 'C', label='b-c') G2.add_edge('A', 'D', label='a-d') - assert_equal(graph_edit_distance(G1, G2, node_match=nmatch, edge_match=ematch), 2) + assert graph_edit_distance(G1, G2, node_match=nmatch, edge_match=ematch) == 2 def testGraph4_b(self): G1 = getCanonical() @@ -442,25 +442,25 @@ class TestSimilarity: G2.add_edge('A', 'B', label='a-b') G2.add_edge('B', 'C', label='b-c') G2.add_edge('B', 'D', label='bad') - assert_equal(graph_edit_distance(G1, G2, node_match=nmatch, edge_match=ematch), 1) + assert graph_edit_distance(G1, G2, node_match=nmatch, edge_match=ematch) == 1 def test_simrank_no_source_no_target(self): G = nx.cycle_graph(5) expected = {0: {0: 1, 1: 0.3951219505902448, 2: 0.5707317069281646, 3: 0.5707317069281646, 4: 0.3951219505902449}, 1: {0: 0.3951219505902448, 1: 1, 2: 0.3951219505902449, 3: 0.5707317069281646, 4: 0.5707317069281646}, 2: {0: 0.5707317069281646, 1: 0.3951219505902449, 2: 1, 3: 0.3951219505902449, 4: 0.5707317069281646}, 3: {0: 0.5707317069281646, 1: 0.5707317069281646, 2: 0.3951219505902449, 3: 1, 4: 0.3951219505902449}, 4: {0: 0.3951219505902449, 1: 0.5707317069281646, 2: 0.5707317069281646, 3: 0.3951219505902449, 4: 1}} actual = nx.simrank_similarity(G) - assert_equal(expected, actual) + assert expected == actual def test_simrank_source_no_target(self): G = nx.cycle_graph(5) expected = {0: 1, 1: 0.3951219505902448, 2: 0.5707317069281646, 3: 0.5707317069281646, 4: 0.3951219505902449} actual = nx.simrank_similarity(G, source=0) - assert_equal(expected, actual) + assert expected == actual def test_simrank_source_and_target(self): G = nx.cycle_graph(5) expected = 1 actual = nx.simrank_similarity(G, source=0, target=0) - assert_equal(expected, actual) + assert expected == actual def test_simrank_numpy_no_source_no_target(self): G = nx.cycle_graph(5) diff --git a/networkx/algorithms/tests/test_simple_paths.py b/networkx/algorithms/tests/test_simple_paths.py index df573413..77081509 100644 --- a/networkx/algorithms/tests/test_simple_paths.py +++ b/networkx/algorithms/tests/test_simple_paths.py @@ -26,7 +26,7 @@ class TestIsSimplePath(object): """ G = nx.trivial_graph() - assert_false(nx.is_simple_path(G, [])) + assert not nx.is_simple_path(G, []) def test_trivial_path(self): """Tests that the trivial path, a path of length one, is @@ -34,7 +34,7 @@ class TestIsSimplePath(object): """ G = nx.trivial_graph() - assert_true(nx.is_simple_path(G, [0])) + assert nx.is_simple_path(G, [0]) def test_trivial_nonpath(self): """Tests that a list whose sole element is an object not in the @@ -42,112 +42,112 @@ class TestIsSimplePath(object): """ G = nx.trivial_graph() - assert_false(nx.is_simple_path(G, ['not a node'])) + assert not nx.is_simple_path(G, ['not a node']) def test_simple_path(self): G = nx.path_graph(2) - assert_true(nx.is_simple_path(G, [0, 1])) + assert nx.is_simple_path(G, [0, 1]) def test_non_simple_path(self): G = nx.path_graph(2) - assert_false(nx.is_simple_path(G, [0, 1, 0])) + assert not nx.is_simple_path(G, [0, 1, 0]) def test_cycle(self): G = nx.cycle_graph(3) - assert_false(nx.is_simple_path(G, [0, 1, 2, 0])) + assert not nx.is_simple_path(G, [0, 1, 2, 0]) def test_missing_node(self): G = nx.path_graph(2) - assert_false(nx.is_simple_path(G, [0, 2])) + assert not nx.is_simple_path(G, [0, 2]) def test_directed_path(self): G = nx.DiGraph([(0, 1), (1, 2)]) - assert_true(nx.is_simple_path(G, [0, 1, 2])) + assert nx.is_simple_path(G, [0, 1, 2]) def test_directed_non_path(self): G = nx.DiGraph([(0, 1), (1, 2)]) - assert_false(nx.is_simple_path(G, [2, 1, 0])) + assert not nx.is_simple_path(G, [2, 1, 0]) def test_directed_cycle(self): G = nx.DiGraph([(0, 1), (1, 2), (2, 0)]) - assert_false(nx.is_simple_path(G, [0, 1, 2, 0])) + assert not nx.is_simple_path(G, [0, 1, 2, 0]) def test_multigraph(self): G = nx.MultiGraph([(0, 1), (0, 1)]) - assert_true(nx.is_simple_path(G, [0, 1])) + assert nx.is_simple_path(G, [0, 1]) def test_multidigraph(self): G = nx.MultiDiGraph([(0, 1), (0, 1), (1, 0), (1, 0)]) - assert_true(nx.is_simple_path(G, [0, 1])) + assert nx.is_simple_path(G, [0, 1]) # Tests for all_simple_paths def test_all_simple_paths(): G = nx.path_graph(4) paths = nx.all_simple_paths(G, 0, 3) - assert_equal(set(tuple(p) for p in paths), {(0, 1, 2, 3)}) + assert set(tuple(p) for p in paths) == {(0, 1, 2, 3)} def test_all_simple_paths_with_two_targets_emits_two_paths(): G = nx.path_graph(4) G.add_edge(2, 4) paths = nx.all_simple_paths(G, 0, [3, 4]) - assert_equal(set(tuple(p) for p in paths), {(0, 1, 2, 3), (0, 1, 2, 4)}) + assert set(tuple(p) for p in paths) == {(0, 1, 2, 3), (0, 1, 2, 4)} def test_digraph_all_simple_paths_with_two_targets_emits_two_paths(): G = nx.path_graph(4, create_using=nx.DiGraph()) G.add_edge(2, 4) paths = nx.all_simple_paths(G, 0, [3, 4]) - assert_equal(set(tuple(p) for p in paths), {(0, 1, 2, 3), (0, 1, 2, 4)}) + assert set(tuple(p) for p in paths) == {(0, 1, 2, 3), (0, 1, 2, 4)} def test_all_simple_paths_with_two_targets_cutoff(): G = nx.path_graph(4) G.add_edge(2, 4) paths = nx.all_simple_paths(G, 0, [3, 4], cutoff=3) - assert_equal(set(tuple(p) for p in paths), {(0, 1, 2, 3), (0, 1, 2, 4)}) + assert set(tuple(p) for p in paths) == {(0, 1, 2, 3), (0, 1, 2, 4)} def test_digraph_all_simple_paths_with_two_targets_cutoff(): G = nx.path_graph(4, create_using=nx.DiGraph()) G.add_edge(2, 4) paths = nx.all_simple_paths(G, 0, [3, 4], cutoff=3) - assert_equal(set(tuple(p) for p in paths), {(0, 1, 2, 3), (0, 1, 2, 4)}) + assert set(tuple(p) for p in paths) == {(0, 1, 2, 3), (0, 1, 2, 4)} def test_all_simple_paths_with_two_targets_in_line_emits_two_paths(): G = nx.path_graph(4) paths = nx.all_simple_paths(G, 0, [2, 3]) - assert_equal(set(tuple(p) for p in paths), {(0, 1, 2), (0, 1, 2, 3)}) + assert set(tuple(p) for p in paths) == {(0, 1, 2), (0, 1, 2, 3)} def test_all_simple_paths_ignores_cycle(): G = nx.cycle_graph(3, create_using=nx.DiGraph()) G.add_edge(1, 3) paths = nx.all_simple_paths(G, 0, 3) - assert_equal(set(tuple(p) for p in paths), {(0, 1, 3)}) + assert set(tuple(p) for p in paths) == {(0, 1, 3)} def test_all_simple_paths_with_two_targets_inside_cycle_emits_two_paths(): G = nx.cycle_graph(3, create_using=nx.DiGraph()) G.add_edge(1, 3) paths = nx.all_simple_paths(G, 0, [2, 3]) - assert_equal(set(tuple(p) for p in paths), {(0, 1, 2), (0, 1, 3)}) + assert set(tuple(p) for p in paths) == {(0, 1, 2), (0, 1, 3)} def test_all_simple_paths_source_target(): G = nx.path_graph(4) paths = nx.all_simple_paths(G, 1, 1) - assert_equal(paths, []) + assert paths == [] def test_all_simple_paths_cutoff(): G = nx.complete_graph(4) paths = nx.all_simple_paths(G, 0, 1, cutoff=1) - assert_equal(set(tuple(p) for p in paths), {(0, 1)}) + assert set(tuple(p) for p in paths) == {(0, 1)} paths = nx.all_simple_paths(G, 0, 1, cutoff=2) - assert_equal(set(tuple(p) for p in paths), {(0, 1), (0, 2, 1), (0, 3, 1)}) + assert set(tuple(p) for p in paths) == {(0, 1), (0, 2, 1), (0, 3, 1)} def test_all_simple_paths_on_non_trivial_graph(): @@ -155,31 +155,31 @@ def test_all_simple_paths_on_non_trivial_graph(): G = nx.path_graph(5, create_using=nx.DiGraph()) G.add_edges_from([(0, 5), (1, 5), (1, 3), (5, 4), (4, 2), (4, 3)]) paths = nx.all_simple_paths(G, 1, [2, 3]) - assert_equal(set(tuple(p) for p in paths), { + assert set(tuple(p) for p in paths) == { (1, 2), (1, 3, 4, 2), (1, 5, 4, 2), (1, 3), (1, 2, 3), (1, 5, 4, 3), - (1, 5, 4, 2, 3)}) + (1, 5, 4, 2, 3)} paths = nx.all_simple_paths(G, 1, [2, 3], cutoff=3) - assert_equal(set(tuple(p) for p in paths), { - (1, 2), (1, 3, 4, 2), (1, 5, 4, 2), (1, 3), (1, 2, 3), (1, 5, 4, 3)}) + assert set(tuple(p) for p in paths) == { + (1, 2), (1, 3, 4, 2), (1, 5, 4, 2), (1, 3), (1, 2, 3), (1, 5, 4, 3)} paths = nx.all_simple_paths(G, 1, [2, 3], cutoff=2) - assert_equal(set(tuple(p) for p in paths), {(1, 2), (1, 3), (1, 2, 3)}) + assert set(tuple(p) for p in paths) == {(1, 2), (1, 3), (1, 2, 3)} def test_all_simple_paths_multigraph(): G = nx.MultiGraph([(1, 2), (1, 2)]) paths = nx.all_simple_paths(G, 1, 1) - assert_equal(paths, []) + assert paths == [] nx.add_path(G, [3, 1, 10, 2]) paths = list(nx.all_simple_paths(G, 1, 2)) - assert_equal(len(paths), 3) - assert_equal(set(tuple(p) for p in paths), {(1, 2), (1, 2), (1, 10, 2)}) + assert len(paths) == 3 + assert set(tuple(p) for p in paths) == {(1, 2), (1, 2), (1, 10, 2)} def test_all_simple_paths_multigraph_with_cutoff(): G = nx.MultiGraph([(1, 2), (1, 2), (1, 10), (10, 2)]) paths = list(nx.all_simple_paths(G, 1, 2, cutoff=1)) - assert_equal(len(paths), 2) - assert_equal(set(tuple(p) for p in paths), {(1, 2), (1, 2)}) + assert len(paths) == 2 + assert set(tuple(p) for p in paths) == {(1, 2), (1, 2)} def test_all_simple_paths_directed(): @@ -187,19 +187,19 @@ def test_all_simple_paths_directed(): nx.add_path(G, [1, 2, 3]) nx.add_path(G, [3, 2, 1]) paths = nx.all_simple_paths(G, 1, 3) - assert_equal(set(tuple(p) for p in paths), {(1, 2, 3)}) + assert set(tuple(p) for p in paths) == {(1, 2, 3)} def test_all_simple_paths_empty(): G = nx.path_graph(4) paths = nx.all_simple_paths(G, 0, 3, cutoff=2) - assert_equal(list(paths), []) + assert list(paths) == [] def test_all_simple_paths_corner_cases(): - assert_equal(list(nx.all_simple_paths(nx.empty_graph(2), 0, 0)), []) - assert_equal(list(nx.all_simple_paths(nx.empty_graph(2), 0, 1)), []) - assert_equal(list(nx.all_simple_paths(nx.path_graph(9), 0, 8, 0)), []) + assert list(nx.all_simple_paths(nx.empty_graph(2), 0, 0)) == [] + assert list(nx.all_simple_paths(nx.empty_graph(2), 0, 1)) == [] + assert list(nx.all_simple_paths(nx.path_graph(9), 0, 8, 0)) == [] def hamiltonian_path(G, source): @@ -217,15 +217,15 @@ def test_hamiltonian_path(): G = nx.complete_graph(4) paths = [list(p) for p in hamiltonian_path(G, 0)] exact = [[0] + list(p) for p in permutations([1, 2, 3], 3)] - assert_equal(sorted(paths), sorted(exact)) + assert sorted(paths) == sorted(exact) def test_cutoff_zero(): G = nx.complete_graph(4) paths = nx.all_simple_paths(G, 0, 3, cutoff=0) - assert_equal(list(list(p) for p in paths), []) + assert list(list(p) for p in paths) == [] paths = nx.all_simple_paths(nx.MultiGraph(G), 0, 3, cutoff=0) - assert_equal(list(list(p) for p in paths), []) + assert list(list(p) for p in paths) == [] @raises(nx.NodeNotFound) @@ -246,16 +246,16 @@ def test_target_missing(): def test_shortest_simple_paths(): G = cnlti(nx.grid_2d_graph(4, 4), first_label=1, ordering="sorted") paths = nx.shortest_simple_paths(G, 1, 12) - assert_equal(next(paths), [1, 2, 3, 4, 8, 12]) - assert_equal(next(paths), [1, 5, 6, 7, 8, 12]) - assert_equal([len(path) for path in nx.shortest_simple_paths(G, 1, 12)], + assert next(paths) == [1, 2, 3, 4, 8, 12] + assert next(paths) == [1, 5, 6, 7, 8, 12] + assert ([len(path) for path in nx.shortest_simple_paths(G, 1, 12)] == sorted([len(path) for path in nx.all_simple_paths(G, 1, 12)])) def test_shortest_simple_paths_directed(): G = nx.cycle_graph(7, create_using=nx.DiGraph()) paths = nx.shortest_simple_paths(G, 0, 3) - assert_equal([path for path in paths], [[0, 1, 2, 3]]) + assert [path for path in paths] == [[0, 1, 2, 3]] def test_Greg_Bernstein(): @@ -269,7 +269,7 @@ def test_Greg_Bernstein(): g1.add_edge("N1", "N2", weight=15.0, capacity=42, name="L3") solution = [['N1', 'N0', 'N3'], ['N1', 'N2', 'N3'], ['N1', 'N4', 'N0', 'N3']] result = list(nx.shortest_simple_paths(g1, 'N1', 'N3', weight='weight')) - assert_equal(result, solution) + assert result == solution def test_weighted_shortest_simple_path(): @@ -282,7 +282,7 @@ def test_weighted_shortest_simple_path(): cost = 0 for path in nx.shortest_simple_paths(G, 0, 3, weight='weight'): this_cost = cost_func(path) - assert_true(cost <= this_cost) + assert cost <= this_cost cost = this_cost @@ -297,7 +297,7 @@ def test_directed_weighted_shortest_simple_path(): cost = 0 for path in nx.shortest_simple_paths(G, 0, 3, weight='weight'): this_cost = cost_func(path) - assert_true(cost <= this_cost) + assert cost <= this_cost cost = this_cost @@ -307,14 +307,14 @@ def test_weighted_shortest_simple_path_issue2427(): G.add_edge('IN', 'A', weight=1) G.add_edge('IN', 'B', weight=2) G.add_edge('B', 'OUT', weight=2) - assert_equal(list(nx.shortest_simple_paths(G, 'IN', 'OUT', weight="weight")), + assert (list(nx.shortest_simple_paths(G, 'IN', 'OUT', weight="weight")) == [['IN', 'OUT'], ['IN', 'B', 'OUT']]) G = nx.Graph() G.add_edge('IN', 'OUT', weight=10) G.add_edge('IN', 'A', weight=1) G.add_edge('IN', 'B', weight=1) G.add_edge('B', 'OUT', weight=1) - assert_equal(list(nx.shortest_simple_paths(G, 'IN', 'OUT', weight="weight")), + assert (list(nx.shortest_simple_paths(G, 'IN', 'OUT', weight="weight")) == [['IN', 'B', 'OUT'], ['IN', 'OUT']]) @@ -324,14 +324,14 @@ def test_directed_weighted_shortest_simple_path_issue2427(): G.add_edge('IN', 'A', weight=1) G.add_edge('IN', 'B', weight=2) G.add_edge('B', 'OUT', weight=2) - assert_equal(list(nx.shortest_simple_paths(G, 'IN', 'OUT', weight="weight")), + assert (list(nx.shortest_simple_paths(G, 'IN', 'OUT', weight="weight")) == [['IN', 'OUT'], ['IN', 'B', 'OUT']]) G = nx.DiGraph() G.add_edge('IN', 'OUT', weight=10) G.add_edge('IN', 'A', weight=1) G.add_edge('IN', 'B', weight=1) G.add_edge('B', 'OUT', weight=1) - assert_equal(list(nx.shortest_simple_paths(G, 'IN', 'OUT', weight="weight")), + assert (list(nx.shortest_simple_paths(G, 'IN', 'OUT', weight="weight")) == [['IN', 'B', 'OUT'], ['IN', 'OUT']]) @@ -342,7 +342,7 @@ def test_weight_name(): G.adj[1][2]['foo'] = 7 paths = list(nx.shortest_simple_paths(G, 0, 3, weight='foo')) solution = [[0, 6, 5, 4, 3], [0, 1, 2, 3]] - assert_equal(paths, solution) + assert paths == solution @raises(nx.NodeNotFound) @@ -377,28 +377,28 @@ def test_ssp_source_missing(): def test_bidirectional_shortest_path_restricted_cycle(): cycle = nx.cycle_graph(7) length, path = _bidirectional_shortest_path(cycle, 0, 3) - assert_equal(path, [0, 1, 2, 3]) + assert path == [0, 1, 2, 3] length, path = _bidirectional_shortest_path(cycle, 0, 3, ignore_nodes=[1]) - assert_equal(path, [0, 6, 5, 4, 3]) + assert path == [0, 6, 5, 4, 3] def test_bidirectional_shortest_path_restricted_wheel(): wheel = nx.wheel_graph(6) length, path = _bidirectional_shortest_path(wheel, 1, 3) - assert_true(path in [[1, 0, 3], [1, 2, 3]]) + assert path in [[1, 0, 3], [1, 2, 3]] length, path = _bidirectional_shortest_path(wheel, 1, 3, ignore_nodes=[0]) - assert_equal(path, [1, 2, 3]) + assert path == [1, 2, 3] length, path = _bidirectional_shortest_path(wheel, 1, 3, ignore_nodes=[0, 2]) - assert_equal(path, [1, 5, 4, 3]) + assert path == [1, 5, 4, 3] length, path = _bidirectional_shortest_path(wheel, 1, 3, ignore_edges=[(1, 0), (5, 0), (2, 3)]) - assert_true(path in [[1, 2, 0, 3], [1, 5, 4, 3]]) + assert path in [[1, 2, 0, 3], [1, 5, 4, 3]] def test_bidirectional_shortest_path_restricted_directed_cycle(): directed_cycle = nx.cycle_graph(7, create_using=nx.DiGraph()) length, path = _bidirectional_shortest_path(directed_cycle, 0, 3) - assert_equal(path, [0, 1, 2, 3]) + assert path == [0, 1, 2, 3] assert_raises( nx.NetworkXNoPath, _bidirectional_shortest_path, @@ -408,7 +408,7 @@ def test_bidirectional_shortest_path_restricted_directed_cycle(): ) length, path = _bidirectional_shortest_path(directed_cycle, 0, 3, ignore_edges=[(2, 1)]) - assert_equal(path, [0, 1, 2, 3]) + assert path == [0, 1, 2, 3] assert_raises( nx.NetworkXNoPath, _bidirectional_shortest_path, @@ -451,14 +451,14 @@ def test_bidirectional_shortest_path_ignore(): def validate_path(G, s, t, soln_len, path): - assert_equal(path[0], s) - assert_equal(path[-1], t) - assert_equal(soln_len, sum(G[u][v].get('weight', 1) - for u, v in zip(path[:-1], path[1:]))) + assert path[0] == s + assert path[-1] == t + assert soln_len == sum(G[u][v].get('weight', 1) + for u, v in zip(path[:-1], path[1:])) def validate_length_path(G, s, t, soln_len, length, path): - assert_equal(soln_len, length) + assert soln_len == length validate_path(G, s, t, length, path) diff --git a/networkx/algorithms/tests/test_smallworld.py b/networkx/algorithms/tests/test_smallworld.py index d10df437..9808074c 100644 --- a/networkx/algorithms/tests/test_smallworld.py +++ b/networkx/algorithms/tests/test_smallworld.py @@ -14,7 +14,7 @@ def test_random_reference(): Gr = random_reference(G, niter=1, seed=rng) C = nx.average_clustering(G) Cr = nx.average_clustering(Gr) - assert_true(C > Cr) + assert C > Cr assert_raises(nx.NetworkXError, random_reference, nx.Graph()) assert_raises(nx.NetworkXNotImplemented, random_reference, nx.DiGraph()) @@ -28,7 +28,7 @@ def test_lattice_reference(): Gl = lattice_reference(G, niter=1, seed=rng) L = nx.average_shortest_path_length(G) Ll = nx.average_shortest_path_length(Gl) - assert_true(Ll > L) + assert Ll > L assert_raises(nx.NetworkXError, lattice_reference, nx.Graph()) assert_raises(nx.NetworkXNotImplemented, lattice_reference, nx.DiGraph()) @@ -42,7 +42,7 @@ def test_sigma(): Gr = nx.connected_watts_strogatz_graph(50, 6, 1, seed=rng) sigmas = sigma(Gs, niter=1, nrand=2, seed=rng) sigmar = sigma(Gr, niter=1, nrand=2, seed=rng) - assert_true(sigmar < sigmas) + assert sigmar < sigmas def test_omega(): @@ -54,7 +54,7 @@ def test_omega(): omegas = omega(Gs, niter=1, nrand=1, seed=rng) print("omegas, omegal, omegar") print(omegas, omegal, omegar) - assert_true(omegal < omegas and omegas < omegar) + assert omegal < omegas and omegas < omegar # fixture for nose tests diff --git a/networkx/algorithms/tests/test_smetric.py b/networkx/algorithms/tests/test_smetric.py index 06b33a5e..30385304 100644 --- a/networkx/algorithms/tests/test_smetric.py +++ b/networkx/algorithms/tests/test_smetric.py @@ -11,7 +11,7 @@ def test_smetric(): g.add_edge(2, 4) g.add_edge(1, 4) sm = nx.s_metric(g, normalized=False) - assert_equal(sm, 19.0) + assert sm == 19.0 # smNorm = nx.s_metric(g,normalized=True) # assert_equal(smNorm, 0.95) diff --git a/networkx/algorithms/tests/test_structuralholes.py b/networkx/algorithms/tests/test_structuralholes.py index f4195326..67875c35 100644 --- a/networkx/algorithms/tests/test_structuralholes.py +++ b/networkx/algorithms/tests/test_structuralholes.py @@ -109,17 +109,17 @@ class TestStructuralHoles(object): G = self.G.copy() G.add_node(1) constraint = nx.constraint(G) - assert_true(math.isnan(constraint[1])) + assert math.isnan(constraint[1]) def test_effective_size_isolated(self): G = self.G.copy() G.add_node(1) nx.set_edge_attributes(G, self.G_weights, 'weight') effective_size = nx.effective_size(G, weight='weight') - assert_true(math.isnan(effective_size[1])) + assert math.isnan(effective_size[1]) def test_effective_size_borgatti_isolated(self): G = self.G.copy() G.add_node(1) effective_size = nx.effective_size(G) - assert_true(math.isnan(effective_size[1])) + assert math.isnan(effective_size[1]) diff --git a/networkx/algorithms/tests/test_swap.py b/networkx/algorithms/tests/test_swap.py index 4e219680..a7971552 100644 --- a/networkx/algorithms/tests/test_swap.py +++ b/networkx/algorithms/tests/test_swap.py @@ -10,22 +10,22 @@ def test_double_edge_swap(): graph = nx.barabasi_albert_graph(200, 1) degrees = sorted(d for n, d in graph.degree()) G = nx.double_edge_swap(graph, 40) - assert_equal(degrees, sorted(d for n, d in graph.degree())) + assert degrees == sorted(d for n, d in graph.degree()) def test_double_edge_swap_seed(): graph = nx.barabasi_albert_graph(200, 1) degrees = sorted(d for n, d in graph.degree()) G = nx.double_edge_swap(graph, 40, seed=1) - assert_equal(degrees, sorted(d for n, d in graph.degree())) + assert degrees == sorted(d for n, d in graph.degree()) def test_connected_double_edge_swap(): graph = nx.barabasi_albert_graph(200, 1) degrees = sorted(d for n, d in graph.degree()) G = nx.connected_double_edge_swap(graph, 40, seed=1) - assert_true(nx.is_connected(graph)) - assert_equal(degrees, sorted(d for n, d in graph.degree())) + assert nx.is_connected(graph) + assert degrees == sorted(d for n, d in graph.degree()) @raises(nx.NetworkXError) @@ -54,4 +54,4 @@ def test_degree_seq_c4(): G = nx.cycle_graph(4) degrees = sorted(d for n, d in G.degree()) G = nx.double_edge_swap(G, 1, 100) - assert_equal(degrees, sorted(d for n, d in G.degree())) + assert degrees == sorted(d for n, d in G.degree()) diff --git a/networkx/algorithms/tests/test_threshold.py b/networkx/algorithms/tests/test_threshold.py index 83d52c13..745b63e1 100644 --- a/networkx/algorithms/tests/test_threshold.py +++ b/networkx/algorithms/tests/test_threshold.py @@ -17,21 +17,21 @@ cnlti = nx.convert_node_labels_to_integers class TestGeneratorThreshold(): def test_threshold_sequence_graph_test(self): G = nx.star_graph(10) - assert_true(nxt.is_threshold_graph(G)) - assert_true(nxt.is_threshold_sequence(list(d for n, d in G.degree()))) + assert nxt.is_threshold_graph(G) + assert nxt.is_threshold_sequence(list(d for n, d in G.degree())) G = nx.complete_graph(10) - assert_true(nxt.is_threshold_graph(G)) - assert_true(nxt.is_threshold_sequence(list(d for n, d in G.degree()))) + assert nxt.is_threshold_graph(G) + assert nxt.is_threshold_sequence(list(d for n, d in G.degree())) deg = [3, 2, 2, 1, 1, 1] - assert_false(nxt.is_threshold_sequence(deg)) + assert not nxt.is_threshold_sequence(deg) deg = [3, 2, 2, 1] - assert_true(nxt.is_threshold_sequence(deg)) + assert nxt.is_threshold_sequence(deg) G = nx.generators.havel_hakimi_graph(deg) - assert_true(nxt.is_threshold_graph(G)) + assert nxt.is_threshold_graph(G) def test_creation_sequences(self): deg = [3, 2, 2, 1] @@ -42,48 +42,48 @@ class TestGeneratorThreshold(): cs0 = nxt.creation_sequence(deg) H0 = nxt.threshold_graph(cs0) - assert_equal(''.join(cs0), 'ddid') + assert ''.join(cs0) == 'ddid' cs1 = nxt.creation_sequence(deg, with_labels=True) H1 = nxt.threshold_graph(cs1) - assert_equal(cs1, [(1, 'd'), (2, 'd'), (3, 'i'), (0, 'd')]) + assert cs1 == [(1, 'd'), (2, 'd'), (3, 'i'), (0, 'd')] cs2 = nxt.creation_sequence(deg, compact=True) H2 = nxt.threshold_graph(cs2) - assert_equal(cs2, [2, 1, 1]) - assert_equal(''.join(nxt.uncompact(cs2)), 'ddid') - assert_true(graph_could_be_isomorphic(H0, G)) - assert_true(graph_could_be_isomorphic(H0, H1)) - assert_true(graph_could_be_isomorphic(H0, H2)) + assert cs2 == [2, 1, 1] + assert ''.join(nxt.uncompact(cs2)) == 'ddid' + assert graph_could_be_isomorphic(H0, G) + assert graph_could_be_isomorphic(H0, H1) + assert graph_could_be_isomorphic(H0, H2) def test_make_compact(self): - assert_equal(nxt.make_compact(['d', 'd', 'd', 'i', 'd', 'd']), [3, 1, 2]) - assert_equal(nxt.make_compact([3, 1, 2]), [3, 1, 2]) + assert nxt.make_compact(['d', 'd', 'd', 'i', 'd', 'd']) == [3, 1, 2] + assert nxt.make_compact([3, 1, 2]) == [3, 1, 2] assert_raises(TypeError, nxt.make_compact, [3., 1., 2.]) def test_uncompact(self): - assert_equal(nxt.uncompact([3, 1, 2]), ['d', 'd', 'd', 'i', 'd', 'd']) - assert_equal(nxt.uncompact(['d', 'd', 'i', 'd']), ['d', 'd', 'i', 'd']) - assert_equal(nxt.uncompact(nxt.uncompact([(1, 'd'), (2, 'd'), (3, 'i'), (0, 'd')])), + assert nxt.uncompact([3, 1, 2]) == ['d', 'd', 'd', 'i', 'd', 'd'] + assert nxt.uncompact(['d', 'd', 'i', 'd']) == ['d', 'd', 'i', 'd'] + assert (nxt.uncompact(nxt.uncompact([(1, 'd'), (2, 'd'), (3, 'i'), (0, 'd')])) == nxt.uncompact([(1, 'd'), (2, 'd'), (3, 'i'), (0, 'd')])) assert_raises(TypeError, nxt.uncompact, [3., 1., 2.]) def test_creation_sequence_to_weights(self): - assert_equal(nxt.creation_sequence_to_weights([3, 1, 2]), [0.5, 0.5, 0.5, 0.25, 0.75, 0.75]) + assert nxt.creation_sequence_to_weights([3, 1, 2]) == [0.5, 0.5, 0.5, 0.25, 0.75, 0.75] assert_raises(TypeError, nxt.creation_sequence_to_weights, [3., 1., 2.]) def test_weights_to_creation_sequence(self): deg = [3, 2, 2, 1] with assert_raises(ValueError): nxt.weights_to_creation_sequence(deg, with_labels=True, compact=True) - assert_equal(nxt.weights_to_creation_sequence(deg, with_labels=True), + assert (nxt.weights_to_creation_sequence(deg, with_labels=True) == [(3, 'd'), (1, 'd'), (2, 'd'), (0, 'd')]) - assert_equal(nxt.weights_to_creation_sequence(deg, compact=True), [4]) + assert nxt.weights_to_creation_sequence(deg, compact=True) == [4] def test_find_alternating_4_cycle(self): G = nx.Graph() G.add_edge(1, 2) - assert_false(nxt.find_alternating_4_cycle(G)) + assert not nxt.find_alternating_4_cycle(G) def test_shortest_path(self): deg = [3, 2, 2, 1] @@ -91,46 +91,46 @@ class TestGeneratorThreshold(): cs1 = nxt.creation_sequence(deg, with_labels=True) for n, m in [(3, 0), (0, 3), (0, 2), (0, 1), (1, 3), (3, 1), (1, 2), (2, 3)]: - assert_equal(nxt.shortest_path(cs1, n, m), + assert (nxt.shortest_path(cs1, n, m) == nx.shortest_path(G, n, m)) spl = nxt.shortest_path_length(cs1, 3) spl2 = nxt.shortest_path_length([t for v, t in cs1], 2) - assert_equal(spl, spl2) + assert spl == spl2 spld = {} for j, pl in enumerate(spl): n = cs1[j][0] spld[n] = pl - assert_equal(spld, nx.single_source_shortest_path_length(G, 3)) + assert spld == nx.single_source_shortest_path_length(G, 3) - assert_equal(nxt.shortest_path(['d', 'd', 'd', 'i', 'd', 'd'], 1, 2), [1, 2]) - assert_equal(nxt.shortest_path([3, 1, 2], 1, 2), [1, 2]) + assert nxt.shortest_path(['d', 'd', 'd', 'i', 'd', 'd'], 1, 2) == [1, 2] + assert nxt.shortest_path([3, 1, 2], 1, 2) == [1, 2] assert_raises(TypeError, nxt.shortest_path, [3., 1., 2.], 1, 2) assert_raises(ValueError, nxt.shortest_path, [3, 1, 2], 'a', 2) assert_raises(ValueError, nxt.shortest_path, [3, 1, 2], 1, 'b') - assert_equal(nxt.shortest_path([3, 1, 2], 1, 1), [1]) + assert nxt.shortest_path([3, 1, 2], 1, 1) == [1] def test_shortest_path_length(self): - assert_equal(nxt.shortest_path_length([3, 1, 2], 1), [1, 0, 1, 2, 1, 1]) - assert_equal(nxt.shortest_path_length(['d', 'd', 'd', 'i', 'd', 'd'], 1), + assert nxt.shortest_path_length([3, 1, 2], 1) == [1, 0, 1, 2, 1, 1] + assert (nxt.shortest_path_length(['d', 'd', 'd', 'i', 'd', 'd'], 1) == [1, 0, 1, 2, 1, 1]) - assert_equal(nxt.shortest_path_length(('d', 'd', 'd', 'i', 'd', 'd'), 1), + assert (nxt.shortest_path_length(('d', 'd', 'd', 'i', 'd', 'd'), 1) == [1, 0, 1, 2, 1, 1]) assert_raises(TypeError, nxt.shortest_path, [3., 1., 2.], 1) def random_threshold_sequence(self): - assert_equal(len(nxt.random_threshold_sequence(10, 0.5)), 10) - assert_equal(nxt.random_threshold_sequence(10, 0.5, seed=42), + assert len(nxt.random_threshold_sequence(10, 0.5)) == 10 + assert (nxt.random_threshold_sequence(10, 0.5, seed=42) == ['d', 'i', 'd', 'd', 'd', 'i', 'i', 'i', 'd', 'd']) assert_raises(ValueError, nxt.random_threshold_sequence, 10, 1.5) def test_right_d_threshold_sequence(self): - assert_equal(nxt.right_d_threshold_sequence(3, 2), ['d', 'i', 'd']) + assert nxt.right_d_threshold_sequence(3, 2) == ['d', 'i', 'd'] assert_raises(ValueError, nxt.right_d_threshold_sequence, 2, 3) def test_left_d_threshold_sequence(self): - assert_equal(nxt.left_d_threshold_sequence(3, 2), ['d', 'i', 'd']) + assert nxt.left_d_threshold_sequence(3, 2) == ['d', 'i', 'd'] assert_raises(ValueError, nxt.left_d_threshold_sequence, 2, 3) def test_weights_thresholds(self): @@ -138,27 +138,27 @@ class TestGeneratorThreshold(): cs = nxt.weights_to_creation_sequence(wseq, threshold=10) wseq = nxt.creation_sequence_to_weights(cs) cs2 = nxt.weights_to_creation_sequence(wseq) - assert_equal(cs, cs2) + assert cs == cs2 wseq = nxt.creation_sequence_to_weights(nxt.uncompact([3, 1, 2, 3, 3, 2, 3])) - assert_equal(wseq, + assert (wseq == [s * 0.125 for s in [4, 4, 4, 3, 5, 5, 2, 2, 2, 6, 6, 6, 1, 1, 7, 7, 7]]) wseq = nxt.creation_sequence_to_weights([3, 1, 2, 3, 3, 2, 3]) - assert_equal(wseq, + assert (wseq == [s * 0.125 for s in [4, 4, 4, 3, 5, 5, 2, 2, 2, 6, 6, 6, 1, 1, 7, 7, 7]]) wseq = nxt.creation_sequence_to_weights(list(enumerate('ddidiiidididi'))) - assert_equal(wseq, + assert (wseq == [s * 0.1 for s in [5, 5, 4, 6, 3, 3, 3, 7, 2, 8, 1, 9, 0]]) wseq = nxt.creation_sequence_to_weights('ddidiiidididi') - assert_equal(wseq, + assert (wseq == [s * 0.1 for s in [5, 5, 4, 6, 3, 3, 3, 7, 2, 8, 1, 9, 0]]) wseq = nxt.creation_sequence_to_weights('ddidiiidididid') ws = [s / float(12) for s in [6, 6, 5, 7, 4, 4, 4, 8, 3, 9, 2, 10, 1, 11]] - assert_true(sum([abs(c - d) for c, d in zip(wseq, ws)]) < 1e-14) + assert sum([abs(c - d) for c, d in zip(wseq, ws)]) < 1e-14 def test_finding_routines(self): G = nx.Graph({1: [2], 2: [3], 3: [4], 4: [5], 5: [6]}) @@ -169,26 +169,26 @@ class TestGeneratorThreshold(): G.add_edge(4, 6) # Alternating 4 cycle - assert_equal(nxt.find_alternating_4_cycle(G), [1, 2, 3, 6]) + assert nxt.find_alternating_4_cycle(G) == [1, 2, 3, 6] # Threshold graph TG = nxt.find_threshold_graph(G) - assert_true(nxt.is_threshold_graph(TG)) - assert_equal(sorted(TG.nodes()), [1, 2, 3, 4, 5, 7]) + assert nxt.is_threshold_graph(TG) + assert sorted(TG.nodes()) == [1, 2, 3, 4, 5, 7] cs = nxt.creation_sequence(dict(TG.degree()), with_labels=True) - assert_equal(nxt.find_creation_sequence(G), cs) + assert nxt.find_creation_sequence(G) == cs def test_fast_versions_properties_threshold_graphs(self): cs = 'ddiiddid' G = nxt.threshold_graph(cs) - assert_equal(nxt.density('ddiiddid'), nx.density(G)) - assert_equal(sorted(nxt.degree_sequence(cs)), + assert nxt.density('ddiiddid') == nx.density(G) + assert (sorted(nxt.degree_sequence(cs)) == sorted(d for n, d in G.degree())) ts = nxt.triangle_sequence(cs) - assert_equal(ts, list(nx.triangles(G).values())) - assert_equal(sum(ts) // 3, nxt.triangles(cs)) + assert ts == list(nx.triangles(G).values()) + assert sum(ts) // 3 == nxt.triangles(cs) c1 = nxt.cluster_sequence(cs) c2 = list(nx.clustering(G).values()) @@ -196,17 +196,17 @@ class TestGeneratorThreshold(): b1 = nx.betweenness_centrality(G).values() b2 = nxt.betweenness_sequence(cs) - assert_true(sum([abs(c - d) for c, d in zip(b1, b2)]) < 1e-14) + assert sum([abs(c - d) for c, d in zip(b1, b2)]) < 1e-14 - assert_equal(nxt.eigenvalues(cs), [0, 1, 3, 3, 5, 7, 7, 8]) + assert nxt.eigenvalues(cs) == [0, 1, 3, 3, 5, 7, 7, 8] # Degree Correlation - assert_true(abs(nxt.degree_correlation(cs) + 0.593038821954) < 1e-12) - assert_equal(nxt.degree_correlation('diiiddi'), -0.8) - assert_equal(nxt.degree_correlation('did'), -1.0) - assert_equal(nxt.degree_correlation('ddd'), 1.0) - assert_equal(nxt.eigenvalues('dddiii'), [0, 0, 0, 0, 3, 3]) - assert_equal(nxt.eigenvalues('dddiiid'), [0, 1, 1, 1, 4, 4, 7]) + assert abs(nxt.degree_correlation(cs) + 0.593038821954) < 1e-12 + assert nxt.degree_correlation('diiiddi') == -0.8 + assert nxt.degree_correlation('did') == -1.0 + assert nxt.degree_correlation('ddd') == 1.0 + assert nxt.eigenvalues('dddiii') == [0, 0, 0, 0, 3, 3] + assert nxt.eigenvalues('dddiiid') == [0, 1, 1, 1, 4, 4, 7] def test_tg_creation_routines(self): s = nxt.left_d_threshold_sequence(5, 7) @@ -227,7 +227,7 @@ class TestGeneratorThreshold(): G = nxt.threshold_graph(cs) (tgeval, tgevec) = nxt.eigenvectors(cs) dot = N.dot - assert_equal([abs(dot(lv, lv) - 1.0) < 1e-9 for lv in tgevec], [True] * 8) + assert [abs(dot(lv, lv) - 1.0) < 1e-9 for lv in tgevec] == [True] * 8 lapl = nx.laplacian_matrix(G) # tgev=[ dot(lv,dot(lapl,lv)) for lv in tgevec ] # assert_true(sum([abs(c-d) for c,d in zip(tgev,tgeval)]) < 1e-9) @@ -242,4 +242,4 @@ class TestGeneratorThreshold(): assert_raises(nx.exception.NetworkXError, nxt.threshold_graph, cs, create_using=nx.DiGraph()) MG = nxt.threshold_graph(cs, create_using=nx.MultiGraph()) - assert_equal(sorted(MG.edges()), sorted(G.edges())) + assert sorted(MG.edges()) == sorted(G.edges()) diff --git a/networkx/algorithms/tests/test_tournament.py b/networkx/algorithms/tests/test_tournament.py index dc56bb16..9fe21ded 100644 --- a/networkx/algorithms/tests/test_tournament.py +++ b/networkx/algorithms/tests/test_tournament.py @@ -30,14 +30,14 @@ class TestIsTournament(object): def test_is_tournament(self): G = DiGraph() G.add_edges_from([(0, 1), (1, 2), (2, 3), (3, 0), (1, 3), (0, 2)]) - assert_true(is_tournament(G)) + assert is_tournament(G) def test_self_loops(self): """A tournament must have no self-loops.""" G = DiGraph() G.add_edges_from([(0, 1), (1, 2), (2, 3), (3, 0), (1, 3), (0, 2)]) G.add_edge(0, 0) - assert_false(is_tournament(G)) + assert not is_tournament(G) def test_missing_edges(self): """A tournament must not have any pair of nodes without at least @@ -46,7 +46,7 @@ class TestIsTournament(object): """ G = DiGraph() G.add_edges_from([(0, 1), (1, 2), (2, 3), (3, 0), (1, 3)]) - assert_false(is_tournament(G)) + assert not is_tournament(G) def test_bidirectional_edges(self): """A tournament must not have any pair of nodes with greater @@ -56,7 +56,7 @@ class TestIsTournament(object): G = DiGraph() G.add_edges_from([(0, 1), (1, 2), (2, 3), (3, 0), (1, 3), (0, 2)]) G.add_edge(1, 0) - assert_false(is_tournament(G)) + assert not is_tournament(G) class TestRandomTournament(object): @@ -67,12 +67,12 @@ class TestRandomTournament(object): def test_graph_is_tournament(self): for n in range(10): G = random_tournament(5) - assert_true(is_tournament(G)) + assert is_tournament(G) def test_graph_is_tournament_seed(self): for n in range(10): G = random_tournament(5, seed=1) - assert_true(is_tournament(G)) + assert is_tournament(G) class TestHamiltonianPath(object): @@ -85,8 +85,8 @@ class TestHamiltonianPath(object): G = DiGraph() G.add_edges_from([(0, 1), (1, 2), (2, 3), (3, 0), (1, 3), (0, 2)]) path = hamiltonian_path(G) - assert_equal(len(path), 4) - assert_true(all(v in G[u] for u, v in zip(path, path[1:]))) + assert len(path) == 4 + assert all(v in G[u] for u, v in zip(path, path[1:])) def test_hamiltonian_cycle(self): """Tests that :func:`networkx.tournament.hamiltonian_path` @@ -97,9 +97,9 @@ class TestHamiltonianPath(object): G = DiGraph() G.add_edges_from([(0, 1), (1, 2), (2, 3), (3, 0), (1, 3), (0, 2)]) path = hamiltonian_path(G) - assert_equal(len(path), 4) - assert_true(all(v in G[u] for u, v in zip(path, path[1:]))) - assert_true(path[0] in G[path[-1]]) + assert len(path) == 4 + assert all(v in G[u] for u, v in zip(path, path[1:])) + assert path[0] in G[path[-1]] class TestReachability(object): @@ -111,18 +111,18 @@ class TestReachability(object): def test_reachable_pair(self): """Tests for a reachable pair of nodes.""" G = DiGraph([(0, 1), (1, 2), (2, 0)]) - assert_true(is_reachable(G, 0, 2)) + assert is_reachable(G, 0, 2) def test_same_node_is_reachable(self): """Tests that a node is always reachable from itself.""" # G is an arbitrary tournament on ten nodes. G = DiGraph(sorted(p) for p in combinations(range(10), 2)) - assert_true(all(is_reachable(G, v, v) for v in G)) + assert all(is_reachable(G, v, v) for v in G) def test_unreachable_pair(self): """Tests for an unreachable pair of nodes.""" G = DiGraph([(0, 1), (0, 2), (1, 2)]) - assert_false(is_reachable(G, 1, 0)) + assert not is_reachable(G, 1, 0) class TestStronglyConnected(object): @@ -134,9 +134,9 @@ class TestStronglyConnected(object): def test_is_strongly_connected(self): """Tests for a strongly connected tournament.""" G = DiGraph([(0, 1), (1, 2), (2, 0)]) - assert_true(is_strongly_connected(G)) + assert is_strongly_connected(G) def test_not_strongly_connected(self): """Tests for a tournament that is not strongly connected.""" G = DiGraph([(0, 1), (0, 2), (1, 2)]) - assert_false(is_strongly_connected(G)) + assert not is_strongly_connected(G) diff --git a/networkx/algorithms/tests/test_triads.py b/networkx/algorithms/tests/test_triads.py index 160c534f..8cd594c8 100644 --- a/networkx/algorithms/tests/test_triads.py +++ b/networkx/algorithms/tests/test_triads.py @@ -22,4 +22,4 @@ def test_triadic_census(): '021U': 0, '111U': 0, '003': 8, '030C': 0, '021D': 9, '201': 0, '111D': 1, '300': 0, '120D': 0, '021C': 2} actual = nx.triadic_census(G) - assert_equal(expected, actual) + assert expected == actual diff --git a/networkx/algorithms/tests/test_vitality.py b/networkx/algorithms/tests/test_vitality.py index db083677..ece31285 100644 --- a/networkx/algorithms/tests/test_vitality.py +++ b/networkx/algorithms/tests/test_vitality.py @@ -8,32 +8,32 @@ class TestClosenessVitality(object): def test_unweighted(self): G = nx.cycle_graph(3) vitality = nx.closeness_vitality(G) - assert_equal(vitality, {0: 2, 1: 2, 2: 2}) + assert vitality == {0: 2, 1: 2, 2: 2} def test_weighted(self): G = nx.Graph() nx.add_cycle(G, [0, 1, 2], weight=2) vitality = nx.closeness_vitality(G, weight='weight') - assert_equal(vitality, {0: 4, 1: 4, 2: 4}) + assert vitality == {0: 4, 1: 4, 2: 4} def test_unweighted_digraph(self): G = nx.DiGraph(nx.cycle_graph(3)) vitality = nx.closeness_vitality(G) - assert_equal(vitality, {0: 4, 1: 4, 2: 4}) + assert vitality == {0: 4, 1: 4, 2: 4} def test_weighted_digraph(self): G = nx.DiGraph() nx.add_cycle(G, [0, 1, 2], weight=2) nx.add_cycle(G, [2, 1, 0], weight=2) vitality = nx.closeness_vitality(G, weight='weight') - assert_equal(vitality, {0: 8, 1: 8, 2: 8}) + assert vitality == {0: 8, 1: 8, 2: 8} def test_weighted_multidigraph(self): G = nx.MultiDiGraph() nx.add_cycle(G, [0, 1, 2], weight=2) nx.add_cycle(G, [2, 1, 0], weight=2) vitality = nx.closeness_vitality(G, weight='weight') - assert_equal(vitality, {0: 8, 1: 8, 2: 8}) + assert vitality == {0: 8, 1: 8, 2: 8} def test_disconnecting_graph(self): """Tests that the closeness vitality of a node whose removal @@ -41,4 +41,4 @@ class TestClosenessVitality(object): """ G = nx.path_graph(3) - assert_equal(nx.closeness_vitality(G, node=1), -float('inf')) + assert nx.closeness_vitality(G, node=1) == -float('inf') diff --git a/networkx/algorithms/tests/test_voronoi.py b/networkx/algorithms/tests/test_voronoi.py index 15eadc0b..cafee551 100644 --- a/networkx/algorithms/tests/test_voronoi.py +++ b/networkx/algorithms/tests/test_voronoi.py @@ -23,20 +23,20 @@ class TestVoronoiCells(object): G = nx.empty_graph(5) cells = nx.voronoi_cells(G, {0, 2, 4}) expected = {0: {0}, 2: {2}, 4: {4}, 'unreachable': {1, 3}} - assert_equal(expected, cells) + assert expected == cells def test_undirected_unweighted(self): G = nx.cycle_graph(6) cells = nx.voronoi_cells(G, {0, 3}) expected = {0: {0, 1, 5}, 3: {2, 3, 4}} - assert_equal(expected, cells) + assert expected == cells def test_directed_unweighted(self): # This is the singly-linked directed cycle graph on six nodes. G = nx.DiGraph(pairwise(range(6), cyclic=True)) cells = nx.voronoi_cells(G, {0, 3}) expected = {0: {0, 1, 2}, 3: {3, 4, 5}} - assert_equal(expected, cells) + assert expected == cells def test_directed_inward(self): """Tests that reversing the graph gives the "inward" Voronoi @@ -48,7 +48,7 @@ class TestVoronoiCells(object): G = G.reverse(copy=False) cells = nx.voronoi_cells(G, {0, 3}) expected = {0: {0, 4, 5}, 3: {1, 2, 3}} - assert_equal(expected, cells) + assert expected == cells def test_undirected_weighted(self): edges = [(0, 1, 10), (1, 2, 1), (2, 3, 1)] @@ -56,7 +56,7 @@ class TestVoronoiCells(object): G.add_weighted_edges_from(edges) cells = nx.voronoi_cells(G, {0, 3}) expected = {0: {0}, 3: {1, 2, 3}} - assert_equal(expected, cells) + assert expected == cells def test_directed_weighted(self): edges = [(0, 1, 10), (1, 2, 1), (2, 3, 1), (3, 2, 1), (2, 1, 1)] @@ -64,7 +64,7 @@ class TestVoronoiCells(object): G.add_weighted_edges_from(edges) cells = nx.voronoi_cells(G, {0, 3}) expected = {0: {0}, 3: {1, 2, 3}} - assert_equal(expected, cells) + assert expected == cells def test_multigraph_unweighted(self): """Tests that the Voronoi cells for a multigraph are the same as @@ -76,7 +76,7 @@ class TestVoronoiCells(object): H = nx.Graph(G) G_cells = nx.voronoi_cells(G, {0, 3}) H_cells = nx.voronoi_cells(H, {0, 3}) - assert_equal(G_cells, H_cells) + assert G_cells == H_cells def test_multidigraph_unweighted(self): # This is the twice-singly-linked directed cycle graph on six nodes. @@ -85,7 +85,7 @@ class TestVoronoiCells(object): H = nx.DiGraph(G) G_cells = nx.voronoi_cells(G, {0, 3}) H_cells = nx.voronoi_cells(H, {0, 3}) - assert_equal(G_cells, H_cells) + assert G_cells == H_cells def test_multigraph_weighted(self): edges = [(0, 1, 10), (0, 1, 10), (1, 2, 1), (1, 2, 100), (2, 3, 1), @@ -94,7 +94,7 @@ class TestVoronoiCells(object): G.add_weighted_edges_from(edges) cells = nx.voronoi_cells(G, {0, 3}) expected = {0: {0}, 3: {1, 2, 3}} - assert_equal(expected, cells) + assert expected == cells def test_multidigraph_weighted(self): edges = [(0, 1, 10), (0, 1, 10), (1, 2, 1), (2, 3, 1), (3, 2, 10), @@ -103,4 +103,4 @@ class TestVoronoiCells(object): G.add_weighted_edges_from(edges) cells = nx.voronoi_cells(G, {0, 3}) expected = {0: {0}, 3: {1, 2, 3}} - assert_equal(expected, cells) + assert expected == cells diff --git a/networkx/algorithms/traversal/tests/test_beamsearch.py b/networkx/algorithms/traversal/tests/test_beamsearch.py index b9c7fbe9..2b806946 100644 --- a/networkx/algorithms/traversal/tests/test_beamsearch.py +++ b/networkx/algorithms/traversal/tests/test_beamsearch.py @@ -30,9 +30,9 @@ class TestBeamSearch(TestCase): # search terminates. G = nx.cycle_graph(4) edges = nx.bfs_beam_edges(G, 0, identity, width=1) - assert_equal(list(edges), [(0, 3), (3, 2)]) + assert list(edges) == [(0, 3), (3, 2)] def test_wide(self): G = nx.cycle_graph(4) edges = nx.bfs_beam_edges(G, 0, identity, width=2) - assert_equal(list(edges), [(0, 3), (0, 1), (3, 2)]) + assert list(edges) == [(0, 3), (0, 1), (3, 2)] diff --git a/networkx/algorithms/traversal/tests/test_bfs.py b/networkx/algorithms/traversal/tests/test_bfs.py index 1922f903..72c90f44 100644 --- a/networkx/algorithms/traversal/tests/test_bfs.py +++ b/networkx/algorithms/traversal/tests/test_bfs.py @@ -12,35 +12,35 @@ class TestBFS: cls.G = G def test_successor(self): - assert_equal(dict(nx.bfs_successors(self.G, source=0)), + assert (dict(nx.bfs_successors(self.G, source=0)) == {0: [1], 1: [2, 3], 2: [4]}) def test_predecessor(self): - assert_equal(dict(nx.bfs_predecessors(self.G, source=0)), + assert (dict(nx.bfs_predecessors(self.G, source=0)) == {1: 0, 2: 1, 3: 1, 4: 2}) def test_bfs_tree(self): T = nx.bfs_tree(self.G, source=0) - assert_equal(sorted(T.nodes()), sorted(self.G.nodes())) - assert_equal(sorted(T.edges()), [(0, 1), (1, 2), (1, 3), (2, 4)]) + assert sorted(T.nodes()) == sorted(self.G.nodes()) + assert sorted(T.edges()) == [(0, 1), (1, 2), (1, 3), (2, 4)] def test_bfs_edges(self): edges = nx.bfs_edges(self.G, source=0) - assert_equal(list(edges), [(0, 1), (1, 2), (1, 3), (2, 4)]) + assert list(edges) == [(0, 1), (1, 2), (1, 3), (2, 4)] def test_bfs_edges_reverse(self): D = nx.DiGraph() D.add_edges_from([(0, 1), (1, 2), (1, 3), (2, 4), (3, 4)]) edges = nx.bfs_edges(D, source=4, reverse=True) - assert_equal(list(edges), [(4, 2), (4, 3), (2, 1), (1, 0)]) + assert list(edges) == [(4, 2), (4, 3), (2, 1), (1, 0)] def test_bfs_tree_isolates(self): G = nx.Graph() G.add_node(1) G.add_node(2) T = nx.bfs_tree(G, source=1) - assert_equal(sorted(T.nodes()), [1]) - assert_equal(sorted(T.edges()), []) + assert sorted(T.nodes()) == [1] + assert sorted(T.edges()) == [] class TestBreadthLimitedSearch: @@ -59,25 +59,25 @@ class TestBreadthLimitedSearch: cls.D = D def bfs_test_successor(self): - assert_equal(dict(nx.bfs_successors(self.G, source=1, depth_limit=3)), + assert (dict(nx.bfs_successors(self.G, source=1, depth_limit=3)) == {1: [0, 2], 2: [3, 7], 3: [4], 7: [8]}) result = {n: sorted(s) for n, s in nx.bfs_successors(self.D, source=7, depth_limit=2)} - assert_equal(result, {8: [9], 2: [3], 7: [2, 8]}) + assert result == {8: [9], 2: [3], 7: [2, 8]} def bfs_test_predecessor(self): - assert_equal(dict(nx.bfs_predecessors(self.G, source=1, - depth_limit=3)), + assert (dict(nx.bfs_predecessors(self.G, source=1, + depth_limit=3)) == {0: 1, 2: 1, 3: 2, 4: 3, 7: 2, 8: 7}) - assert_equal(dict(nx.bfs_predecessors(self.D, source=7, - depth_limit=2)), + assert (dict(nx.bfs_predecessors(self.D, source=7, + depth_limit=2)) == {2: 7, 3: 2, 8: 7, 9: 8}) def bfs_test_tree(self): T = nx.bfs_tree(self.G, source=3, depth_limit=1) - assert_equal(sorted(T.edges()), [(3, 2), (3, 4)]) + assert sorted(T.edges()) == [(3, 2), (3, 4)] def bfs_test_edges(self): edges = nx.bfs_edges(self.G, source=9, depth_limit=4) - assert_equal(list(edges), [(9, 8), (9, 10), (8, 7), - (7, 2), (2, 1), (2, 3)]) + assert list(edges) == [(9, 8), (9, 10), (8, 7), + (7, 2), (2, 1), (2, 3)] diff --git a/networkx/algorithms/traversal/tests/test_dfs.py b/networkx/algorithms/traversal/tests/test_dfs.py index f604ecb5..df61d125 100644 --- a/networkx/algorithms/traversal/tests/test_dfs.py +++ b/networkx/algorithms/traversal/tests/test_dfs.py @@ -17,67 +17,67 @@ class TestDFS: cls.D = D def test_preorder_nodes(self): - assert_equal(list(nx.dfs_preorder_nodes(self.G, source=0)), + assert (list(nx.dfs_preorder_nodes(self.G, source=0)) == [0, 1, 2, 4, 3]) - assert_equal(list(nx.dfs_preorder_nodes(self.D)), [0, 1, 2, 3]) + assert list(nx.dfs_preorder_nodes(self.D)) == [0, 1, 2, 3] def test_postorder_nodes(self): - assert_equal(list(nx.dfs_postorder_nodes(self.G, source=0)), + assert (list(nx.dfs_postorder_nodes(self.G, source=0)) == [3, 4, 2, 1, 0]) - assert_equal(list(nx.dfs_postorder_nodes(self.D)), [1, 0, 3, 2]) + assert list(nx.dfs_postorder_nodes(self.D)) == [1, 0, 3, 2] def test_successor(self): - assert_equal(nx.dfs_successors(self.G, source=0), + assert (nx.dfs_successors(self.G, source=0) == {0: [1], 1: [2], 2: [4], 4: [3]}) - assert_equal(nx.dfs_successors(self.D), {0: [1], 2: [3]}) + assert nx.dfs_successors(self.D) == {0: [1], 2: [3]} def test_predecessor(self): - assert_equal(nx.dfs_predecessors(self.G, source=0), + assert (nx.dfs_predecessors(self.G, source=0) == {1: 0, 2: 1, 3: 4, 4: 2}) - assert_equal(nx.dfs_predecessors(self.D), {1: 0, 3: 2}) + assert nx.dfs_predecessors(self.D) == {1: 0, 3: 2} def test_dfs_tree(self): exp_nodes = sorted(self.G.nodes()) exp_edges = [(0, 1), (1, 2), (2, 4), (4, 3)] # Search from first node T = nx.dfs_tree(self.G, source=0) - assert_equal(sorted(T.nodes()), exp_nodes) - assert_equal(sorted(T.edges()), exp_edges) + assert sorted(T.nodes()) == exp_nodes + assert sorted(T.edges()) == exp_edges # Check source=None T = nx.dfs_tree(self.G, source=None) - assert_equal(sorted(T.nodes()), exp_nodes) - assert_equal(sorted(T.edges()), exp_edges) + assert sorted(T.nodes()) == exp_nodes + assert sorted(T.edges()) == exp_edges # Check source=None is the default T = nx.dfs_tree(self.G) - assert_equal(sorted(T.nodes()), exp_nodes) - assert_equal(sorted(T.edges()), exp_edges) + assert sorted(T.nodes()) == exp_nodes + assert sorted(T.edges()) == exp_edges def test_dfs_edges(self): edges = nx.dfs_edges(self.G, source=0) - assert_equal(list(edges), [(0, 1), (1, 2), (2, 4), (4, 3)]) + assert list(edges) == [(0, 1), (1, 2), (2, 4), (4, 3)] edges = nx.dfs_edges(self.D) - assert_equal(list(edges), [(0, 1), (2, 3)]) + assert list(edges) == [(0, 1), (2, 3)] def test_dfs_labeled_edges(self): edges = list(nx.dfs_labeled_edges(self.G, source=0)) forward = [(u, v) for (u, v, d) in edges if d == 'forward'] - assert_equal(forward, [(0, 0), (0, 1), (1, 2), (2, 4), (4, 3)]) + assert forward == [(0, 0), (0, 1), (1, 2), (2, 4), (4, 3)] def test_dfs_labeled_disconnected_edges(self): edges = list(nx.dfs_labeled_edges(self.D)) forward = [(u, v) for (u, v, d) in edges if d == 'forward'] - assert_equal(forward, [(0, 0), (0, 1), (2, 2), (2, 3)]) + assert forward == [(0, 0), (0, 1), (2, 2), (2, 3)] def test_dfs_tree_isolates(self): G = nx.Graph() G.add_node(1) G.add_node(2) T = nx.dfs_tree(G, source=1) - assert_equal(sorted(T.nodes()), [1]) - assert_equal(sorted(T.edges()), []) + assert sorted(T.nodes()) == [1] + assert sorted(T.edges()) == [] T = nx.dfs_tree(G, source=None) - assert_equal(sorted(T.nodes()), [1, 2]) - assert_equal(sorted(T.edges()), []) + assert sorted(T.nodes()) == [1, 2] + assert sorted(T.edges()) == [] class TestDepthLimitedSearch: @@ -96,46 +96,46 @@ class TestDepthLimitedSearch: cls.D = D def dls_test_preorder_nodes(self): - assert_equal(list(nx.dfs_preorder_nodes(self.G, source=0, - depth_limit=2)), [0, 1, 2]) - assert_equal(list(nx.dfs_preorder_nodes(self.D, source=1, - depth_limit=2)), ([1, 0])) + assert list(nx.dfs_preorder_nodes(self.G, source=0, + depth_limit=2)) == [0, 1, 2] + assert list(nx.dfs_preorder_nodes(self.D, source=1, + depth_limit=2)) == ([1, 0]) def dls_test_postorder_nodes(self): - assert_equal(list(nx.dfs_postorder_nodes(self.G, - source=3, depth_limit=3)), [1, 7, 2, 5, 4, 3]) - assert_equal(list(nx.dfs_postorder_nodes(self.D, - source=2, depth_limit=2)), ([3, 7, 2])) + assert list(nx.dfs_postorder_nodes(self.G, + source=3, depth_limit=3)) == [1, 7, 2, 5, 4, 3] + assert list(nx.dfs_postorder_nodes(self.D, + source=2, depth_limit=2)) == ([3, 7, 2]) def dls_test_successor(self): result = nx.dfs_successors(self.G, source=4, depth_limit=3) - assert_equal({n: set(v) for n, v in result.items()}, + assert ({n: set(v) for n, v in result.items()} == {2: {1, 7}, 3: {2}, 4: {3, 5}, 5: {6}}) result = nx.dfs_successors(self.D, source=7, depth_limit=2) - assert_equal({n: set(v) for n, v in result.items()}, + assert ({n: set(v) for n, v in result.items()} == {8: {9}, 2: {3}, 7: {8, 2}}) def dls_test_predecessor(self): - assert_equal(nx.dfs_predecessors(self.G, source=0, depth_limit=3), + assert (nx.dfs_predecessors(self.G, source=0, depth_limit=3) == {1: 0, 2: 1, 3: 2, 7: 2}) - assert_equal(nx.dfs_predecessors(self.D, source=2, depth_limit=3), + assert (nx.dfs_predecessors(self.D, source=2, depth_limit=3) == {8: 7, 9: 8, 3: 2, 7: 2}) def test_dls_tree(self): T = nx.dfs_tree(self.G, source=3, depth_limit=1) - assert_equal(sorted(T.edges()), [(3, 2), (3, 4)]) + assert sorted(T.edges()) == [(3, 2), (3, 4)] def test_dls_edges(self): edges = nx.dfs_edges(self.G, source=9, depth_limit=4) - assert_equal(list(edges), [(9, 8), (8, 7), - (7, 2), (2, 1), (2, 3), (9, 10)]) + assert list(edges) == [(9, 8), (8, 7), + (7, 2), (2, 1), (2, 3), (9, 10)] def test_dls_labeled_edges(self): edges = list(nx.dfs_labeled_edges(self.G, source=5, depth_limit=1)) forward = [(u, v) for (u, v, d) in edges if d == 'forward'] - assert_equal(forward, [(5, 5), (5, 4), (5, 6)]) + assert forward == [(5, 5), (5, 4), (5, 6)] def test_dls_labeled_disconnected_edges(self): edges = list(nx.dfs_labeled_edges(self.G, source=6, depth_limit=2)) forward = [(u, v) for (u, v, d) in edges if d == 'forward'] - assert_equal(forward, [(6, 6), (6, 5), (5, 4)]) + assert forward == [(6, 6), (6, 5), (5, 4)] diff --git a/networkx/algorithms/traversal/tests/test_edgebfs.py b/networkx/algorithms/traversal/tests/test_edgebfs.py index c5884158..47fbb13b 100644 --- a/networkx/algorithms/traversal/tests/test_edgebfs.py +++ b/networkx/algorithms/traversal/tests/test_edgebfs.py @@ -17,26 +17,26 @@ class TestEdgeBFS(object): def test_empty(self): G = nx.Graph() edges = list(edge_bfs(G)) - assert_equal(edges, []) + assert edges == [] def test_graph_single_source(self): G = nx.Graph(self.edges) G.add_edge(4, 5) x = list(edge_bfs(G, [0])) x_ = [(0, 1), (0, 2), (1, 2), (1, 3)] - assert_equal(x, x_) + assert x == x_ def test_graph(self): G = nx.Graph(self.edges) x = list(edge_bfs(G, self.nodes)) x_ = [(0, 1), (0, 2), (1, 2), (1, 3)] - assert_equal(x, x_) + assert x == x_ def test_digraph(self): G = nx.DiGraph(self.edges) x = list(edge_bfs(G, self.nodes)) x_ = [(0, 1), (1, 0), (2, 0), (2, 1), (3, 1)] - assert_equal(x, x_) + assert x == x_ def test_digraph_orientation_invalid(self): G = nx.DiGraph(self.edges) @@ -47,35 +47,35 @@ class TestEdgeBFS(object): G = nx.DiGraph(self.edges) x = list(edge_bfs(G, self.nodes, orientation=None)) x_ = [(0, 1), (1, 0), (2, 0), (2, 1), (3, 1)] - assert_equal(x, x_) + assert x == x_ def test_digraph_orientation_original(self): G = nx.DiGraph(self.edges) x = list(edge_bfs(G, self.nodes, orientation='original')) x_ = [(0, 1, FORWARD), (1, 0, FORWARD), (2, 0, FORWARD), (2, 1, FORWARD), (3, 1, FORWARD)] - assert_equal(x, x_) + assert x == x_ def test_digraph2(self): G = nx.DiGraph() nx.add_path(G, range(4)) x = list(edge_bfs(G, [0])) x_ = [(0, 1), (1, 2), (2, 3)] - assert_equal(x, x_) + assert x == x_ def test_digraph_rev(self): G = nx.DiGraph(self.edges) x = list(edge_bfs(G, self.nodes, orientation='reverse')) x_ = [(1, 0, REVERSE), (2, 0, REVERSE), (0, 1, REVERSE), (2, 1, REVERSE), (3, 1, REVERSE)] - assert_equal(x, x_) + assert x == x_ def test_digraph_rev2(self): G = nx.DiGraph() nx.add_path(G, range(4)) x = list(edge_bfs(G, [3], orientation='reverse')) x_ = [(2, 3, REVERSE), (1, 2, REVERSE), (0, 1, REVERSE)] - assert_equal(x, x_) + assert x == x_ def test_multigraph(self): G = nx.MultiGraph(self.edges) @@ -87,13 +87,13 @@ class TestEdgeBFS(object): # But note, the edges (1,2,0) and (1,3,0) always follow the (0,1,k) # edges. So the algorithm only guarantees a partial order. A total # order is guaranteed only if the graph data structures are ordered. - assert_equal(x, x_) + assert x == x_ def test_multidigraph(self): G = nx.MultiDiGraph(self.edges) x = list(edge_bfs(G, self.nodes)) x_ = [(0, 1, 0), (1, 0, 0), (1, 0, 1), (2, 0, 0), (2, 1, 0), (3, 1, 0)] - assert_equal(x, x_) + assert x == x_ def test_multidigraph_rev(self): G = nx.MultiDiGraph(self.edges) @@ -104,21 +104,21 @@ class TestEdgeBFS(object): (0, 1, 0, REVERSE), (2, 1, 0, REVERSE), (3, 1, 0, REVERSE)] - assert_equal(x, x_) + assert x == x_ def test_digraph_ignore(self): G = nx.DiGraph(self.edges) x = list(edge_bfs(G, self.nodes, orientation='ignore')) x_ = [(0, 1, FORWARD), (1, 0, REVERSE), (2, 0, REVERSE), (2, 1, REVERSE), (3, 1, REVERSE)] - assert_equal(x, x_) + assert x == x_ def test_digraph_ignore2(self): G = nx.DiGraph() nx.add_path(G, range(4)) x = list(edge_bfs(G, [0], orientation='ignore')) x_ = [(0, 1, FORWARD), (1, 2, FORWARD), (2, 3, FORWARD)] - assert_equal(x, x_) + assert x == x_ def test_multidigraph_ignore(self): G = nx.MultiDiGraph(self.edges) @@ -127,4 +127,4 @@ class TestEdgeBFS(object): (1, 0, 1, REVERSE), (2, 0, 0, REVERSE), (2, 1, 0, REVERSE), (3, 1, 0, REVERSE), ] - assert_equal(x, x_) + assert x == x_ diff --git a/networkx/algorithms/traversal/tests/test_edgedfs.py b/networkx/algorithms/traversal/tests/test_edgedfs.py index 343b997b..fdd9fec7 100644 --- a/networkx/algorithms/traversal/tests/test_edgedfs.py +++ b/networkx/algorithms/traversal/tests/test_edgedfs.py @@ -27,19 +27,19 @@ class TestEdgeDFS(object): def test_empty(self): G = nx.Graph() edges = list(edge_dfs(G)) - assert_equal(edges, []) + assert edges == [] def test_graph(self): G = nx.Graph(self.edges) x = list(edge_dfs(G, self.nodes)) x_ = [(0, 1), (1, 2), (1, 3)] - assert_equal(x, x_) + assert x == x_ def test_digraph(self): G = nx.DiGraph(self.edges) x = list(edge_dfs(G, self.nodes)) x_ = [(0, 1), (1, 0), (2, 1), (3, 1)] - assert_equal(x, x_) + assert x == x_ def test_digraph_orientation_invalid(self): G = nx.DiGraph(self.edges) @@ -50,35 +50,35 @@ class TestEdgeDFS(object): G = nx.DiGraph(self.edges) x = list(edge_dfs(G, self.nodes, orientation=None)) x_ = [(0, 1), (1, 0), (2, 1), (3, 1)] - assert_equal(x, x_) + assert x == x_ def test_digraph_orientation_original(self): G = nx.DiGraph(self.edges) x = list(edge_dfs(G, self.nodes, orientation='original')) x_ = [(0, 1, FORWARD), (1, 0, FORWARD), (2, 1, FORWARD), (3, 1, FORWARD)] - assert_equal(x, x_) + assert x == x_ def test_digraph2(self): G = nx.DiGraph() nx.add_path(G, range(4)) x = list(edge_dfs(G, [0])) x_ = [(0, 1), (1, 2), (2, 3)] - assert_equal(x, x_) + assert x == x_ def test_digraph_rev(self): G = nx.DiGraph(self.edges) x = list(edge_dfs(G, self.nodes, orientation='reverse')) x_ = [(1, 0, REVERSE), (0, 1, REVERSE), (2, 1, REVERSE), (3, 1, REVERSE)] - assert_equal(x, x_) + assert x == x_ def test_digraph_rev2(self): G = nx.DiGraph() nx.add_path(G, range(4)) x = list(edge_dfs(G, [3], orientation='reverse')) x_ = [(2, 3, REVERSE), (1, 2, REVERSE), (0, 1, REVERSE)] - assert_equal(x, x_) + assert x == x_ def test_multigraph(self): G = nx.MultiGraph(self.edges) @@ -90,13 +90,13 @@ class TestEdgeDFS(object): # But note, the edges (1,2,0) and (1,3,0) always follow the (0,1,k) # edges. So the algorithm only guarantees a partial order. A total # order is guaranteed only if the graph data structures are ordered. - assert_equal(x, x_) + assert x == x_ def test_multidigraph(self): G = nx.MultiDiGraph(self.edges) x = list(edge_dfs(G, self.nodes)) x_ = [(0, 1, 0), (1, 0, 0), (1, 0, 1), (2, 1, 0), (3, 1, 0)] - assert_equal(x, x_) + assert x == x_ def test_multidigraph_rev(self): G = nx.MultiDiGraph(self.edges) @@ -106,21 +106,21 @@ class TestEdgeDFS(object): (1, 0, 1, REVERSE), (2, 1, 0, REVERSE), (3, 1, 0, REVERSE)] - assert_equal(x, x_) + assert x == x_ def test_digraph_ignore(self): G = nx.DiGraph(self.edges) x = list(edge_dfs(G, self.nodes, orientation='ignore')) x_ = [(0, 1, FORWARD), (1, 0, FORWARD), (2, 1, REVERSE), (3, 1, REVERSE)] - assert_equal(x, x_) + assert x == x_ def test_digraph_ignore2(self): G = nx.DiGraph() nx.add_path(G, range(4)) x = list(edge_dfs(G, [0], orientation='ignore')) x_ = [(0, 1, FORWARD), (1, 2, FORWARD), (2, 3, FORWARD)] - assert_equal(x, x_) + assert x == x_ def test_multidigraph_ignore(self): G = nx.MultiDiGraph(self.edges) @@ -128,4 +128,4 @@ class TestEdgeDFS(object): x_ = [(0, 1, 0, FORWARD), (1, 0, 0, FORWARD), (1, 0, 1, REVERSE), (2, 1, 0, REVERSE), (3, 1, 0, REVERSE)] - assert_equal(x, x_) + assert x == x_ diff --git a/networkx/algorithms/tree/tests/test_branchings.py b/networkx/algorithms/tree/tests/test_branchings.py index fe130773..d22eba6e 100644 --- a/networkx/algorithms/tree/tests/test_branchings.py +++ b/networkx/algorithms/tree/tests/test_branchings.py @@ -112,7 +112,7 @@ def sorted_edges(G, attr='weight', default=1): def assert_equal_branchings(G1, G2, attr='weight', default=1): edges1 = list(G1.edges(data=True)) edges2 = list(G2.edges(data=True)) - assert_equal(len(edges1), len(edges2)) + assert len(edges1) == len(edges2) # Grab the weights only. e1 = sorted_edges(G1, attr, default) @@ -124,7 +124,7 @@ def assert_equal_branchings(G1, G2, attr='weight', default=1): print for a, b in zip(e1, e2): - assert_equal(a[:2], b[:2]) + assert a[:2] == b[:2] np.testing.assert_almost_equal(a[2], b[2]) @@ -132,38 +132,38 @@ def assert_equal_branchings(G1, G2, attr='weight', default=1): def test_optimal_branching1(): G = build_branching(optimal_arborescence_1) - assert_true(recognition.is_arborescence(G), True) - assert_equal(branchings.branching_weight(G), 131) + assert recognition.is_arborescence(G), True + assert branchings.branching_weight(G) == 131 def test_optimal_branching2a(): G = build_branching(optimal_branching_2a) - assert_true(recognition.is_arborescence(G), True) - assert_equal(branchings.branching_weight(G), 53) + assert recognition.is_arborescence(G), True + assert branchings.branching_weight(G) == 53 def test_optimal_branching2b(): G = build_branching(optimal_branching_2b) - assert_true(recognition.is_arborescence(G), True) - assert_equal(branchings.branching_weight(G), 53) + assert recognition.is_arborescence(G), True + assert branchings.branching_weight(G) == 53 def test_optimal_arborescence2(): G = build_branching(optimal_arborescence_2) - assert_true(recognition.is_arborescence(G), True) - assert_equal(branchings.branching_weight(G), 51) + assert recognition.is_arborescence(G), True + assert branchings.branching_weight(G) == 51 def test_greedy_suboptimal_branching1a(): G = build_branching(greedy_subopt_branching_1a) - assert_true(recognition.is_arborescence(G), True) - assert_equal(branchings.branching_weight(G), 128) + assert recognition.is_arborescence(G), True + assert branchings.branching_weight(G) == 128 def test_greedy_suboptimal_branching1b(): G = build_branching(greedy_subopt_branching_1b) - assert_true(recognition.is_arborescence(G), True) - assert_equal(branchings.branching_weight(G), 127) + assert recognition.is_arborescence(G), True + assert branchings.branching_weight(G) == 127 def test_greedy_max1(): @@ -302,9 +302,9 @@ def test_mst(): edges = [(set([0, 1]), 7), (set([0, 3]), 5), (set([3, 5]), 6), (set([1, 4]), 7), (set([4, 2]), 5), (set([4, 6]), 9)] - assert_equal(x.number_of_edges(), len(edges)) + assert x.number_of_edges() == len(edges) for u, v, d in x.edges(data=True): - assert_true((set([u, v]), d['weight']) in edges) + assert (set([u, v]), d['weight']) in edges def test_mixed_nodetypes(): @@ -349,8 +349,8 @@ def test_edge_attribute_preservation_normal_graph(): ed = branchings.Edmonds(G) B = ed.find_optimum('weight', preserve_attrs=True, seed=1) - assert_equal(B[0][1]['otherattr'], 1) - assert_equal(B[0][1]['otherattr2'], 3) + assert B[0][1]['otherattr'] == 1 + assert B[0][1]['otherattr2'] == 3 def test_edge_attribute_preservation_multigraph(): @@ -367,8 +367,8 @@ def test_edge_attribute_preservation_multigraph(): ed = branchings.Edmonds(G) B = ed.find_optimum('weight', preserve_attrs=True) - assert_equal(B[0][1][0]['otherattr'], 1) - assert_equal(B[0][1][0]['otherattr2'], 3) + assert B[0][1][0]['otherattr'] == 1 + assert B[0][1][0]['otherattr2'] == 3 def test_edge_attribute_discard(): diff --git a/networkx/algorithms/tree/tests/test_coding.py b/networkx/algorithms/tree/tests/test_coding.py index 2e5e8a54..25fe7644 100644 --- a/networkx/algorithms/tree/tests/test_coding.py +++ b/networkx/algorithms/tree/tests/test_coding.py @@ -51,7 +51,7 @@ class TestPruferSequence(object): # Example from Wikipedia. tree = nx.Graph([(0, 3), (1, 3), (2, 3), (3, 4), (4, 5)]) sequence = nx.to_prufer_sequence(tree) - assert_equal(sequence, [3, 3, 3, 4]) + assert sequence == [3, 3, 3, 4] def test_decoding(self): """Tests for decoding a tree from a Prüfer sequence.""" @@ -81,7 +81,7 @@ class TestPruferSequence(object): for seq in product(range(4), repeat=2): seq2 = nx.to_prufer_sequence(nx.from_prufer_sequence(seq)) - assert_equal(list(seq), seq2) + assert list(seq) == seq2 class TestNestedTuple(object): @@ -113,13 +113,13 @@ class TestNestedTuple(object): root = 0 actual = nx.to_nested_tuple(T, root, canonical_form=True) expected = ((), ((), ()), ((), ())) - assert_equal(actual, expected) + assert actual == expected def test_decoding(self): balanced = (((), ()), ((), ())) expected = nx.full_rary_tree(2, 2 ** 3 - 1) actual = nx.from_nested_tuple(balanced) - assert_true(nx.is_isomorphic(expected, actual)) + assert nx.is_isomorphic(expected, actual) def test_sensible_relabeling(self): balanced = (((), ()), ((), ())) diff --git a/networkx/algorithms/tree/tests/test_mst.py b/networkx/algorithms/tree/tests/test_mst.py index 642ce362..803f9c7b 100644 --- a/networkx/algorithms/tree/tests/test_mst.py +++ b/networkx/algorithms/tree/tests/test_mst.py @@ -152,7 +152,7 @@ class MinimumSpanningTreeTestBase(object): G = nx.empty_graph(3) T = nx.minimum_spanning_tree(G, algorithm=self.algo) assert_nodes_equal(sorted(T), list(range(3))) - assert_equal(T.number_of_edges(), 0) + assert T.number_of_edges() == 0 def test_attributes(self): G = nx.Graph() @@ -161,10 +161,10 @@ class MinimumSpanningTreeTestBase(object): G.add_edge(1, 3, weight=10, color='blue', distance=1) G.graph['foo'] = 'bar' T = nx.minimum_spanning_tree(G, algorithm=self.algo) - assert_equal(T.graph, G.graph) + assert T.graph == G.graph assert_nodes_equal(T, G) for u, v in T.edges(): - assert_equal(T.adj[u][v], G.adj[u][v]) + assert T.adj[u][v] == G.adj[u][v] def test_weight_attribute(self): G = nx.Graph() diff --git a/networkx/algorithms/tree/tests/test_operations.py b/networkx/algorithms/tree/tests/test_operations.py index 3d99835a..c3385e59 100644 --- a/networkx/algorithms/tree/tests/test_operations.py +++ b/networkx/algorithms/tree/tests/test_operations.py @@ -26,8 +26,8 @@ class TestJoin(object): """ T = nx.join([]) - assert_equal(len(T), 1) - assert_equal(T.number_of_edges(), 0) + assert len(T) == 1 + assert T.number_of_edges() == 0 def test_single(self): """Tests that joining just one tree yields a tree with one more @@ -45,4 +45,4 @@ class TestJoin(object): trees = [(nx.full_rary_tree(2, 2 ** 2 - 1), 0) for i in range(2)] actual = nx.join(trees) expected = nx.full_rary_tree(2, 2 ** 3 - 1) - assert_true(nx.is_isomorphic(actual, expected)) + assert nx.is_isomorphic(actual, expected) diff --git a/networkx/algorithms/tree/tests/test_recognition.py b/networkx/algorithms/tree/tests/test_recognition.py index 574a9362..2f7f14a8 100644 --- a/networkx/algorithms/tree/tests/test_recognition.py +++ b/networkx/algorithms/tree/tests/test_recognition.py @@ -56,26 +56,26 @@ class TestTreeRecognition(object): nx.is_forest(self.multigraph()) def test_is_tree(self): - assert_true(nx.is_tree(self.T2)) - assert_true(nx.is_tree(self.T3)) - assert_true(nx.is_tree(self.T5)) + assert nx.is_tree(self.T2) + assert nx.is_tree(self.T3) + assert nx.is_tree(self.T5) def test_is_not_tree(self): - assert_false(nx.is_tree(self.N4)) - assert_false(nx.is_tree(self.N5)) - assert_false(nx.is_tree(self.N6)) + assert not nx.is_tree(self.N4) + assert not nx.is_tree(self.N5) + assert not nx.is_tree(self.N6) def test_is_forest(self): - assert_true(nx.is_forest(self.T2)) - assert_true(nx.is_forest(self.T3)) - assert_true(nx.is_forest(self.T5)) - assert_true(nx.is_forest(self.F1)) - assert_true(nx.is_forest(self.N5)) + assert nx.is_forest(self.T2) + assert nx.is_forest(self.T3) + assert nx.is_forest(self.T5) + assert nx.is_forest(self.F1) + assert nx.is_forest(self.N5) def test_is_not_forest(self): - assert_false(nx.is_forest(self.N4)) - assert_false(nx.is_forest(self.N6)) - assert_false(nx.is_forest(self.NF1)) + assert not nx.is_forest(self.N4) + assert not nx.is_forest(self.N6) + assert not nx.is_forest(self.NF1) class TestDirectedTreeRecognition(TestTreeRecognition): @@ -87,39 +87,39 @@ def test_disconnected_graph(): # https://github.com/networkx/networkx/issues/1144 G = nx.Graph() G.add_edges_from([(0, 1), (1, 2), (2, 0), (3, 4)]) - assert_false(nx.is_tree(G)) + assert not nx.is_tree(G) G = nx.DiGraph() G.add_edges_from([(0, 1), (1, 2), (2, 0), (3, 4)]) - assert_false(nx.is_tree(G)) + assert not nx.is_tree(G) def test_dag_nontree(): G = nx.DiGraph() G.add_edges_from([(0, 1), (0, 2), (1, 2)]) - assert_false(nx.is_tree(G)) - assert_true(nx.is_directed_acyclic_graph(G)) + assert not nx.is_tree(G) + assert nx.is_directed_acyclic_graph(G) def test_multicycle(): G = nx.MultiDiGraph() G.add_edges_from([(0, 1), (0, 1)]) - assert_false(nx.is_tree(G)) - assert_true(nx.is_directed_acyclic_graph(G)) + assert not nx.is_tree(G) + assert nx.is_directed_acyclic_graph(G) def test_emptybranch(): G = nx.DiGraph() G.add_nodes_from(range(10)) - assert_true(nx.is_branching(G)) - assert_false(nx.is_arborescence(G)) + assert nx.is_branching(G) + assert not nx.is_arborescence(G) def test_path(): G = nx.DiGraph() nx.add_path(G, range(5)) - assert_true(nx.is_branching(G)) - assert_true(nx.is_arborescence(G)) + assert nx.is_branching(G) + assert nx.is_arborescence(G) def test_notbranching1(): @@ -127,8 +127,8 @@ def test_notbranching1(): G = nx.MultiDiGraph() G.add_nodes_from(range(10)) G.add_edges_from([(0, 1), (1, 0)]) - assert_false(nx.is_branching(G)) - assert_false(nx.is_arborescence(G)) + assert not nx.is_branching(G) + assert not nx.is_arborescence(G) def test_notbranching2(): @@ -136,8 +136,8 @@ def test_notbranching2(): G = nx.MultiDiGraph() G.add_nodes_from(range(10)) G.add_edges_from([(0, 1), (0, 2), (3, 2)]) - assert_false(nx.is_branching(G)) - assert_false(nx.is_arborescence(G)) + assert not nx.is_branching(G) + assert not nx.is_arborescence(G) def test_notarborescence1(): @@ -145,8 +145,8 @@ def test_notarborescence1(): G = nx.MultiDiGraph() G.add_nodes_from(range(10)) G.add_edges_from([(0, 1), (0, 2), (1, 3), (5, 6)]) - assert_true(nx.is_branching(G)) - assert_false(nx.is_arborescence(G)) + assert nx.is_branching(G) + assert not nx.is_arborescence(G) def test_notarborescence2(): @@ -154,5 +154,5 @@ def test_notarborescence2(): G = nx.MultiDiGraph() nx.add_path(G, range(5)) G.add_edge(6, 4) - assert_false(nx.is_branching(G)) - assert_false(nx.is_arborescence(G)) + assert not nx.is_branching(G) + assert not nx.is_arborescence(G) |