def main(pythonFile): info = cdmpyparser.getBriefModuleInfoFromFile(pythonFile) if not info.isOK: print("Error parsing the file " + pythonFile) return 1 print(info.niceStringify()) return 0
def test_print_func(self): """Test print statements""" pythonFile = self.dir + "print2.py" info = cdmpyparser.getBriefModuleInfoFromFile(pythonFile) if not info.isOK: outFileName = pythonFile.replace(".py", ".out") outFile = open(outFileName, "w") for item in info.errors: outFile.write("\n" + item) for item in info.lexerErrors: outFile.write("\n" + item) outFile.close() if not info.isOK: self.fail("Error testing the print function")
def get(self, path): """Provides the required modinfo""" path = realpath(path) try: modInfo = self.__cache[path] if not exists(path): del self.__cache[path] raise Exception("Cannot open " + path) lastModTime = getmtime(path) if lastModTime <= modInfo[0]: return modInfo[1] # update the key info = getBriefModuleInfoFromFile(path) self.__cache[path] = (lastModTime, info) return info except KeyError: if not exists(path): raise Exception("Cannot open " + path) info = getBriefModuleInfoFromFile(path) self.__cache[path] = (getmtime(path), info) return info
def test_lone_import(self): """Test for lone import keyword""" pythonFile = self.dir + "loneimport.py" info = cdmpyparser.getBriefModuleInfoFromFile(pythonFile) if info.isOK: self.fail("lone import test failure. Expected error. Option: " "directly from file: " + pythonFile) f = open(pythonFile) content = f.read() f.close() info = cdmpyparser.getBriefModuleInfoFromMemory(content) if info.isOK: self.fail("lone import test failure. Expected error. Option: " "from memory. File: " + pythonFile)
def cdmpyparserTest(files): """Loop for the codimension parser""" errorCount = 0 count = 0 for item in files: # print("Processing " + item + " ...") tempObj = cdmpyparser.getBriefModuleInfoFromFile(item) if SHOW_ERRORS: if not tempObj.isOK: errorCount += 1 print("Failed to parse: " + item) for item in tempObj.errors: print(item) for item in tempObj.lexerErrors: print(" L: " + item) count += 1 print("cdmpyparser: processed " + str(count) + " file(s)") print("cdmpyparser: number of errors: " + str(errorCount))
def test_wrong_indent(self): """Test wrong indent""" pythonFile = self.dir + "wrong_indent.py" info = cdmpyparser.getBriefModuleInfoFromFile(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(info.niceStringify()) for item in info.errors: outFile.write("\n" + item) outFile.close() okFileName = pythonFile.replace(".py", ".ok") if not files_equal(outFileName, okFileName): self.fail("wrong indent test failed")
def test_wrong_stop(self): """Test wrong stop of the parser""" pythonFile = self.dir + "wrong_stop.py" info = cdmpyparser.getBriefModuleInfoFromFile(pythonFile) if info.isOK: self.fail("Wrong stop test failed. Expected error. Option: " "directly from file " + pythonFile) outFileName = pythonFile.replace(".py", ".out") outFile = open(outFileName, "w") outFile.write(info.niceStringify()) for item in info.errors: outFile.write("\n" + item) for item in info.lexerErrors: outFile.write("\n" + item) outFile.close() okFileName = pythonFile.replace(".py", ".ok") if not files_equal(outFileName, okFileName): self.fail("wrong stop of the parser test failed")
def meat(self, pythonFile, errorMsg): """The test process meat""" info = cdmpyparser.getBriefModuleInfoFromFile(pythonFile) if not info.isOK: self.fail("Error parsing the file " + pythonFile + ". Option: directly from a file.") f = open(pythonFile) content = f.read() f.close() info = cdmpyparser.getBriefModuleInfoFromMemory(content) if not info.isOK: self.fail("Error parsing the file " + pythonFile + ". Option: from memory.") outFileName = pythonFile.replace(".py", ".out") outFile = open(outFileName, "w") outFile.write(info.niceStringify()) outFile.close() okFileName = pythonFile.replace(".py", ".ok") if not files_equal(outFileName, okFileName): self.fail(errorMsg)