Minor edit of inline markup documentation (no change of behaviour).
[docutils.git] / test / alltests.py
blob46b61223946620f6604852cacd40a42606cb7b3b
1 #!/bin/sh
2 ''''exec python -u "$0" "$@" #'''
4 # $Id$
5 # Author: David Goodger <goodger@python.org>
6 # Copyright: This module has been placed in the public domain.
8 __doc__ = \
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 DocutilsTestSupport # must be imported before docutils
23 import docutils
26 class Tee:
28 """Write to a file and a stream (default: stdout) simultaneously."""
30 def __init__(self, filename, stream=sys.__stdout__):
31 self.file = open(filename, 'w')
32 self.stream = stream
33 self.encoding = getattr(stream, 'encoding', None)
35 def write(self, string):
36 self.stream.write(string)
37 self.file.write(string)
39 def flush(self):
40 self.stream.flush()
41 self.file.flush()
44 def pformat(suite):
45 step = 4
46 suitestr = repr(suite).replace('=[<', '=[\n<').replace(', ', ',\n')
47 indent = 0
48 output = []
49 for line in suitestr.splitlines():
50 output.append(' ' * indent + line)
51 if line[-1:] == '[':
52 indent += step
53 else:
54 if line [-5:] == ']>]>,':
55 indent -= step * 2
56 elif line[-3:] == ']>,':
57 indent -= step
58 return '\n'.join(output)
60 def suite():
61 path, script = os.path.split(sys.argv[0])
62 suite = package_unittest.loadTestModules(DocutilsTestSupport.testroot,
63 'test_', packages=1)
64 sys.stdout.flush()
65 return suite
67 # must redirect stderr *before* first import of unittest
68 sys.stdout = sys.stderr = Tee('alltests.out')
70 import package_unittest
73 if __name__ == '__main__':
74 suite = suite()
75 print ('Testing Docutils %s [%s] with Python %s on %s at %s'
76 % (docutils.__version__, docutils.__version_details__,
77 sys.version.split()[0],
78 time.strftime('%Y-%m-%d'), time.strftime('%H:%M:%S')))
79 print 'Working directory: %s' % os.getcwd()
80 print 'Docutils package: %s' % os.path.dirname(docutils.__file__)
81 sys.stdout.flush()
82 result = package_unittest.main(suite)
83 #if package_unittest.verbosity > 1:
84 # print >>sys.stderr, pformat(suite) # check the test suite
85 finish = time.time()
86 print 'Elapsed time: %.3f seconds' % (finish - start)
87 sys.exit(not result.wasSuccessful())