def testPrint(self): io = StringIO() oldout = sys.stdout sys.stdout = io try: aexec([(I('println'), "hello")]) #if this fails, you'll want to remove the sys.stdout munging code to debug finally: sys.stdout = oldout self.assertEquals(io.getvalue(), 'hello\n') #if this fails, you'll want to remove the sys.stdout munging code to debug
def interact(): ns = {} while 1: try: code = collectForm() sub2py.aexec(code, ns=ns) except EOFError: sys.exit("\nBye!") except: traceback.print_exc()
def testReturnExpression(self): raise unittest.SkipTest("Return-izing a function when the last thing isn't an expression is broken") ns = {} aexec([(I('def'), [I('foo')], "doc", [I('='), I('x'), 3])], ns=ns) self.assert_(ns.has_key('foo')) self.assertEquals(aeval((I('foo'),), ns=ns), 3)
def testDef(self): ns = {} aexec([(I('def'), [I('foo')], "doc", [I('return'), 3])], ns=ns) self.assert_(ns.has_key('foo')) self.assertEquals(aeval((I('foo'),), ns=ns), 3)
def testSyntaxy(self): self.assert_(aeval((I('=='), 4, 4))) ns = {} aexec([(I('='), I('foo'), 1)], ns=ns) self.assert_(ns.has_key('foo')) self.assertEquals(ns['foo'], 1)
def testSet(self): ns = {} aexec([(I('set'), I('foo'), 1)], ns=ns) self.assert_(ns.has_key('foo')) self.assertEquals(ns['foo'], 1)
def testImport(self): ns = {} aexec([(I('import'), I('os'))], ns=ns) self.assertEquals(ns['os'], os)