def run(self): """ run the interpreter """ print( "\n******* beginning to run Ezhil test with timeout = %d(s)*******" % (self.timeout)) self._tested = True self.success = False try: #redirect output = True, when you need a TIMEOUT ezhil.EzhilFileExecuter(self.filename, debug=False, redirectop=True, TIMEOUT=self.timeout) except TimeoutException as tex: self.success = True #expected to raise an exception except Exception as ex: if (self.debug): print("Ezhil Interpreter stopped with the exception ....") if (self.debug): print(ex.message, ex.args) raise ex finally: print("********* completed Ezhil test *********") # cleanup process files for fileName in glob("*.out"): os.unlink(fileName) pass return self.success
def MPRunner_actor(pipe, filename): multiprocessing.freeze_support() GObject.threads_init() is_success = False ezhil.EzhilCustomFunction.set(GtkStaticWindow.dummy_input) old_stdin = sys.stdin old_stdout = sys.stdout old_stderr = sys.stderr tmpfilename = tempfile.mktemp() + ".n" res_std_out = u"" old_exit = sys.exit sys.exit = lambda x: 0 try: sys.stdout = codecs.open(tmpfilename, "w", "utf-8") sys.stderr = sys.stdout executer = ezhil.EzhilFileExecuter(filename) executer.run() is_success = True except Exception as e: print(u" '{0}':\n{1}'".format(filename, unicode(e))) finally: print(u"######- நிரல் இயக்கி முடிந்தது-######") sys.exit = old_exit sys.stdout.flush() sys.stdout.close() with codecs.open(tmpfilename, u"r", u"utf-8") as fp: res_std_out = fp.read() sys.stdout = old_stdout sys.stderr = old_stderr sys.stdin = old_stdin #print(pipe) #print("sending data back to source via pipe") pipe.send([res_std_out, is_success]) pipe.close()
def run(self): """ this class expects to receive an exception on running the Ezhil interpreter, and when we match the exception message the test is supposed to pass """ print("\n" * 3) try: self._tested = True ezhil.EzhilFileExecuter(file_input=self.filename, debug=self.debug, redirectop=False, TIMEOUT=None, safe_mode=self.safe_mode) self.success = False # we expected an exception except Exception as ex: if self.partial: return True self.success = False # we expected a particular kind of exception if self.exception: self.success = isinstance(ex, self.exception) if (self.debug): print(">>>>>>>>>>>> We found an exception \n %s \n" % ex) if not self.success: traceback.print_stack() raise Exception( "Expected exception class %s was not found; instead %s was received." % (self.exception, ex)) if (self.debug): print(u"### EXCEPTION ==> \n %s" % unicode(ex)) if self.message: self.success = True # check multiple messages if not isinstance(self.message, list): self.message = [self.message] for msg in self.message: if (self.debug): print(self.success) if (self.debug): print("### testing ", unicode(msg)) self.success = self.success and \ (( ex.message.find( msg ) >= 0 ) or \ len(filter(lambda x: x.find( msg ) >=0, ex.args )) > 0 or unicode(ex).find( msg ) >= 0 ) if (self.debug): print(self.success) if not self.success and not self.partial: print("######## TEST FAILED #############") print(self.success, self.partial) print(u"ACTUAL == %s" % unicode(ex)) print(u"EXPECTED == %s" % unicode(self.message)) raise Exception( u"Expected message %s was not found. We found message %s" % (self.message, unicode(ex))) return self.success raise Exception(u"Expected message %s was not found.", unicode(self.exception))
def run( self ): """ run the interpreter """ print("\n******* beginning to run Ezhil test *******") self._tested = True try: ezhil.EzhilFileExecuter( self.filename , False, False ) self.success = True except Exception as ex: print("Ezhil Interpreter stopped with the exception ....") print( ex.message, ex.args ) raise ex finally: print("********* completed Ezhil test *********") pass return self.success
def run( self ): """ this class expects to receive an exception on running the Ezhil interpreter, and when we match the exception message the test is supposed to pass """ print "\n"*3 try: self._tested = True ezhil.EzhilFileExecuter( self.filename , self.dbg, False ) self.success = False # we expected an exception except Exception as ex: if self.partial: return True self.success = False # we expected a particular kind of exception if self.exception: self.success = isinstance( ex, self.exception ) print(">>>>>>>>>>>> We found an exception \n %s \n"%ex) if not self.success: raise Exception("Expected exception class %s was not found"%(self.exception,ex)) print( u"### EXCEPTION ==> \n %s"%unicode(ex) ) if self.message: self.success = True # check multiple messages if not isinstance(self.message, list): self.message = [self.message] for msg in self.message: print self.success print "### testing ",unicode(msg) self.success = self.success and \ (( ex.message.find( msg ) >= 0 ) or \ len(filter(lambda x: x.find( msg ) >=0, ex.args )) > 0 or unicode(ex).find( msg ) >= 0 ) print self.success if not self.success and not self.partial: print "######## TEST FAILED #############" print self.success,self.partial print(u"ACTUAL == %s"%unicode(ex)) print(u"EXPECTED == %s"%unicode(self.message)) raise Exception(u"Expected message %s was not found. We found message %s"%(self.message,unicode(ex))) return self.success raise Exception(u"Expected message %s was not found.",str(self.exception))
def MPRunner_actor(pipe, filename): multiprocessing.freeze_support() is_success = False old_stdin = sys.stdin old_stdout = sys.stdout old_stderr = sys.stderr tmpfilename = tempfile.mktemp() + ".n" res_std_out = u"" old_exit = sys.exit sys.exit = lambda x: 0 try: sys.stdout = codecs.open(tmpfilename, "w", "utf-8") sys.stderr = sys.stdout executer = ezhil.EzhilFileExecuter(filename, debug=False, redirectop=False, TIMEOUT=3, encoding="utf-8", doprofile=False, safe_mode=True) executer.run() is_success = True except Exception as e: print(u" '{0}':\n{1}'".format(filename, unicode(e))) finally: print(u"######- நிரல் இயக்கி முடிந்தது-######") sys.exit = old_exit sys.stdout.flush() sys.stdout.close() with codecs.open(tmpfilename, u"r", u"utf-8") as fp: res_std_out = fp.read() sys.stdout = old_stdout sys.stderr = old_stderr sys.stdin = old_stdin #print(pipe) #print("sending data back to source via pipe") pipe.send([res_std_out, is_success]) pipe.close()
def run(self): print("Kickstarting ... ThreadedRunner") ezhil.EzhilCustomFunction.set(Editor.dummy_input) ed = Editor.get_instance() filename = ed.filename old_stdin = sys.stdin old_stdout = sys.stdout old_stderr = sys.stderr is_success = False tmpfilename = tempfile.mktemp()+".n" res_std_out = u"" old_exit = sys.exit sys.exit = Editor.dummy_exit try: sys.stdout = codecs.open(tmpfilename,"w","utf-8") sys.stderr = sys.stdout; executer = ezhil.EzhilFileExecuter(filename) executer.run() is_success = True except Exception as e: print(u"Failed executing file '{0}':\n{1}'".format(filename, unicode(e))) finally: sys.exit = old_exit sys.stdout.flush() sys.stdout.close() with codecs.open(tmpfilename,u"r",u"utf-8") as fp: res_std_out = fp.read() sys.stdout = old_stdout sys.stderr = old_stderr sys.stdin = old_stdin ezhil.EzhilCustomFunction.reset() GLib.idle_add( ThreadedRunner.update_fcn, [ res_std_out,is_success ]) print("All done") return None