github.com/imran-kn/cilium-fork@v1.6.9/Documentation/_themes/sphinx_rtd_theme/tests/test_builders.py (about) 1 import os 2 3 import pytest 4 import sphinx 5 from sphinx import addnodes 6 from sphinx.builders.html import SingleFileHTMLBuilder, DirectoryHTMLBuilder 7 8 from .util import build_all 9 10 11 def test_basic(): 12 for (app, status, warning) in build_all('test-basic'): 13 assert app.env.get_doctree('index').traverse(addnodes.toctree) 14 content = open(os.path.join(app.outdir, 'index.html')).read() 15 16 if isinstance(app.builder, DirectoryHTMLBuilder): 17 search = ( 18 '<div class="toctree-wrapper compound">\n' 19 '<ul>\n' 20 '<li class="toctree-l1">' 21 '<a class="reference internal" href="foo/">foo</a>' 22 '<ul>\n' 23 '<li class="toctree-l2">' 24 '<a class="reference internal" href="bar/">bar</a></li>\n' 25 '</ul>\n' 26 '</li>\n' 27 '</ul>\n' 28 '</div>' 29 ) 30 assert search in content 31 elif isinstance(app.builder, SingleFileHTMLBuilder): 32 search = ( 33 '<div class="local-toc"><ul>\n' 34 '<li class="toctree-l1">' 35 '<a class="reference internal" href="index.html#document-foo">foo</a>' 36 '<ul>\n' 37 '<li class="toctree-l2">' 38 '<a class="reference internal" href="index.html#document-bar">bar</a>' 39 '</li>\n' 40 '</ul>' 41 ) 42 assert search in content 43 else: 44 search = ( 45 '<div class="toctree-wrapper compound">\n' 46 '<ul>\n' 47 '<li class="toctree-l1">' 48 '<a class="reference internal" href="foo.html">foo</a>' 49 '<ul>\n' 50 '<li class="toctree-l2">' 51 '<a class="reference internal" href="bar.html">bar</a></li>\n' 52 '</ul>\n' 53 '</li>\n' 54 '</ul>\n' 55 '</div>' 56 ) 57 assert search in content, ('Missing search with builder {0}' 58 .format(app.builder.name)) 59 60 61 def test_empty(): 62 """Local TOC is showing, as toctree was empty""" 63 for (app, status, warning) in build_all('test-empty'): 64 assert app.env.get_doctree('index').traverse(addnodes.toctree) 65 content = open(os.path.join(app.outdir, 'index.html')).read() 66 if sphinx.version_info < (1, 4): 67 if isinstance(app.builder, SingleFileHTMLBuilder): 68 assert '<div class="toctree-wrapper compound">\n</div>' in content 69 assert '<div class="local-toc">' in content 70 else: 71 global_toc = ( 72 '<div class="toctree-wrapper compound">\n' 73 '<ul class="simple">\n</ul>\n' 74 '</div>' 75 ) 76 local_toc = ( 77 '<div class="local-toc"><ul class="simple">' 78 '</ul>\n</div>' 79 ) 80 assert global_toc in content 81 assert local_toc not in content 82 else: 83 global_toc = '<div class="toctree-wrapper compound">\n</div>' 84 local_toc = ( 85 '<div class="local-toc"><ul>\n' 86 '<li><a class="reference internal" href="#">test-empty</a></li>' 87 '</ul>\n</div>' 88 ) 89 assert global_toc in content 90 assert local_toc not in content 91 92 93 def test_missing_toctree(): 94 """Local TOC is showing, as toctree was missing""" 95 for (app, status, warning) in build_all('test-missing-toctree'): 96 assert app.env.get_doctree('index').traverse(addnodes.toctree) == [] 97 content = open(os.path.join(app.outdir, 'index.html')).read() 98 assert '<div class="toctree' not in content 99 assert '<div class="local-toc">' in content