本文整理汇总了Python中sphinx.testing.util.assert_node函数的典型用法代码示例。如果您正苦于以下问题:Python assert_node函数的具体用法?Python assert_node怎么用?Python assert_node使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assert_node函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_toctree_twice
def test_toctree_twice(app):
text = (".. toctree::\n"
"\n"
" foo\n"
" foo\n")
app.env.find_files(app.config, app.builder)
doctree = parse(app, 'index', text)
assert_node(doctree, [nodes.document, nodes.compound, addnodes.toctree])
assert_node(doctree[0][0],
entries=[(None, 'foo'), (None, 'foo')],
includefiles=['foo', 'foo'])
示例2: test_toctree_glob_and_url
def test_toctree_glob_and_url(app):
text = (".. toctree::\n"
" :glob:\n"
"\n"
" https://example.com/?q=sphinx\n")
app.env.find_files(app.config, app.builder)
doctree = parse(app, 'index', text)
assert_node(doctree, [nodes.document, nodes.compound, addnodes.toctree])
assert_node(doctree[0][0],
entries=[(None, 'https://example.com/?q=sphinx')],
includefiles=[])
示例3: assert_refnode
def assert_refnode(node, module_name, class_name, target, reftype=None,
domain='py'):
attributes = {
'refdomain': domain,
'reftarget': target,
}
if reftype is not None:
attributes['reftype'] = reftype
if module_name is not False:
attributes['py:module'] = module_name
if class_name is not False:
attributes['py:class'] = class_name
assert_node(node, **attributes)
示例4: assert_refnode
def assert_refnode(node, mod_name, prefix, target, reftype=None,
domain='js'):
attributes = {
'refdomain': domain,
'reftarget': target,
}
if reftype is not None:
attributes['reftype'] = reftype
if mod_name is not False:
attributes['js:module'] = mod_name
if prefix is not False:
attributes['js:object'] = prefix
assert_node(node, **attributes)
示例5: test_toctree_urls_and_titles
def test_toctree_urls_and_titles(app):
text = (".. toctree::\n"
"\n"
" Sphinx <https://www.sphinx-doc.org/>\n"
" https://readthedocs.org/\n"
" The BAR <bar/index>\n")
app.env.find_files(app.config, app.builder)
doctree = parse(app, 'index', text)
assert_node(doctree, [nodes.document, nodes.compound, addnodes.toctree])
assert_node(doctree[0][0],
entries=[('Sphinx', 'https://www.sphinx-doc.org/'),
(None, 'https://readthedocs.org/'),
('The BAR', 'bar/index')],
includefiles=['bar/index'])
示例6: test_relative_toctree
def test_relative_toctree(app):
text = (".. toctree::\n"
"\n"
" bar_1\n"
" bar_2\n"
" bar_3\n"
" ../quux\n")
app.env.find_files(app.config, app.builder)
doctree = parse(app, 'bar/index', text)
assert_node(doctree, [nodes.document, nodes.compound, addnodes.toctree])
assert_node(doctree[0][0],
entries=[(None, 'bar/bar_1'), (None, 'bar/bar_2'), (None, 'bar/bar_3'),
(None, 'quux')],
includefiles=['bar/bar_1', 'bar/bar_2', 'bar/bar_3', 'quux'])
示例7: test_compact_refonly_bullet_list
def test_compact_refonly_bullet_list(app, status, warning):
app.builder.build_all()
doctree = pickle.loads((app.doctreedir / 'index.doctree').bytes())
assert_node(doctree[0], nodes.section)
assert len(doctree[0]) == 5
assert doctree[0][1].astext() == 'List A:'
assert_node(doctree[0][2], nodes.bullet_list)
assert_node(doctree[0][2][0][0], addnodes.compact_paragraph)
assert doctree[0][2][0][0].astext() == 'genindex'
assert doctree[0][3].astext() == 'List B:'
assert_node(doctree[0][4], nodes.bullet_list)
assert_node(doctree[0][4][0][0], nodes.paragraph)
assert doctree[0][4][0][0].astext() == 'Hello'
示例8: test_get_toc_for
def test_get_toc_for(app):
app.build()
toctree = TocTree(app.env).get_toc_for('index', app.builder)
assert_node(toctree,
[bullet_list, ([list_item, (compact_paragraph, # [0][0]
[bullet_list, (addnodes.toctree, # [0][1][0]
comment, # [0][1][1]
list_item)])], # [0][1][2]
[list_item, (compact_paragraph, # [1][0]
[bullet_list, (addnodes.toctree,
addnodes.toctree)])],
[list_item, compact_paragraph])]) # [2][0]
assert_node(toctree[0][0],
[compact_paragraph, reference, u"Welcome to Sphinx Tests’s documentation!"])
assert_node(toctree[0][1][2],
([compact_paragraph, reference, "subsection"],
[bullet_list, list_item, compact_paragraph, reference, "subsubsection"]))
assert_node(toctree[1][0],
[compact_paragraph, reference, "Test for issue #1157"])
assert_node(toctree[2][0],
[compact_paragraph, reference, "Indices and tables"])
示例9: test_get_toc_for_tocdepth
def test_get_toc_for_tocdepth(app):
app.build()
toctree = TocTree(app.env).get_toc_for('tocdepth', app.builder)
assert_node(toctree,
[bullet_list, list_item, (compact_paragraph, # [0][0]
bullet_list)]) # [0][1]
assert_node(toctree[0][0],
[compact_paragraph, reference, "level 1"])
assert_node(toctree[0][1],
[bullet_list, list_item, compact_paragraph, reference, "level 2"])
示例10: test_math_compat
def test_math_compat(app, status, warning):
with warnings.catch_warnings(record=True):
app.builder.build_all()
doctree = app.env.get_and_resolve_doctree('index', app.builder)
assert_node(doctree,
[nodes.document, nodes.section, (nodes.title,
[nodes.section, (nodes.title,
nodes.paragraph)],
nodes.section)])
assert_node(doctree[0][1][1],
('Inline: ',
[nodes.math, "E=mc^2"],
'\nInline my math: ',
[nodes.math, "E = mc^2"]))
assert_node(doctree[0][2],
([nodes.title, "block"],
[nodes.math_block, "a^2+b^2=c^2\n\n"],
[nodes.paragraph, "Second math"],
[nodes.math_block, "e^{i\\pi}+1=0\n\n"],
[nodes.paragraph, "Multi math equations"],
[nodes.math_block, "E = mc^2"]))
示例11: test_keep_warnings_is_False
def test_keep_warnings_is_False(app, status, warning):
app.builder.build_all()
doctree = pickle.loads((app.doctreedir / 'index.doctree').bytes())
assert_node(doctree[0], nodes.section)
assert len(doctree[0]) == 1
示例12: test_rst_prolog
def test_rst_prolog(app, status, warning):
app.builder.build_all()
rst = pickle.loads((app.doctreedir / 'restructuredtext.doctree').bytes())
md = pickle.loads((app.doctreedir / 'markdown.doctree').bytes())
# rst_prolog
assert_node(rst[0], nodes.paragraph)
assert_node(rst[0][0], nodes.emphasis)
assert_node(rst[0][0][0], nodes.Text)
assert rst[0][0][0] == 'Hello world'
# rst_epilog
assert_node(rst[-1], nodes.section)
assert_node(rst[-1][-1], nodes.paragraph)
assert_node(rst[-1][-1][0], nodes.emphasis)
assert_node(rst[-1][-1][0][0], nodes.Text)
assert rst[-1][-1][0][0] == 'Good-bye world'
# rst_prolog & rst_epilog on exlucding reST parser
assert not md.rawsource.startswith('*Hello world*.')
assert not md.rawsource.endswith('*Good-bye world*.\n')
示例13: test_samp
def test_samp():
# normal case
text = 'print 1+{variable}'
ret, msg = emph_literal_role('samp', text, text, 0, Mock())
assert_node(ret, ([nodes.literal, ("print 1+",
[nodes.emphasis, "variable"])],))
assert msg == []
# two emphasis items
text = 'print {1}+{variable}'
ret, msg = emph_literal_role('samp', text, text, 0, Mock())
assert_node(ret, ([nodes.literal, ("print ",
[nodes.emphasis, "1"],
"+",
[nodes.emphasis, "variable"])],))
assert msg == []
# empty curly brace
text = 'print 1+{}'
ret, msg = emph_literal_role('samp', text, text, 0, Mock())
assert_node(ret, ([nodes.literal, "print 1+{}"],))
assert msg == []
# half-opened variable
text = 'print 1+{variable'
ret, msg = emph_literal_role('samp', text, text, 0, Mock())
assert_node(ret, ([nodes.literal, "print 1+{variable"],))
assert msg == []
# nested
text = 'print 1+{{variable}}'
ret, msg = emph_literal_role('samp', text, text, 0, Mock())
assert_node(ret, ([nodes.literal, ("print 1+",
[nodes.emphasis, "{variable"],
"}")],))
assert msg == []
# emphasized item only
text = '{variable}'
ret, msg = emph_literal_role('samp', text, text, 0, Mock())
assert_node(ret, ([nodes.literal, nodes.emphasis, "variable"],))
assert msg == []
# escaping
text = r'print 1+\{variable}'
ret, msg = emph_literal_role('samp', text, text, 0, Mock())
assert_node(ret, ([nodes.literal, "print 1+{variable}"],))
assert msg == []
# escaping (2)
text = r'print 1+\{{variable}\}'
ret, msg = emph_literal_role('samp', text, text, 0, Mock())
assert_node(ret, ([nodes.literal, ("print 1+{",
[nodes.emphasis, "variable"],
"}")],))
assert msg == []
# escape a backslash
text = r'print 1+\\{variable}'
ret, msg = emph_literal_role('samp', text, text, 0, Mock())
assert_node(ret, ([nodes.literal, ("print 1+\\",
[nodes.emphasis, "variable"])],))
assert msg == []
示例14: test_image_glob_intl_using_figure_language_filename
def test_image_glob_intl_using_figure_language_filename(app):
app.build()
# index.rst
doctree = pickle.loads((app.doctreedir / 'index.doctree').bytes())
assert_node(doctree[0][1], nodes.image, uri='rimg.png.xx',
candidates={'*': 'rimg.png.xx'})
assert isinstance(doctree[0][2], nodes.figure)
assert_node(doctree[0][2][0], nodes.image, uri='rimg.png.xx',
candidates={'*': 'rimg.png.xx'})
assert_node(doctree[0][3], nodes.image, uri='img.*',
candidates={'application/pdf': 'img.pdf',
'image/gif': 'img.gif',
'image/png': 'img.png'})
assert isinstance(doctree[0][4], nodes.figure)
assert_node(doctree[0][4][0], nodes.image, uri='img.*',
candidates={'application/pdf': 'img.pdf',
'image/gif': 'img.gif',
'image/png': 'img.png'})
# subdir/index.rst
doctree = pickle.loads((app.doctreedir / 'subdir/index.doctree').bytes())
assert_node(doctree[0][1], nodes.image, uri='subdir/rimg.png',
candidates={'*': 'subdir/rimg.png'})
assert_node(doctree[0][2], nodes.image, uri='subdir/svgimg.*',
candidates={'application/pdf': 'subdir/svgimg.pdf',
'image/svg+xml': 'subdir/svgimg.svg'})
assert isinstance(doctree[0][3], nodes.figure)
assert_node(doctree[0][3][0], nodes.image, uri='subdir/svgimg.*',
candidates={'application/pdf': 'subdir/svgimg.pdf',
'image/svg+xml': 'subdir/svgimg.svg'})
示例15: test_default_role2
def test_default_role2(app, status, warning):
app.builder.build_all()
# default-role directive is stronger than configratuion
doctree = pickle.loads((app.doctreedir / 'index.doctree').bytes())
assert_node(doctree[0], nodes.section)
assert_node(doctree[0][1], nodes.paragraph)
assert_node(doctree[0][1][0], addnodes.index)
assert_node(doctree[0][1][1], nodes.target)
assert_node(doctree[0][1][2], nodes.reference, classes=["pep"])
# default_role changes the default behavior
doctree = pickle.loads((app.doctreedir / 'foo.doctree').bytes())
assert_node(doctree[0], nodes.section)
assert_node(doctree[0][1], nodes.paragraph)
assert_node(doctree[0][1][0], nodes.inline, classes=["guilabel"])
assert_node(doctree[0][1][1], nodes.Text)