Beispiel #1
0
def test_html(app):
    app.builder.build_all()
    html_warnings = html_warnfile.getvalue().replace(os.sep, '/')
    html_warnings_exp = HTML_WARNINGS % {'root': app.srcdir}
    assert html_warnings == html_warnings_exp, 'Warnings don\'t match:\n' + \
           '\n'.join(difflib.ndiff(html_warnings_exp.splitlines(),
                                   html_warnings.splitlines()))

    if not ET:
        return
    for fname, paths in HTML_XPATH.iteritems():
        parser = NslessParser()
        parser.entity.update(htmlentitydefs.entitydefs)
        etree = ET.parse(os.path.join(app.outdir, fname), parser)
        for path, text in paths.iteritems():
            nodes = list(etree.findall(path))
            assert nodes != []
            if not text:
                # only check for node presence
                continue
            for node in nodes:
                if node.text and text in node.text:
                    break
            else:
                assert False, ('%r not found in any node matching '
                               'path %s in %s' % (text, path, fname))
Beispiel #2
0
def test_enumerable_node(app, status, warning):
    app.builder.build_all()

    expects = {
        'index.html': [
            (".//div[@class='figure']/p[@class='caption']/span[@class='caption-number']",
             "Fig. 1", True),
            (".//div[@class='figure']/p[@class='caption']/span[@class='caption-number']",
             "Fig. 2", True),
            (".//div[@class='figure']/p[@class='caption']/span[@class='caption-number']",
             "Fig. 3", True),
            (".//div//span[@class='caption-number']", "No.1 ", True),
            (".//div//span[@class='caption-number']", "No.2 ", True),
            (".//li/a/span", 'Fig. 1', True),
            (".//li/a/span", 'Fig. 2', True),
            (".//li/a/span", 'Fig. 3', True),
            (".//li/a/span", 'No.1', True),
            (".//li/a/span", 'No.2', True),
        ],
    }

    for fname, paths in iteritems(expects):
        parser = NslessParser()
        parser.entity.update(html_entities.entitydefs)
        with (app.outdir / fname).open('rb') as fp:
            etree = ET.parse(fp, parser)

        for xpath, check, be_found in paths:
            yield check_xpath, etree, fname, xpath, check, be_found
Beispiel #3
0
def test_tocdepth_singlehtml(app, status, warning):
    app.builder.build_all()

    expects = {
        "index.html": [
            (".//li[@class='toctree-l3']/a", "1.1.1. Foo A1", True),
            (".//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),
            # index.rst
            (".//h1", "test-tocdepth", True),
            # foo.rst
            (".//h2", "1. Foo", True),
            (".//h3", "1.1. Foo A", True),
            (".//h4", "1.1.1. Foo A1", True),
            (".//h3", "1.2. Foo B", True),
            (".//h4", "1.2.1. Foo B1", True),
            # bar.rst
            (".//h2", "2. Bar", True),
            (".//h3", "2.1. Bar A", True),
            (".//h3", "2.2. Bar B", True),
            (".//h4", "2.2.1. Bar B1", True),
            # baz.rst
            (".//h4", "2.1.1. Baz A", True),
        ]
    }

    for fname, paths in iteritems(expects):
        parser = NslessParser()
        parser.entity.update(html_entities.entitydefs)
        with (app.outdir / fname).open("rb") as fp:
            etree = ET.parse(fp, parser)

        for xpath, check, be_found in paths:
            yield check_xpath, etree, fname, xpath, check, be_found
Beispiel #4
0
def test_numfig_disabled(app, status, warning):
    app.builder.build_all()

    assert 'WARNING: invalid numfig_format: invalid' not in warning.getvalue()
    assert 'WARNING: invalid numfig_format: Fig %s %s' not in warning.getvalue()

    expects = {
        'index.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", None, True),
            (".//table/caption/span[@class='caption-number']", None, True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", None, True),
            (".//li/code/span", '^fig1$', True),
            (".//li/code/span", '^Figure%s$', True),
            (".//li/code/span", '^table-1$', True),
            (".//li/code/span", '^Table:%s$', True),
            (".//li/code/span", '^CODE_1$', True),
            (".//li/code/span", '^Code-%s$', True),
        ],
        'foo.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", None, True),
            (".//table/caption/span[@class='caption-number']", None, True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", None, True),
        ],
        'bar.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", None, True),
            (".//table/caption/span[@class='caption-number']", None, True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", None, True),
        ],
        'baz.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", None, True),
            (".//table/caption/span[@class='caption-number']", None, True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", None, 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
def test_html_output(app, status, warning):
    app.builder.build_all()
    for fname, paths in iteritems(HTML_XPATH):
        parser = NslessParser()
        parser.entity.update(html_entities.entitydefs)
        with (app.outdir / fname).open('rb') as fp:
            etree = ET.parse(fp, parser)
        for path, check in paths:
            yield check_xpath, etree, fname, path, check

    check_static_entries(app.builder.outdir)
    check_extra_entries(app.builder.outdir)
Beispiel #6
0
def test_html(app):
    app.builder.build_all()
    html_warnings = html_warnfile.getvalue().replace(os.sep, '/')
    html_warnings_exp = HTML_WARNINGS % {'root': app.srcdir}
    assert html_warnings == html_warnings_exp, 'Warnings don\'t match:\n' + \
           '\n'.join(difflib.ndiff(html_warnings_exp.splitlines(),
                                   html_warnings.splitlines()))

    for fname, paths in HTML_XPATH.iteritems():
        parser = NslessParser()
        parser.entity.update(htmlentitydefs.entitydefs)
        etree = ET.parse(os.path.join(app.outdir, fname), parser)
        for path, check in paths.iteritems():
            yield check_xpath, etree, fname, path, check
def test_tocdepth(app, status, warning):
    # issue #1251
    app.builder.build_all()

    expects = {
        'index.html': [
            (".//li[@class='toctree-l3']/a", '1.1.1. Foo A1', True),
            (".//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),
        ],
        'foo.html': [
            (".//h1", '1. Foo', True),
            (".//h2", '1.1. Foo A', True),
            (".//h3", '1.1.1. Foo A1', True),
            (".//h2", '1.2. Foo B', True),
            (".//h3", '1.2.1. Foo B1', True),
            (".//div[@class='sphinxsidebarwrapper']//li/a", '1.1. Foo A', True),
            (".//div[@class='sphinxsidebarwrapper']//li/a", '1.1.1. Foo A1', True),
            (".//div[@class='sphinxsidebarwrapper']//li/a", '1.2. Foo B', True),
            (".//div[@class='sphinxsidebarwrapper']//li/a", '1.2.1. Foo B1', 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='sphinxsidebarwrapper']//li/a", '2. Bar', True),
            (".//div[@class='sphinxsidebarwrapper']//li/a", '2.1. Bar A', True),
            (".//div[@class='sphinxsidebarwrapper']//li/a", '2.2. Bar B', True),
            (".//div[@class='sphinxsidebarwrapper']//li/a", '2.2.1. Bar B1', False),
        ],
        'baz.html': [
            (".//h1", '2.1.1. Baz A', 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
Beispiel #8
0
def test_html(app):
    app.builder.build_all()
    html_warnings = html_warnfile.getvalue().replace(os.sep, '/')
    html_warnings_exp = HTML_WARNINGS % {'root': re.escape(app.srcdir)}
    assert re.match(html_warnings_exp + '$', html_warnings), \
           'Warnings don\'t match:\n' + \
           '--- Expected (regex):\n' + html_warnings_exp + \
           '--- Got:\n' + html_warnings

    for fname, paths in HTML_XPATH.iteritems():
        parser = NslessParser()
        parser.entity.update(htmlentitydefs.entitydefs)
        etree = ET.parse(os.path.join(app.outdir, fname), parser)
        for path, check in paths:
            yield check_xpath, etree, fname, path, check

    check_static_entries(app.builder.outdir)
Beispiel #9
0
def test_tocdepth(app, status, warning):
    # issue #1251
    app.builder.build_all()

    expects = {
        'index.html': [
            (".//li[@class='toctree-l3']/a", '1.1.1. Foo A1', True),
            (".//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),
        ],
        'foo.html': [
            (".//h1", '1. Foo', True),
            (".//h2", '1.1. Foo A', True),
            (".//h3", '1.1.1. Foo A1', True),
            (".//h2", '1.2. Foo B', True),
            (".//h3", '1.2.1. Foo B1', True),
            (".//div[@class='sphinxsidebarwrapper']//li/a", '1.1. Foo A', True),
            (".//div[@class='sphinxsidebarwrapper']//li/a", '1.1.1. Foo A1', True),
            (".//div[@class='sphinxsidebarwrapper']//li/a", '1.2. Foo B', True),
            (".//div[@class='sphinxsidebarwrapper']//li/a", '1.2.1. Foo B1', 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='sphinxsidebarwrapper']//li/a", '2. Bar', True),
            (".//div[@class='sphinxsidebarwrapper']//li/a", '2.1. Bar A', True),
            (".//div[@class='sphinxsidebarwrapper']//li/a", '2.2. Bar B', True),
            (".//div[@class='sphinxsidebarwrapper']//li/a", '2.2.1. Bar B1', False),
        ],
        'baz.html': [
            (".//h1", '2.1.1. Baz A', True),
        ],
    }

    for fname, paths in iteritems(expects):
        parser = NslessParser()
        parser.entity.update(html_entities.entitydefs)
        with (app.outdir / fname).open('rb') as fp:
            etree = ET.parse(fp, parser)

        for xpath, check, be_found in paths:
            yield check_xpath, etree, fname, xpath, check, be_found
Beispiel #10
0
def test_html_output(app, status, warning):
    app.builder.build_all()
    html_warnings = warning.getvalue().replace(os.sep, "/")
    html_warnings_exp = HTML_WARNINGS % {"root": re.escape(app.srcdir.replace(os.sep, "/"))}
    assert re.match(html_warnings_exp + "$", html_warnings), (
        "Warnings don't match:\n" + "--- Expected (regex):\n" + html_warnings_exp + "--- Got:\n" + html_warnings
    )

    for fname, paths in iteritems(HTML_XPATH):
        parser = NslessParser()
        parser.entity.update(html_entities.entitydefs)
        with (app.outdir / fname).open("rb") as fp:
            etree = ET.parse(fp, parser)
        for path, check in paths:
            yield check_xpath, etree, fname, path, check

    check_static_entries(app.builder.outdir)
    check_extra_entries(app.builder.outdir)
Beispiel #11
0
def test_numfig_disabled(app, status, warning):
    app.builder.build_all()

    assert "index.rst:45: WARNING: numfig is disabled. :numref: is ignored." in warning.getvalue()
    assert "index.rst:51: WARNING: invalid numfig_format: invalid" not in warning.getvalue()
    assert "index.rst:52: WARNING: invalid numfig_format: Fig %s %s" not in warning.getvalue()

    expects = {
        "index.html": [
            (".//div[@class='figure']/p[@class='caption']/" "span[@class='caption-number']", None, True),
            (".//table/caption/span[@class='caption-number']", None, True),
            (".//div[@class='code-block-caption']/" "span[@class='caption-number']", None, True),
            (".//li/code/span", "^fig1$", True),
            (".//li/code/span", "^Figure%s$", True),
            (".//li/code/span", "^table-1$", True),
            (".//li/code/span", "^Table:%s$", True),
            (".//li/code/span", "^CODE_1$", True),
            (".//li/code/span", "^Code-%s$", True),
        ],
        "foo.html": [
            (".//div[@class='figure']/p[@class='caption']/" "span[@class='caption-number']", None, True),
            (".//table/caption/span[@class='caption-number']", None, True),
            (".//div[@class='code-block-caption']/" "span[@class='caption-number']", None, True),
        ],
        "bar.html": [
            (".//div[@class='figure']/p[@class='caption']/" "span[@class='caption-number']", None, True),
            (".//table/caption/span[@class='caption-number']", None, True),
            (".//div[@class='code-block-caption']/" "span[@class='caption-number']", None, True),
        ],
        "baz.html": [
            (".//div[@class='figure']/p[@class='caption']/" "span[@class='caption-number']", None, True),
            (".//table/caption/span[@class='caption-number']", None, True),
            (".//div[@class='code-block-caption']/" "span[@class='caption-number']", None, True),
        ],
    }

    for fname, paths in iteritems(expects):
        parser = NslessParser()
        parser.entity.update(html_entities.entitydefs)
        with (app.outdir / fname).open("rb") as fp:
            etree = ET.parse(fp, parser)

        for xpath, check, be_found in paths:
            yield check_xpath, etree, fname, xpath, check, be_found
Beispiel #12
0
def test_tocdepth(app, status, warning):
    # issue #1251
    app.builder.build_all()

    expects = {
        "index.html": [
            (".//li[@class='toctree-l3']/a", "1.1.1. Foo A1", True),
            (".//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),
        ],
        "foo.html": [
            (".//h1", "1. Foo", True),
            (".//h2", "1.1. Foo A", True),
            (".//h3", "1.1.1. Foo A1", True),
            (".//h2", "1.2. Foo B", True),
            (".//h3", "1.2.1. Foo B1", True),
            (".//div[@class='sphinxsidebarwrapper']//li/a", "1.1. Foo A", True),
            (".//div[@class='sphinxsidebarwrapper']//li/a", "1.1.1. Foo A1", True),
            (".//div[@class='sphinxsidebarwrapper']//li/a", "1.2. Foo B", True),
            (".//div[@class='sphinxsidebarwrapper']//li/a", "1.2.1. Foo B1", 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='sphinxsidebarwrapper']//li/a", "2. Bar", True),
            (".//div[@class='sphinxsidebarwrapper']//li/a", "2.1. Bar A", True),
            (".//div[@class='sphinxsidebarwrapper']//li/a", "2.2. Bar B", True),
            (".//div[@class='sphinxsidebarwrapper']//li/a", "2.2.1. Bar B1", False),
        ],
        "baz.html": [(".//h1", "2.1.1. Baz A", True)],
    }

    for fname, paths in iteritems(expects):
        parser = NslessParser()
        parser.entity.update(html_entities.entitydefs)
        with (app.outdir / fname).open("rb") as fp:
            etree = ET.parse(fp, parser)

        for xpath, check, be_found in paths:
            yield check_xpath, etree, fname, xpath, check, be_found
Beispiel #13
0
def test_tocdepth_singlehtml(app, status, warning):
    app.builder.build_all()

    expects = {
        'index.html': [
            (".//li[@class='toctree-l3']/a", '1.1.1. Foo A1', True),
            (".//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),

            # index.rst
            (".//h1", 'test-tocdepth', True),

            # foo.rst
            (".//h2", '1. Foo', True),
            (".//h3", '1.1. Foo A', True),
            (".//h4", '1.1.1. Foo A1', True),
            (".//h3", '1.2. Foo B', True),
            (".//h4", '1.2.1. Foo B1', True),

            # bar.rst
            (".//h2", '2. Bar', True),
            (".//h3", '2.1. Bar A', True),
            (".//h3", '2.2. Bar B', True),
            (".//h4", '2.2.1. Bar B1', True),

            # baz.rst
            (".//h4", '2.1.1. Baz A', 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
Beispiel #14
0
def test_html_output(app, status, warning):
    app.builder.build_all()
    html_warnings = warning.getvalue().replace(os.sep, '/')
    html_warnings_exp = HTML_WARNINGS % {
        'root': re.escape(app.srcdir.replace(os.sep, '/'))}
    assert re.match(html_warnings_exp + '$', html_warnings), \
        'Warnings don\'t match:\n' + \
        '--- Expected (regex):\n' + html_warnings_exp + \
        '--- Got:\n' + html_warnings

    for fname, paths in iteritems(HTML_XPATH):
        parser = NslessParser()
        parser.entity.update(html_entities.entitydefs)
        with (app.outdir / fname).open('rb') as fp:
            etree = ET.parse(fp, parser)
        for path, check in paths:
            yield check_xpath, etree, fname, path, check

    check_static_entries(app.builder.outdir)
    check_extra_entries(app.builder.outdir)
Beispiel #15
0
def test_html(app):
    app.builder.build_all()
    html_warnings = html_warnfile.getvalue().replace(os.sep, '/')
    html_warnings_exp = HTML_WARNINGS % {'root': re.escape(app.srcdir)}
    assert re.match(html_warnings_exp + '$', html_warnings), \
           'Warnings don\'t match:\n' + \
           '--- Expected (regex):\n' + html_warnings_exp + \
           '--- Got:\n' + html_warnings

    for fname, paths in HTML_XPATH.iteritems():
        parser = NslessParser()
        parser.entity.update(htmlentitydefs.entitydefs)
        fp = open(os.path.join(app.outdir, fname))
        try:
            etree = ET.parse(fp, parser)
        finally:
            fp.close()
        for path, check in paths:
            yield check_xpath, etree, fname, path, check

    check_static_entries(app.builder.outdir)
def test_html_output(app, status, warning):
    app.builder.build_all()
    html_warnings = warning.getvalue().replace(os.sep, '/')
    html_warnings_exp = HTML_WARNINGS % {
        'root': re.escape(app.srcdir.replace(os.sep, '/'))}
    assert re.match(html_warnings_exp + '$', html_warnings), \
        'Warnings don\'t match:\n' + \
        '--- Expected (regex):\n' + html_warnings_exp + \
        '--- Got:\n' + html_warnings

    for fname, paths in iteritems(HTML_XPATH):
        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 path, check in paths:
            yield check_xpath, etree, fname, path, check

    check_static_entries(app.builder.outdir)
    check_extra_entries(app.builder.outdir)
Beispiel #17
0
def test_numfig_with_secnum_depth(app, status, warning):
    app.builder.build_all()

    expects = {
        'index.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 1 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 2 $', True),
            (".//table/caption/span[@class='caption-number']", '^Table 1 $',
             True),
            (".//table/caption/span[@class='caption-number']", '^Table 2 $',
             True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 2 $', True),
            (".//li/a/span", '^Fig. 1$', True),
            (".//li/a/span", '^Figure2.1.2$', True),
            (".//li/a/span", '^Table 1$', True),
            (".//li/a/span", '^Table:2.1.2$', True),
            (".//li/a/span", '^Listing 1$', True),
            (".//li/a/span", '^Code-2.1.2$', True),
        ],
        'foo.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 1.1 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 1.1.1 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 1.1.2 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 1.2.1 $', True),
            (".//table/caption/span[@class='caption-number']", '^Table 1.1 $',
             True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 1.1.1 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 1.1.2 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 1.2.1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 1.1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 1.1.1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 1.1.2 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 1.2.1 $', True),
        ],
        'bar.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 2.1.1 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 2.1.3 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 2.2.1 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 2.1.1 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 2.1.3 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 2.2.1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 2.1.1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 2.1.3 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 2.2.1 $', True),
        ],
        'baz.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 2.1.2 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 2.1.2 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 2.1.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
Beispiel #18
0
def test_numfig_with_secnum_depth(app, status, warning):
    app.builder.build_all()

    assert ('index.rst:45: WARNING: numfig is disabled. :numref: is ignored.'
            not in warning.getvalue())
    assert 'index.rst:51: WARNING: invalid numfig_format: invalid' in warning.getvalue()
    assert 'index.rst:52: WARNING: invalid numfig_format: Fig %s %s' in warning.getvalue()

    expects = {
        'index.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 1 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 2 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 1 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 2 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 2 $', True),
            (".//li/a/span", '^Fig. 1$', True),
            (".//li/a/span", '^Figure2.1.2$', True),
            (".//li/a/span", '^Table 1$', True),
            (".//li/a/span", '^Table:2.1.2$', True),
            (".//li/a/span", '^Listing 1$', True),
            (".//li/a/span", '^Code-2.1.2$', True),
            ],
        'foo.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 1.1 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 1.1.1 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 1.1.2 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 1.2.1 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 1.1 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 1.1.1 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 1.1.2 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 1.2.1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 1.1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 1.1.1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 1.1.2 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 1.2.1 $', True),
            ],
        'bar.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 2.1.1 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 2.1.3 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 2.2.1 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 2.1.1 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 2.1.3 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 2.2.1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 2.1.1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 2.1.3 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 2.2.1 $', True),
        ],
        'baz.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 2.1.2 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 2.1.2 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 2.1.2 $', True),
        ],
    }

    for fname, paths in iteritems(expects):
        parser = NslessParser()
        parser.entity.update(html_entities.entitydefs)
        with (app.outdir / fname).open('rb') as fp:
            etree = ET.parse(fp, parser)

        for xpath, check, be_found in paths:
            yield check_xpath, etree, fname, xpath, check, be_found
Beispiel #19
0
def test_numfig_with_prefix(app, status, warning):
    app.builder.build_all()

    assert ('index.rst:45: WARNING: numfig is disabled. :numref: is ignored.'
            not in warning.getvalue())
    assert 'index.rst:51: WARNING: invalid numfig_format: invalid' in warning.getvalue()
    assert 'index.rst:52: WARNING: invalid numfig_format: Fig %s %s' in warning.getvalue()

    expects = {
        'index.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Figure:1 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Figure:2 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Tab_1 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Tab_2 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Code-1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Code-2 $', True),
            (".//li/a/span", '^Figure:1$', True),
            (".//li/a/span", '^Figure2.2$', True),
            (".//li/a/span", '^Tab_1$', True),
            (".//li/a/span", '^Table:2.2$', True),
            (".//li/a/span", '^Code-1$', True),
            (".//li/a/span", '^Code-2.2$', True),
            ],
        'foo.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Figure:1.1 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Figure:1.2 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Figure:1.3 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Figure:1.4 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Tab_1.1 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Tab_1.2 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Tab_1.3 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Tab_1.4 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Code-1.1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Code-1.2 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Code-1.3 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Code-1.4 $', True),
            ],
        'bar.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Figure:2.1 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Figure:2.3 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Figure:2.4 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Tab_2.1 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Tab_2.3 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Tab_2.4 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Code-2.1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Code-2.3 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Code-2.4 $', True),
        ],
        'baz.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Figure:2.2 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Tab_2.2 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Code-2.2 $', True),
        ],
    }

    for fname, paths in iteritems(expects):
        parser = NslessParser()
        parser.entity.update(html_entities.entitydefs)
        with (app.outdir / fname).open('rb') as fp:
            etree = ET.parse(fp, parser)

        for xpath, check, be_found in paths:
            yield check_xpath, etree, fname, xpath, check, be_found
def test_numfig_without_numbered_toctree(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']/"
             "span[@class='caption-number']", '^Fig. 9 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 10 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 9 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 10 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 9 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 10 $', 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", '^Listing 9$', True),
            (".//li/a/em", '^Code-6$', True),
            ],
        'foo.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 1 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 2 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 3 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 4 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 1 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 2 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 3 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 4 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 2 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 3 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 4 $', True),
            ],
        'bar.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 5 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 7 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 8 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 5 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 7 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 8 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 5 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 7 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 8 $', True),
        ],
        'baz.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 6 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 6 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 6 $', 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
Beispiel #21
0
def test_numfig_without_numbered_toctree(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()

    assert 'WARNING: invalid numfig_format: invalid' in warning.getvalue()
    assert 'WARNING: invalid numfig_format: Fig %s %s' in warning.getvalue()

    expects = {
        'index.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 9 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 10 $', True),
            (".//table/caption/span[@class='caption-number']", '^Table 9 $',
             True),
            (".//table/caption/span[@class='caption-number']", '^Table 10 $',
             True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 9 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 10 $', True),
            (".//li/a/span", '^Fig. 9$', True),
            (".//li/a/span", '^Figure6$', True),
            (".//li/a/span", '^Table 9$', True),
            (".//li/a/span", '^Table:6$', True),
            (".//li/a/span", '^Listing 9$', True),
            (".//li/a/span", '^Code-6$', True),
        ],
        'foo.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 1 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 2 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 3 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 4 $', True),
            (".//table/caption/span[@class='caption-number']", '^Table 1 $',
             True),
            (".//table/caption/span[@class='caption-number']", '^Table 2 $',
             True),
            (".//table/caption/span[@class='caption-number']", '^Table 3 $',
             True),
            (".//table/caption/span[@class='caption-number']", '^Table 4 $',
             True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 2 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 3 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 4 $', True),
        ],
        'bar.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 5 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 7 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 8 $', True),
            (".//table/caption/span[@class='caption-number']", '^Table 5 $',
             True),
            (".//table/caption/span[@class='caption-number']", '^Table 7 $',
             True),
            (".//table/caption/span[@class='caption-number']", '^Table 8 $',
             True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 5 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 7 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 8 $', True),
        ],
        'baz.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 6 $', True),
            (".//table/caption/span[@class='caption-number']", '^Table 6 $',
             True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 6 $', True),
        ],
    }

    for fname, paths in iteritems(expects):
        parser = NslessParser()
        parser.entity.update(html_entities.entitydefs)
        with (app.outdir / fname).open('rb') as fp:
            etree = ET.parse(fp, parser)

        for xpath, check, be_found in paths:
            yield check_xpath, etree, fname, xpath, check, be_found
Beispiel #22
0
def test_numfig_with_prefix(app, status, warning):
    app.builder.build_all()

    assert 'WARNING: invalid numfig_format: invalid' in warning.getvalue()
    assert 'WARNING: invalid numfig_format: Fig %s %s' in warning.getvalue()

    expects = {
        'index.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Figure:1 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Figure:2 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Tab_1 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Tab_2 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Code-1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Code-2 $', True),
            (".//li/a/span", '^Figure:1$', True),
            (".//li/a/span", '^Figure2.2$', True),
            (".//li/a/span", '^Tab_1$', True),
            (".//li/a/span", '^Table:2.2$', True),
            (".//li/a/span", '^Code-1$', True),
            (".//li/a/span", '^Code-2.2$', True),
            ],
        'foo.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Figure:1.1 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Figure:1.2 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Figure:1.3 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Figure:1.4 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Tab_1.1 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Tab_1.2 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Tab_1.3 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Tab_1.4 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Code-1.1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Code-1.2 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Code-1.3 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Code-1.4 $', True),
            ],
        'bar.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Figure:2.1 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Figure:2.3 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Figure:2.4 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Tab_2.1 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Tab_2.3 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Tab_2.4 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Code-2.1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Code-2.3 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Code-2.4 $', True),
        ],
        'baz.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Figure:2.2 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Tab_2.2 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Code-2.2 $', True),
        ],
    }

    for fname, paths in iteritems(expects):
        parser = NslessParser()
        parser.entity.update(html_entities.entitydefs)
        with (app.outdir / fname).open('rb') as fp:
            etree = ET.parse(fp, parser)

        for xpath, check, be_found in paths:
            yield check_xpath, etree, fname, xpath, check, be_found
def test_numfig_with_secnum_depth(app, status, warning):
    app.builder.build_all()

    expects = {
        'index.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 1 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 2 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 1 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 2 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 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", '^Listing 1$', True),
            (".//li/a/em", '^Code-2.1.2$', True),
            ],
        'foo.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 1.1 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 1.1.1 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 1.1.2 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 1.2.1 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 1.1 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 1.1.1 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 1.1.2 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 1.2.1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 1.1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 1.1.1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 1.1.2 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 1.2.1 $', True),
            ],
        'bar.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 2.1.1 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 2.1.3 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 2.2.1 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 2.1.1 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 2.1.3 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 2.2.1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 2.1.1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 2.1.3 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 2.2.1 $', True),
        ],
        'baz.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 2.1.2 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 2.1.2 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 2.1.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
Beispiel #24
0
def test_numfig_with_secnum_depth(app, status, warning):
    app.builder.build_all()

    assert 'WARNING: invalid numfig_format: invalid' in warning.getvalue()
    assert 'WARNING: invalid numfig_format: Fig %s %s' in warning.getvalue()

    expects = {
        'index.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 1 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 2 $', True),
            (".//table/caption/span[@class='caption-number']", '^Table 1 $',
             True),
            (".//table/caption/span[@class='caption-number']", '^Table 2 $',
             True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 2 $', True),
            (".//li/a/span", '^Fig. 1$', True),
            (".//li/a/span", '^Figure2.1.2$', True),
            (".//li/a/span", '^Table 1$', True),
            (".//li/a/span", '^Table:2.1.2$', True),
            (".//li/a/span", '^Listing 1$', True),
            (".//li/a/span", '^Code-2.1.2$', True),
        ],
        'foo.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 1.1 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 1.1.1 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 1.1.2 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 1.2.1 $', True),
            (".//table/caption/span[@class='caption-number']", '^Table 1.1 $',
             True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 1.1.1 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 1.1.2 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 1.2.1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 1.1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 1.1.1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 1.1.2 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 1.2.1 $', True),
        ],
        'bar.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 2.1.1 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 2.1.3 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 2.2.1 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 2.1.1 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 2.1.3 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 2.2.1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 2.1.1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 2.1.3 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 2.2.1 $', True),
        ],
        'baz.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 2.1.2 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 2.1.2 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 2.1.2 $', True),
        ],
    }

    for fname, paths in iteritems(expects):
        parser = NslessParser()
        parser.entity.update(html_entities.entitydefs)
        with (app.outdir / fname).open('rb') as fp:
            etree = ET.parse(fp, parser)

        for xpath, check, be_found in paths:
            yield check_xpath, etree, fname, xpath, check, be_found
Beispiel #25
0
def test_numfig_without_numbered_toctree(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()

    assert ('index.rst:45: WARNING: numfig is disabled. :numref: is ignored.'
            not in warning.getvalue())
    assert 'index.rst:51: WARNING: invalid numfig_format: invalid' in warning.getvalue()
    assert 'index.rst:52: WARNING: invalid numfig_format: Fig %s %s' in warning.getvalue()

    expects = {
        'index.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 9 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 10 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 9 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 10 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 9 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 10 $', True),
            (".//li/a/span", '^Fig. 9$', True),
            (".//li/a/span", '^Figure6$', True),
            (".//li/a/span", '^Table 9$', True),
            (".//li/a/span", '^Table:6$', True),
            (".//li/a/span", '^Listing 9$', True),
            (".//li/a/span", '^Code-6$', True),
            ],
        'foo.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 1 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 2 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 3 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 4 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 1 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 2 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 3 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 4 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 1 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 2 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 3 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 4 $', True),
            ],
        'bar.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 5 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 7 $', True),
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 8 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 5 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 7 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 8 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 5 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 7 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 8 $', True),
        ],
        'baz.html': [
            (".//div[@class='figure']/p[@class='caption']/"
             "span[@class='caption-number']", '^Fig. 6 $', True),
            (".//table/caption/span[@class='caption-number']",
             '^Table 6 $', True),
            (".//div[@class='code-block-caption']/"
             "span[@class='caption-number']", '^Listing 6 $', True),
        ],
    }

    for fname, paths in iteritems(expects):
        parser = NslessParser()
        parser.entity.update(html_entities.entitydefs)
        with (app.outdir / fname).open('rb') as fp:
            etree = ET.parse(fp, parser)

        for xpath, check, be_found in paths:
            yield check_xpath, etree, fname, xpath, check, be_found