Fixed non-working dummy reader to make publish_from_doctree work again.
[docutils.git] / test / alltests.py
blob9c5d8b0aa7e331fadca5255527418f584a9a6ffc
1 #!/bin/sh
2 ''''exec python -u "$0" "$@" #'''
4 # Author: David Goodger
5 # Contact: goodger@users.sourceforge.net
6 # Revision: $Revision$
7 # Date: $Date$
8 # Copyright: This module has been placed in the public domain.
10 __doc__ = \
11 """
12 All modules named 'test_*.py' in the current directory, and recursively in
13 subdirectories (packages) called 'test_*', are loaded and test suites within
14 are run.
15 """
17 import time
18 # Start point for actual elapsed time, including imports
19 # and setup outside of unittest.
20 start = time.time()
22 import sys
23 import os
24 from types import UnicodeType
25 import docutils
28 def new_exception_str(self):
29 for i in self.args:
30 if isinstance(i, UnicodeType):
31 raise RuntimeError('Error (unicode): %r' % (self.args,))
32 return old_exception_str(self)
34 old_exception_str = Exception.__str__
35 Exception.__str__ = new_exception_str
38 class Tee:
40 """Write to a file and a stream (default: stdout) simultaneously."""
42 def __init__(self, filename, stream=sys.__stdout__):
43 self.file = open(filename, 'w')
44 self.stream = stream
46 def write(self, string):
47 self.stream.write(string)
48 self.file.write(string)
50 def flush(self):
51 self.stream.flush()
52 self.file.flush()
55 def pformat(suite):
56 step = 4
57 suitestr = repr(suite).replace('=[<', '=[\n<').replace(', ', ',\n')
58 indent = 0
59 output = []
60 for line in suitestr.splitlines():
61 output.append(' ' * indent + line)
62 if line[-1:] == '[':
63 indent += step
64 else:
65 if line [-5:] == ']>]>,':
66 indent -= step * 2
67 elif line[-3:] == ']>,':
68 indent -= step
69 return '\n'.join(output)
72 # must redirect stderr *before* first import of unittest
73 sys.stdout = sys.stderr = Tee('alltests.out')
75 import package_unittest
77 print ('Testing Docutils %s [%s] with Python %s on %s at %s'
78 % (docutils.__version__, docutils.__version_details__,
79 sys.version.split()[0],
80 time.strftime('%Y-%m-%d'), time.strftime('%H:%M:%S')))
81 sys.stdout.flush()
83 path, script = os.path.split(sys.argv[0])
84 suite = package_unittest.loadTestModules(path, 'test_', packages=1)
85 sys.stdout.flush()
87 package_unittest.main(suite)
88 #if package_unittest.verbosity > 1:
89 # print >>sys.stderr, pformat(suite) # check the test suite
90 finish = time.time()
92 print 'Elapsed time: %.3f seconds' % (finish - start)