Beispiel #1
0
 def new_cap_ex(body_func, except_type):
     e = capture_exception(body_func, Exception)
     if e:
         if (str(type(e)) == str(except_type)):
             return e
         raise e
     return None
 def fails_m(self, message, func, *args, **kwargs):
     def try_block():
         func(*args, **kwargs)
     ae = capture_exception(try_block, ASSERTION_ERROR)
     self.assertTrue(ae is not None)
     self.assertTrue(type(ae) is ASSERTION_ERROR)
     self.assertEqual(message, str(ae))
 def new_cap_ex(body_func, except_type):
     e = capture_exception(body_func, Exception)
     if e:
         if (str(type(e)) == str(except_type)):
             return e
         raise e
     return None
    def fails_m(self, message, func, *args, **kwargs):
        def try_block():
            func(*args, **kwargs)

        ae = capture_exception(try_block, ASSERTION_ERROR)
        self.assertTrue(ae is not None)
        self.assertTrue(type(ae) is ASSERTION_ERROR)
        self.assertEqual(message, str(ae))
 def test_assert_raises4(self):
     def not_precise():
         raise Exception("HELLO!!")
     def try_block():
         assert_raises(RuntimeError, not_precise)
     ex = capture_exception(try_block, Exception)
     self.assertTrue(ex is not None)
     self.assertTrue(type(ex) is Exception)
     # Make sure assert_raises gives us the original exception.
     self.assertEqual("HELLO!!", str(ex))
Beispiel #6
0
def assert_raises_instance(exception_type, function, *args, **kwargs):
    """Calls function and fails the test if an exception is not raised.

    The exception thrown must only be an instance of the given type.

    """
    actual_exception = compatability.capture_exception(
        lambda : function(*args, **kwargs),
        exception_type)
    if actual_exception is None:
        fail("Expected an exception of type %s to be raised." % exception_type)
    def test_assert_raises4(self):
        def not_precise():
            raise Exception("HELLO!!")

        def try_block():
            assert_raises(RuntimeError, not_precise)

        ex = capture_exception(try_block, Exception)
        self.assertTrue(ex is not None)
        self.assertTrue(type(ex) is Exception)
        # Make sure assert_raises gives us the original exception.
        self.assertEqual("HELLO!!", str(ex))
Beispiel #8
0
 def _run_assertion(self, assert_func, *args, **kwargs):
     """
     Runs an assertion method, but catches any failure and adds it as a
     string to the messages list.
     """
     if self.protected:
         def func():
             assert_func(*args, **kwargs)
         ae = capture_exception(func, ASSERTION_ERROR)
         if ae is not None:
             st = get_stack_trace_of_caller(2)
             self._add_exception(ASSERTION_ERROR, ae, st)
     else:
         assert_func(*args, **kwargs)
Beispiel #9
0
def assert_raises_instance(exception_type, function, *args, **kwargs):
    """Calls function and fails the test if an exception is not raised.

    The exception thrown must only be an instance of the given type. This means
    if "Exception" is expected but "RuntimeException" is raised the test will
    still pass. For a stricter function see assert_raises.

    :param exception_type: The expected exception type.
    :param function: The function to call, followed by its arguments.

    """
    actual_exception = compatability.capture_exception(
        lambda: function(*args, **kwargs), exception_type)
    if actual_exception is None:
        fail("Expected an exception of type %s to be raised." % exception_type)
Beispiel #10
0
def assert_raises_instance(exception_type, function, *args, **kwargs):
    """Calls function and fails the test if an exception is not raised.

    The exception thrown must only be an instance of the given type. This means
    if "Exception" is expected but "RuntimeException" is raised the test will
    still pass. For a stricter function see assert_raises.

    :param exception_type: The expected exception type.
    :param function: The function to call, followed by its arguments.

    """
    actual_exception = compatability.capture_exception(
        lambda : function(*args, **kwargs),
        exception_type)
    if actual_exception is None:
        fail("Expected an exception of type %s to be raised." % exception_type)
Beispiel #11
0
    def _run_assertion(self, assert_func, *args, **kwargs):
        """
        Runs an assertion method, but catches any failure and adds it as a
        string to the messages list.
        """
        if self.protected:

            def func():
                assert_func(*args, **kwargs)

            ae = capture_exception(func, ASSERTION_ERROR)
            if ae is not None:
                st = get_stack_trace_of_caller(2)
                self._add_exception(ASSERTION_ERROR, ae, st)
        else:
            assert_func(*args, **kwargs)
Beispiel #12
0
def assert_raises(exception_type, function, *args, **kwargs):
    """Calls function and fails the test if an exception is not raised.

    The exact type of exception must be thrown.

    """
    actual_exception = compatability.capture_exception(
        lambda : function(*args, **kwargs),
        exception_type)
    if actual_exception is None:
        fail("Expected an exception of type %s to be raised." % exception_type)
    elif type(actual_exception) != exception_type:
        _a, _b, tb = sys.exc_info()
        info = traceback.format_list(traceback.extract_tb(tb))
        fail("Expected a raised exception of type %s, but found type %s. "
            "%s" % (exception_type, type(actual_exception), info))
    def test_do_not_allow_sneaky_cycle(self):
        from proboscis.case import TestPlan
        from proboscis.sorting import TestGraph
        from proboscis import TestRegistry

        registry = TestRegistry()
        registry.register(N2, depends_on_classes=[N11])
        registry.register(N3)
        registry.register(N5, depends_on_groups=["something"])
        registry.register(N7)
        registry.register(N8, depends_on_classes=[N3])
        registry.register(N9, depends_on_classes=[N8, N11])
        registry.register(N10, depends_on_classes=[N3, N11])
        registry.register(N11, groups=["something"], depends_on_classes=[N5, N7])
        cases = TestPlan.create_cases(registry.tests, [])
        graph = TestGraph(registry.groups, registry.tests, cases)

        re = compatability.capture_exception(graph.sort, RuntimeError)
        self.assertTrue(re is not None)
        self.assertTrue(isinstance(re, RuntimeError))
        self.assertTrue(str(re).find("Cycle found") >= 0)
    def test_do_not_allow_sneaky_cycle(self):
        from proboscis.case import TestPlan
        from proboscis.sorting import TestGraph
        from proboscis import TestRegistry

        registry = TestRegistry()
        registry.register(N2, depends_on_classes=[N11])
        registry.register(N3)
        registry.register(N5, depends_on_groups=["something"])
        registry.register(N7)
        registry.register(N8, depends_on_classes=[N3])
        registry.register(N9, depends_on_classes=[N8, N11])
        registry.register(N10, depends_on_classes=[N3, N11])
        registry.register(N11,
                          groups=["something"],
                          depends_on_classes=[N5, N7])
        cases = TestPlan.create_cases(registry.tests, [])
        graph = TestGraph(registry.groups, registry.tests, cases)

        re = compatability.capture_exception(graph.sort, RuntimeError)
        self.assertTrue(re is not None)
        self.assertTrue(isinstance(re, RuntimeError))
        self.assertTrue(str(re).find("Cycle found") >= 0)
Beispiel #15
0
def assert_raises(exception_type, function, *args, **kwargs):
    """Calls function and fails the test if an exception is not raised.

    Unlike nose.Tool's assert_raises or TestCase.assertRaises the given
    exception type must match the exactly: if the raised exception is a
    subclass the test will fail. For example, it fails if the exception_type
    param is "Exception" but "RuntimeException" is raised. To be less demanding
    use assert_raises_instance.

    :param exception_type: The exact type of exception to be raised.
    :param function: The function to call, followed by its arguments.

    """
    actual_exception = compatability.capture_exception(
        lambda : function(*args, **kwargs),
        exception_type)
    if actual_exception is None:
        fail("Expected an exception of type %s to be raised." % exception_type)
    elif type(actual_exception) != exception_type:
        _a, _b, tb = sys.exc_info()
        info = traceback.format_list(traceback.extract_tb(tb))
        fail("Expected a raised exception of type %s, but found type %s. "
            "%s" % (exception_type, type(actual_exception), info))
Beispiel #16
0
def assert_raises(exception_type, function, *args, **kwargs):
    """Calls function and fails the test if an exception is not raised.

    Unlike nose.Tool's assert_raises or TestCase.assertRaises the given
    exception type must match the exactly: if the raised exception is a
    subclass the test will fail. For example, it fails if the exception_type
    param is "Exception" but "RuntimeException" is raised. To be less demanding
    use assert_raises_instance.

    :param exception_type: The exact type of exception to be raised.
    :param function: The function to call, followed by its arguments.

    """
    actual_exception = compatability.capture_exception(
        lambda: function(*args, **kwargs), exception_type)
    if actual_exception is None:
        fail("Expected an exception of type %s to be raised." % exception_type)
    elif type(actual_exception) != exception_type:
        _a, _b, tb = sys.exc_info()
        info = traceback.format_list(traceback.extract_tb(tb))
        fail("Expected a raised exception of type %s, but found type %s. "
             "%s" % (exception_type, type(actual_exception), info))
    return actual_exception
Beispiel #17
0
 def skip_capture_func():
     st = compatability.capture_exception(func, SkipTest)
     if st is not None:
         dependencies.skip_test(test_case, st.message)