def load_grammar(gt="Grammar.txt", gp=None,
save=True, force=False, logger=None):
"""Load the grammar (maybe from a pickle)."""
if logger is None:
logger = logging.getLogger()
if gp is None:
head, tail = os.path.splitext(gt)
if tail == ".txt":
tail = ""
# embed Sphinx major version for the case we ever change the grammar...
gp = head + tail + "-sphinx" + \
".".join(map(str, sphinx.version_info[:2])) + ".pickle"
if force or not _newer(gp, gt):
logger.info("Generating grammar tables from %s", gt)
g = pgen.generate_grammar(gt)
if save:
logger.info("Writing grammar tables to %s", gp)
try:
g.dump(gp)
except IOError as e:
logger.info("Writing failed:"+str(e))
else:
g = grammar.Grammar()
g.load(gp)
return g
python类version_info()的实例源码
def test_empty():
"""Local TOC is showing, as toctree was empty"""
for (app, status, warning) in build_all('test-empty'):
assert app.env.get_doctree('index').traverse(addnodes.toctree)
content = open(os.path.join(app.outdir, 'index.html')).read()
if sphinx.version_info < (1, 4):
if isinstance(app.builder, SingleFileHTMLBuilder):
assert '<div class="toctree-wrapper compound">\n</div>' in content
assert '<div class="local-toc">' in content
else:
global_toc = (
'<div class="toctree-wrapper compound">\n'
'<ul class="simple">\n</ul>\n'
'</div>'
)
local_toc = (
'<div class="local-toc"><ul class="simple">'
'</ul>\n</div>'
)
assert global_toc in content
assert local_toc not in content
else:
global_toc = '<div class="toctree-wrapper compound">\n</div>'
local_toc = (
'<div class="local-toc"><ul>\n'
'<li><a class="reference internal" href="#">test-empty</a></li>'
'</ul>\n</div>'
)
assert global_toc in content
assert local_toc not in content
def test_empty():
"""Local TOC is showing, as toctree was empty"""
for (app, status, warning) in build_all('test-empty'):
assert app.env.get_doctree('index').traverse(addnodes.toctree)
content = open(os.path.join(app.outdir, 'index.html')).read()
if sphinx.version_info < (1, 4):
if isinstance(app.builder, SingleFileHTMLBuilder):
assert '<div class="toctree-wrapper compound">\n</div>' in content
assert '<div class="local-toc">' in content
else:
global_toc = (
'<div class="toctree-wrapper compound">\n'
'<ul class="simple">\n</ul>\n'
'</div>'
)
local_toc = (
'<div class="local-toc"><ul class="simple">'
'</ul>\n</div>'
)
assert global_toc in content
assert local_toc not in content
else:
global_toc = '<div class="toctree-wrapper compound">\n</div>'
local_toc = (
'<div class="local-toc"><ul>\n'
'<li><a class="reference internal" href="#">test-empty</a></li>'
'</ul>\n</div>'
)
assert global_toc in content
assert local_toc not in content