def unitTesting(codeGen): # Create the class suite first = True testing = [] for test in self._inlineTests: if not first: testing.append( Schema.BlankLine() ) testing.append( Schema.BlankLine() ) testing.append( test._createTestClass( codeGen ) ) first = False testing.append( Schema.BlankLine() ) testing.append( Schema.BlankLine() ) for test in self._inlineTests: testAst = codeGen.embeddedValue( test ) testing.append( Schema.ExprStmt( expr=Schema.Call( target=Schema.AttributeRef( target=testAst, name='_registerTestClass' ), args=[ Schema.Load( name=test._className ) ] ) ) ) selfAST = codeGen.embeddedValue( self ) moduleAST = codeGen.embeddedValue( codeGen.module ) globalsAST = Schema.Call( target=Schema.Load( name='globals' ), args=[] ) localsAST = Schema.Call( target=Schema.Load( name='locals' ), args=[] ) testing.append( Schema.ExprStmt( expr=Schema.Call( target=Schema.AttributeRef( target=selfAST, name='runTests' ), args=[] ) ) ) testing.append( Schema.ExprStmt( expr=Schema.Call( target=Schema.AttributeRef( target=selfAST, name='_registerScope' ), args=[ moduleAST, globalsAST, localsAST ] ) ) ) return Schema.PythonSuite( suite=testing )
def _createMethodAST(self, codeGen): valueStmts, resultVarName = self._createValueStmtsAndResultVarName( codeGen ) JythonExceptionAST = codeGen.embeddedValue( JythonException ) sysAST = codeGen.embeddedValue( sys ) getCurrentExceptionCallAST = Schema.Call( target=Schema.AttributeRef( target=JythonExceptionAST, name='getCurrentException' ), args=[] ) getExcInfoTypeAST = Schema.Subscript( target=Schema.Call( target=Schema.AttributeRef( target=sysAST, name='exc_info' ), args=[] ), index=Schema.IntLiteral( format='decimal', numType='int', value='0' ) ) selfAST = codeGen.embeddedValue( self ) testValueAST = Schema.AttributeRef( target=selfAST, name='_testValue' ) kindExceptionAST = Schema.StringLiteral( format='ascii', quotation='single', value='exception' ) kindValueAST = Schema.StringLiteral( format='ascii', quotation='single', value='value' ) exceptStmts = [ Schema.ExprStmt( expr=Schema.Call( target=testValueAST, args=[ kindExceptionAST, getCurrentExceptionCallAST, getExcInfoTypeAST ] ) ) ] elseStmts = [ Schema.ExprStmt( expr=Schema.Call( target=testValueAST, args=[ kindValueAST, Schema.Load( name=resultVarName ) ] ) ) ] methodBody = [ Schema.TryStmt( suite=valueStmts, exceptBlocks=[ Schema.ExceptBlock( suite=exceptStmts ) ], elseSuite=elseStmts ) ] methodAST = Schema.DefStmt( name=self._methodName, decorators=[], params=[ Schema.SimpleParam( name='self' ) ], suite=methodBody ) return methodAST
def _exprModelAsStmts(exprModel): return [ Schema.ExprStmt( expr=exprModel ) ]