Fixes in linepsacing doc.
[docutils.git] / test / alltests.py
blob26b8838d083b1c17501d4923f028e8f5cb203697
1 #!/usr/bin/env python
3 # Author: David Goodger
4 # Contact: goodger@users.sourceforge.net
5 # Revision: $Revision$
6 # Date: $Date$
7 # Copyright: This module has been placed in the public domain.
9 """
10 All modules named 'test_*.py' in the current directory, and recursively in
11 subdirectories (packages) called 'test_*', are loaded and test suites within
12 are run.
13 """
15 import time
16 # Start point for actual elapsed time, including imports
17 # and setup outside of unittest.
18 start = time.time()
20 import sys
21 import os
22 import docutils
25 class Tee:
27 """Write to a file and a stream (default: stdout) simultaneously."""
29 def __init__(self, filename, stream=sys.__stdout__):
30 self.file = open(filename, 'w')
31 self.stream = stream
33 def write(self, string):
34 self.stream.write(string)
35 self.file.write(string)
37 def flush(self):
38 self.stream.flush()
39 self.file.flush()
42 def pformat(suite):
43 step = 4
44 suitestr = repr(suite).replace('=[<', '=[\n<').replace(', ', ',\n')
45 indent = 0
46 output = []
47 for line in suitestr.splitlines():
48 output.append(' ' * indent + line)
49 if line[-1:] == '[':
50 indent += step
51 else:
52 if line [-5:] == ']>]>,':
53 indent -= step * 2
54 elif line[-3:] == ']>,':
55 indent -= step
56 return '\n'.join(output)
59 # must redirect stderr *before* first import of unittest
60 sys.stdout = sys.stderr = Tee('alltests.out')
62 import package_unittest
64 print ('Testing Docutils %s with Python %s'
65 % (docutils.__version__, sys.version.split()[0]))
67 path, script = os.path.split(sys.argv[0])
68 suite = package_unittest.loadTestModules(path, 'test_', packages=1)
69 package_unittest.main(suite)
70 #if package_unittest.verbosity > 1:
71 # print >>sys.stderr, pformat(suite) # check the test suite
72 finish = time.time()
74 print 'Elapsed time: %.3f seconds' % (finish - start)