예제 #1
0
    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))
예제 #2
0
 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)
예제 #3
0
 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))
예제 #4
0
    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)
예제 #5
0
    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))
예제 #6
0
    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
예제 #7
0
    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
예제 #8
0
    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))
예제 #9
0
 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
예제 #10
0
 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