Exemplo n.º 1
0
    def test_traceback_clear(self):
        import inspect, sys

        sys.exc_clear = Mock()
        frame_list = []

        def raise_dummy():
            frame_str_temp = str(inspect.currentframe().__repr__)
            frame_list.append(frame_str_temp)
            local_value = 1214
            raise KeyError('foo')

        try:
            raise_dummy()
        except KeyError as exc:
            traceback_clear(exc)

            if sys.version_info >= (3, 5, 0):
                tb_ = exc.__traceback__
                while tb_ is not None:
                    if str(tb_.tb_frame.__repr__) == frame_list[0]:
                        assert len(tb_.tb_frame.f_locals) == 0
                    tb_ = tb_.tb_next
            elif (2, 7, 0) <= sys.version_info < (3, 0, 0):
                sys.exc_clear.assert_called()

        try:
            raise_dummy()
        except KeyError as exc:
            traceback_clear()

            if sys.version_info >= (3, 5, 0):
                tb_ = exc.__traceback__
                while tb_ is not None:
                    if str(tb_.tb_frame.__repr__) == frame_list[0]:
                        assert len(tb_.tb_frame.f_locals) == 0
                    tb_ = tb_.tb_next
            elif (2, 7, 0) <= sys.version_info < (3, 0, 0):
                sys.exc_clear.assert_called()

        try:
            raise_dummy()
        except KeyError as exc:
            traceback_clear(str(exc))

            if sys.version_info >= (3, 5, 0):
                tb_ = exc.__traceback__
                while tb_ is not None:
                    if str(tb_.tb_frame.__repr__) == frame_list[0]:
                        assert len(tb_.tb_frame.f_locals) == 0
                    tb_ = tb_.tb_next
            elif (2, 7, 0) <= sys.version_info < (3, 0, 0):
                sys.exc_clear.assert_called()
Exemplo n.º 2
0
    def test_traceback_clear(self):
        import inspect
        import sys
        sys.exc_clear = Mock()
        frame_list = []

        def raise_dummy():
            frame_str_temp = str(inspect.currentframe().__repr__)
            frame_list.append(frame_str_temp)
            raise KeyError('foo')

        try:
            raise_dummy()
        except KeyError as exc:
            traceback_clear(exc)

            tb_ = exc.__traceback__
            while tb_ is not None:
                if str(tb_.tb_frame.__repr__) == frame_list[0]:
                    assert len(tb_.tb_frame.f_locals) == 0
                tb_ = tb_.tb_next

        try:
            raise_dummy()
        except KeyError as exc:
            traceback_clear()

            tb_ = exc.__traceback__
            while tb_ is not None:
                if str(tb_.tb_frame.__repr__) == frame_list[0]:
                    assert len(tb_.tb_frame.f_locals) == 0
                tb_ = tb_.tb_next

        try:
            raise_dummy()
        except KeyError as exc:
            traceback_clear(str(exc))

            tb_ = exc.__traceback__
            while tb_ is not None:
                if str(tb_.tb_frame.__repr__) == frame_list[0]:
                    assert len(tb_.tb_frame.f_locals) == 0
                tb_ = tb_.tb_next