def testSetFlushConsole(self): flush = {'count': 0} def f(): flush['count'] = flush['count'] + 1 rinterface.set_flushconsole(f) self.assertEqual(rinterface.get_flushconsole(), f) rinterface.baseenv.get("flush.console")() self.assertEqual(1, flush['count']) rinterface.set_writeconsole(rinterface.consoleFlush)
def testSetFlushConsole(self): flush = {"count": 0} def f(): flush["count"] = flush["count"] + 1 rinterface.set_flushconsole(f) self.assertEqual(rinterface.get_flushconsole(), f) rinterface.baseenv.get("flush.console")() self.assertEqual(1, flush["count"]) rinterface.set_writeconsole_regular(rinterface.consoleFlush)
def testFlushConsoleWithError(self): def f(prompt): raise Exception("Doesn't work.") rinterface.set_flushconsole(f) tmp_file = tempfile.NamedTemporaryFile() stderr = sys.stderr sys.stderr = tmp_file try: res = rinterface.baseenv.get("flush.console")() except Exception, e: sys.stderr = stderr raise e
def testFlushConsoleWithError(self): def f(prompt): raise Exception("Doesn't work.") rinterface.set_flushconsole(f) tmp_file = tempfile.NamedTemporaryFile() stderr = sys.stderr sys.stderr = tmp_file try: res = rinterface.baseenv.get("flush.console")() except Exception as e: sys.stderr = stderr raise e sys.stderr = stderr tmp_file.flush() tmp_file.seek(0) self.assertEqual("Doesn't work.", str(sys.last_value))