def test_bang_compile_exec(): scope = {'cut': cut} source = '''a = ['abc', 'def', 'ghi'] b = [] print('Test tokenizer !!') for i in range(3): b.append(str(a!2)) b.append('End') ''' code = bang_compile(source, '<test>', 'exec') if sys.version_info[0] > 2: exec(code, scope, scope) else: exec('exec code in scope, scope') assert 'a' in scope assert 'b' in scope assert scope['b'] == [ "['c', 'f', 'i'].", "['c', 'f', 'i'].", "['c', 'f', 'i'].", 'End']
def run(code): return eval(bang_compile(code, '<test>', 'eval'), globals())