def test_nop_if_no_exception(self, sio):
     """
     If there is no exception, don't print anything.
     """
     epp = ExceptionPrettyPrinter(sio)
     epp(None, None, {})
     assert '' == sio.getvalue()
Beispiel #2
0
    def test_stdout_by_default(self):
        """
        If no file is supplied, use stdout.
        """
        epp = ExceptionPrettyPrinter()

        assert sys.stdout is epp._file
 def test_exception_on_py3(self, sio):
     """
     On Python 3, it's also legal to pass an Exception.
     """
     epp = ExceptionPrettyPrinter(sio)
     try:
         raise ValueError("XXX")
     except ValueError as e:
         epp(None, None, {"exc_info": e})
     assert "XXX" in sio.getvalue()
 def test_removes_exc_info_after_printing(self, sio):
     """
     After pretty printing `exception` is removed from the event_dict.
     """
     epp = ExceptionPrettyPrinter(sio)
     try:
         raise ValueError
     except ValueError:
         ed = epp(None, None, {'exc_info': True})
     assert 'exc_info' not in ed
    def test_own_exc_info(self, sio):
        """
        If exc_info is a tuple, use it.
        """
        epp = ExceptionPrettyPrinter(sio)
        try:
            raise ValueError("XXX")
        except ValueError:
            ei = sys.exc_info()

        epp(None, None, {"exc_info": ei})
        assert "XXX" in sio.getvalue()
    def test_handles_exc_info(self, sio):
        """
        If `exc_info` is passed in, it behaves like `format_exc_info`.
        """
        epp = ExceptionPrettyPrinter(sio)
        try:
            raise ValueError
        except ValueError:
            epp(None, None, {'exc_info': True})

        out = sio.getvalue()
        assert 'test_handles_exc_info' in out
        assert 'raise ValueError' in out
Beispiel #7
0
    def test_removes_exception_after_printing(self, sio):
        """
        After pretty printing `exception` is removed from the event_dict.
        """
        epp = ExceptionPrettyPrinter(sio)
        try:
            raise ValueError
        except ValueError:
            ed = format_exc_info(None, None, {"exc_info": True})

        assert "exception" in ed

        new_ed = epp(None, None, ed)

        assert "exception" not in new_ed
    def test_prints_exception(self, sio):
        """
        If there's an `exception` key in the event_dict, just print it out.
        This happens if `format_exc_info` was run before us in the chain.
        """
        epp = ExceptionPrettyPrinter(file=sio)
        try:
            raise ValueError
        except ValueError:
            ed = format_exc_info(None, None, {'exc_info': True})
        epp(None, None, ed)

        out = sio.getvalue()
        assert 'test_prints_exception' in out
        assert 'raise ValueError' in out