def execButNoTest(name='__main__'): module = sys.modules.get(name) # the syntax of doctest changed substantially between Python 2.3 and 2.4 # <http://sourceforge.net/tracker/index.php?func=detail&aid=1120348&group_id=118428&atid=681141> if sys.version_info >= (2, 4): tests = doctest.DocTestFinder().find(module) tests = [doctest.script_from_examples(t.docstring) for t in tests] # Python 2.4 returns comments, too, and doesn't always end in a \n, # which chokes exec/compile. Arguably a bug in Python. # <http://sourceforge.net/tracker/index.php?func=detail&aid=1172785&group_id=5470&atid=105470> tests = [t + '\n' for t in tests] else: tests = [ doc for (dummy, doc, dummy, dummy) in doctest._find_tests(module, "") ] tests = [doctest._extract_examples(t) for t in tests] tests = [ "\n".join([source for source, expect, dummy in t]) for t in tests ] if not tests: raise ValueError("no tests found") for t in tests: exec t
def execButNoTest(name='__main__'): module = sys.modules.get(name) # the syntax of doctest changed substantially between Python 2.3 and 2.4 # <http://sourceforge.net/tracker/index.php?func=detail&aid=1120348&group_id=118428&atid=681141> if sys.version_info >= (2, 4): tests = doctest.DocTestFinder().find(module) tests = [doctest.script_from_examples(t.docstring) for t in tests] # Python 2.4 returns comments, too, and doesn't always end in a \n, # which chokes exec/compile. Arguably a bug in Python. # <http://sourceforge.net/tracker/index.php?func=detail&aid=1172785&group_id=5470&atid=105470> tests = [t + '\n' for t in tests] else: tests = [doc for (dummy, doc, dummy, dummy) in doctest._find_tests(module, "")] tests = [doctest._extract_examples(t) for t in tests] tests = ["\n".join([source for source, expect, dummy in t]) for t in tests] if not tests: raise ValueError("no tests found") for t in tests: exec t
True,False = 1==1,1==0 SEPARATOR = """ ========== %r ========== """ LASTLINE = "Tests completed." BUFFERFILE = "buffer-basetests.txt" EXPECTEDFILE = "expected-basetests.txt" INPUTSCRIPT = "input-basetexts.py" TESTS = open('btrun.py', 'r').read() if hasattr(doctest, '_extract_examples'): tests = doctest._extract_examples(TESTS) else: examples = doctest.DocTestParser().get_examples(TESTS) tests = [(example.source, example.want, example.lineno) for example in examples] # --- def main(quiet=False): PRELUDE = '' for inp, outp, line in tests[:]: if not outp: PRELUDE += inp + '\n' tests.remove((inp, outp, line)) random.shuffle(tests) # first run all tests in any order tests_again = tests[:]
import sys, os, random, doctest, cStringIO True, False = 1 == 1, 1 == 0 SEPARATOR = """ ========== %r ========== """ LASTLINE = "Tests completed." BUFFERFILE = "buffer-basetests.txt" EXPECTEDFILE = "expected-basetests.txt" INPUTSCRIPT = "input-basetexts.py" TESTS = open('btrun.py', 'r').read() if hasattr(doctest, '_extract_examples'): tests = doctest._extract_examples(TESTS) else: examples = doctest.DocTestParser().get_examples(TESTS) tests = [(example.source, example.want, example.lineno) for example in examples] # --- def main(quiet=False): PRELUDE = '' for inp, outp, line in tests[:]: if not outp: PRELUDE += inp + '\n' tests.remove((inp, outp, line)) random.shuffle(tests) # first run all tests in any order