Esempio n. 1
0
    def test_getRaisesException(self):
        """
        L{IntersphinxCache.get} returns L{None} if an exception is
        raised while C{GET}ing a URL and logs the exception.
        """
        loggedExceptions = []

        class _Logger(object):
            @staticmethod
            def exception(*args, **kwargs):
                loggedExceptions.append((args, kwargs))

        class _RaisesOnGet(object):
            @staticmethod
            def get(url):
                raise Exception()

        cache = sphinx.IntersphinxCache(session=_RaisesOnGet, logger=_Logger)

        assert cache.get(u"some url") is None

        assert len(loggedExceptions)
Esempio n. 2
0
    def test_getRaisesException(self, caplog: CapLog) -> None:
        """
        L{IntersphinxCache.get} returns L{None} if an exception is
        raised while C{GET}ing a URL and logs the exception.
        """
        class _TestException(Exception):
            pass

        class _RaisesOnGet:
            @staticmethod
            def get(url: str) -> bytes:
                raise _TestException()

        session = cast(requests.Session, _RaisesOnGet)
        cache = sphinx.IntersphinxCache(session=session)

        assert cache.get("some url") is None

        assert len(caplog.records) == 1
        assert caplog.records[0].levelname == "ERROR"
        assert caplog.records[0].exc_info is not None
        assert caplog.records[0].exc_info[0] is _TestException