comparison tests/test.py @ 15:cf920f85fb98

more stubbing
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 24 Nov 2011 12:58:32 -0800
parents c3c65fb15ab3
children d3e3a506dd29
comparison
equal deleted inserted replaced
14:ed9d64d1fd32 15:cf920f85fb98
4 doctest runner 4 doctest runner
5 """ 5 """
6 6
7 import doctest 7 import doctest
8 import os 8 import os
9 import shutil
9 import sys 10 import sys
11 import tempfile
10 from optparse import OptionParser 12 from optparse import OptionParser
11
12 13
13 def run_tests(raise_on_error=False, report_first=False): 14 def run_tests(raise_on_error=False, report_first=False):
14 15
15 # add results here 16 # add results here
16 results = {} 17 results = {}
26 tests = [ test for test in os.listdir(directory) 27 tests = [ test for test in os.listdir(directory)
27 if test.endswith('.txt') ] 28 if test.endswith('.txt') ]
28 29
29 # run the tests 30 # run the tests
30 for test in tests: 31 for test in tests:
32
33 # make a temporary directory for example files
34 tempdir = tempfile.mktemp()
35 shutil.copytree(os.path.join(directory, 'example'), tempdir)
36 doctest_args['extraglobs']['directory'] = tempdir
37
31 try: 38 try:
32 results[test] = doctest.testfile(test, **doctest_args) 39 results[test] = doctest.testfile(test, **doctest_args)
33 except doctest.DocTestFailure, failure: 40 except doctest.DocTestFailure, failure:
34 raise 41 raise
35 except doctest.UnexpectedException, failure: 42 except doctest.UnexpectedException, failure:
36 raise failure.exc_info[0], failure.exc_info[1], failure.exc_info[2] 43 raise failure.exc_info[0], failure.exc_info[1], failure.exc_info[2]
44 finally:
45 # cleanup
46 shutil.rmtree(tempdir)
37 47
38 return results 48 return results
39 49
40 def main(args=sys.argv[1:]): 50 def main(args=sys.argv[1:]):
41 51