def test_print_exception_unhashable(self):
        class UnhashableException(Exception):
            def __eq__(self, other):
                return True

        ex1 = UnhashableException('ex1')
        ex2 = UnhashableException('ex2')
        try:
            raise ex2 from ex1
        except UnhashableException:
            try:
                raise ex1
            except UnhashableException:
                with captured_stderr() as output:
                    with mock.patch.object(run, 'cleanup_traceback') as ct:
                        ct.side_effect = lambda t, e: t
                        run.print_exception()

        tb = output.getvalue().strip().splitlines()
        if has_no_debug_ranges():
            self.assertEqual(11, len(tb))
            self.assertIn('UnhashableException: ex2', tb[3])
            self.assertIn('UnhashableException: ex1', tb[10])
        else:
            self.assertEqual(13, len(tb))
            self.assertIn('UnhashableException: ex2', tb[4])
            self.assertIn('UnhashableException: ex1', tb[12])
Exemple #2
0
def main(del_exitfunc=False):

    global exit_now
    global quitting
    global no_exitfunc
    no_exitfunc = del_exitfunc
    #time.sleep(15) # test subprocess not responding
    try:
        assert (len(sys.argv) > 1)
        port = int(sys.argv[-1])
    except:
        print >> sys.stderr, "IDLE Subprocess: no IP port passed in sys.argv."
        return
    sys.argv[:] = [""]
    sockthread = threading.Thread(target=manage_socket,
                                  name='SockThread',
                                  args=((run.LOCALHOST, port), ))
    sockthread.setDaemon(True)
    sockthread.start()
    while 1:
        try:
            if exit_now:
                try:
                    exit()
                except KeyboardInterrupt:
                    # exiting but got an extra KBI? Try again!
                    continue
            try:
                seq, request = rpc.request_queue.get(block=True, timeout=0.05)
#                 print "request:",request
            except Queue.Empty:
                continue
            method, args, kwargs = request
            ret = method(*args, **kwargs)
            #             print "respone:",ret
            rpc.response_queue.put((seq, ret))
        except KeyboardInterrupt:
            if quitting:
                exit_now = True
            continue
        except SystemExit:
            raise
        except:
            type, value, tb = sys.exc_info()
            try:
                run.print_exception()
                rpc.response_queue.put((seq, None))
            except:
                # Link didn't work, print same exception to __stderr__
                traceback.print_exception(type, value, tb, file=sys.__stderr__)
                exit()
            else:
                continue
 def test_get_multiple_message(self, mock):
     d = self.data
     data2 = ((d[0], d[1]), (d[1], d[2]), (d[2], d[0]))
     subtests = 0
     for (code1, exc1, msg1), (code2, exc2, msg2) in data2:
         with self.subTest(codes=(code1, code2)):
             try:
                 eval(compile(code1, '', 'eval'))
             except exc1:
                 try:
                     eval(compile(code2, '', 'eval'))
                 except exc2:
                     with captured_stderr() as output:
                         run.print_exception()
                     actual = output.getvalue()
                     self.assertIn(msg1, actual)
                     self.assertIn(msg2, actual)
                     subtests += 1
     self.assertEqual(subtests, len(data2))  # All subtests ran?
Exemple #4
0
    def test_print_exception_unhashable(self):
        class UnhashableException(Exception):
            def __eq__(self, other):
                return True

        ex1 = UnhashableException('ex1')
        ex2 = UnhashableException('ex2')
        try:
            raise ex2 from ex1
        except UnhashableException:
            try:
                raise ex1
            except UnhashableException:
                with captured_stderr() as output:
                    with mock.patch.object(run,
                                           'cleanup_traceback') as ct:
                        ct.side_effect = lambda t, e: t
                        run.print_exception()

        tb = output.getvalue().strip().splitlines()
        self.assertEqual(11, len(tb))
        self.assertIn('UnhashableException: ex2', tb[3])
        self.assertIn('UnhashableException: ex1', tb[10])
    def test_exceptions(self):
        ex = self.ex
        ex.runcode('1/0')
        self.assertIs(ex.user_exc_info[0], ZeroDivisionError)

        self.addCleanup(setattr, sys, 'excepthook', sys.__excepthook__)
        sys.excepthook = lambda t, e, tb: run.print_exception(t)
        ex.runcode('1/0')
        self.assertIs(self.prt.args[0], ZeroDivisionError)

        sys.excepthook = lambda: None
        ex.runcode('1/0')
        t, e, tb = ex.user_exc_info
        self.assertIs(t, TypeError)
        self.assertTrue(isinstance(e.__context__, ZeroDivisionError))