Exemple #1
0
 def testSetFlushConsole(self):
     flush = {'count': 0}
     def f():
         flush['count'] = flush['count'] + 1
         
     rinterface.setFlushConsole(f)
     self.assertEquals(rinterface.getFlushConsole(), f)
     rinterface.baseNameSpaceEnv.get("flush.console")()
     self.assertEquals(1, flush['count'])
     rinterface.setWriteConsole(rinterface.consoleFlush)
Exemple #2
0
    def testFlushConsoleWithError(self):
        if sys.version_info[0] == 2 and sys.version_info[1] < 6:
            self.assertTrue(False) # cannot be tested with Python < 2.6
            return None
        def f(prompt):
            raise Exception("Doesn't work.")
        rinterface.setFlushConsole(f)

        outfile = tempfile.NamedTemporaryFile(mode = 'w', 
                                              delete=False)
        stderr = sys.stderr
        sys.stderr = outfile
        try:
            res = rinterface.baseNameSpaceEnv.get("flush.console")()
        except Exception, e:
            sys.stderr = stderr
            raise e