def process( self ): """ Parses the content and displays the results """ if not self.__connected: self.__connectEditorSignals() content = self.__editor.text() self.__cf = getControlFlowFromMemory( content ) if len( self.__cf.errors ) != 0: self.__navBar.updateInfoIcon( self.__navBar.STATE_BROKEN_UTD ) return self.__navBar.updateInfoIcon( self.__navBar.STATE_OK_UTD ) # if len( self.__cf.warnings ) != 0: # self.logMessage( "Parser warnings: " ) # for warn in self.__cf.warnings: # print str( warn[0] ) + ": " + warn[1] self.scene.clear() try: # Top level canvas has no adress and no parent canvas canvas = VirtualCanvas( self.cflowSettings, None, None, None ) canvas.layout( self.__cf ) canvas.setEditor( self.__editor ) width, height = canvas.render() self.scene.setSceneRect( 0, 0, width, height ) canvas.draw( self.scene, 0, 0 ) except Exception, exc: print "Exception:\n" + str( exc )
def process( self ): """ Parses the content and displays the results """ if not self.__connected: self.__connectEditorSignals() content = self.__editor.text() cf = getControlFlowFromMemory( content ) if cf.errors: self.__navBar.updateInfoIcon( self.__navBar.STATE_BROKEN_UTD ) errors = [] for err in cf.errors: if err[ 0 ] == -1 and err[ 1 ] == -1: errors.append( err[ 2 ] ) elif err[ 1 ] == -1: errors.append( "[" + str( err[0] ) + ":] " + err[ 2 ] ) elif err[ 0 ] == -1: errors.append( "[:" + str( err[1] ) + "] " + err[ 2 ] ) else: errors.append( "[" + str( err[0] ) + ":" + str( err[1] ) + "] " + err[ 2 ] ) self.__navBar.setErrors( errors ) return self.__cf = cf # Validate CML comments cmlWarnings = CMLVersion.validateCMLComments( self.__cf ) if cmlWarnings: self.__cf.warnings += cmlWarnings # That will clear the error tooltip as well self.__navBar.updateInfoIcon( self.__navBar.STATE_OK_UTD ) if self.__cf.warnings: warnings = [] for warn in self.__cf.warnings: if warn[ 0 ] == -1 and warn[ 1 ] == -1: warnings.append( warn[ 2 ] ) elif warn[ 1 ] == -1: warnings.append( "[" + str( warn[0] ) + ":] " + warn[ 2 ] ) elif warn[ 0 ] == -1: warnings.append( "[:" + str( warn[1] ) + "] " + warn[ 2 ] ) else: warnings.append( "[" + str( warn[0] ) + ":" + str( warn[1] ) + "] " + warn[ 2 ] ) self.__navBar.setWarnings( warnings ) else: self.__navBar.clearWarnings() self.scene.clear() try: # Top level canvas has no adress and no parent canvas canvas = VirtualCanvas( self.cflowSettings, None, None, None ) canvas.layoutModule( self.__cf ) canvas.setEditor( self.__editor ) width, height = canvas.render() self.scene.setSceneRect( 0, 0, width, height ) canvas.draw( self.scene, 0, 0 ) except Exception, exc: logging.error( str( exc ) ) raise
def meat( self, pythonFile, errorMsg, expectedOK = True ): " The test process meat " controlFlow = getControlFlowFromFile( pythonFile ) if controlFlow.isOK != expectedOK: self.fail( "Error parsing the file " + pythonFile + ". Option: directly from a file." ) f = open( pythonFile ) content = f.read() f.close() controlFlow = getControlFlowFromMemory( content ) if controlFlow.isOK != expectedOK: self.fail( "Error parsing the file " + pythonFile + ". Option: from memory." ) outFileName = pythonFile.replace( ".py", ".out" ) outFile = open( outFileName, "w" ) outFile.write( formatFlow( str( controlFlow ) ) + "\n" ) outFile.close() okFileName = pythonFile.replace( ".py", ".ok" ) if files_equal( outFileName, okFileName ): return # Python 3 may serialize dictionary items in different order depending # on a particular run. This causes troubles with .ok file which # can have only one order. This is a quick and dirty workaround. index = 1 while True: okFileNameOption = okFileName + str( index ) if not os.path.exists( okFileNameOption ): break # Bad: no option matched if files_equal( outFileName, okFileNameOption ): return # Good: matched index += 1 self.fail( errorMsg ) return
def meat( self, pythonFile, errorMsg ): " The test process meat " controlFlow = getControlFlowFromFile( pythonFile ) self.failUnless( controlFlow.isOK == True ) f = open( pythonFile ) content = f.read() f.close() controlFlow = getControlFlowFromMemory( content ) self.failUnless( controlFlow.isOK == True ) outFileName = pythonFile.replace( ".py", ".out" ) outFile = open( outFileName, "w" ) outFile.write( formatFlow( str( controlFlow ) ) + "\n" ) outFile.close() okFileName = pythonFile.replace( ".py", ".ok" ) self.failUnless( files_equal( outFileName, okFileName ), errorMsg ) return
def process(self): """ Parses the content and displays the results """ if not self.__connected: self.__connectEditorSignals() content = self.__editor.text() cf = getControlFlowFromMemory(content) if cf.errors: self.__navBar.updateInfoIcon(self.__navBar.STATE_BROKEN_UTD) errors = [] for err in cf.errors: if err[0] == -1 and err[1] == -1: errors.append(err[2]) elif err[1] == -1: errors.append("[" + str(err[0]) + ":] " + err[2]) elif err[0] == -1: errors.append("[:" + str(err[1]) + "] " + err[2]) else: errors.append("[" + str(err[0]) + ":" + str(err[1]) + "] " + err[2]) self.__navBar.setErrors(errors) return self.__cf = cf # Validate CML comments cmlWarnings = CMLVersion.validateCMLComments(self.__cf) if cmlWarnings: self.__cf.warnings += cmlWarnings # That will clear the error tooltip as well self.__navBar.updateInfoIcon(self.__navBar.STATE_OK_UTD) if self.__cf.warnings: warnings = [] for warn in self.__cf.warnings: if warn[0] == -1 and warn[1] == -1: warnings.append(warn[2]) elif warn[1] == -1: warnings.append("[" + str(warn[0]) + ":] " + warn[2]) elif warn[0] == -1: warnings.append("[:" + str(warn[1]) + "] " + warn[2]) else: warnings.append("[" + str(warn[0]) + ":" + str(warn[1]) + "] " + warn[2]) self.__navBar.setWarnings(warnings) else: self.__navBar.clearWarnings() self.scene.clear() try: # Top level canvas has no adress and no parent canvas canvas = VirtualCanvas(self.cflowSettings, None, None, None) canvas.layoutModule(self.__cf) canvas.setEditor(self.__editor) width, height = canvas.render() self.scene.setSceneRect(0, 0, width, height) canvas.draw(self.scene, 0, 0) except Exception, exc: logging.error(str(exc)) raise