コード例 #1
0
    def process(self):
        """Parses the content and displays the results"""
        if not self.__connected:
            self.__connectEditorSignals()

        start = timer()
        cf = getControlFlowFromMemory(self.__editor.text)
        end = timer()
        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
        if self.isDebugMode():
            logging.info('Parsed file: %s', formatFlow(str(self.__cf)))
            logging.info('Parse timing: %f', end - start)

        # Collect warnings (parser + CML warnings) and valid groups
        self.__validGroups = []
        self.__allGroupId = set()
        allWarnings = self.__cf.warnings + \
                      CMLVersion.validateCMLComments(self.__cf,
                                                     self.__validGroups,
                                                     self.__allGroupId)

        # That will clear the error tooltip as well
        self.__navBar.updateInfoIcon(self.__navBar.STATE_OK_UTD)

        if allWarnings:
            warnings = []
            for warn in allWarnings:
                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.redrawScene()
コード例 #2
0
    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()

        controlFlowMemory = getControlFlowFromMemory(content)
        if controlFlowMemory.isOK != expectedOK:
            self.fail("Error parsing the file " + pythonFile +
                      ". Option: from memory.")

        #if formatFlow(str(controlFlow)) != formatFlow(str(controlFlowMemory)):
        #    print('Memory:\n' + formatFlow(str(controlFlowMemory)))
        #    print('File:\n' + formatFlow(str(controlFlow)))
        #    self.fail("Control flow from memory differs the one from file")

        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)