def testSetReadConsole(self): yes = "yes\n" def sayyes(prompt): return yes rinterface.setReadConsole(sayyes) self.assertEquals(rinterface.getReadConsole(), sayyes) res = rinterface.baseNameSpaceEnv["readline"]() self.assertEquals(yes.strip(), res[0]) rinterface.setReadConsole(rinterface.consoleRead)
def testReadConsoleWithError(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.setReadConsole(f) outfile = tempfile.NamedTemporaryFile(mode = 'w', delete=False) stderr = sys.stderr sys.stderr = outfile try: res = rinterface.baseNameSpaceEnv["readline"]() except Exception, e: sys.stderr = stderr raise e
def tearDown(self): rinterface.setWriteConsole(rinterface.consolePrint) rinterface.setReadConsole(rinterface.consoleRead) rinterface.setReadConsole(rinterface.consoleFlush)