Ejemplo n.º 1
0
 def shouldUseWithTypeAdapter(self):
     obj = MockObject()
     givenTA = TypeAdapter.on(obj, "sFloat1")
     givenCell = Parse(tag="td", body="6.45")
     obj.parseAndSet(givenCell, givenTA)
     assert obj.sFloat1 == 6.45
     assert isinstance(obj.sFloat1, ScientificFloat)
     assert givenCell.tagIsNotAnnotated()
     resultTA = TypeAdapter.on(obj, "sFloat2")
     resultCell = Parse(tag="td", body="6.45")
     obj.check(resultCell, resultTA)
     assert resultCell.tagIsRight()
Ejemplo n.º 2
0
 def shouldUseWithTypeAdapter(self):
     obj = MockObject()
     givenTA = TypeAdapter.on(obj, "sFloat1")
     givenCell = Parse(tag="td", body="6.45")
     obj.parseAndSet(givenCell, givenTA)
     assert obj.sFloat1 == 6.45
     assert isinstance(obj.sFloat1, ScientificFloat)
     assert givenCell.tagIsNotAnnotated()
     resultTA = TypeAdapter.on(obj, "sFloat2")
     resultCell = Parse(tag="td", body="6.45")
     obj.check(resultCell, resultTA)
     assert resultCell.tagIsRight()
Ejemplo n.º 3
0
 def _checkTest(self, method, cellContent, resultObjName):
     obj = testClass()
     adapter = ta.on(obj, method)
     cell = Parse(tag="td", body=cellContent)
     checkResult = adapter.check(cell)
     assert checkResult.__class__.__name__ == resultObjName
     return checkResult
Ejemplo n.º 4
0
    def getTypeAdapter(self, typeName):
        metadata = {}
        if typeName.endswith("s"):
            shortName = typeName[:-1]
        else:
            shortName = typeName
        adapter = self.typeAdapterMap.get(shortName)
        if adapter is None:
            adapter = shortName.title()
        metadata = {typeName: adapter}

        if not isinstance(adapter, types.StringTypes):
            metadata = {
                typeName: "Generic",
                "%s.ValueClass" % typeName: adapter
            }

        if typeName.endswith("s"):
            metadata["%s.scalarType" % typeName] = metadata[typeName]
            metadata[typeName] = "List"

        if shortName.lower() == "real":
            metadata[typeName + ".precision"] = 5

        return TypeAdapter.on(self, typeName, metadata)
Ejemplo n.º 5
0
 def _checkTest(self, method, cellContent, resultObjName):        
     obj = testClass()
     adapter = ta.on(obj, method)
     cell = Parse(tag="td", body=cellContent)
     checkResult = adapter.check(cell)
     assert checkResult.__class__.__name__ == resultObjName
     return checkResult
Ejemplo n.º 6
0
 def _check(self, cell, obj, identifier, typeName):
     cell = self._getCell(cell)
     ta = TypeAdapter.on(obj, identifier, {identifier: typeName})
     checkResult = self.check(cell, ta)
     isValid = checkResult.isRight()
     self.valid.itemValid(isValid)
     return isValid
Ejemplo n.º 7
0
 def _check(self, cell, obj, identifier, typeName):
     cell = self._getCell(cell)
     ta = TypeAdapter.on(obj, identifier, {identifier: typeName})
     checkResult = self.check(cell, ta)
     isValid = checkResult.isRight()
     self.valid.itemValid(isValid)
     return isValid
 def _getTypeAdapterFromDict(self, subject, name, metaDataDict):
     # ??? what was typeThing all about? should we change the on. call?
     #        typeThing = metaDataDict.get(name)
     return TypeAdapter.on(subject,
                           name,
                           metaDataDict,
                           accClass=TypeAdapter.AccessorBaseClass)
Ejemplo n.º 9
0
 def check(self, cell, value):
     text = cell.text()
     adapter = TypeAdapter.on(self, "dummy", {"dummy": "Boolean"})
     expected = adapter.parse(text)
     if expected != value:
         self.wrong(cell, str(value))
     else:
         self.right(cell)
 def _bindAdapter(self, name, heads, i):
     try:
         adapter = TypeAdapter.on(self, name, None, self, self.getTargetClass())
         self.columnBindings[i] = adapter
     except Exception, e:
         self.exception(heads, e)
         self._bindColumnExecutor("unimplementedExecutor",
                                  "ignore", i, name)
Ejemplo n.º 11
0
 def check(self, cell, value):
     text = cell.text()
     adapter = TypeAdapter.on(self, "dummy", {"dummy": "Boolean"})
     expected = adapter.parse(text)
     if expected != value:
         self.wrong(cell, str(value))
     else:
         self.right(cell)
Ejemplo n.º 12
0
 def className(self):
     metadata = {"stuff": self.name}
     accessor = TypeAdapter.on(self, "stuff", metadata)
     adapter = accessor.adapter
     if accessor.protocol.protocolName == "ApplicationObject":
         classObj = adapter
     else:
         classObj = adapter.__class__
     return classObj.__name__
Ejemplo n.º 13
0
 def className(self):
     metadata = {"stuff": self.name}
     accessor = TypeAdapter.on(self, "stuff", metadata)
     adapter = accessor.adapter
     if accessor.protocol.protocolName == "ApplicationObject":
         classObj = adapter
     else:
         classObj = adapter.__class__
     return classObj.__name__
 def bind(self, labels):
     wasError = False
     #        usedField = [False] * labels.size()
     adapters = []
     fieldNames = []
     symRefs = []
     #        targetClass = self.getTargetClass()
     typeDict = self.paramTypeDict
     typeDict = typeDict or getattr(self, "_typeDict", None)  # legacy
     typeDict = typeDict or self.getTargetClass()._typeDict
     extendedLabelProcess = typeDict.get(".extendedLabelProcess", "off")
     colNum = 0
     while labels is not None:
         fieldName = labels.text()
         if extendedLabelProcess == "on":
             colType, camelName = self.processLabel(fieldName, colNum)
             isSymRef = (colType == "checkSymbol")
         else:
             isSymRef, camelName = self._decodeLabel(fieldName, typeDict)
         if not self._isFieldInAnyObject(camelName, self.actuals):
             self.exception(labels, FitException("FieldNotInCollection"))
             wasError = True
             accessor = None
         else:
             #                metaData = typeDict.get(camelName)
             colType = typeDict.get(camelName + ".columnType")
             if colType == "checkSymbol":
                 isSymRef = True
             try:
                 accessor = TypeAdapter.on(
                     self,
                     camelName,
                     typeDict,
                     #                            {camelName: metaData},
                     accClass=TypeAdapter.AccessorBaseClass)
             except FitException, e:
                 self.exception(labels, e)
                 accessor = None
         adapters.append(accessor)
         fieldNames.append(camelName)
         symRefs.append(isSymRef)
         labels = labels.more
         colNum += 1
Ejemplo n.º 15
0
    def getTypeAdapter(self, typeName):
        metadata = {}
        if typeName.endswith("s"):
            shortName = typeName[:-1]
        else:
            shortName = typeName
        adapter = self.typeAdapterMap.get(shortName)
        if adapter is None:
            adapter = shortName.title()
        metadata = {typeName: adapter}

        if type(adapter) not in (type(""), type(u"")):
            metadata = {typeName: "Generic",
                        "%s.ValueClass" % typeName: adapter}

        if typeName.endswith("s"):
            metadata["%s.scalarType" % typeName] = metadata[typeName]
            metadata[typeName] = "List"

        return TypeAdapter.on(self, typeName, metadata)
Ejemplo n.º 16
0
    def bind(self, labels):
        wasError = False
#        usedField = [False] * labels.size()
        adapters = []
        fieldNames = []
        symRefs = []
#        targetClass = self.getTargetClass()
        typeDict = self.paramTypeDict
        typeDict = typeDict or getattr(self, "_typeDict", None) # legacy
        typeDict = typeDict or self.getTargetClass()._typeDict
        extendedLabelProcess = typeDict.get(".extendedLabelProcess", "off")
        colNum = 0
        while labels is not None:
            fieldName = labels.text()
            if extendedLabelProcess == "on":
                colType, camelName = self.processLabel(fieldName, colNum)
                isSymRef = (colType == "checkSymbol")
            else:
                isSymRef, camelName = self._decodeLabel(fieldName, typeDict)
            if not self._isFieldInAnyObject(camelName, self.actuals):
                self.exception(labels,
                    FitException("FieldNotInCollection"))
                wasError = True
                accessor = None
            else:
#                metaData = typeDict.get(camelName)
                colType = typeDict.get(camelName + ".columnType")
                if colType == "checkSymbol":
                    isSymRef = True
                try:
                    accessor = TypeAdapter.on(self, camelName, typeDict,
#                            {camelName: metaData},
                            accClass = TypeAdapter.AccessorBaseClass)
                except FitException, e:
                    self.exception(labels, e)
                    accessor = None
            adapters.append(accessor)
            fieldNames.append(camelName)
            symRefs.append(isSymRef)
            labels = labels.more
            colNum += 1
Ejemplo n.º 17
0
    def getTypeAdapter(self, typeName):
        metadata = {}
        if typeName.endswith("s"):
            shortName = typeName[:-1]
        else:
            shortName = typeName
        adapter = self.typeAdapterMap.get(shortName)
        if adapter is None:
            adapter = shortName.title()
        metadata = {typeName: adapter}

        if type(adapter) not in (type(""), type(u"")):
            metadata = {
                typeName: "Generic",
                "%s.ValueClass" % typeName: adapter
            }

        if typeName.endswith("s"):
            metadata["%s.scalarType" % typeName] = metadata[typeName]
            metadata[typeName] = "List"

        return TypeAdapter.on(self, typeName, metadata)
Ejemplo n.º 18
0
    def getTypeAdapter(self, typeName):
        metadata = {}
        if typeName.endswith("s"):
            shortName = typeName[:-1]
        else:
            shortName = typeName
        adapter = self.typeAdapterMap.get(shortName)
        if adapter is None:
            adapter = shortName.title()
        metadata = {typeName: adapter}

        if not isinstance(adapter, types.StringTypes):
            metadata = {typeName: "Generic",
                        "%s.ValueClass" % typeName: adapter}

        if typeName.endswith("s"):
            metadata["%s.scalarType" % typeName] = metadata[typeName]
            metadata[typeName] = "List"

        if shortName.lower() == "real":
            metadata[typeName + ".precision"] = 5

        return TypeAdapter.on(self, typeName, metadata)
 def setTypeAdapter(self, typeDict):
     for key in typeDict.keys():
         parts = key.split(".")
         break
     self._typeAdapter = TypeAdapter.on(self, parts[0], typeDict)
Ejemplo n.º 20
0
 def _getTypeAdapterFromDict(self, subject, name, metaDataDict):
     # ??? what was typeThing all about? should we change the on. call?
     #        typeThing = metaDataDict.get(name)
     return TypeAdapter.on(subject, name, metaDataDict, accClass=TypeAdapter.AccessorBaseClass)
Ejemplo n.º 21
0
 def setTypeAdapter(self, typeDict):
     for key in typeDict.keys():
         parts = key.split(".")
         break
     self._typeAdapter = TypeAdapter.on(self, parts[0], typeDict)