示例#1
0
文件: ut.py 项目: topin89/codimension
    def proceedWithFile(self, needToParse=True):
        """Taks the file from settings and processes it"""
        if needToParse:
            if self.verbose:
                self.logMessage("Parsing file " + self.fName)
            self.cFlow = getControlFlowFromFile(self.fName)
            if self.verbose:
                self.logMessage("Parsed file:")
                self.logMessage(formatFlow(str(self.cFlow)))

            if len(self.cFlow.errors) != 0:
                self.logMessage("No drawing due to parsing errors")
                return

            if len(self.cFlow.warnings) != 0:
                self.logMessage("Parser warnings: ")
                for warn in self.cFlow.warnings:
                    self.logMessage(str(warn[0]) + ": " + warn[1])
        else:
            if self.cFlow is None:
                self.logMessage("No control flow object")
                return
            if len(self.cFlow.errors) != 0:
                self.logMessage("No drawing due to parsing errors")
                return

        self.scene.clear()

        if self.verbose:
            self.logMessage("Layouting ...")
        try:
            # To pick up possibly changed settings
            importlib.reload(cflowsettings)
            cflowSettings = cflowsettings.getDefaultCflowSettings(self)
            if DEBUG:
                cflowSettings.debug = True

            # Top level canvas has no adress and no parent canvas
            canvas = vcanvas.VirtualCanvas(cflowSettings, None, None, None)
            canvas.layout(self.cFlow, CellElement.FILE_SCOPE)
            if self.verbose:
                self.logMessage("Layout is done:")
                self.logMessage(str(canvas))
                self.logMessage("Rendering ...")

            width, height = canvas.render()
            if self.verbose:
                self.logMessage("Rendering is done. Scene size: " +
                                str(width) + "x" + str(height) +
                                ". Drawing ...")

            self.scene.setSceneRect(0, 0, width, height)
            canvas.draw(self.scene, 0, 0)
        except Exception as exc:
            self.logMessage("Exception:\n" + str(exc))
            raise

        if self.verbose:
            self.logMessage("Drawing is done.")
示例#2
0
def cdmcfparserTest(files):
    """Loop for the codimension parser"""
    count = 0
    for item in files:
        # print("Processing " + item + " ...")
        tempObj = getControlFlowFromFile(item)
        count += 1
    print("cdmcf: processed " + str(count) + " file(s)")
示例#3
0
    def test_wrong_indent(self):
        """Test wrong indent"""
        pythonFile = self.dir + "wrong_indent.py"
        info = getControlFlowFromFile(pythonFile)
        if info.isOK:
            self.fail("Expected parsing error for file " + pythonFile +
                      ". Option: directly from file.")

        outFileName = pythonFile.replace(".py", ".out")
        outFile = open(outFileName, "w")
        outFile.write(str(info) + "\n")
        outFile.close()

        okFileName = pythonFile.replace(".py", ".ok")
        if not files_equal(outFileName, okFileName):
            self.fail("wrong indent test failed")
示例#4
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)
示例#5
0
def cdmcfparserTest(fName):
    """Loop for the codimension parser"""
    tempObj = getControlFlowFromFile(fName)
    tempObj = None
示例#6
0
            shift = shifts[-1]
            result += '\n'
            result += shift * " "
            pos = shift
            result += sym
            pos += 1
            if IsNextList(index, maxIndex, s):
                nextIsList = True
            else:
                del shifts[-1]
                nextIsList = False
            continue
        result += sym
        pos += 1
    return result


import cdmcfparser
from cdmcfparser import getControlFlowFromFile, VERSION

if len(sys.argv) != 2:
    print("A file name is expected", file=sys.stderr)
    sys.exit(1)

print("Running control flow parser version: " + VERSION)
print("Module location: " + cdmcfparser.__file__)

controlFlow = getControlFlowFromFile(sys.argv[1])
print(formatFlow(str(controlFlow)))
sys.exit(0)