def test_printUnions(self): ''' it should print the unions ''' capturedOutput = io.StringIO() # setup an io sys.stdout = capturedOutput # redirect stdout tmpVar = classes.variableClass() tmpVar.name = 'name' tmpVar.desc = 'desc' tmpVar.type = 'type' tmpUnion = classes.unionClass() tmpUnion.name = 'name' tmpUnion.include = 'import' tmpUnion.members = [tmpVar] tmpUnion.briefDesc = 'desc brief' tmpUnion.detailedDesc = 'desc detail' unions = [tmpUnion] printingFunctions.printUnions(unions) sys.stdout = sys.__stdout__ # reset stdout self.assertEqual(capturedOutput.getvalue(), '\033[1mUnions:\033[0m\n\n' 'name = name\n' 'import = import\n' 'brief desc = desc brief\n' 'detailed desc = desc detail\n' '\t- type name ( desc )\n\n')
def test_printDefines(self): ''' it should print the defines ''' capturedOutput = io.StringIO() # setup an io sys.stdout = capturedOutput # redirect stdout tmpVar = classes.variableClass() tmpVar.name = 'name' tmpVar.desc = 'desc' tmpDef = classes.defineClass() tmpDef.name = 'name' tmpDef.include = 'import' tmpDef.initializer = 'init' tmpDef.params = [tmpVar] tmpDef.briefDesc = 'desc brief' tmpDef.detailedDesc = 'desc detail' defines = [tmpDef] printingFunctions.printDefines(defines) sys.stdout = sys.__stdout__ # reset stdout self.assertEqual(capturedOutput.getvalue(), '\033[1mMacros:\033[0m\n\n' 'name = name\n' 'import = import\n' 'initializer = init\n' 'brief desc = desc brief\n' 'detailed desc = desc detail\n' '\t- name ( desc )\n\n')
def getEnumParams(define): params = [] try: for param in define.findall("enumvalue"): tmpParam = variableClass() tmpParam.name = param.find("name").text if (param.find("initializer")): tmpParam.initializer = " " + param.find("initializer").text tmpParam.desc = param.find("briefdescription").text params.append(tmpParam) return params except Exception as error: useful.printExceptionVerbose(error) return params
def getParams(define): params = [] try: for param in define.findall("param"): tmpParam = variableClass() try: tmpParam.name = strOp.epurStr(param.find("defname").text) if (param.find("defval")): tmpParam.value = strOp.epurStr(param.find("defval").text) except Exception as error: useful.printExceptionVerbose(error) tmpParam.name = strOp.epurStr(param.find("declname").text) t = param.find("type") if (t.find("ref") != None): tmpParam.ref = t.find("ref").get("refid") tmpParam.type = getType(param) params.append(tmpParam) return params except Exception as error: useful.printExceptionVerbose(error) return params
def test_printVariables(self): ''' it should print the variables ''' capturedOutput = io.StringIO() # setup an io sys.stdout = capturedOutput # redirect stdout tmp = classes.variableClass() tmp.name = 'name' tmp.type = 'type' tmp.value = 'value' tmp.desc = 'desc' variables = [tmp] printingFunctions.printVariables(variables) sys.stdout = sys.__stdout__ # reset stdout self.assertEqual(capturedOutput.getvalue(), '\033[1mVariables:\033[0m\n\n' 'name = name\n' 'type = type\n' 'value = value\n' 'description = desc\n\n\n')
def getRetvals(elem): retvals = [] try: for parameterlist in elem.findall( "detaileddescription/para/parameterlist"): if parameterlist.get("kind") == "retval": for retval in parameterlist.findall("parameteritem"): tmp = variableClass() tmpName = "" for txt in retval.find( "parameternamelist/parametername").itertext(): tmpName += " " + strOp.epurStr(txt) tmpDesc = "" for txt in retval.find("parameterdescription").itertext(): tmpDesc += " " + strOp.epurStr(txt) tmp.value = strOp.epurStr(tmpName) tmp.desc = strOp.epurStr(tmpDesc) retvals.append(tmp) return retvals except Exception as error: useful.printExceptionVerbose(error) return retvals
def test_printFunctions(self): ''' it should print the functions ''' capturedOutput = io.StringIO() # setup an io sys.stdout = capturedOutput # redirect stdout tmpVar = classes.variableClass() tmpVar.name = 'name' tmpVar.desc = 'desc' tmpVar.type = 'type' tmpFunction = classes.functionClass() tmpFunction.name = 'name' tmpFunction.include = 'import' tmpFunction.briefDesc = 'desc brief' tmpFunction.detailedDesc = 'desc detail' tmpFunction.params = [tmpVar] tmpFunction.returnType = 'type' tmpFunction.returnDesc = 'desc' tmpVar.value = 'val' tmpVar.desc = 'desc' tmpFunction.returnValues = [tmpVar] functions = [tmpFunction] printingFunctions.printFunctions(functions) sys.stdout = sys.__stdout__ # reset stdout self.assertEqual(capturedOutput.getvalue(), '\033[1mFunctions:\033[0m\n\n' 'name = name\n' 'import = import\n' 'brief desc = desc brief\n' 'detailed desc = desc detail\n' 'parameters :\n' '\t- type name ( desc )\n' 'return type = type\n' 'return = desc\n' 'return values :\n' '\t- val ( desc )\n\n')
def parseClass(root): #Obtain generic information about the class cpdef = root.find("compounddef") name = cpdef.find("compoundname").text path = name.replace("::", "/") classProto = cpdef.get("prot") + " " importStr = cpdef.find("location").get("file") isAbstract = cpdef.get("abstract") if (isAbstract == "yes"): classProto = classProto + "abstract " classProto = classProto + "class " + name briefDesc = getters.getBriefDesc(cpdef) detailedDesc = getters.getDetailedDesc(cpdef) description = briefDesc if (len(detailedDesc) > 0): description = detailedDesc templatePars = [] tlist = cpdef.find("templateparamlist") if (tlist != None): for elem in tlist.iter('param'): v = variableClass() v.type = elem.find("type") if (elem.find("declname") == None): #Found bug in Doxygen logWarning( "A terrible error has occured in Doxygen: template is corrupted, attempting restore..." ) txt = v.type.text vals = txt.split(" ") if (len(vals) < 2): logError("Unable to restore corrupted template!") continue v.type = vals[0] v.name = vals[1] logInfo("Successfully restored corrupted template!") else: if (v.type.find("ref") != None): v.ref = v.type.find("ref").get("refid") if (resolveReference(v.ref) != None): v.ref = resolveReference(v.ref).path v.type = v.type.find("ref").text else: v.type = v.type.text v.name = elem.find("declname").text if (elem.find("defval") != None): v.value = elem.find("defval").text templatePars.append(v) if (len(templatePars) > 0): prefix = "template <" for v in templatePars: prefix = prefix + v.type + " " + v.name if (v.value != None and len(v.value) > 0): prefix = prefix + " = " + v.value prefix = prefix + ", " prefix = prefix[:-2] prefix = prefix + ">" classProto = prefix + classProto templatePars = getters.getParamDesc(cpdef, templatePars) #Build a symbol for the class proto = buildPrototype(prototype=classProto, description=description) for v in templatePars: proto.addParameter( buildParameter(prototype=v.type + " " + v.name, description=v.desc)) cl = buildClass(path=path, prototypeObj=proto, importString=importStr) syms = [] for elem in root.iter('memberdef'): kind = elem.get('kind') pp3b = path + "/" + elem.find("name").text cl.addMember(pp3b) syms1 = [] if (kind in kindTable): syms1 = kindTable[kind](elem) for s in syms1: s.typename = "member " + s.typename s.path = pp3b syms.append(s) for elem in root.iter('innerclass'): pp3b = elem.text.replace("::", "/") cl.addMember(pp3b) syms.append(cl) return (syms)
def parseFunction(root): protoPrefix = root.get("prot") if (root.get("static") == "yes"): protoPrefix = protoPrefix + " static" if (root.get("explicit") == "yes"): protoPrefix = protoPrefix + " explicit" if (root.get("inline") == "yes"): protoPrefix = protoPrefix + " inline" virt = root.get("virt") protoSuffix = "" if (root.get("const") == "yes"): protoSuffix = protoSuffix + " const" if (virt == "virtual"): protoPrefix = protoPrefix + " virtual" elif (virt == "pure-virtual"): protoPrefix = protoPrefix + " virtual" protoSuffix = protoSuffix + " = 0" name = getters.getName(root) params = getters.getParamDesc(root, getters.getParams(root)) briefDesc = getters.getBriefDesc(root) tlist = root.find("templateparamlist") if (tlist != None): for elem in tlist.iter('param'): v = variableClass() v.type = elem.find("type") if (elem.find("declname") == None): #Found bug in Doxygen logWarning( "A terrible error has occured in Doxygen: template is corrupted, attempting restore..." ) txt = v.type.text vals = txt.split(" ") if (len(vals) < 2): logError("Unable to restore corrupted template!") continue v.type = vals[0] v.name = vals[1] logInfo("Successfully restored corrupted template!") else: if (v.type.find("ref") != None): v.ref = v.type.find("ref").get("refid") if (resolveReference(v.ref) != None): v.ref = resolveReference(v.ref).path v.type = v.type.find("ref").text else: v.type = v.type.text v.name = elem.find("declname").text if (elem.find("defval") != None): v.value = elem.find("defval").text params.append(v) detailedDesc = getters.getDetailedDesc(root) returnType = root.find("type") if (returnType.find("ref") != None): returnType = returnType.find("ref").text else: returnType = returnType.text if (returnType == None): #XML lib of python is bugged logError( "A terrible error in Python XML has been detected: XML lib returned None when the node exists" ) returnType = "" returnDesc = getters.getReturnDesc(root) exceptions = getters.getExceptions(root) func = buildFunctionPrototype(protoPrefix, protoSuffix, name, returnType, briefDesc, detailedDesc, params, returnDesc, exceptions) func = buildFunction("", func) if (returnType == ""): func.typename = "constructor" return ([func])