def __py_execmodel__(self, codeGen): self._clear() prevTestingBlock = [ None ] # Use a guard to push self onto the TestingBlock stack def beginGuard(codeGen): prevTestingBlock[0] = AbstractInlineTest.__current_testing_block__ AbstractInlineTest.__current_testing_block__ = self def endGuard(codeGen): AbstractInlineTest.__current_testing_block__ = prevTestingBlock[0] mainContent = codeGen.guard( beginGuard, Schema.PythonSuite( suite=self._suite.model['suite'] ), endGuard ) # Defer the generation of the unit test class @codeGen.deferred 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 ) return Schema.PythonSuite( suite=[ mainContent, unitTesting ] )
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 __py_execmodel__(self, codeGen): assigns = [] for definition in self._definitions_: target = definition.target.model['target'] value = definition.value.model['expr'] assign = Py.AssignStmt(targets=[target], value=value) assigns.append(assign) return Py.PythonSuite(suite=assigns)
def __init__(self, model=None): if isinstance( model, DMNode ) and model.isInstanceOf( Schema.PythonSuite ): pass elif model is None: model = _py25NewSuite() elif isinstance( model, list ) or isinstance( model, java.util.List ): model = Schema.PythonSuite( suite=model ) else: raise TypeError, 'Cannot construct EmbeddedPython2Suite from %s' % model super(EmbeddedPython2Suite, self).__init__( model )
def fromExprModel(exprModel): return EmbeddedPython2Suite( Schema.PythonSuite( suite=EmbeddedPython2Executable._exprModelAsStmts( deepcopy( exprModel ) ) ) )
def _py25NewSuite(): return Schema.PythonSuite( suite=[] )
def __py_execmodel__(self, codeGen): if self.__current_testing_block__ is not None: self.__current_testing_block__._registerInlineTest( self ) self.__testedBlock = self.__current_testing_block__ return Schema.PythonSuite( suite=[] )