def test_fetchIntersphinxInventories_content(): """ Download and parse intersphinx inventories for each configured intersphix. """ options, _ = parse_args([]) options.intersphinx = [ "http://sphinx/objects.inv", "file:///twisted/index.inv" ] url_content = { "http://sphinx/objects.inv": zlib.compress("sphinx.module py:module -1 sp.html -"), "file:///twisted/index.inv": zlib.compress("twisted.package py:module -1 tm.html -"), } sut = model.System(options=options) log = [] sut.msg = lambda part, msg: log.append((part, msg)) # Patch url getter to avoid touching the network. sut.intersphinx._getURL = lambda url: url_content[url] sut.fetchIntersphinxInventories(sphinx.StubCache(url_content)) assert [] == log assert "http://sphinx/sp.html" == sut.intersphinx.getLink("sphinx.module") assert "file:///twisted/tm.html" == sut.intersphinx.getLink( "twisted.package")
def test_not_in_cache(self): """ L{sphinx.StubCache.get} returns L{None} if it has no cached content for a URL. """ cache = sphinx.StubCache({}) assert cache.get(b"url") is None
def test_getFromCache(self): """ L{sphinx.StubCache.get} returns its cached content for a URL. """ url = u"url" content = b"content" cache = sphinx.StubCache({url: content}) assert cache.get(url) is content
def test_update_bad_url(): """ Log an error when failing to get base url from url. """ sut, log = make_SphinxInventoryWithLog() sut.update(sphinx.StubCache({}), "really.bad.url") assert sut._links == {} expected_log = [("sphinx", "Failed to get remote base url for really.bad.url", -1)] assert expected_log == log
def test_fetchIntersphinxInventories_empty(): """ Convert option to empty dict. """ options, _ = parse_args([]) options.intersphinx = [] sut = model.System(options=options) sut.fetchIntersphinxInventories(sphinx.StubCache({})) # Use internal state since I don't know how else to # check for SphinxInventory state. assert {} == sut.intersphinx._links
def test_update_fail(): """ Log an error when failing to get content from url. """ sut, log = make_SphinxInventoryWithLog() sut.update(sphinx.StubCache({}), "http://some.tld/o.inv") assert sut._links == {} expected_log = [ ("sphinx", "Failed to get object inventory from http://some.tld/o.inv", -1) ] assert expected_log == log
def test_update_functional(): """ Functional test for updating from an empty inventory. """ payload = ("some.module1 py:module -1 module1.html -\n" "other.module2 py:module 0 module2.html Other description\n") sut = make_SphinxInventory() # Patch URL loader to avoid hitting the system. content = """# Sphinx inventory version 2 # Project: some-name # Version: 2.0 # The rest of this file is compressed with zlib. %s""" % (zlib.compress(payload), ) url = "http://some.url/api/objects.inv" sut.update(sphinx.StubCache({url: content}), url) assert "http://some.url/api/module1.html" == sut.getLink("some.module1") assert "http://some.url/api/module2.html" == sut.getLink("other.module2")
def test_update_functional(): """ Functional test for updating from an empty inventory. """ payload = (b'some.module1 py:module -1 module1.html -\n' b'other.module2 py:module 0 module2.html Other description\n') sut = sphinx.SphinxInventory(logger=object()) # Patch URL loader to avoid hitting the system. content = b"""# Sphinx inventory version 2 # Project: some-name # Version: 2.0 # The rest of this file is compressed with zlib. %s""" % (zlib.compress(payload), ) url = 'http://some.url/api/objects.inv' sut.update(sphinx.StubCache({url: content}), url) assert 'http://some.url/api/module1.html' == sut.getLink('some.module1') assert 'http://some.url/api/module2.html' == sut.getLink('other.module2')