diff --git a/tests/root/conf.py b/tests/root/conf.py index d12e8167f..5186f3715 100644 --- a/tests/root/conf.py +++ b/tests/root/conf.py @@ -24,6 +24,7 @@ exclude_patterns = ['_build', '**/excluded.*'] keep_warnings = True pygments_style = 'sphinx' show_authors = True +numfig = True rst_epilog = '.. |subst| replace:: global substitution' diff --git a/tests/root/markup.txt b/tests/root/markup.txt index 6ed396ac0..1ad7a13b6 100644 --- a/tests/root/markup.txt +++ b/tests/root/markup.txt @@ -143,6 +143,9 @@ Adding \n to test unescaping. * :ref:`my-figure` * :ref:`my-table` * :ref:`my-code-block` +* :numref:`my-figure` +* :numref:`my-table` +* :numref:`my-code-block` * :doc:`subdir/includes` * ``:download:`` is tested in includes.txt * :option:`Python -c option ` diff --git a/tests/roots/test-numfig/baz.rst b/tests/roots/test-numfig/baz.rst index 9e2ccfebb..da9e0fe0a 100644 --- a/tests/roots/test-numfig/baz.rst +++ b/tests/roots/test-numfig/baz.rst @@ -1,15 +1,21 @@ Baz A ----- +.. _fig22: + .. figure:: rimg.png should be Fig.2.2 +.. _table22: + .. csv-table:: should be Table 2.2 :header-rows: 0 hello,world +.. _code22: + .. code-block:: python :caption: should be List 2.2 diff --git a/tests/roots/test-numfig/index.rst b/tests/roots/test-numfig/index.rst index 564018e36..7bdf135c8 100644 --- a/tests/roots/test-numfig/index.rst +++ b/tests/roots/test-numfig/index.rst @@ -7,6 +7,8 @@ test-tocdepth foo bar +.. _fig1: + .. figure:: rimg.png should be Fig.1 @@ -15,6 +17,8 @@ test-tocdepth should be Fig.2 +.. _table1: + .. csv-table:: should be Table 1 :header-rows: 0 @@ -25,6 +29,8 @@ test-tocdepth hello,world +.. _code1: + .. code-block:: python :caption: should be List 1 @@ -34,3 +40,11 @@ test-tocdepth :caption: should be List 2 print('hello world') + + +* Fig.1 is :numref:`fig1` +* Fig.2.2 is :numref:`Figure# ` +* Table.1 is :numref:`table1` +* Table.2.2 is :numref:`Table:# ` +* List.1 is :numref:`code1` +* List.2.2 is :numref:`Code-# ` diff --git a/tests/test_build_html.py b/tests/test_build_html.py index ae518062a..6d71c7a6c 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -458,8 +458,7 @@ def test_tocdepth_singlehtml(app, status, warning): @gen_with_app(buildername='html', testroot='numfig') -def test_numfig(app, status, warning): - # issue #1251 +def test_numfig_disabled(app, status, warning): app.builder.build_all() expects = { @@ -474,6 +473,12 @@ def test_numfig(app, status, warning): '^should be List 1$', True), (".//div[@class='code-block-caption']", '^should be List 2$', True), + (".//li/code/span", '^fig1$', True), + (".//li/code/span", '^Figure#$', True), + (".//li/code/span", '^table1$', True), + (".//li/code/span", '^Table:#$', True), + (".//li/code/span", '^code1$', True), + (".//li/code/span", '^Code-#$', True), ], 'foo.html': [ (".//div[@class='figure']/p[@class='caption']", @@ -557,6 +562,12 @@ def test_numfig_without_numbered_toctree(app, status, warning): '^List 9 should be List 1$', True), (".//div[@class='code-block-caption']", '^List 10 should be List 2$', True), + (".//li/a/em", '^Fig.9$', True), + (".//li/a/em", '^Figure6$', True), + (".//li/a/em", '^Table 9$', True), + (".//li/a/em", '^Table:6$', True), + (".//li/a/em", '^List 9$', True), + (".//li/a/em", '^Code-6$', True), ], 'foo.html': [ (".//div[@class='figure']/p[@class='caption']", @@ -636,6 +647,12 @@ def test_numfig_with_numbered_toctree(app, status, warning): '^List 1 should be List 1$', True), (".//div[@class='code-block-caption']", '^List 2 should be List 2$', True), + (".//li/a/em", '^Fig.1$', True), + (".//li/a/em", '^Figure2.2$', True), + (".//li/a/em", '^Table 1$', True), + (".//li/a/em", '^Table:2.2$', True), + (".//li/a/em", '^List 1$', True), + (".//li/a/em", '^Code-2.2$', True), ], 'foo.html': [ (".//div[@class='figure']/p[@class='caption']", @@ -715,6 +732,12 @@ def test_numfig_with_prefix(app, status, warning): '^Code-1 should be List 1$', True), (".//div[@class='code-block-caption']", '^Code-2 should be List 2$', True), + (".//li/a/em", '^Figure:1$', True), + (".//li/a/em", '^Figure2.2$', True), + (".//li/a/em", '^Tab_1$', True), + (".//li/a/em", '^Table:2.2$', True), + (".//li/a/em", '^Code-1$', True), + (".//li/a/em", '^Code-2.2$', True), ], 'foo.html': [ (".//div[@class='figure']/p[@class='caption']", @@ -794,6 +817,12 @@ def test_numfig_with_secnum_depth(app, status, warning): '^List 1 should be List 1$', True), (".//div[@class='code-block-caption']", '^List 2 should be List 2$', True), + (".//li/a/em", '^Fig.1$', True), + (".//li/a/em", '^Figure2.1.2$', True), + (".//li/a/em", '^Table 1$', True), + (".//li/a/em", '^Table:2.1.2$', True), + (".//li/a/em", '^List 1$', True), + (".//li/a/em", '^Code-2.1.2$', True), ], 'foo.html': [ (".//div[@class='figure']/p[@class='caption']", diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 374b54a22..3b6dd3e22 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -93,6 +93,22 @@ def test_latex(app, status, warning): os.chdir(cwd) +@with_app(buildername='latex', testroot='numfig', + confoverrides={'numfig': True}) +def test_numref(app, status, warning): + app.builder.build_all() + result = (app.outdir / 'Python.tex').text(encoding='utf8') + print(result) + print(status.getvalue()) + print(warning.getvalue()) + assert '\\ref{index:fig1}' in result + assert '\\ref{baz:fig22}' in result + assert '\\ref{index:table1}' in result + assert '\\ref{baz:table22}' in result + assert '\\ref{index:code1}' in result + assert '\\ref{baz:code22}' in result + + @with_app(buildername='latex') def test_latex_add_latex_package(app, status, warning): app.add_latex_package('foo')