Esempio n. 1
0
def getClassObj(type, module=False):
    """This method will return a class instance object with name specified in type."""
    if module:
        return getattr(token[module], type)()
    else:
        keys = [key for key in token.keys() if key != 'device']
        for key in keys:
            if type in getAttrList(token[key]):
                return getattr(token[key], type)()
Esempio n. 2
0
    def processsXml(self, xml):
        myData=''
        obj=XmlHandler().XmlStringToObj(xml, keyword='events')
        if obj:
            myData=geoLocationData()
            attrs=classUtility.getAttrList(myData)
            for attr in obj[0].attributes:
                if attr.name in attrs:
                    setattr(myData, attr.name, attr.value)

        return myData
Esempio n. 3
0
    def _ClassToXml(self, name, obj):
        node = self.doc.createElement(name)
        for attr in classUtility.getAttrList(obj):
            subval = getattr(obj, attr)
            if attr == 'attribute':
                for attrVal in subval.keys():
                    node.setAttribute(attrVal, subval[attrVal])
            else:
                subnode = self._ObjToXml(attr, subval)
                node.appendChild(subnode)

        return node
Esempio n. 4
0
def getDataFromFile(type, path, keyAttrs, orderAttrs, asCsv=True):
    """This method will read data from a CSV file."""
    if asCsv:
        if '.csv' not in path:
            path += '.csv'
    objData = {}
    reader = csv.DictReader(open(path),
                            fieldnames=orderAttrs,
                            restkey='Extra',
                            restval='Miss')
    keyword = []
    for line in reader:
        if not orderAttrs:
            orderAttrs = line.keys()
            if 'Extra' in orderAttrs:
                orderAttrs.remove('Extra')
            if 'Miss' in orderAttrs:
                orderAttrs.remove('Miss')
        if 'Extra' in line.keys():
            line[orderAttrs[-1]] += ', ' + ','.join(line['Extra'])
            del line['Extra']
        if __metCondition(line):
            if '$' in line[orderAttrs[0]]:
                keyword = []
                keyword.append(line[orderAttrs[0]].split('$')[-1])
            elif line[orderAttrs[0]] in csv_device_info:
                keyword.append(line[orderAttrs[1]])
            else:
                obj = getClassObj(type)
                for key in line.keys():
                    if key in classUtility.getAttrList(obj):
                        setattr(obj, key, line[key])
                map = {}
                if keyAttrs and keyword:
                    if classUtility.getType(keyAttrs) == 'list':
                        map = testUtility.listToHash(keyAttrs, keyword)
                    elif len(keyword) > 1:
                        keyVal = '-'.join(keyword)
                        map[keyAttrs] = keyVal
                    else:
                        map[keyAttrs] = keyword[0]
                if map:
                    for newKey in map.keys():
                        setattr(obj, newKey, map[newKey])
                indexKey = testUtility.getKey(type, file=True)
                indexValue = classUtility.getIndexValue(obj, indexKey)
                objData[indexValue] = obj

    return objData
Esempio n. 5
0
    def __getOriData(self, task, fileName):
        test, type = fileName.split('.')
        path = self.__getPath(task)
        file = path + fileName
        if type == 'csv':
            data = CSVHandler.getDatafromFile(file)
        elif type == 'xml':
            mydata = XMLHelper.unpickleFile(file, XML_TYPE[test], type='list')
            data = {}
            for item in mydata:
                for attr in classUtility.getAttrList(item):
                    if attr in SPECIAL_LIST:
                        newValue = self.__specialFormat(item, attr)
                        setattr(item, attr, newValue)
                key = getattr(item, XML_DATAKEY[test])
                data[key] = item

        return data
Esempio n. 6
0
    def _XmlToObj(self, node, wrapTag=None, filter=None):
        if wrapTag:
            subnode = ''
            nodes = node.getElementsByTagName(wrapTag)
            if not nodes:
                return None
            else:
                subnode = nodes[0]
                nodelist = self._getElementChilds(subnode)
                if nodelist:
                    if nodelist[0][0] == nodelist[-1][0]:
                        return self._XmlToObjList(nodelist, condition=filter)
                    else:
                        return self._XmlToObj(subnode)
                elif subnode.childNodes:
                    return subnode.childNodes[0].nodeValue.strip()
                else:
                    return None
        else:
            if hasattr(node, 'tagName'):
                tagName = node.tagName
            else:
                tagName = node.nodeName
            obj = getClassObj(tagName)
            objAttrs = classUtility.getAttrList(obj)
            if 'attribute' in objAttrs:
                self._setAttributes(node, obj)
            if 'namedValues' in objAttrs:
                obj = self._setNamedValues(node, obj)
            if tagName in xml_2_obj_special.keys():
                attr = node.attributes.getNamedItem(
                    xml_2_obj_special[tagName]['attr']).nodeValue
                setattr(obj, xml_2_obj_special[tagName]['attr'], attr)
                value = ''
                if len(node.childNodes):
                    value = node.childNodes[0].nodeValue.strip()
                    setattr(obj, xml_2_obj_special[tagName]['text'], value)
            else:
                elementChilds = self._getElementChilds(node)
                for name, element in elementChilds:
                    if name in objAttrs:
                        my_type = classUtility.getType(getattr(obj, name))
                        if my_type == 'NoneType':
                            if len(element.childNodes):
                                value = element.childNodes[0].nodeValue
                                if value:
                                    setattr(obj, name, value.strip())
                        elif my_type == 'list':
                            li = getattr(obj, name)
                            subE = self._getElementChilds(element)
                            subENames = [na[0] for na in subE]
                            subObj = ''
                            if subENames:
                                if generalUtility.isWrap(subENames[0], name):
                                    if subE:
                                        subObj = self._XmlToObjList(subE)
                                else:
                                    if subE:
                                        subObj = self._XmlToObj(element)
                            if subObj:
                                if classUtility.getType(subObj) == 'list':
                                    li.extend(subObj)
                                else:
                                    li.append(subObj)
                            setattr(obj, name, li)
                        else:
                            subObj = self._XmlToObj(element)
                            setattr(obj, name, subObj)

        return obj
Esempio n. 7
0
    def verifyData(self, name, ori, ret):
        resObjList = []
        if ret:
            miss, extraRaw, common = testUtility.processList(
                ori.keys(), ret.keys())
            extra = []
            if name in testConstant.populator_comp_ignore.keys():
                for subKey in extraRaw:
                    if testConstant.populator_comp_ignore[name] not in subKey:
                        extra.append(subKey)
            else:
                extra = extraRaw
            for ikey in common:
                oriData = ori[ikey]
                retData = ret[ikey]
                attrList = classUtility.getAttrList(oriData)
                resObj = getClassObj('TestCaseResult', module='autoTest')
                resObj.name = ikey
                for item in attrList:
                    map = {}
                    map['param'] = item
                    map['expectValue'] = getattr(oriData, item)
                    if hasattr(retData, item):
                        map['actValue'] = getattr(retData, item)
                    else:
                        map['actValue'] = 'Missing'
                    if '\n' in map['actValue']:
                        map['actValue'] = map['actValue'].replace('\n', '')
                    if map['expectValue'].strip().lower(
                    ) == map['actValue'].strip().lower():
                        resObj.Pass.append(map)
                    else:
                        resObj.Fail.append(map)
                if resObj.Fail:
                    resObj.status = 'Fail'
                elif resObj.Missing:
                    resObj.status = 'Missing'
                elif resObj.Extra:
                    resObj.status = 'Extra'
                else:
                    resObj.status = 'Pass'
                resObjList.append(resObj)
            if miss:
                for misskey in miss:
                    resObj = getClassObj('TestCaseResult', module='autoTest')
                    resObj.name = misskey
                    resObj.status = 'NoReturn'
                    setattr(resObj, 'reasons', 'Fail to import')
                    resObjList.append(resObj)
            if extra:
                for extrakey in extra:
                    resObj = getClassObj('TestCaseResult', module='autoTest')
                    resObj.name = extrakey
                    resObj.status = 'Extra'
                    map = {}
                    map['param'] = extrakey
                    map['expectValue'] = 'None'
                    map['actValue'] = extrakey
                    resObj.Extra.append(map)
                    resObjList.append(resObj)
        suiteObj = getClassObj('TestSuiteResult', module='autoTest')
        suiteObj.name = name
        for item in resObjList:
            suiteObj.totalRun += 1
            oldVal = getattr(suiteObj, 'total' + item.status)
            oldVal += 1
            setattr(suiteObj, 'total' + item.status, oldVal)
            suiteObj.caseList.append(item)

        return suiteObj