Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added breakpoint signal #23

Merged
merged 3 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ipdbugger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@
import types
import inspect
import traceback
from bdb import BdbQuit

import colorama
from termcolor import colored
from future.utils import raise_
from IPython.terminal.debugger import TerminalPdb

from .signals import register_break_signal

# Enable color printing on screen.
colorama.init()

Expand Down Expand Up @@ -287,7 +290,8 @@ def get_last_lineno(node):
return max_lineno


def debug(victim=None, ignore_exceptions=(), catch_exception=None, depth=0):
def debug(victim=None, ignore_exceptions=(BdbQuit,),
catch_exception=None, depth=0):
"""A decorator function to catch exceptions and enter debug mode.

Args:
Expand All @@ -313,6 +317,7 @@ def wrapper(real_victim):

return wrapper

register_break_signal()
if inspect.isfunction(victim):
if hasattr(victim, '_ipdebug_wrapped'):
# Don't wrap the function more than once
Expand Down
31 changes: 31 additions & 0 deletions ipdbugger/signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Signals usage in Rotest."""
# pylint: disable=global-statement,no-member
import sys
import signal


BREAKPOINT_SIGNAL_REGISTERED = False


class BreakPointException(Exception):
"""An exception to raise on the break signal."""


def raise_exception_handler(_signum, _frame):
"""Raise a break-point exception."""
raise BreakPointException()


def register_break_signal():
"""Register raising an exception on break signal if needed."""
global BREAKPOINT_SIGNAL_REGISTERED
if BREAKPOINT_SIGNAL_REGISTERED:
return

BREAKPOINT_SIGNAL_REGISTERED = True

if sys.platform == "win32":
signal.signal(signal.SIGBREAK, raise_exception_handler)

else:
signal.signal(signal.SIGQUIT, raise_exception_handler)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Setup file for handling packaging and distribution."""
from setuptools import setup

__version__ = "2.4.1"
__version__ = "2.5.0"

setup(
name="ipdbugger",
Expand Down
15 changes: 15 additions & 0 deletions tests/test_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,21 @@ def func_upper():
assert name_saver.func_name == "func_lowest"


def test_depth_and_catch_attribute():
"""Test wrapping a function one more call level."""
def func_lower():
raise utils.TestError()

def func_upper():
try:
func_lower()
except (utils.TestError, ValueError):
pass

func_upper = debug(func_upper, depth=1)
func_upper()


def test_ignore_all_exceptions():
"""Test ignoring all exceptions."""
def func():
Expand Down