コード例 #1
0
def test_EpydocLinker_translate_identifier_xref_intersphinx_relative_id():
    """
    Return the link from inventory using short names, by resolving them based
    on the imports done in the module.
    """
    system = model.System()
    inventory = SphinxInventory(system.msg, "some-project")
    inventory._links["ext_package.ext_module"] = ("http://tm.tld", "some.html")
    system.intersphinx = inventory
    target = model.Module(system, "ignore-name", "ignore-docstring")
    # Here we set up the target module as it would have this import.
    # from ext_package import ext_module
    ext_package = model.Module(system, "ext_package", "ignore-docstring")
    target.contents["ext_module"] = model.Module(system,
                                                 "ext_module",
                                                 "ignore-docstring",
                                                 parent=ext_package)

    sut = epydoc2stan._EpydocLinker(target)

    # This is called for the L{ext_module<Pretty Text>} markup.
    result = sut.translate_identifier_xref("ext_module", "Pretty Text")

    expected = '<a href="http://tm.tld/some.html"><code>Pretty Text</code></a>'
    assert expected == result
コード例 #2
0
def test_EpydocLinker_translate_identifier_xref_intersphinx_link_not_found():
    """
    A message is sent to stdout when no link could be found for the reference,
    while returning the reference name without an A link tag.
    The message contains the full name under which the reference was resolved.
    """
    system = model.System()
    target = model.Module(system, "ignore-name", "ignore-docstring")
    # Here we set up the target module as it would have this import.
    # from ext_package import ext_module
    ext_package = model.Module(system, "ext_package", "ignore-docstring")
    target.contents["ext_module"] = model.Module(system,
                                                 "ext_module",
                                                 "ignore-docstring",
                                                 parent=ext_package)
    stdout = BytesIO()
    sut = epydoc2stan._EpydocLinker(target)

    try:
        # FIXME: https://github.com/twisted/pydoctor/issues/112
        # We no have this ugly hack to capture stdout.
        previousStdout = sys.stdout
        sys.stdout = stdout
        # This is called for the L{ext_module} markup.
        result = sut.translate_identifier_xref(fullID="ext_module",
                                               prettyID="ext_module")
    finally:
        sys.stdout = previousStdout

    assert "<code>ext_module</code>" == result

    expected = ("ignore-name:0 invalid ref to 'ext_module' "
                "resolved as 'ext_package.ext_module'\n")

    assert expected == stdout.getvalue()
コード例 #3
0
def test_EpydocLinker_resolve_identifier_xref_intersphinx_link_not_found(capsys: CapSys) -> None:
    """
    A message is sent to stdout when no link could be found for the reference,
    while returning the reference name without an A link tag.
    The message contains the full name under which the reference was resolved.
    FIXME: Use a proper logging system instead of capturing stdout. https://github.com/twisted/pydoctor/issues/112
    """
    system = model.System()
    target = model.Module(system, 'ignore-name')
    # Here we set up the target module as it would have this import.
    # from ext_package import ext_module
    ext_package = model.Module(system, 'ext_package')
    target.contents['ext_module'] = model.Module(
        system, 'ext_module', parent=ext_package)
    sut = epydoc2stan._EpydocLinker(target)

    # This is called for the L{ext_module} markup.
    assert sut.resolve_identifier('ext_module') is None
    assert not capsys.readouterr().out
    with raises(LookupError):
        sut._resolve_identifier_xref('ext_module', 0)

    captured = capsys.readouterr().out
    expected = (
        'ignore-name:???: Cannot find link target for "ext_package.ext_module", '
        'resolved from "ext_module" '
        '(you can link to external docs with --intersphinx)\n'
        )
    assert expected == captured
コード例 #4
0
ファイル: test_epydoc2stan.py プロジェクト: Kalebu/pydoctor
def test_EpydocLinker_resolve_identifier_xref_intersphinx_relative_id(
) -> None:
    """
    Return the link from inventory using short names, by resolving them based
    on the imports done in the module.
    """
    system = model.System()
    inventory = SphinxInventory(system.msg)
    inventory._links['ext_package.ext_module'] = ('http://tm.tld', 'some.html')
    system.intersphinx = inventory
    target = model.Module(system, 'ignore-name')
    # Here we set up the target module as it would have this import.
    # from ext_package import ext_module
    ext_package = model.Module(system, 'ext_package')
    target.contents['ext_module'] = model.Module(system,
                                                 'ext_module',
                                                 parent=ext_package)

    sut = epydoc2stan._EpydocLinker(target)

    # This is called for the L{ext_module<Pretty Text>} markup.
    url = sut.resolve_identifier('ext_module')
    url_xref = sut.resolve_identifier_xref('ext_module', 0)

    assert "http://tm.tld/some.html" == url
    assert "http://tm.tld/some.html" == url_xref
コード例 #5
0
ファイル: test_sphinx.py プロジェクト: markrwilliams/pydoctor
def test_generateLine_module():
    """
    Check inventory for module.
    """
    sut = make_SphinxInventory()

    result = sut._generateLine(
        model.Module('ignore-system', 'module1', 'ignore-docstring'))

    assert 'module1 py:module -1 module1.html -\n' == result
コード例 #6
0
ファイル: test_sphinx.py プロジェクト: moshez/pydoctor
def test_generateLine_module():
    """
    Check inventory for module.
    """
    sut = sphinx.SphinxInventoryWriter(logger=object(),
                                       project_name='project_name')

    result = sut._generateLine(model.Module('ignore-system', 'module1'))

    assert 'module1 py:module -1 module1.html -\n' == result
コード例 #7
0
def test_generateLine_module():
    """
    Check inventory for module.
    """
    sut = make_SphinxInventory()

    result = sut._generateLine(
        model.Module("ignore-system", "module1", "ignore-docstring"))

    assert "module1 py:module -1 module1.html -\n" == result
コード例 #8
0
ファイル: test_sphinx.py プロジェクト: tristanlatr/pydoctor
def test_generateLine_module(
        inv_writer_nolog: sphinx.SphinxInventoryWriter) -> None:
    """
    Check inventory for module.
    """

    result = inv_writer_nolog._generateLine(
        model.Module(IGNORE_SYSTEM, 'module1'))

    assert 'module1 py:module -1 module1.html -\n' == result
コード例 #9
0
def test_EpydocLinker_look_for_intersphinx_no_link() -> None:
    """
    Return None if inventory had no link for our markup.
    """
    system = model.System()
    target = model.Module(system, 'ignore-name')
    sut = epydoc2stan._EpydocLinker(target)

    result = sut.look_for_intersphinx('base.module')

    assert None is result
コード例 #10
0
 def test_generateModuleIndex(self):
     # This test is a bit un-unity
     # And *damnit* how do I write teardowners
     html.EPYTEXT = False
     sysw = html.SystemWriter(None)
     pack = model.Package(None, "twisted", None)
     mod = model.Module(None, "threadz", "Woot\nYeah", pack)
     fun = model.Function(None, "blat", "HICKY HECK\nYEAH", mod)
     fun.argspec = [(), None, None, ()]
     out = sysw.getHTMLFor(fun)
     assert "blat()" in out
     assert "HICKY HECK\nYEAH" in out
コード例 #11
0
ファイル: test_sphinx.py プロジェクト: markrwilliams/pydoctor
def test_generateLine_function():
    """
    Check inventory for function.

    Functions are inside a module.
    """
    sut = make_SphinxInventory()
    parent = model.Module('ignore-system', 'module1', 'docstring')

    result = sut._generateLine(
        model.Function('ignore-system', 'func1', 'ignore-docstring', parent))

    assert 'module1.func1 py:function -1 module1.html#func1 -\n' == result
コード例 #12
0
def test_generateLine_function():
    """
    Check inventory for function.

    Functions are inside a module.
    """
    sut = make_SphinxInventory()
    parent = model.Module("ignore-system", "module1", "docstring")

    result = sut._generateLine(
        model.Function("ignore-system", "func1", "ignore-docstring", parent))

    assert "module1.func1 py:function -1 module1.html#func1 -\n" == result
コード例 #13
0
ファイル: test_sphinx.py プロジェクト: moshez/pydoctor
def test_generateLine_function():
    """
    Check inventory for function.

    Functions are inside a module.
    """
    sut = sphinx.SphinxInventoryWriter(logger=object(),
                                       project_name='project_name')
    parent = model.Module('ignore-system', 'module1')

    result = sut._generateLine(model.Function('ignore-system', 'func1',
                                              parent))

    assert 'module1.func1 py:function -1 module1.html#func1 -\n' == result
コード例 #14
0
def test_EpydocLinker_look_for_intersphinx_hit() -> None:
    """
    Return the link from inventory based on first package name.
    """
    system = model.System()
    inventory = SphinxInventory(system.msg)
    inventory._links['base.module.other'] = ('http://tm.tld', 'some.html')
    system.intersphinx = inventory
    target = model.Module(system, 'ignore-name')
    sut = epydoc2stan._EpydocLinker(target)

    result = sut.look_for_intersphinx('base.module.other')

    assert 'http://tm.tld/some.html' == result
コード例 #15
0
def test_EpydocLinker_look_for_intersphinx_hit():
    """
    Return the link from inventory based on first package name.
    """
    system = model.System()
    inventory = SphinxInventory(system.msg, "some-project")
    inventory._links["base.module.other"] = ("http://tm.tld", "some.html")
    system.intersphinx = inventory
    target = model.Module(system, "ignore-name", "ignore-docstring")
    sut = epydoc2stan._EpydocLinker(target)

    result = sut.look_for_intersphinx("base.module.other")

    assert "http://tm.tld/some.html" == result
コード例 #16
0
ファイル: test_sphinx.py プロジェクト: tristanlatr/pydoctor
def test_generateLine_function(
        inv_writer_nolog: sphinx.SphinxInventoryWriter) -> None:
    """
    Check inventory for function.

    Functions are inside a module.
    """

    parent = model.Module(IGNORE_SYSTEM, 'module1')

    result = inv_writer_nolog._generateLine(
        model.Function(IGNORE_SYSTEM, 'func1', parent))

    assert 'module1.func1 py:function -1 module1.html#func1 -\n' == result
コード例 #17
0
def test_EpydocLinker_resolve_identifier_xref_intersphinx_absolute_id():
    """
    Returns the link from Sphinx inventory based on a cross reference
    ID specified in absolute dotted path and with a custom pretty text for the
    URL.
    """
    system = model.System()
    inventory = SphinxInventory(system.msg)
    inventory._links['base.module.other'] = ('http://tm.tld', 'some.html')
    system.intersphinx = inventory
    target = model.Module(system, 'ignore-name')
    sut = epydoc2stan._EpydocLinker(target)

    url = sut.resolve_identifier_xref('base.module.other')

    assert "http://tm.tld/some.html" == url
コード例 #18
0
def test_EpydocLinker_translate_identifier_xref_intersphinx():
    """
    Return the link from inventory.
    """
    system = model.System()
    inventory = SphinxInventory(system.msg, 'some-project')
    inventory._links['base.module.other'] = ('http://tm.tld', 'some.html')
    system.intersphinx = inventory
    target = model.Module(system, 'ignore-name', 'ignore-docstring')
    sut = epydoc2stan._EpydocLinker(target)

    result = sut.translate_identifier_xref(
        'base.module.other', 'base.module.pretty')

    expected = (
        '<a href="http://tm.tld/some.html"><code>base.module.pretty</code></a>'
        )
    assert expected == result
コード例 #19
0
def test_EpydocLinker_translate_identifier_xref_intersphinx_absolute_id():
    """
    Returns the link from Sphinx inventory based on a cross reference
    ID specified in absolute dotted path and with a custom pretty text for the
    URL.
    """
    system = model.System()
    inventory = SphinxInventory(system.msg, "some-project")
    inventory._links["base.module.other"] = ("http://tm.tld", "some.html")
    system.intersphinx = inventory
    target = model.Module(system, "ignore-name", "ignore-docstring")
    sut = epydoc2stan._EpydocLinker(target)

    result = sut.translate_identifier_xref("base.module.other",
                                           "base.module.pretty")

    expected = '<a href="http://tm.tld/some.html"><code>base.module.pretty</code></a>'
    assert expected == result
コード例 #20
0
def test_EpydocLinker_resolve_identifier_xref_internal_full_name() -> None:
    """Link to an internal object referenced by its full name."""

    # Object we want to link to.
    int_mod = fromText('''
    class C:
        pass
    ''', modname='internal_module')
    system = int_mod.system

    # Dummy module that we want to link from.
    target = model.Module(system, 'ignore-name')
    sut = epydoc2stan._EpydocLinker(target)

    url = sut.resolve_identifier('internal_module.C')
    xref = sut._resolve_identifier_xref('internal_module.C', 0)

    assert "internal_module.C.html" == url
    assert int_mod.contents['C'] is xref
コード例 #21
0
def test_EpydocLinker_translate_identifier_xref_intersphinx_absolute_id():
    """
    Returns the link from Sphinx inventory based on a cross reference
    ID specified in absolute dotted path and with a custom pretty text for the
    URL.
    """
    system = model.System()
    inventory = SphinxInventory(system.msg)
    inventory._links['base.module.other'] = ('http://tm.tld', 'some.html')
    system.intersphinx = inventory
    target = model.Module(system, 'ignore-name', 'ignore-docstring')
    sut = epydoc2stan._EpydocLinker(target)

    result = sut.translate_identifier_xref('base.module.other',
                                           'base.module.pretty')

    expected = (
        '<a href="http://tm.tld/some.html"><code>base.module.pretty</code></a>'
    )
    assert expected == flatten(result)