Exemplo n.º 1
0
    def test_exc_tuple(self):
        """
        Supplying 3 args means that a return value from ``sys.exc_info()`` is
        being supplied.
        """
        with self.assertRaises(TypeError) as ctx:
            events.get_exc_info('foo', 'bar', 'baz')

        self.assertTrue(unicode(ctx.exception).startswith(
            u"exc_info tuple must be a valid exception instance"
        ))
Exemplo n.º 2
0
    def test_missing_args(self):
        """
        Supplying no args must raise a ``TypeError``.
        """
        with self.assertRaises(TypeError) as ctx:
            events.get_exc_info()

        self.assertEqual(
            unicode(ctx.exception),
            u'Expected at least one argument',
        )
Exemplo n.º 3
0
    def test_not_an_exception(self):
        """
        Supplying one arg that is not an exception instance must raise a
        ``TypeError``.
        """
        with self.assertRaises(TypeError) as ctx:
            events.get_exc_info('foobar')

        self.assertEqual(
            unicode(ctx.exception),
            u"An exception instance must be supplied as the first argument "
            "(received:'foobar')",
        )
Exemplo n.º 4
0
    def test_return_sys_exc_info(self):
        """
        Supplying an exc_info tuple must return a tuple in a ``sys.exc_info()``
        style format.
        """
        exc_info = (RuntimeError, RuntimeError(), None)

        self.assertEqual(
            events.get_exc_info(*exc_info),
            exc_info
        )
Exemplo n.º 5
0
    def test_exception(self):
        """
        Supplying an exception instance must return a tuple in a
        ``sys.exc_info()`` style format.
        """
        class TestException(Exception):
            pass

        exc = TestException()
        ret = events.get_exc_info(exc)

        self.assertTupleEqual(ret, (TestException, exc, None))
Exemplo n.º 6
0
    def test_exception_class(self):
        """
        Supplying an exception CLASS must return a tuple in a
        ``sys.exc_info()`` style format.
        """
        class TestException(Exception):
            pass

        ret = events.get_exc_info(TestException)

        self.assertEquals(len(ret), 3)
        exc_type, exc_value, exc_tb = ret

        self.assertIs(exc_type, TestException)
        self.assertIsInstance(exc_value, TestException)
        self.assertIsNone(exc_tb)
Exemplo n.º 7
0
 def test_4_args(self):
     """
     Supplying 4 args must raise a ``TypeError``.
     """
     with self.assertRaises(TypeError):
         events.get_exc_info('foo', 'bar', 'baz', 'gak')