diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-05-19 23:15:58 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-05-19 23:15:58 +0900 |
commit | 1514b037d477769dba476d7aa9bdfac64d2f6f6a (patch) | |
tree | c3e2bda2cadddfd943d9c1a104582f8d3b0b4f3a /tests/test_transforms_post_transforms.py | |
parent | 8350736c270c4809429f289b163200c4c8f69d87 (diff) | |
parent | d2d2d7bde350fd5d8dc696cb0eb68e2bc05387ec (diff) | |
download | sphinx-git-1514b037d477769dba476d7aa9bdfac64d2f6f6a.tar.gz |
Merge branch '4.x'
Diffstat (limited to 'tests/test_transforms_post_transforms.py')
-rw-r--r-- | tests/test_transforms_post_transforms.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/test_transforms_post_transforms.py b/tests/test_transforms_post_transforms.py new file mode 100644 index 000000000..26af55031 --- /dev/null +++ b/tests/test_transforms_post_transforms.py @@ -0,0 +1,58 @@ +""" + test_transforms_post_transforms + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + Tests the post_transforms + + :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import pytest +from docutils import nodes + + +@pytest.mark.sphinx('html', testroot='transforms-post_transforms-missing-reference') +def test_nitpicky_warning(app, status, warning): + app.build() + assert ('index.rst:4: WARNING: py:class reference target ' + 'not found: io.StringIO' in warning.getvalue()) + + content = (app.outdir / 'index.html').read_text() + assert ('<p><code class="xref py py-class docutils literal notranslate"><span class="pre">' + 'io.StringIO</span></code></p>' in content) + + +@pytest.mark.sphinx('html', testroot='transforms-post_transforms-missing-reference', + freshenv=True) +def test_missing_reference(app, status, warning): + def missing_reference(app, env, node, contnode): + assert app is app + assert env is app.env + assert node['reftarget'] == 'io.StringIO' + assert contnode.astext() == 'io.StringIO' + + return nodes.inline('', 'missing-reference.StringIO') + + warning.truncate(0) + app.connect('missing-reference', missing_reference) + app.build() + assert warning.getvalue() == '' + + content = (app.outdir / 'index.html').read_text() + assert '<p><span>missing-reference.StringIO</span></p>' in content + + +@pytest.mark.sphinx('html', testroot='domain-py-python_use_unqualified_type_names', + freshenv=True) +def test_missing_reference_conditional_pending_xref(app, status, warning): + def missing_reference(app, env, node, contnode): + return contnode + + warning.truncate(0) + app.connect('missing-reference', missing_reference) + app.build() + assert warning.getvalue() == '' + + content = (app.outdir / 'index.html').read_text() + assert '<span class="n"><span class="pre">Age</span></span>' in content |