Skip to content

Commit 75ee7bb

Browse files
committed
Upgrade to support NetworkX 2.x, fix dependency versions, add test script
1 parent 9e8c4ca commit 75ee7bb

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

requirements.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# Dependencies
2-
networkx
3-
numpy
4-
scipy
2+
networkx == 2.*
3+
numpy == 1.*
4+
scipy == 1.*
55

66
# Optional dependency
77
matplotlib
88

99
# Development
1010
docutils
11-

setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
22

3-
virtualenv env
3+
python3 -m venv env
44
./env/bin/pip install --upgrade pip
55
./env/bin/pip install -r requirements.txt

test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
./env/bin/python3 -m unittest discover test/

test/test_graphpca.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
""" Unit tests for graphpca
44
"""
55

6+
import os
67
import unittest
78

89
import networkx as nx
@@ -12,6 +13,9 @@
1213
import graphpca
1314

1415

16+
def get_fixture_mat(filename):
17+
return scipy.io.loadmat(os.path.dirname(os.path.realpath(__file__)) + "/" + filename)
18+
1519
class TestGraphPCA(unittest.TestCase):
1620

1721
def test_returns_plausible_results(self):
@@ -25,8 +29,8 @@ def test_returns_plausible_results(self):
2529

2630
def test_ok_if_multiple_zero_eigens(self):
2731
g = nx.erdos_renyi_graph(100, 0.3)
28-
node = next(g.nodes_iter())
29-
for neighbor in g.neighbors(node):
32+
node = list(g.nodes)[0]
33+
for neighbor in list(g.neighbors(node)):
3034
g.remove_edge(node, neighbor)
3135
g_5 = graphpca.reduce_graph_efficiently(g, 5)
3236
self.assertEqual(len(g_5), 5)
@@ -51,7 +55,7 @@ def test_similar_output_to_naive_small(self):
5155
'Regular result:\n{}\nNaive result:\n{}\n'.format(G2, G2n))
5256

5357
def test_similar_output_to_naive_mat_3(self):
54-
mat = scipy.io.loadmat('bcspwr01.mat')
58+
mat = get_fixture_mat('bcspwr01.mat')
5559
# I love the UFSMC (https://www.cise.ufl.edu/research/sparse/matrices/)
5660
# but wow they really buried the matrix in this .mat
5761
A = mat['Problem'][0][0][1].todense()
@@ -76,7 +80,7 @@ def test_add_supernode_similar_output_to_naive_small(self):
7680
'Regular result:\n{}\nNaive result:\n{}\n'.format(G2, G2n))
7781

7882
def test_add_supernode_similar_output_to_naive_mat_3(self):
79-
mat = scipy.io.loadmat('bcspwr01.mat')
83+
mat = get_fixture_mat('bcspwr01.mat')
8084
A = mat['Problem'][0][0][1].todense()
8185
G = nx.from_numpy_matrix(A)
8286
G3 = graphpca.reduce_graph_efficiently(G, 3, add_supernode=True)

0 commit comments

Comments
 (0)