Exemple #1
0
 def enable_debug(self):
     """Wrap the resource methods with debugger."""
     debug(self.connect, ignore_exceptions=[KeyboardInterrupt, BdbQuit])
     debug(self.initialize, ignore_exceptions=[KeyboardInterrupt, BdbQuit])
     debug(self.finalize, ignore_exceptions=[KeyboardInterrupt, BdbQuit])
     debug(self.validate, ignore_exceptions=[KeyboardInterrupt, BdbQuit])
     debug(self.store_state, ignore_exceptions=[KeyboardInterrupt, BdbQuit])
     for resource in self.get_sub_resources():
         resource.enable_debug()
Exemple #2
0
def test_ignoring_excepted_specific_attribute_exception():
    """Test ignoring a specific exception that's excepted."""
    def func():
        try:
            raise utils.TestError()
        except utils.TestError:
            pass

    debug(func, catch_exception=utils.TestError)
    func()
Exemple #3
0
def test_ignoring_excepted_specific_exception():
    """Test ignoring a specific exception that's excepted."""
    def func():
        try:
            raise ValueError()
        except ValueError:
            pass

    debug(func, catch_exception=ValueError)
    func()
Exemple #4
0
def test_ignore_all_exceptions():
    """Test ignoring all exceptions."""
    def func():
        raise Exception()

    func = debug(func, ignore_exceptions=None)

    with pytest.raises(Exception):
        func()
Exemple #5
0
def test_non_targeted_exceptions():
    """Test raising exceptions that don't match the targeted exception."""
    def func():
        raise ValueError()

    func = debug(func, catch_exception=AssertionError)

    with pytest.raises(ValueError):
        func()
Exemple #6
0
def test_ignoring_exceptions():
    """Test ignoring specific exceptions that should be raised."""
    def func():
        raise ValueError()

    func = debug(func, ignore_exceptions=[ValueError])

    with pytest.raises(ValueError):
        func()
Exemple #7
0
def test_targeting_specific_exception():
    """Test targeting specific exception that we should stop at it."""
    def func():
        assert False

    func = debug(func, catch_exception=AssertionError)

    with patch('IPython.terminal.debugger.TerminalPdb.__init__'), \
            patch('bdb.Bdb.set_trace') as set_trace:
        func()
        assert set_trace.called
Exemple #8
0
def test_debugging_when_source_code_is_missing():
    """Test debugging code that its source code is not available.

    Note:
        In this kind of code we cannot stop at an error, so we fall-back to
        simply running this code without interference.
    """
    exec("def function(): 1 / 0", locals(), globals())
    func = debug(globals()["function"])

    with pytest.raises(ArithmeticError):
        func()
Exemple #9
0
    def __init__(self,
                 indexer=count(),
                 methodName='runTest',
                 base_work_dir=ROTEST_WORK_DIR,
                 save_state=True,
                 force_initialize=False,
                 config=None,
                 parent=None,
                 run_data=None,
                 enable_debug=True,
                 resource_manager=None,
                 skip_init=False):

        if enable_debug:
            for method_name in (methodName, self.SETUP_METHOD_NAME,
                                self.TEARDOWN_METHOD_NAME):

                debug(getattr(self, method_name),
                      ignore_exceptions=[
                          KeyboardInterrupt, unittest.SkipTest, BdbQuit
                      ])

        super(AbstractTest, self).__init__(methodName)

        self._tags = None
        self.result = None
        self.config = config
        self.parent = parent
        self.skip_init = skip_init
        self.save_state = save_state
        self.identifier = indexer.next()
        self.enable_debug = enable_debug
        self.force_initialize = force_initialize
        self.parents_count = self._get_parents_count()

        self.all_resources = AttrDict()
        self.locked_resources = AttrDict()

        self._is_client_local = False
        self.resource_manager = resource_manager
Exemple #10
0
    def __init__(self,
                 methodName='test_method',
                 indexer=count(),
                 parent=None,
                 save_state=True,
                 config=None,
                 enable_debug=False,
                 resource_manager=None,
                 skip_init=False):

        if enable_debug:
            for method_name in (methodName, self.SETUP_METHOD_NAME,
                                self.TEARDOWN_METHOD_NAME):

                debug(getattr(self, method_name),
                      ignore_exceptions=[
                          KeyboardInterrupt, unittest.SkipTest, BdbQuit
                      ])

        super(AbstractTest, self).__init__(methodName)

        self.result = None
        self.is_main = True
        self.config = config
        self.parent = parent
        self.skip_init = skip_init
        self.save_state = save_state
        self.identifier = next(indexer)
        self.enable_debug = enable_debug
        self.parents_count = self._get_parents_count()

        self.all_resources = AttrDict()
        self.locked_resources = AttrDict()

        self._is_client_local = False
        self.resource_manager = resource_manager

        if parent is not None:
            parent.addTest(self)
Exemple #11
0
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()
Exemple #12
0
def test_debugging_raising_method():
    """Test debugging a raising bounded-method."""
    class A(object):
        def should_raise(self):
            raise Exception()

    a = A()
    a.should_raise = debug(a.should_raise)

    with patch('IPython.terminal.debugger.TerminalPdb.__init__'), \
            patch('bdb.Bdb.set_trace') as set_trace:
        a.should_raise()
        assert set_trace.called
Exemple #13
0
def test_ignoring_excepted_exceptions_only_on_try_except_scope():
    """Test ignoring exceptions that should be only on try except scope."""
    def func():
        try:
            pass
        except ValueError:
            pass

        raise ValueError()

    func = debug(func)

    with patch('IPython.terminal.debugger.TerminalPdb.__init__'), \
            patch('bdb.Bdb.set_trace') as set_trace:
        func()
        assert set_trace.called
Exemple #14
0
def test_depth_infinite():
    """Test wrapping a function infinite call levels."""
    def func_lowest():
        raise ValueError()
        pass

    def func_middle():
        func_lowest()
        pass

    def func_upper():
        func_middle()
        pass

    func_upper = debug(func_upper, depth=-1)

    with patch('IPython.terminal.debugger.TerminalPdb.__init__'), \
            patch('bdb.Bdb.set_trace', SaveFuncName()) as name_saver:
        func_upper()
        assert name_saver.func_name == "func_lowest"
Exemple #15
0
def test_no_depth():
    """Test wrapping a function without propagating to lower calls."""
    def func_lowest():
        raise ValueError()
        pass

    def func_middle():
        func_lowest()
        pass

    def func_upper():
        func_middle()
        pass

    func_upper = debug(func_upper, depth=0)

    with patch('IPython.terminal.debugger.TerminalPdb.__init__'), \
            patch('bdb.Bdb.set_trace', SaveFuncName()) as name_saver:
        func_upper()
        assert name_saver.func_name == "func_upper"
Exemple #16
0
def test_debugging_non_compatible_type():
    """Test raising an indicative error when trying to debug a bad type."""
    with pytest.raises(TypeError,
                       match="Debugger can only wrap functions and classes. "
                             "Got object 1 of type int"):
        debug(1)