Mercurial > hg > simpypi
comparison tests/test.py @ 8:15c7171941ea
more stubbing for tests
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Tue, 28 Feb 2012 13:50:28 -0800 |
| parents | 232e67cac00c |
| children | 9879140a2026 |
comparison
equal
deleted
inserted
replaced
| 7:5ee4fe3decd9 | 8:15c7171941ea |
|---|---|
| 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 | 13 from paste.fixture import TestApp |
| 12 | 14 |
| 13 def run_tests(raise_on_error=False, report_first=False): | 15 def run_tests(raise_on_error=False, report_first=False): |
| 14 | 16 |
| 15 # add results here | 17 # add results here |
| 16 results = {} | 18 results = {} |
| 26 tests = [ test for test in os.listdir(directory) | 28 tests = [ test for test in os.listdir(directory) |
| 27 if test.endswith('.txt') ] | 29 if test.endswith('.txt') ] |
| 28 | 30 |
| 29 # run the tests | 31 # run the tests |
| 30 for test in tests: | 32 for test in tests: |
| 33 | |
| 34 # make a temporary directory | |
| 35 tmpdir = tempfile.mkdtemp() | |
| 36 doctest_args['extraglobs']['directory'] = tmpdir | |
| 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 if os.path.exists(tmpdir): | |
| 46 shutil.rmtree(tmpdir) | |
| 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 |
