Example #1
0
 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
Example #2
0
def interact():
    ns = {}
    while 1:
        try:
            code = collectForm()
            sub2py.aexec(code, ns=ns)
        except EOFError:
            sys.exit("\nBye!")
        except:
            traceback.print_exc()
Example #3
0
 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)
Example #4
0
 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)
Example #5
0
 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)
Example #6
0
 def testSet(self):
     ns = {}
     aexec([(I('set'), I('foo'), 1)], ns=ns)
     self.assert_(ns.has_key('foo'))
     self.assertEquals(ns['foo'], 1)
Example #7
0
 def testImport(self):
     ns = {}
     aexec([(I('import'), I('os'))], ns=ns)
     self.assertEquals(ns['os'], os)