Пример #1
0
def test_patcher():
    p = PyDoctorParser(doc_path=u'foo')
    soup = BeautifulSoup(
        codecs.open(
            os.path.join(HERE, 'function_example.html'),
            mode="r", encoding="utf-8"
        ),
        "lxml",
    )
    assert p.find_and_patch_entry(
        soup,
        TOCEntry(
            name=u'twisted.application.app.ApplicationRunner.startReactor',
            type=u'clm', anchor=u'startReactor'
        )
    )
    toc_link = soup(
        'a',
        attrs={'name': u'//apple_ref/cpp/clm/twisted.application.app.'
               u'ApplicationRunner.startReactor'}
    )
    assert toc_link
    next_tag = toc_link[0].next_sibling
    assert next_tag.name == u'a'
    assert (next_tag['name'] == u'startReactor')
    assert not p.find_and_patch_entry(
        soup, TOCEntry(name=u'invented', type=u'cl', anchor=u'nonex')
    )
Пример #2
0
def test_patcher():
    p = PyDoctorParser(doc_path="foo")
    with codecs.open(
        os.path.join(HERE, "function_example.html"), mode="r", encoding="utf-8"
    ) as fp:
        soup = BeautifulSoup(fp, "html.parser")

    assert p.find_and_patch_entry(
        soup,
        TOCEntry(
            name="twisted.application.app.ApplicationRunner.startReactor",
            type="clm",
            anchor="startReactor",
        ),
    )
    toc_link = soup(
        "a",
        attrs={
            "name": "//apple_ref/cpp/clm/twisted.application.app."
            "ApplicationRunner.startReactor"
        },
    )
    assert toc_link
    next_tag = toc_link[0].next_sibling
    assert next_tag.name == "a"
    assert next_tag["name"] == "startReactor"
    assert not p.find_and_patch_entry(
        soup, TOCEntry(name="invented", type="cl", anchor="nonex")
    )
Пример #3
0
def test_patcher():
    p = PyDoctorParser(doc_path=u'foo')
    soup = BeautifulSoup(
        codecs.open(
            os.path.join(HERE, 'function_example.html'),
            mode="r", encoding="utf-8"
        )
    )
    assert p.find_and_patch_entry(
        soup,
        TOCEntry(
            name=u'twisted.application.app.ApplicationRunner.startReactor',
            type=u'clm', anchor=u'startReactor'
        )
    )
    toc_link = soup(
        'a',
        attrs={'name': u'//apple_ref/cpp/clm/twisted.application.app.'
               u'ApplicationRunner.startReactor'}
    )
    assert toc_link
    next_tag = toc_link[0].next_sibling
    assert next_tag.name == u'a'
    assert (next_tag['name'] == u'startReactor')
    assert not p.find_and_patch_entry(
        soup, TOCEntry(name=u'invented', type=u'cl', anchor=u'nonex')
    )
Пример #4
0
def test_parse():
    """
    The shipped example results in the expected parsing result.
    """
    example = codecs.open(
        os.path.join(HERE, 'pydoctor_example.html'),
        mode="r", encoding="utf-8",
    ).read()
    with patch('doc2dash.parsers.pydoctor.codecs.open',
               mock_open(read_data=example),
               create=True):
        print(list(PyDoctorParser(doc_path=u'foo').parse()))
        assert list(
            PyDoctorParser(doc_path=u'foo').parse()
        ) == EXAMPLE_PARSE_RESULT
Пример #5
0
def test_parse():
    """
    The shipped example results in the expected parsing result.
    """
    with codecs.open(os.path.join(HERE, "pydoctor_example.html"),
                     mode="r",
                     encoding="utf-8") as fp:
        example = fp.read()

    with patch(
            "doc2dash.parsers.pydoctor.codecs.open",
            mock_open(read_data=example),
            create=True,
    ):
        print(list(PyDoctorParser(doc_path=u"foo").parse()))
        assert (list(
            PyDoctorParser(doc_path=u"foo").parse()) == EXAMPLE_PARSE_RESULT)
Пример #6
0
def test_patcher():
    p = PyDoctorParser('foo')
    soup = BeautifulSoup(open(os.path.join(HERE, 'function_example.html')))
    assert p.find_and_patch_entry(
        soup,
        Entry('twisted.application.app.ApplicationRunner.startReactor',
              'clm', 'startReactor')
    )
    toc_link = soup(
        'a',
        attrs={'name': '//apple_ref/cpp/clm/twisted.application.app.'
                       'ApplicationRunner.startReactor'}
    )
    assert toc_link
    next_tag = toc_link[0].next_sibling
    assert next_tag.name == 'a'
    assert (next_tag['name'] == 'startReactor')
    assert not p.find_and_patch_entry(soup, Entry('invented', 'cl', 'nonex'))
Пример #7
0
def test_patcher():
    p = PyDoctorParser('foo')
    soup = BeautifulSoup(open(os.path.join(HERE, 'function_example.html')))
    assert p.find_and_patch_entry(
        soup,
        Entry('twisted.application.app.ApplicationRunner.startReactor',
              'clm', 'startReactor')
    )
    toc_link = soup(
        'a',
        attrs={'name': '//apple_ref/cpp/clm/twisted.application.app.'
                       'ApplicationRunner.startReactor'}
    )
    assert toc_link
    next_tag = toc_link[0].next_sibling
    assert next_tag.name == 'a'
    assert (next_tag['name'] == 'startReactor')
    assert not p.find_and_patch_entry(soup, Entry('invented', 'cl', 'nonex'))
Пример #8
0
def test_parse():
    """
    The shipped example results in the expected parsing result.
    """
    example = open(os.path.join(HERE, 'pydoctor_example.html')).read()
    with patch('doc2dash.parsers.pydoctor.open',
               mock_open(read_data=example),
               create=True):
        assert list(PyDoctorParser('foo').parse()) == EXAMPLE_PARSE_RESULT
Пример #9
0
 def test_interface(self):
     """
     PyDoctorParser fully implements IParser.
     """
     verifyObject(IParser, PyDoctorParser(doc_path=u"foo"))
Пример #10
0
def test_parse():
    example = open(os.path.join(HERE, 'pydoctor_example.html')).read()
    with patch('doc2dash.parsers.pydoctor.open', mock_open(read_data=example),
               create=True):
        assert list(PyDoctorParser('foo').parse()) == EXAMPLE_PARSE_RESULT