def test_read_inventory_v1(): f = BytesIO(inventory_v1) invdata = read_inventory(f, '/util', posixpath.join) assert invdata['py:module']['module'] == \ ('foo', '1.0', '/util/foo.html#module-module', '-') assert invdata['py:class']['module.cls'] == \ ('foo', '1.0', '/util/foo.html#module.cls', '-')
def test_read_inventory_v2(): f = BytesIO(inventory_v2) invdata1 = read_inventory(f, "/util", posixpath.join) # try again with a small buffer size to test the chunking algorithm f = BytesIO(inventory_v2) invdata2 = read_inventory(f, "/util", posixpath.join, bufsize=5) assert invdata1 == invdata2 assert len(invdata1["py:module"]) == 2 assert invdata1["py:module"]["module1"] == ("foo", "2.0", "/util/foo.html#module-module1", "Long Module desc") assert invdata1["py:module"]["module2"] == ("foo", "2.0", "/util/foo.html#module-module2", "-") assert invdata1["py:function"]["module1.func"][2] == "/util/sub/foo.html#module1.func" assert invdata1["c:function"]["CFunc"][2] == "/util/cfunc.html#CFunc" assert invdata1["std:term"]["a term"][2] == "/util/glossary.html#term-a-term" assert invdata1["std:term"]["a term including:colon"][2] == "/util/glossary.html#term-a-term-including-colon"
def test_read_inventory_v2(): f = BytesIO(inventory_v2) invdata1 = read_inventory(f, '/util', posixpath.join) # try again with a small buffer size to test the chunking algorithm f = BytesIO(inventory_v2) invdata2 = read_inventory(f, '/util', posixpath.join, bufsize=5) assert invdata1 == invdata2 assert len(invdata1['py:module']) == 2 assert invdata1['py:module']['module1'] == \ ('foo', '2.0', '/util/foo.html#module-module1', 'Long Module desc') assert invdata1['py:module']['module2'] == \ ('foo', '2.0', '/util/foo.html#module-module2', '-') assert invdata1['py:function']['module1.func'][2] == \ '/util/sub/foo.html#module1.func' assert invdata1['c:function']['CFunc'][2] == '/util/cfunc.html#CFunc' assert invdata1['std:term']['a term'][2] == \ '/util/glossary.html#term-a-term' assert invdata1['std:term']['a term including:colon'][2] == \ '/util/glossary.html#term-a-term-including-colon'
"""This module generates xrefmap from external links.""" import os import urllib.request import yaml from sphinx.ext.intersphinx import read_inventory EXTERNAL_LINKS = ['https://docs.python.org/3.5/', 'http://msrestazure.readthedocs.io/en/latest/', 'http://msrest.readthedocs.io/en/latest/'] xref_map = [] for external_Link in EXTERNAL_LINKS: obj_link = os.path.join(external_Link, 'objects.inv') stream = urllib.request.urlopen(obj_link) inventory = read_inventory(stream, external_Link, os.path.join) for role_key, role_value in inventory.items(): if role_key.startswith('py:'): for ref_name, ref_value in role_value.items(): title_name = ref_name # Only use last element in ref_name for exception if role_key == 'py:exception': title_name = ref_name.split('.')[-1] xref_map.append({'uid': ref_name, 'name': title_name, 'href': ref_value[2], 'fullName': ref_name}) with open('xrefmap.yml', 'w', encoding='utf8') as out_file: yaml.dump({'references': xref_map}, out_file, default_flow_style=False, allow_unicode=True)
def test_read_inventory_v1(): f = BytesIO(inventory_v1) invdata = read_inventory(f, "/util", posixpath.join) assert invdata["py:module"]["module"] == ("foo", "1.0", "/util/foo.html#module-module", "-") assert invdata["py:class"]["module.cls"] == ("foo", "1.0", "/util/foo.html#module.cls", "-")