1
2
3 import glob
4 import os
5 import sys
6 import doctest
7 import unittest
8
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
25
26
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
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
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
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
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