def processTestingFunction_(self, functionName, classNames = None, functionNames = None):
     mainFileName = os.path.join(TEST_FILES_FOLDER, functionName + ".cpp")
     resultMainFileName = os.path.join(TEST_FILES_FOLDER, functionName + "_result.cpp")
     expectedMainFileName = os.path.join(TEST_FILES_FOLDER, functionName + "_expected.cpp")
     dumpFileName = os.path.join(TEST_FILES_FOLDER, functionName + ".json")
     
     try:
         #TODO GERVA: keepBackupFiles == True
         shutil.copy(mainFileName, MAIN_FILE_TO_ANNOTATE)
         myCppAnnotator = CppAnnotator(MAIN_FILE_TO_ANNOTATE, MAIN_FUNCTION, BUILD_SOLUTION_COMMAND, keepBackupFiles = False)
         
         myCppAnnotator.annotateMainFile(dumpFileName)
         if classNames is None and functionNames is None:
             myCppAnnotator.annotateFile(FILE_TO_ANNOTATE, HEADER_TO_INCLUDE)
         else:
             if classNames is not None:
                 myCppAnnotator.annotateClasses(FILE_TO_ANNOTATE, HEADER_TO_INCLUDE, classNames)
             if functionNames is not None:
                 myCppAnnotator.annotateFunctions(FILE_TO_ANNOTATE, HEADER_TO_INCLUDE, functionNames)
         
         with myCppAnnotator:
             #It's annotated, it should generate a result file in resultFileName
             os.system(SAMPLE_PROGRAM_EXE)
             
         with open( dumpFileName, "r") as dumpFileFp:
             with open( resultMainFileName, "w") as equivProgramFp:
                 #Get equivalent program
                 myCodeGenerator = CodeGenerator(dumpFileFp)
                 myCodeGenerator.generateEquivalentProgram(equivProgramFp)
         self.compareFileContents_(resultMainFileName, expectedMainFileName)
     finally:
         if os.path.exists(resultMainFileName):
             os.remove(resultMainFileName)
         if os.path.exists(dumpFileName):
             os.remove(dumpFileName)
 def generateEquivalentProgram(self):
     '''
     User asks to generate an equivalent program from the selected program execution.
     '''
     FT = ExecutionsTreeWidgetItem.FileType
     currentItem = self.executionsExplorerTreeWidget.currentItem()
     myType = currentItem.getFileType()
     if myType == FT.EXECUTION:
         dumpFileName = currentItem.getFilePath()
         equivProgramPath = getEquivalentProgramPathFromExecution(
             dumpFileName, self.currentProject.getLanguage())
         with open(dumpFileName, "r") as dumpFileFp:
             with open(equivProgramPath, "w") as equivProgramFp:
                 #Get equivalent program
                 myCodeGenerator = CodeGenerator(
                     dumpFileFp, projectName=self.currentProject.getName())
                 mySourceType = GeneratedSourceType.UNIT_TEST if self.unitTestRadioButton.isChecked(
                 ) else GeneratedSourceType.MAIN_FILE
                 myCodeGenerator.generateEquivalentProgram(
                     equivProgramFp,
                     searchLevel=ProgramExecution.MIN_LEVEL,
                     sourceType=mySourceType)
         equivProgramTreeItem = createExecutionsTreeWidgetItem(
             ExecutionsTreeWidgetItem.FileType.EQUIV_PROGRAM,
             equivProgramPath)
         currentItem.addChild(equivProgramTreeItem)
         self.refreshFileContents(equivProgramPath)
 def generateEquivalentProgram(self):
     """
     User asks to generate an equivalent program from the selected program execution.
     """
     FT = ExecutionsTreeWidgetItem.FileType
     currentItem = self.executionsExplorerTreeWidget.currentItem()
     myType = currentItem.getFileType()
     if myType == FT.EXECUTION:
         dumpFileName = currentItem.getFilePath()
         equivProgramPath = getEquivalentProgramPathFromExecution(dumpFileName, self.currentProject.getLanguage())
         with open(dumpFileName, "r") as dumpFileFp:
             with open(equivProgramPath, "w") as equivProgramFp:
                 # Get equivalent program
                 myCodeGenerator = CodeGenerator(dumpFileFp, projectName=self.currentProject.getName())
                 mySourceType = (
                     GeneratedSourceType.UNIT_TEST
                     if self.unitTestRadioButton.isChecked()
                     else GeneratedSourceType.MAIN_FILE
                 )
                 myCodeGenerator.generateEquivalentProgram(
                     equivProgramFp, searchLevel=ProgramExecution.MIN_LEVEL, sourceType=mySourceType
                 )
         equivProgramTreeItem = createExecutionsTreeWidgetItem(
             ExecutionsTreeWidgetItem.FileType.EQUIV_PROGRAM, equivProgramPath
         )
         currentItem.addChild(equivProgramTreeItem)
         self.refreshFileContents(equivProgramPath)
示例#4
0
    def processTestingFunction_(self,
                                functionName,
                                classNames=None,
                                functionNames=None):
        mainFileName = os.path.join(TEST_FILES_FOLDER, functionName + ".cpp")
        resultMainFileName = os.path.join(TEST_FILES_FOLDER,
                                          functionName + "_result.cpp")
        expectedMainFileName = os.path.join(TEST_FILES_FOLDER,
                                            functionName + "_expected.cpp")
        dumpFileName = os.path.join(TEST_FILES_FOLDER, functionName + ".json")

        try:
            #TODO GERVA: keepBackupFiles == True
            shutil.copy(mainFileName, MAIN_FILE_TO_ANNOTATE)
            myCppAnnotator = CppAnnotator(MAIN_FILE_TO_ANNOTATE,
                                          MAIN_FUNCTION,
                                          BUILD_SOLUTION_COMMAND,
                                          keepBackupFiles=False)

            myCppAnnotator.annotateMainFile(dumpFileName)
            if classNames is None and functionNames is None:
                myCppAnnotator.annotateFile(FILE_TO_ANNOTATE,
                                            HEADER_TO_INCLUDE)
            else:
                if classNames is not None:
                    myCppAnnotator.annotateClasses(FILE_TO_ANNOTATE,
                                                   HEADER_TO_INCLUDE,
                                                   classNames)
                if functionNames is not None:
                    myCppAnnotator.annotateFunctions(FILE_TO_ANNOTATE,
                                                     HEADER_TO_INCLUDE,
                                                     functionNames)

            with myCppAnnotator:
                #It's annotated, it should generate a result file in resultFileName
                os.system(SAMPLE_PROGRAM_EXE)

            with open(dumpFileName, "r") as dumpFileFp:
                with open(resultMainFileName, "w") as equivProgramFp:
                    #Get equivalent program
                    myCodeGenerator = CodeGenerator(dumpFileFp)
                    myCodeGenerator.generateEquivalentProgram(equivProgramFp)
            self.compareFileContents_(resultMainFileName, expectedMainFileName)
        finally:
            if os.path.exists(resultMainFileName):
                os.remove(resultMainFileName)
            if os.path.exists(dumpFileName):
                os.remove(dumpFileName)