Close #8487: csv-table now considers abspath as relpath from srcdir

To make directives' behavior consistent, the :file: option for
csv-table directive now recognizes an absolute path as a relative
path from source directory.
This commit is contained in:
Takeshi KOMIYA
2021-03-07 01:59:48 +09:00
parent ae413e95ed
commit fb4220d0a2
7 changed files with 61 additions and 17 deletions

View File

@@ -8,6 +8,7 @@
:license: BSD, see LICENSE for details.
"""
import pytest
from docutils import nodes
from sphinx.testing import restructuredtext
@@ -54,6 +55,37 @@ def test_code_directive(app):
assert_node(doctree[0], language="python", linenos=True, highlight_args={'linenostart': 5})
@pytest.mark.sphinx(testroot='directive-csv-table')
def test_csv_table_directive(app):
# relative path from current document
text = ('.. csv-table::\n'
' :file: example.csv\n')
doctree = restructuredtext.parse(app, text, docname="subdir/index")
assert_node(doctree,
([nodes.table, nodes.tgroup, (nodes.colspec,
nodes.colspec,
nodes.colspec,
[nodes.tbody, nodes.row])],))
assert_node(doctree[0][0][3][0],
([nodes.entry, nodes.paragraph, "FOO"],
[nodes.entry, nodes.paragraph, "BAR"],
[nodes.entry, nodes.paragraph, "BAZ"]))
# absolute path from source directory
text = ('.. csv-table::\n'
' :file: /example.csv\n')
doctree = restructuredtext.parse(app, text, docname="subdir/index")
assert_node(doctree,
([nodes.table, nodes.tgroup, (nodes.colspec,
nodes.colspec,
nodes.colspec,
[nodes.tbody, nodes.row])],))
assert_node(doctree[0][0][3][0],
([nodes.entry, nodes.paragraph, "foo"],
[nodes.entry, nodes.paragraph, "bar"],
[nodes.entry, nodes.paragraph, "baz"]))
def test_math_directive(app):
# normal case
text = '.. math:: E = mc^2'