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') )
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") )
def test_patch_method(self): """ Patching a method adds a TOC entry. """ with codecs.open( os.path.join(HERE, "function_example.html"), mode="r", encoding="utf-8", ) as fp: soup = BeautifulSoup(fp, "html.parser") assert True is find_and_patch_entry( soup, TOCEntry( name="pyramid.config.Configurator.add_route", type="Method", anchor="pyramid.config.Configurator.add_route", ), ) toc_link = soup( "a", attrs={ "name": "//apple_ref/cpp/Method/pyramid.config.Configurator." "add_route" }, ) assert toc_link
def test_patch_method(self): """ Patching a method adds a TOC entry. """ soup = BeautifulSoup( codecs.open(os.path.join(HERE, 'function_example.html'), mode="r", encoding="utf-8"), "lxml", ) assert True is find_and_patch_entry( soup, TOCEntry( name=u'pyramid.config.Configurator.add_route', type=u'Method', anchor=u'pyramid.config.Configurator.add_route', ) ) toc_link = soup( u'a', attrs={ u'name': u'//apple_ref/cpp/Method/pyramid.config.Configurator.' u'add_route' } ) assert toc_link
def test_patch_modules(self): """ Patching a module adds the TOC entry into the next <h1>. Non-ASCII works. """ soup = BeautifulSoup(u"<h1>Some Module</h1>", ) assert True is find_and_patch_entry( soup, TOCEntry( name=u"some_module", type=u"M\xc3\xb6dule", anchor=u"module-some_module", )) assert '<a name="//apple_ref' in str(soup)
def test_single_entry(self, monkeypatch, tmpdir, entries): """ Only entries with URL anchors get patched. """ foo = tmpdir.mkdir("foo") foo.join("bar.html").write("docs!") parser = FakeParser(doc_path=str(foo)) toc = patch_anchors(parser, show_progressbar=False) for e in entries: print(e) toc.send(e) toc.close() assert [TOCEntry(name="foo", type="Method", anchor="foo")] == parser._patched_entries
def test_patch_fail(self): """ Return `False` if anchor can't be found """ with codecs.open( os.path.join(HERE, "function_example.html"), mode="r", encoding="utf-8", ) as fp: soup = BeautifulSoup(fp, "html.parser") assert False is find_and_patch_entry( soup, TOCEntry(name="foo", type="Nothing", anchor="does-not-exist"))
def test_patch_fail(self): """ Return `False` if anchor can't be found """ soup = BeautifulSoup( codecs.open(os.path.join(HERE, 'function_example.html'), mode="r", encoding="utf-8")) assert False is find_and_patch_entry( soup, TOCEntry( name=u"foo", type=u"Nothing", anchor=u"does-not-exist", ))