def __runFile(self): PythonLib.ensureDirectoryExists(self.USER_FILE_PATH) outputFromDebugger = open(self.USER_FILE_PATH + self.userID + 'ResultFile.txt', 'w+') inputForDebugger = io.StringIO(unicode(self.pythonFileBuilder.getPdcInstructions(self.stepNumber))) debugger = pdb.Pdb(completekey='tab', stdin=inputForDebugger, stdout=outputFromDebugger) self.userCodeException = '' try: debugger.run('import ' + self.userCodeFilePath, {}, {}) fileParser = FileParser.FileParser(self.USER_FILE_PATH + self.userID + 'ResultFile.txt') self.currentLineInUserCode = fileParser.get_current_line() except Exception, e: print "\n\n__runFile = " + str(e) + "\n\n" self.userCodeException = PythonLib.parseExceptionMessage(e) # Exception line number is off by eight self.currentLineInUserCode = PythonLib.parseExceptionLineNumber(e)-8
def __check_For_Function_Name_And_Local_Vars(self, line): if PythonLib.startsWith(line, 'FunctionName==='): function_Name = line.split('===')[1]; local_vars = line.split('===')[2]; if self.__is_user_code_function(function_Name): depth = str(self.frame_depth).zfill(3) + ") " self.frame_depth += 1 self.functions_including_their_vars[depth + function_Name] = self.__format_local_vars(local_vars)
def getResults(self): tests = self.unitTests.split('\n') testResults = {} for test in tests: if len(str(test)) > 0: try: testResults[test] = self.__runTest(self.methodBody, test) except Exception, e: testResults[test] = PythonLib.parseExceptionMessage(e)