FIX quotehandling in inline literals (in work?).
[docutils.git] / test / alltests.py
blob8cacec5f269845a092cd715c36986ed572ac3204
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
24 class Tee:
26 """Write to a file and a stream (default: stdout) simultaneously."""
28 def __init__(self, filename, stream=sys.__stdout__):
29 self.file = open(filename, 'w')
30 self.stream = stream
32 def write(self, string):
33 self.stream.write(string)
34 self.file.write(string)
36 def flush(self):
37 self.stream.flush()
38 self.file.flush()
41 def pformat(suite):
42 step = 4
43 suitestr = repr(suite).replace('=[<', '=[\n<').replace(', ', ',\n')
44 indent = 0
45 output = []
46 for line in suitestr.splitlines():
47 output.append(' ' * indent + line)
48 if line[-1:] == '[':
49 indent += step
50 else:
51 if line [-5:] == ']>]>,':
52 indent -= step * 2
53 elif line[-3:] == ']>,':
54 indent -= step
55 return '\n'.join(output)
58 # must redirect stderr *before* first import of unittest
59 sys.stdout = sys.stderr = Tee('alltests.out')
61 import package_unittest
63 path, script = os.path.split(sys.argv[0])
64 suite = package_unittest.loadTestModules(path, 'test_', packages=1)
65 package_unittest.main(suite)
66 #if package_unittest.verbosity > 1:
67 # print >>sys.stderr, pformat(suite) # check the test suite
68 finish = time.time()
70 print 'Elapsed time: %.3f seconds' % (finish - start)