33""" Unit tests for graphpca
44"""
55
6+ import os
67import unittest
78
89import networkx as nx
1213import graphpca
1314
1415
16+ def get_fixture_mat (filename ):
17+ return scipy .io .loadmat (os .path .dirname (os .path .realpath (__file__ )) + "/" + filename )
18+
1519class 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 {}\n Naive 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 {}\n Naive 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