<commit_before>from pydoctor import nevowhtml, model
from pydoctor.nevowhtml import util, pages
from pydoctor.test.test_astbuilder import fromText
from nevow import flat
import cStringIO
import py

class System:
    class options:
        htmlusesorttable = False
        verbosity = 0

def getHTMLOf(ob):
    writer = nevowhtml.NevowWriter('')
    writer.system = System
    f = cStringIO.StringIO()
    writer.writeDocsForOne(ob, f)
    return f.getvalue()

def test_simple():
    src = '''
    def f():
        """This is a docstring."""
    '''
    mod = fromText(src)
    v = getHTMLOf(mod.contents['f'])
    assert 'This is a docstring' in v

def test_empty_table():
    class O:
        class system:
            urlprefix = ''
            class options:
                htmlusesorttable = True
                verbosity = 0
    t = pages.TableFragment(O, True, [])
    flattened = flat.flatten(t)
    assert 'The renderer named' not in flattened

def test_nonempty_table():
    class Child:
        kind = "kooky"
        docstring = None
        document_in_parent_page = False
        linenumber = 10
        parent = None
        sourceHref = None
        class system:
            urlprefix = ''
            sourcebase = None
            class options:
                htmlusesorttable = True
                verbosity = 0
        def fullName(self):
            return 'fullName'
        name = 'name'
        contents = {}
    t = pages.TableFragment(Child(), True, [Child()])
    flattened = flat.flatten(t)
    assert 'The renderer named' not in flattened

def test_rest_support():
    try:
        import docutils, epydoc
    except ImportError:
        py.test.skip("Requires both docutils and epydoc to be importable")
    system = model.System()
    system.options.docformat = 'restructuredtext'
    system.options.verbosity = 4
    src = '''
    def f():
        """This is a docstring for f."""
    '''
    mod = fromText(src, system=system)
    html = getHTMLOf(mod.contents['f'])
    assert "<pre>" not in html

def test_document_code_in_init_module():
    from pydoctor.test.test_packages import processPackage
    system = processPackage("codeininit")
    html = getHTMLOf(system.allobjects['codeininit'])
    assert 'functionInInit' in html
<commit_msg>make these tests less horrible hostages against future changes. makes them a bit less unity, but......<commit_after>from pydoctor import nevowhtml, model
from pydoctor.nevowhtml import util, pages
from pydoctor.test.test_astbuilder import fromText
from nevow import flat
import cStringIO
import py

def getHTMLOf(ob):
    writer = nevowhtml.NevowWriter('')
    writer.system = ob.system
    f = cStringIO.StringIO()
    writer.writeDocsForOne(ob, f)
    return f.getvalue()

def test_simple():
    src = '''
    def f():
        """This is a docstring."""
    '''
    mod = fromText(src)
    v = getHTMLOf(mod.contents['f'])
    assert 'This is a docstring' in v

def test_empty_table():
    mod = fromText('')
    t = pages.TableFragment(mod, True, [])
    flattened = flat.flatten(t)
    assert 'The renderer named' not in flattened

def test_nonempty_table():
    mod = fromText('def f(): pass')
    t = pages.TableFragment(mod, True, mod.orderedcontents)
    flattened = flat.flatten(t)
    assert 'The renderer named' not in flattened

def test_rest_support():
    try:
        import docutils, epydoc
    except ImportError:
        py.test.skip("Requires both docutils and epydoc to be importable")
    system = model.System()
    system.options.docformat = 'restructuredtext'
    system.options.verbosity = 4
    src = '''
    def f():
        """This is a docstring for f."""
    '''
    mod = fromText(src, system=system)
    html = getHTMLOf(mod.contents['f'])
    assert "<pre>" not in html

def test_document_code_in_init_module():
    from pydoctor.test.test_packages import processPackage
    system = processPackage("codeininit")
    html = getHTMLOf(system.allobjects['codeininit'])
    assert 'functionInInit' in html

{'fraction_non_alphanumeric': 0.10333665338645419, 'fraction_numerical': 0.0017430278884462151, 'mean_word_length': 2.750700280112045, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '102545', 'n_tokens_mistral': 1259, 'n_tokens_neox': 1214, 'n_words': 348}