diff options
author | tk0miya <i.tkomiya@gmail.com> | 2014-09-26 00:36:38 +0900 |
---|---|---|
committer | tk0miya <i.tkomiya@gmail.com> | 2014-09-26 00:36:38 +0900 |
commit | 6202a4d80a7da4c5523e6cdd6ae97d778d91bf98 (patch) | |
tree | bf1cee10f5582b743759b275e238bc6906341292 /tests | |
parent | 52fd7a2734e33e0824a7f7f9851fc7a7d2c1454f (diff) | |
download | sphinx-6202a4d80a7da4c5523e6cdd6ae97d778d91bf98.tar.gz |
Add testcases for numfig
Diffstat (limited to 'tests')
-rw-r--r-- | tests/roots/test-tocdepth/bar.rst | 11 | ||||
-rw-r--r-- | tests/roots/test-tocdepth/baz.rst | 3 | ||||
-rw-r--r-- | tests/roots/test-tocdepth/foo.rst | 15 | ||||
-rw-r--r-- | tests/roots/test-tocdepth/index.rst | 8 | ||||
-rw-r--r-- | tests/roots/test-tocdepth/rimg.png | bin | 0 -> 218 bytes | |||
-rw-r--r-- | tests/test_build_html.py | 220 |
6 files changed, 257 insertions, 0 deletions
diff --git a/tests/roots/test-tocdepth/bar.rst b/tests/roots/test-tocdepth/bar.rst index d70dec90..96c692c5 100644 --- a/tests/roots/test-tocdepth/bar.rst +++ b/tests/roots/test-tocdepth/bar.rst @@ -11,10 +11,18 @@ Bar A should be 2.1 +.. figure:: rimg.png + + should be Fig.2.1 + .. toctree:: baz +.. figure:: rimg.png + + should be Fig.2.3 + Bar B ===== @@ -25,3 +33,6 @@ Bar B1 should be 2.2.1 +.. figure:: rimg.png + + should be Fig.2.4 diff --git a/tests/roots/test-tocdepth/baz.rst b/tests/roots/test-tocdepth/baz.rst index b07fa050..a1cb0512 100644 --- a/tests/roots/test-tocdepth/baz.rst +++ b/tests/roots/test-tocdepth/baz.rst @@ -3,3 +3,6 @@ Baz A should be 2.1.1 +.. figure:: rimg.png + + should be Fig.2.2 diff --git a/tests/roots/test-tocdepth/foo.rst b/tests/roots/test-tocdepth/foo.rst index 61fd539f..7fad902d 100644 --- a/tests/roots/test-tocdepth/foo.rst +++ b/tests/roots/test-tocdepth/foo.rst @@ -4,11 +4,23 @@ Foo should be 1 +.. figure:: rimg.png + + should be Fig.1.1 + Foo A ===== should be 1.1 +.. figure:: rimg.png + + should be Fig.1.2 + +.. figure:: rimg.png + + should be Fig.1.3 + Foo A1 ------ @@ -24,3 +36,6 @@ Foo B1 should be 1.2.1 +.. figure:: rimg.png + + should be Fig.1.4 diff --git a/tests/roots/test-tocdepth/index.rst b/tests/roots/test-tocdepth/index.rst index 0b651d48..ee32ef4c 100644 --- a/tests/roots/test-tocdepth/index.rst +++ b/tests/roots/test-tocdepth/index.rst @@ -6,3 +6,11 @@ test-tocdepth foo bar + +.. figure:: rimg.png + + should be Fig.1 + +.. figure:: rimg.png + + should be Fig.2 diff --git a/tests/roots/test-tocdepth/rimg.png b/tests/roots/test-tocdepth/rimg.png Binary files differnew file mode 100644 index 00000000..1081dc14 --- /dev/null +++ b/tests/roots/test-tocdepth/rimg.png diff --git a/tests/test_build_html.py b/tests/test_build_html.py index 52604468..02a4f02d 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -380,6 +380,10 @@ def test_tocdepth(app, status, warning): (".//li[@class='toctree-l3']/a", '1.2.1. Foo B1', True), (".//li[@class='toctree-l3']/a", '2.1.1. Bar A1', False), (".//li[@class='toctree-l3']/a", '2.2.1. Bar B1', False), + (".//div[@class='figure']/p[@class='caption']", + '^should be Fig.1$', True), + (".//div[@class='figure']/p[@class='caption']", + '^should be Fig.2$', True), ], 'foo.html': [ (".//h1", '1. Foo', True), @@ -387,15 +391,231 @@ def test_tocdepth(app, status, warning): (".//h3", '1.1.1. Foo A1', True), (".//h2", '1.2. Foo B', True), (".//h3", '1.2.1. Foo B1', True), + (".//div[@class='figure']/p[@class='caption']", + '^should be Fig.1.1$', True), + (".//div[@class='figure']/p[@class='caption']", + '^should be Fig.1.2$', True), + (".//div[@class='figure']/p[@class='caption']", + '^should be Fig.1.3$', True), + (".//div[@class='figure']/p[@class='caption']", + '^should be Fig.1.4$', True), ], 'bar.html': [ (".//h1", '2. Bar', True), (".//h2", '2.1. Bar A', True), (".//h2", '2.2. Bar B', True), (".//h3", '2.2.1. Bar B1', True), + (".//div[@class='figure']/p[@class='caption']", + '^should be Fig.2.1$', True), + (".//div[@class='figure']/p[@class='caption']", + '^should be Fig.2.3$', True), + (".//div[@class='figure']/p[@class='caption']", + '^should be Fig.2.4$', True), ], 'baz.html': [ (".//h1", '2.1.1. Baz A', True), + (".//div[@class='figure']/p[@class='caption']", + '^should be Fig.2.2$', True), + ], + } + + for fname, paths in iteritems(expects): + parser = NslessParser() + parser.entity.update(html_entities.entitydefs) + fp = open(os.path.join(app.outdir, fname), 'rb') + try: + etree = ET.parse(fp, parser) + finally: + fp.close() + + for xpath, check, be_found in paths: + yield check_xpath, etree, fname, xpath, check, be_found + + +@gen_with_app(buildername='html', testroot='tocdepth', + confoverrides={'numfig': True}) +def test_unnumbered_toctree_with_numfig(app, status, warning): + # remove :numbered: option + index = (app.srcdir / 'index.rst').text() + index = re.sub(':numbered:.*', '', index, re.MULTILINE) + (app.srcdir / 'index.rst').write_text(index, encoding='utf-8') + app.builder.build_all() + + expects = { + 'index.html': [ + (".//div[@class='figure']/p[@class='caption']", + '^Fig.9 should be Fig.1$', True), + (".//div[@class='figure']/p[@class='caption']", + '^Fig.10 should be Fig.2$', True), + ], + 'foo.html': [ + (".//div[@class='figure']/p[@class='caption']", + '^Fig.1 should be Fig.1.1$', True), + (".//div[@class='figure']/p[@class='caption']", + '^Fig.2 should be Fig.1.2$', True), + (".//div[@class='figure']/p[@class='caption']", + '^Fig.3 should be Fig.1.3$', True), + (".//div[@class='figure']/p[@class='caption']", + '^Fig.4 should be Fig.1.4$', True), + ], + 'bar.html': [ + (".//div[@class='figure']/p[@class='caption']", + '^Fig.5 should be Fig.2.1$', True), + (".//div[@class='figure']/p[@class='caption']", + '^Fig.7 should be Fig.2.3$', True), + (".//div[@class='figure']/p[@class='caption']", + '^Fig.8 should be Fig.2.4$', True), + ], + 'baz.html': [ + (".//div[@class='figure']/p[@class='caption']", + '^Fig.6 should be Fig.2.2$', True), + ], + } + + for fname, paths in iteritems(expects): + parser = NslessParser() + parser.entity.update(html_entities.entitydefs) + fp = open(os.path.join(app.outdir, fname), 'rb') + try: + etree = ET.parse(fp, parser) + finally: + fp.close() + + for xpath, check, be_found in paths: + yield check_xpath, etree, fname, xpath, check, be_found + + +@gen_with_app(buildername='html', testroot='tocdepth', + confoverrides={'numfig': True}) +def test_numbered_toctree_with_numfig(app, status, warning): + app.builder.build_all() + + expects = { + 'index.html': [ + (".//div[@class='figure']/p[@class='caption']", + '^Fig.1 should be Fig.1$', True), + (".//div[@class='figure']/p[@class='caption']", + '^Fig.2 should be Fig.2$', True), + ], + 'foo.html': [ + (".//div[@class='figure']/p[@class='caption']", + '^Fig.1.1 should be Fig.1.1$', True), + (".//div[@class='figure']/p[@class='caption']", + '^Fig.1.2 should be Fig.1.2$', True), + (".//div[@class='figure']/p[@class='caption']", + '^Fig.1.3 should be Fig.1.3$', True), + (".//div[@class='figure']/p[@class='caption']", + '^Fig.1.4 should be Fig.1.4$', True), + ], + 'bar.html': [ + (".//div[@class='figure']/p[@class='caption']", + '^Fig.2.1 should be Fig.2.1$', True), + (".//div[@class='figure']/p[@class='caption']", + '^Fig.2.3 should be Fig.2.3$', True), + (".//div[@class='figure']/p[@class='caption']", + '^Fig.2.4 should be Fig.2.4$', True), + ], + 'baz.html': [ + (".//div[@class='figure']/p[@class='caption']", + '^Fig.2.2 should be Fig.2.2$', True), + ], + } + + for fname, paths in iteritems(expects): + parser = NslessParser() + parser.entity.update(html_entities.entitydefs) + fp = open(os.path.join(app.outdir, fname), 'rb') + try: + etree = ET.parse(fp, parser) + finally: + fp.close() + + for xpath, check, be_found in paths: + yield check_xpath, etree, fname, xpath, check, be_found + + +@gen_with_app(buildername='html', testroot='tocdepth', + confoverrides={'numfig': True, 'numfig_prefix': {'figure': 'Figure:'}}) +def test_numbered_toctree_with_numfig_prefix(app, status, warning): + app.builder.build_all() + + expects = { + 'index.html': [ + (".//div[@class='figure']/p[@class='caption']", + '^Figure:1 should be Fig.1$', True), + (".//div[@class='figure']/p[@class='caption']", + '^Figure:2 should be Fig.2$', True), + ], + 'foo.html': [ + (".//div[@class='figure']/p[@class='caption']", + '^Figure:1.1 should be Fig.1.1$', True), + (".//div[@class='figure']/p[@class='caption']", + '^Figure:1.2 should be Fig.1.2$', True), + (".//div[@class='figure']/p[@class='caption']", + '^Figure:1.3 should be Fig.1.3$', True), + (".//div[@class='figure']/p[@class='caption']", + '^Figure:1.4 should be Fig.1.4$', True), + ], + 'bar.html': [ + (".//div[@class='figure']/p[@class='caption']", + '^Figure:2.1 should be Fig.2.1$', True), + (".//div[@class='figure']/p[@class='caption']", + '^Figure:2.3 should be Fig.2.3$', True), + (".//div[@class='figure']/p[@class='caption']", + '^Figure:2.4 should be Fig.2.4$', True), + ], + 'baz.html': [ + (".//div[@class='figure']/p[@class='caption']", + '^Figure:2.2 should be Fig.2.2$', True), + ], + } + + for fname, paths in iteritems(expects): + parser = NslessParser() + parser.entity.update(html_entities.entitydefs) + fp = open(os.path.join(app.outdir, fname), 'rb') + try: + etree = ET.parse(fp, parser) + finally: + fp.close() + + for xpath, check, be_found in paths: + yield check_xpath, etree, fname, xpath, check, be_found + + +@gen_with_app(buildername='html', testroot='tocdepth', + confoverrides={'numfig': True, 'numfig_secnum_depth': 2}) +def test_numbered_toctree_with_numfig_secnum_depth(app, status, warning): + app.builder.build_all() + + expects = { + 'index.html': [ + (".//div[@class='figure']/p[@class='caption']", + '^Fig.1 should be Fig.1$', True), + (".//div[@class='figure']/p[@class='caption']", + '^Fig.2 should be Fig.2$', True), + ], + 'foo.html': [ + (".//div[@class='figure']/p[@class='caption']", + '^Fig.1.1 should be Fig.1.1$', True), + (".//div[@class='figure']/p[@class='caption']", + '^Fig.1.1.1 should be Fig.1.2$', True), + (".//div[@class='figure']/p[@class='caption']", + '^Fig.1.1.2 should be Fig.1.3$', True), + (".//div[@class='figure']/p[@class='caption']", + '^Fig.1.2.1 should be Fig.1.4$', True), + ], + 'bar.html': [ + (".//div[@class='figure']/p[@class='caption']", + '^Fig.2.1.1 should be Fig.2.1$', True), + (".//div[@class='figure']/p[@class='caption']", + '^Fig.2.1.3 should be Fig.2.3$', True), + (".//div[@class='figure']/p[@class='caption']", + '^Fig.2.2.1 should be Fig.2.4$', True), + ], + 'baz.html': [ + (".//div[@class='figure']/p[@class='caption']", + '^Fig.2.1.2 should be Fig.2.2$', True), ], } |