def test_TypedField_editor(self):
        a = self.TypedFieldTest(x=10, y=20)

        codeGen = Python2CodeGenerator('test')

        self.assertEqual(10, a.x.getValueForEditor())
        self.assertEqual(20, a.y.getValueForEditor())

        self.assertEqual(
            Py.IntLiteral(format='decimal', numType='int', value='10'),
            a.x.__py_evalmodel__(codeGen))
        self.assertEqual(
            Py.IntLiteral(format='decimal', numType='int', value='20'),
            a.y.__py_evalmodel__(codeGen))

        self.assertEqual(
            Py.Call(target=Py.Load(name='A'),
                    args=[
                        Py.IntLiteral(format='decimal',
                                      numType='int',
                                      value='10'),
                        Py.IntLiteral(format='decimal',
                                      numType='int',
                                      value='20')
                    ]), a.__py_evalmodel__(codeGen))
    def test_ChildField_editor(self):
        a1 = self.TypedFieldTest(x=10, y=20)
        a2 = self.TypedFieldTest(x=3, y=4)
        b = self.ChildFieldTest(p=a1, q=[a2])

        codeGen = Python2CodeGenerator('test')

        self.assertEqual(a1, b.p.getValueForEditor())
        self.assertEqual([a2], b.q.getValueForEditor())

        self.assertEqual(
            Py.Call(target=Py.Load(name='B'),
                    args=[
                        Py.Call(target=Py.Load(name='A'),
                                args=[
                                    Py.IntLiteral(format='decimal',
                                                  numType='int',
                                                  value='10'),
                                    Py.IntLiteral(format='decimal',
                                                  numType='int',
                                                  value='20')
                                ]),
                        Py.ListLiteral(values=[
                            Py.Call(target=Py.Load(name='A'),
                                    args=[
                                        Py.IntLiteral(format='decimal',
                                                      numType='int',
                                                      value='3'),
                                        Py.IntLiteral(format='decimal',
                                                      numType='int',
                                                      value='4')
                                    ])
                        ])
                    ]), b.__py_evalmodel__(codeGen))
Ejemplo n.º 3
0
 def test_IntLit(self):
     self._buildTest(
         Py.IntLiteral(value='123', numType='int', format='decimal'),
         IntLit(123))
     self._buildTest(
         Py.IntLiteral(value='123', numType='long', format='decimal'),
         IntLit(123L))
     self._buildTest(Py.IntLiteral(value='40', numType='int', format='hex'),
                     IntLit(64, format='hex'))
Ejemplo n.º 4
0
 def __component_py_evalmodel__(self, codeGen):
     flowGrid = codeGen.embeddedValue(FlowGrid)
     targetNumColumns = self._targetNumColumns.getValue()
     args = []
     if targetNumColumns is not None:
         args.append(Py.IntLiteral(value=repr(targetNumColumns)))
     args.append(self._py_evalmodel_forChildren(codeGen))
     return Py.Call(target=flowGrid, args=args)
	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
Ejemplo n.º 6
0
 def build(self):
     return Py.IntLiteral(value=self.valueString,
                          format=self.format,
                          numType=self.numType)
 def __py_evalmodel__(self, codeGen):
     return Py.IntLiteral(format='decimal',
                          numType='int',
                          value=repr(self.value))