def test_exceptions(self): if len(allGenerators) == 0: raise Exception("Need at least one generator from test_exceptions") stateful = [raise_generator, return_generator] ch = CodeHolder() curTest = 0 # a counter so that trace backs have unique method names and we check left over info properly for depth in range(3): def do_generate(test): global loopCnt, yieldState, finallyCnt, tryOrCatchCount, uniqueCount yieldState += 1 if test in (for_loop_maker, while_loop_maker): loopCnt += 1 if test in (try_finally_maker1, try_finally_maker2, try_finally_maker3): finallyCnt += 1 if test in (try_except_maker1, try_except_maker2, try_except_maker3, try_else_maker1): tryOrCatchCount += 1 genSet = [ for_loop_maker, while_loop_maker, try_except_maker1, try_except_maker2, try_except_maker3, try_finally_maker1, try_finally_maker2, try_finally_maker3, try_else_maker1, if_false_generator, if_true_generator, define_maker, ] if loopCnt > 0: if finallyCnt > 0: genSet = genSet + [break_maker] else: genSet = genSet + [break_maker, continue_maker] if ch.depth > depth: yield test(ch, pass_generator(ch)) else: for testCase in genSet: ch.depth += 1 x = do_generate(testCase) for body in x: yield test(ch, body) ch.depth -= 1 for statefulGuy in stateful: yield test(ch, statefulGuy(ch, yieldState)) if finallyCnt == 0: yield test(ch, yield_generator(ch, yieldState)) if test in (for_loop_maker, while_loop_maker): loopCnt -= 1 if test in (try_finally_maker1, try_finally_maker2, try_finally_maker3): finallyCnt -= 1 if test in (try_except_maker1, try_except_maker2, try_except_maker3, try_else_maker1): tryOrCatchCount -= 1 for testCase in allGenerators: x = do_generate(testCase) for y in x: curTest += 1 if curTest in knownFailures: continue if 'IRONPYTHON_RUNSLOWTESTS' in os.environ: uniqueCount = 0 # run without a function y.code.text = '' y.generate(0) y.code.text += 'print log' d = {'log': '', 'dump_exc_info': dump_exc_info} try: #printwith(y.code.text) exec(y.code.text, d, d) except Exception as e: printwith('same', sys.exc_info()[0]) uniqueCount = 0 # run within a function y.code.text = 'def test' + str(curTest) + '():\n' y.code.text += ' global log\n' y.generate() d = {'log': '', 'dump_exc_info': dump_exc_info} try: printwith(y.code.text) exec(y.code.text, d, d) except SyntaxError: printwith("same", sys.exc_info()[0]) continue retval = None try: retval = d['test' + str(curTest)]() if isinstance(retval, generator_type): for it in retval: printwith('same', it) else: printwith('same', retval) except: printwith("same", sys.exc_info()[0]) if isinstance(retval, generator_type): retval.close() printwith('same', d['log'])
def test_exceptions(self): if len(allGenerators)==0: raise Exception("Need at least one generator from test_exceptions") stateful = [raise_generator, return_generator] ch = CodeHolder() curTest = 0 # a counter so that trace backs have unique method names and we check left over info properly for depth in xrange(3): def do_generate(test): global loopCnt, yieldState, finallyCnt, tryOrCatchCount, uniqueCount yieldState += 1 if test in (for_loop_maker, while_loop_maker): loopCnt += 1 if test in (try_finally_maker1, try_finally_maker2, try_finally_maker3): finallyCnt += 1 if test in (try_except_maker1, try_except_maker2, try_except_maker3, try_else_maker1): tryOrCatchCount += 1 genSet = [ for_loop_maker, while_loop_maker, try_except_maker1, try_except_maker2, try_except_maker3, try_finally_maker1, try_finally_maker2, try_finally_maker3, try_else_maker1, if_false_generator, if_true_generator, define_maker, ] if loopCnt > 0: if finallyCnt > 0: genSet = genSet + [break_maker] else: genSet = genSet + [break_maker, continue_maker] if ch.depth > depth: yield test(ch, pass_generator(ch)) else: for testCase in genSet: ch.depth += 1 x = do_generate(testCase) for body in x: yield test(ch, body) ch.depth -= 1 for statefulGuy in stateful: yield test(ch, statefulGuy(ch, yieldState)) if finallyCnt == 0: yield test(ch, yield_generator(ch, yieldState)) if test in (for_loop_maker, while_loop_maker): loopCnt -= 1 if test in (try_finally_maker1, try_finally_maker2, try_finally_maker3): finallyCnt -= 1 if test in (try_except_maker1, try_except_maker2, try_except_maker3, try_else_maker1): tryOrCatchCount -= 1 for testCase in allGenerators: x = do_generate(testCase) for y in x: curTest += 1 if curTest in knownFailures: continue if 'IRONPYTHON_RUNSLOWTESTS' in nt.environ: uniqueCount = 0 # run without a function y.code.text = '' y.generate(0) y.code.text += 'print log' d = {'log': '', 'dump_exc_info': dump_exc_info} try: #printwith(y.code.text) exec y.code.text in d, d except Exception, e: printwith('same', sys.exc_type) uniqueCount = 0 # run within a function y.code.text = 'def test' + str(curTest) + '():\n' y.code.text += ' global log\n' y.generate() d = {'log' : '', 'dump_exc_info': dump_exc_info} try: printwith(y.code.text) exec y.code.text in d, d except SyntaxError: printwith("same", sys.exc_type) continue retval = None try: retval = d['test' + str(curTest)]() if isinstance(retval, generator_type): for it in retval: printwith('same', it) else: printwith('same', retval) except: printwith("same", sys.exc_type) if isinstance(retval, generator_type): retval.close() printwith('same', d['log'])