def testChooseFileWithError(self): def noconsole(x): pass rinterface.set_writeconsole( noconsole) # reverted by the tearDown method def f(prompt): raise Exception("Doesn't work.") rinterface.set_choosefile(f) tmp_file = tempfile.NamedTemporaryFile() stderr = sys.stderr sys.stderr = tmp_file try: res = rinterface.baseenv["file.choose"]() except rinterface.RRuntimeError: pass 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))
def testSetChooseFile(self): me = "me" def chooseMe(prompt): return me rinterface.set_choosefile(chooseMe) self.assertEqual(rinterface.get_choosefile(), chooseMe) res = rinterface.baseenv["file.choose"]() self.assertEqual(me, res[0]) rinterface.set_choosefile(rinterface.chooseFile)
def testChooseFileWithError(self): def noconsole(x): pass rinterface.set_writeconsole_regular(noconsole) # reverted by the tearDown method def f(prompt): raise Exception("Doesn't work.") rinterface.set_choosefile(f) self.assertRaises(rinterface.RRuntimeError, rinterface.baseenv["file.choose"]) self.assertEqual("Doesn't work.", str(sys.last_value))
def testChooseFileWithError(self): def noconsole(x): pass rinterface.set_writeconsole_regular( noconsole) # reverted by the tearDown method def f(prompt): raise Exception("Doesn't work.") rinterface.set_choosefile(f) self.assertRaises(rinterface.RRuntimeError, rinterface.baseenv["file.choose"]) self.assertEqual("Doesn't work.", str(sys.last_value))
def testChooseFileWithError(self): def noconsole(x): pass rinterface.set_writeconsole(noconsole) # reverted by the tearDown method def f(prompt): raise Exception("Doesn't work.") rinterface.set_choosefile(f) tmp_file = tempfile.NamedTemporaryFile() stderr = sys.stderr sys.stderr = tmp_file try: res = rinterface.baseenv["file.choose"]() except rinterface.RRuntimeError, rre: pass
def testChooseFileWithError(self): def noconsole(x): pass rinterface.set_writeconsole( noconsole) # reverted by the tearDown method def f(prompt): raise Exception("Doesn't work.") rinterface.set_choosefile(f) tmp_file = tempfile.NamedTemporaryFile() stderr = sys.stderr sys.stderr = tmp_file try: res = rinterface.baseenv["file.choose"]() except rinterface.RRuntimeError, rre: pass
def testChooseFileWithError(self): def noconsole(x): pass rinterface.set_writeconsole(noconsole) # reverted by the tearDown method def f(prompt): raise Exception("Doesn't work.") rinterface.set_choosefile(f) tmp_file = tempfile.NamedTemporaryFile() stderr = sys.stderr sys.stderr = tmp_file try: res = rinterface.baseenv["file.choose"]() except rinterface.RRuntimeError: pass 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))
def tearDown(self): rinterface.set_writeconsole(rinterface.consolePrint) rinterface.set_readconsole(rinterface.consoleRead) rinterface.set_readconsole(rinterface.consoleFlush) rinterface.set_choosefile(rinterface.chooseFile) sys.last_value = None