def test_hasdocstring() -> None:
    system = processPackage("basic")
    from pydoctor.templatewriter.summary import hasdocstring
    assert not hasdocstring(system.allobjects['basic._private_mod'])
    assert hasdocstring(system.allobjects['basic.mod.C.f'])
    sub_f = system.allobjects['basic.mod.D.f']
    assert hasdocstring(sub_f) and not sub_f.docstring
Example #2
0
def test_hasdocstring():
    system = processPackage("basic")
    from pydoctor.templatewriter.summary import hasdocstring
    assert not hasdocstring(system.allobjects['basic._private_mod'])
    assert hasdocstring(system.allobjects['basic.mod.C.f'])
    sub_f = system.allobjects['basic.mod.D.f']
    assert hasdocstring(sub_f) and not sub_f.docstring
def test_interfaceallgames() -> None:
    system = processPackage('interfaceallgames', systemcls=ZopeInterfaceSystem)
    mod = system.allobjects['interfaceallgames.interface']
    iface = mod.contents['IAnInterface']
    assert [o.fullName() for o in iface.implementedby_directly] == [
        'interfaceallgames.implementation.Implementation'
        ]
Example #4
0
def test_recentChanges():
    system = processPackage('basic')
    root = server.EditingPyDoctorResource(system)
    ob = system.allobjects['basic.mod.D.f']
    root.newDocstring('xxx', ob, '"""Tee hee."""')
    # just "assertNotRaises"
    getTextOfPage(root, 'recentChanges')
Example #5
0
def test_recentChanges():
    system = processPackage('basic')
    root = server.EditingPyDoctorResource(system)
    ob = system.allobjects['basic.mod.D.f']
    root.newDocstring('xxx', ob, '"""Tee hee."""')
    # just "assertNotRaises"
    getTextOfPage(root, 'recentChanges')
Example #6
0
def test_diff():
    system = processPackage('basic')
    root = server.EditingPyDoctorResource(system)

    ob = system.allobjects['basic.mod.C']

    performEdit(root, ob, repr("This *is* a docstring"))

    args = {'ob': ob.fullName(), 'revA': '0', 'revB': '1'}
    difftext = getTextOfPage(root, 'diff', args)
    assert "*is*" in difftext
Example #7
0
def test_history():
    system = processPackage('basic')
    root = server.EditingPyDoctorResource(system)

    ob = system.allobjects['basic.mod.C']

    performEdit(root, ob, repr("This *is* a docstring"))

    args = {'ob': ob.fullName()}
    historytext = getTextOfPage(root, 'history', args)
    assert "*is*" in historytext
Example #8
0
def test_diff_newDocstring():
    system = processPackage('basic')
    root = server.EditingPyDoctorResource(system)

    ob = system.allobjects['basic.mod.D.f']

    root.newDocstring('xxx', ob, '"""Tee hee."""')

    args = {'ob': ob.fullName(), 'revA': 0, 'revB': 1}
    html = getTextOfPage(root, 'diff', args)
    assert '+        """Tee hee."""' in html
Example #9
0
def test_diff():
    system = processPackage('basic')
    root = server.EditingPyDoctorResource(system)

    ob = system.allobjects['basic.mod.C']

    performEdit(root, ob, repr("This *is* a docstring"))

    args = {'ob':ob.fullName(), 'revA':'0', 'revB':'1'}
    difftext = getTextOfPage(root, 'diff', args)
    assert "*is*" in difftext
Example #10
0
def test_history():
    system = processPackage('basic')
    root = server.EditingPyDoctorResource(system)

    ob = system.allobjects['basic.mod.C']

    performEdit(root, ob, repr("This *is* a docstring"))

    args = {'ob':ob.fullName()}
    historytext = getTextOfPage(root, 'history', args)
    assert "*is*" in historytext
Example #11
0
def test_edit_direct():
    system = processPackage('basic')
    root = server.EditingPyDoctorResource(system)

    ob = system.allobjects['basic.mod.C']
    docstring = root.currentDocstringForObject(ob)
    assert docstring == ob.docstring

    newDocstring = '"""This *is* a docstring"""'
    root.newDocstring('xxx', ob, newDocstring)
    docstring = root.currentDocstringForObject(ob)
    assert docstring == eval(newDocstring)
    assert ob.docstring != docstring
Example #12
0
def test_edit_direct():
    system = processPackage('basic')
    root = server.EditingPyDoctorResource(system)

    ob = system.allobjects['basic.mod.C']
    docstring = root.currentDocstringForObject(ob)
    assert docstring == ob.docstring

    newDocstring = '"""This *is* a docstring"""'
    root.newDocstring('xxx', ob, newDocstring)
    docstring = root.currentDocstringForObject(ob)
    assert docstring == eval(newDocstring)
    assert ob.docstring != docstring
Example #13
0
def test_diff_newDocstring():
    system = processPackage('basic')
    root = server.EditingPyDoctorResource(system)

    ob = system.allobjects['basic.mod.D.f']

    root.newDocstring('xxx', ob, '"""Tee hee."""')

    args = {'ob': ob.fullName(),
            'revA': 0,
            'revB': 1}
    html = getTextOfPage(root, 'diff', args)
    assert '+        """Tee hee."""' in html
Example #14
0
def DONT_test_simple():
    system = processPackage("liveobject")
    liveCheck(system)
    mod = system.allobjects["liveobject.mod"]
    assert mod.contents["m"].docstring == "this is a docstring"
    assert "D" in mod.contents
    D = mod.contents["D"]
    B = mod.contents["B"]
    assert D.name == "D"
    assert D.baseobjects == [B]
    assert B.subclasses == [D]

    # we shouldn't find a "new" method called _C__m
    assert len(mod.contents["C"].contents) == 2
Example #15
0
def DONT_test_simple():
    system = processPackage('liveobject')
    liveCheck(system)
    mod = system.allobjects['liveobject.mod']
    assert mod.contents['m'].docstring == 'this is a docstring'
    assert 'D' in mod.contents
    D = mod.contents['D']
    B = mod.contents['B']
    assert D.name == 'D'
    assert D.baseobjects == [B]
    assert B.subclasses == [D]

    # we shouldn't find a "new" method called _C__m
    assert len(mod.contents['C'].contents) == 2
Example #16
0
def test_multipleInheritanceNewClass(className: str) -> None:
    """
    A class that has multiple bases has all methods in its MRO
    rendered.
    """
    system = processPackage("multipleinheritance")

    cls = next(cls for cls in system.allobjects.values()
               if cls.name == className)

    html = getHTMLOf(cls)

    assert "methodA" in html
    assert "methodB" in html
Example #17
0
def DONT_test_simple():
    system = processPackage('liveobject')
    liveCheck(system)
    mod = system.allobjects['liveobject.mod']
    assert mod.contents['m'].docstring == 'this is a docstring'
    assert 'D' in mod.contents
    D = mod.contents['D']
    B = mod.contents['B']
    assert D.name == 'D'
    assert D.baseobjects == [B]
    assert B.subclasses == [D]

    # we shouldn't find a "new" method called _C__m
    assert len(mod.contents['C'].contents) == 2
Example #18
0
def test_edit_renders_ok():
    system = processPackage('basic')
    root = server.EditingPyDoctorResource(system)
    args = {'ob': 'basic'}
    result = getTextOfPage(root, 'edit', args=args)
    assert '# pre comment -7' not in result
    assert '# pre comment -6' in result
    assert '# pre comment -1' in result
    assert '# post comment 1' in result
    assert '# post comment 6' in result
    assert '# post comment 7' not in result

    args = {'ob': 'does.not.exist'}
    result = getTextOfPage(root, 'edit', args=args)
    assert 'An error occurred' in result
Example #19
0
def test_edit_renders_ok():
    system = processPackage('basic')
    root = server.EditingPyDoctorResource(system)
    args = {'ob':'basic'}
    result = getTextOfPage(root, 'edit', args=args)
    assert '# pre comment -7' not in result
    assert '# pre comment -6' in result
    assert '# pre comment -1' in result
    assert '# post comment 1' in result
    assert '# post comment 6' in result
    assert '# post comment 7' not in result

    args = {'ob':'does.not.exist'}
    result = getTextOfPage(root, 'edit', args=args)
    assert 'An error occurred' in result
Example #20
0
def test_basic_package(tmp_path: Path) -> None:
    system = processPackage("basic")
    w = writer.TemplateWriter(str(tmp_path))
    system.options.htmlusesplitlinks = True
    system.options.htmlusesorttable = True
    w.prepOutputDirectory()
    root, = system.rootobjects
    w._writeDocsFor(root)
    w.writeModuleIndex(system)
    for ob in system.allobjects.values():
        url = ob.url
        if '#' in url:
            url = url[:url.find('#')]
        assert (tmp_path / url).is_file()
    with open(tmp_path / 'basic.html') as f:
        assert 'Package docstring' in f.read()
Example #21
0
def test_docstrings_from_superclass():
    system = processPackage('basic')
    root = server.EditingPyDoctorResource(system)

    html = getTextOfPage(root, 'basic.mod.D.html')
    assert 'Method docstring of C.f' in html

    ob = system.allobjects['basic.mod.D.f']
    root.newDocstring('xxx', ob, repr('Method docstring of D.f.'))

    html = getTextOfPage(root, 'basic.mod.D.html')
    assert 'Method docstring of C.f' not in html

    ob = system.allobjects['basic.mod.D.f']
    root.newDocstring('xxx', ob, '')

    html = getTextOfPage(root, 'basic.mod.D.html')
    assert 'Method docstring of C.f' in html
Example #22
0
def test_basic_package():
    system = processPackage("basic")
    targetdir = tempfile.mkdtemp()
    try:
        w = writer.TemplateWriter(targetdir)
        w.system = system
        system.options.htmlusesplitlinks = True
        system.options.htmlusesorttable = True
        w.prepOutputDirectory()
        root, = system.rootobjects
        w.writeDocsFor(root, False)
        w.writeModuleIndex(system)
        for ob in system.allobjects.itervalues():
            if ob.documentation_location == model.DocLocation.OWN_PAGE:
                assert os.path.isfile(os.path.join(targetdir, ob.fullName() + '.html'))
        assert 'Package docstring' in open(os.path.join(targetdir, 'basic.html')).read()
    finally:
        shutil.rmtree(targetdir)
Example #23
0
def test_docstrings_from_superclass():
    system = processPackage('basic')
    root = server.EditingPyDoctorResource(system)

    html = getTextOfPage(root, 'basic.mod.D.html')
    assert 'Method docstring of C.f' in html

    ob = system.allobjects['basic.mod.D.f']
    root.newDocstring('xxx', ob, repr('Method docstring of D.f.'))

    html = getTextOfPage(root, 'basic.mod.D.html')
    assert 'Method docstring of C.f' not in html

    ob = system.allobjects['basic.mod.D.f']
    root.newDocstring('xxx', ob, '')

    html = getTextOfPage(root, 'basic.mod.D.html')
    assert 'Method docstring of C.f' in html
Example #24
0
def test_edit():
    system = processPackage('basic')
    root = server.EditingPyDoctorResource(system)

    ob = system.allobjects['basic.mod.C']
    docstring = root.currentDocstringForObject(ob)
    assert docstring == ob.docstring

    newDocstring = '"""This *is* a docstring"""'
    performEdit(root, ob, newDocstring)
    docstring = root.currentDocstringForObject(ob)
    assert docstring == eval(newDocstring)
    assert ob.docstring != docstring

    result = getTextOfPage(root, 'basic.mod.C.html')
    assert eval(newDocstring) in result

    result = getTextOfPage(root, 'basic.mod.html')
    assert eval(newDocstring) in result
Example #25
0
def test_edit():
    system = processPackage('basic')
    root = server.EditingPyDoctorResource(system)

    ob = system.allobjects['basic.mod.C']
    docstring = root.currentDocstringForObject(ob)
    assert docstring == ob.docstring

    newDocstring = '"""This *is* a docstring"""'
    performEdit(root, ob, newDocstring)
    docstring = root.currentDocstringForObject(ob)
    assert docstring == eval(newDocstring)
    assert ob.docstring != docstring

    result = getTextOfPage(root, 'basic.mod.C.html')
    assert eval(newDocstring) in result

    result = getTextOfPage(root, 'basic.mod.html')
    assert eval(newDocstring) in result
Example #26
0
def test_document_code_in_init_module():
    system = processPackage("codeininit")
    html = getHTMLOf(system.allobjects["codeininit"])
    assert "functionInInit" in html
Example #27
0
def test_document_code_in_init_module():
    system = processPackage("codeininit")
    html = getHTMLOf(system.allobjects['codeininit'])
    assert 'functionInInit' in html
Example #28
0
def test_interfaceclass():
    system = processPackage('interfaceclass', systemcls=ZopeInterfaceSystem)
    mod = system.allobjects['interfaceclass.mod']
    assert mod.contents['AnInterface'].isinterface
def test_interfaceclass() -> None:
    system = processPackage('interfaceclass', systemcls=ZopeInterfaceSystem)
    mod = system.allobjects['interfaceclass.mod']
    assert mod.contents['MyInterface'].isinterface
    assert mod.contents['MyInterface'].docstring == "This is my interface."
    assert mod.contents['AnInterface'].isinterface
Example #30
0
def test_interfaceclass():
    system = processPackage('interfaceclass', systemcls=ZopeInterfaceSystem)
    mod = system.allobjects['interfaceclass.mod']
    assert mod.contents['AnInterface'].isinterface
Example #31
0
def test_document_code_in_init_module() -> None:
    system = processPackage("codeininit")
    html = getHTMLOf(system.allobjects['codeininit'])
    assert 'functionInInit' in html
Example #32
0
def test_interfaceallgames():
    system = processPackage('interfaceallgames', systemcls=ZopeInterfaceSystem)
    mod = system.allobjects['interfaceallgames.interface']
    assert [o.fullName() for o in mod.contents['IAnInterface'].allImplementations] == ['interfaceallgames.implementation.Implementation']
Example #33
0
def test_interfaceallgames():
    system = processPackage('interfaceallgames', systemcls=ZopeInterfaceSystem)
    mod = system.allobjects['interfaceallgames.interface']
    assert [
        o.fullName() for o in mod.contents['IAnInterface'].allImplementations
    ] == ['interfaceallgames.implementation.Implementation']