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_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", ))
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", ) )
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_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") ) 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