Package networkx :: Package tests :: Module test
[hide private]
[frames] | no frames]

Source Code for Module networkx.tests.test

 1  #!/usr/bin/env python 
 2   
 3  import glob 
 4  import os 
 5  import sys 
 6  import doctest 
 7  import unittest 
 8   
9 -def all():
10 try: 11 from pkg_resources import resource_filename, resource_listdir 12 tests=[resource_filename(__name__, t) 13 for t in resource_listdir("networkx",'tests') if t.endswith("txt")] 14 tests+=[resource_filename(__name__, 'generators/'+t) 15 for t in resource_listdir("networkx",'tests/generators') if t.endswith("txt")] 16 tests+=[resource_filename(__name__, 'readwrite/'+t) 17 for t in resource_listdir("networkx",'tests/readwrite') if t.endswith("txt")] 18 except: 19 import networkx 20 base=os.path.dirname(networkx.__file__)+"/tests/" 21 tests=glob.glob(base+"*.txt") 22 tests+=glob.glob(base+"generators/*.txt") 23 tests+=glob.glob(base+"readwrite/*.txt") 24 #tests+=glob.glob("drawing/*.txt") 25 26 # tests depending on numpy 27 try: 28 import numpy 29 except ImportError: 30 print "numpy not found: skipping tests of spectrum.py, threshold.py, convert.py (numpy)" 31 tests=[t for t in tests \ 32 if 'spectrum.txt' not in t \ 33 if 'threshold.txt' not in t\ 34 if 'convert_numpy.txt' not in t\ 35 ] 36 37 # tests depending on scipy 38 try: 39 import scipy 40 except ImportError: 41 print "scipy not found: skipping tests of convert.py (scipy)" 42 tests=[t for t in tests \ 43 if 'convert_scipy.txt' not in t\ 44 ] 45 # tests depending on yaml 46 try: 47 import yaml 48 except ImportError: 49 print "yaml not found: skipping tests of nx_yaml.py (yaml)" 50 tests=[t for t in tests \ 51 if 'nx_yaml.txt' not in t\ 52 ] 53 # tests depending on pyparsing 54 try: 55 import pyparsing 56 except ImportError: 57 print "pyparsing not found: skipping tests of gml.py" 58 tests=[t for t in tests \ 59 if 'gml.txt' not in t\ 60 ] 61 62 63 64 65 66 suite = unittest.TestSuite() 67 for t in tests: 68 s = doctest.DocFileSuite(t,module_relative=False) 69 suite.addTest(s) 70 return suite
71
72 -def run():
73 if sys.version_info[:2] < (2, 4): 74 print "Python version 2.4 or later required for tests (%d.%d detected)." % sys.version_info[:2] 75 sys.exit(-1) 76 runner = unittest.TextTestRunner() 77 runner.run(all())
78 79 80 if __name__ == "__main__": 81 try: 82 import networkx 83 except: 84 print "Can't import networkx module, not in path" 85 print sys.path 86 raise 87 88 run() 89