def changeAnnotationState_(self, doAnnotate): ''' Change the class annotation state. ''' LANG = ProgramExecution.Languages currentProject = getCurrentProject() mySourceCodeParser = SourceCodeParser(currentProject.getLanguage(), currentProject.getMainFile(), currentProject.getMainFunction()) auxFileName = self.fileToAnnotate_ + ".aux" shutil.copy(self.fileToAnnotate_, auxFileName) try: if currentProject.getLanguage() == LANG.C_PLUS_PLUS: if doAnnotate: mySourceCodeParser.annotateCppClasses(auxFileName, self.fileToAnnotate_, self.headerToInclude_, [self.className_]) else: mySourceCodeParser.unannotateCppClasses(auxFileName, self.fileToAnnotate_, [self.className_]) else: assert currentProject.getLanguage() == LANG.PYTHON classNameStr = self.headerToInclude_ + '.' + self.className_ if doAnnotate: mySourceCodeParser.annotatePythonObject(classNameStr, False) else: mySourceCodeParser.unAnnotatePythonObject(classNameStr, False) except Exception: QMessageBox.about(None, 'ERROR','Error al (des)anotar la clase. Traceback:\n\n' + traceback.format_exc()) shutil.copy(auxFileName, self.fileToAnnotate_) os.remove(auxFileName)
def processAnnotatePythonObject_(self, doAdd, testingFunctionName, pythonObjectName, itsAModule, functionName=None): mainFileName = os.path.join(TEST_FILES_FOLDER, testingFunctionName + '.py') expectedFileName = os.path.join( TEST_FILES_FOLDER, testingFunctionName + "_expected" + '.py') if not doAdd: aux = mainFileName mainFileName = expectedFileName expectedFileName = aux mainFileBackup = mainFileName + ".mybkp" try: shutil.copy(mainFileName, mainFileBackup) #Verify second (un)annotation yields the same file for i in range(2): mySourceCodeParser = SourceCodeParser( ProgramExecution.Languages.PYTHON, mainFileName) if doAdd: mySourceCodeParser.annotatePythonObject( pythonObjectName, itsAModule, functionName) else: mySourceCodeParser.unAnnotatePythonObject( pythonObjectName, itsAModule, functionName) self.compareFileContents_(mainFileName, expectedFileName) finally: if os.path.exists(mainFileBackup): shutil.copy(mainFileBackup, mainFileName) os.remove(mainFileBackup)
def changeAnnotationState_(self, doAnnotate): ''' Change the class annotation state. ''' LANG = ProgramExecution.Languages currentProject = getCurrentProject() mySourceCodeParser = SourceCodeParser(currentProject.getLanguage(), currentProject.getMainFile(), currentProject.getMainFunction()) auxFileName = self.fileToAnnotate_ + ".aux" shutil.copy(self.fileToAnnotate_, auxFileName) try: if currentProject.getLanguage() == LANG.C_PLUS_PLUS: if doAnnotate: mySourceCodeParser.annotateCppClasses( auxFileName, self.fileToAnnotate_, self.headerToInclude_, [self.className_]) else: mySourceCodeParser.unannotateCppClasses( auxFileName, self.fileToAnnotate_, [self.className_]) else: assert currentProject.getLanguage() == LANG.PYTHON classNameStr = self.headerToInclude_ + '.' + self.className_ if doAnnotate: mySourceCodeParser.annotatePythonObject( classNameStr, False) else: mySourceCodeParser.unAnnotatePythonObject( classNameStr, False) except Exception: QMessageBox.about( None, 'ERROR', 'Error al (des)anotar la clase. Traceback:\n\n' + traceback.format_exc()) shutil.copy(auxFileName, self.fileToAnnotate_) os.remove(auxFileName)