mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge with 'stable'
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
from codecs import open
|
||||
from io import open
|
||||
|
||||
from six import PY2, text_type
|
||||
|
||||
@@ -126,35 +126,31 @@ class path(text_type):
|
||||
def utime(self, arg):
|
||||
os.utime(self, arg)
|
||||
|
||||
def write_text(self, text, **kwargs):
|
||||
def open(self, mode='r', **kwargs):
|
||||
return open(self, mode, **kwargs)
|
||||
|
||||
def write_text(self, text, encoding='utf-8', **kwargs):
|
||||
"""
|
||||
Writes the given `text` to the file.
|
||||
"""
|
||||
f = open(self, 'w', **kwargs)
|
||||
try:
|
||||
if isinstance(text, bytes):
|
||||
text = text.decode(encoding)
|
||||
with open(self, 'w', encoding=encoding, **kwargs) as f:
|
||||
f.write(text)
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
def text(self, **kwargs):
|
||||
def text(self, encoding='utf-8', **kwargs):
|
||||
"""
|
||||
Returns the text in the file.
|
||||
"""
|
||||
f = open(self, mode='U', **kwargs)
|
||||
try:
|
||||
with open(self, mode='U', encoding=encoding, **kwargs) as f:
|
||||
return f.read()
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
def bytes(self):
|
||||
"""
|
||||
Returns the bytes in the file.
|
||||
"""
|
||||
f = open(self, mode='rb')
|
||||
try:
|
||||
with open(self, mode='rb') as f:
|
||||
return f.read()
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
def write_bytes(self, bytes, append=False):
|
||||
"""
|
||||
@@ -167,11 +163,8 @@ class path(text_type):
|
||||
mode = 'ab'
|
||||
else:
|
||||
mode = 'wb'
|
||||
f = open(self, mode=mode)
|
||||
try:
|
||||
with open(self, mode=mode) as f:
|
||||
f.write(bytes)
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
def exists(self):
|
||||
"""
|
||||
|
||||
45
tests/roots/test-footnotes/index.rst
Normal file
45
tests/roots/test-footnotes/index.rst
Normal file
@@ -0,0 +1,45 @@
|
||||
===============
|
||||
test-footenotes
|
||||
===============
|
||||
|
||||
The section with a reference to [AuthorYear]_
|
||||
=============================================
|
||||
|
||||
.. figure:: rimg.png
|
||||
|
||||
This is the figure caption with a reference to [AuthorYear]_.
|
||||
|
||||
.. list-table:: The table title with a reference to [AuthorYear]_
|
||||
:header-rows: 1
|
||||
|
||||
* - Header1
|
||||
- Header2
|
||||
* - Content
|
||||
- Content
|
||||
|
||||
.. rubric:: The rubric title with a reference to [AuthorYear]_
|
||||
|
||||
.. [#] First
|
||||
|
||||
* First footnote: [#]_
|
||||
* Second footnote: [1]_
|
||||
* `Sphinx <http://sphinx-doc.org/>`_
|
||||
* Third footnote: [#]_
|
||||
* `URL including tilde <http://sphinx-doc.org/~test/>`_
|
||||
* GitHub Page: `https://github.com/sphinx-doc/sphinx <https://github.com/sphinx-doc/sphinx>`_
|
||||
* Mailing list: `sphinx-dev@googlegroups.com <mailto:sphinx-dev@googlegroups.com>`_
|
||||
|
||||
.. [AuthorYear] Author, Title, Year
|
||||
.. [1] Second
|
||||
.. [#] Third
|
||||
|
||||
`URL in term <http://sphinx-doc.org/>`_
|
||||
Description Description Description ...
|
||||
|
||||
Footnote in term [#]_
|
||||
Description Description Description ...
|
||||
|
||||
`Term in deflist <http://sphinx-doc.org/>`_
|
||||
Description2
|
||||
|
||||
.. [#] Footnote in term
|
||||
|
Before Width: | Height: | Size: 218 B After Width: | Height: | Size: 218 B |
@@ -1,22 +0,0 @@
|
||||
==============
|
||||
test-reference
|
||||
==============
|
||||
|
||||
The section with a reference to [AuthorYear]_
|
||||
=============================================
|
||||
|
||||
.. figure:: rimg.png
|
||||
|
||||
This is the figure caption with a reference to [AuthorYear]_.
|
||||
|
||||
.. list-table:: The table title with a reference to [AuthorYear]_
|
||||
:header-rows: 1
|
||||
|
||||
* - Header1
|
||||
- Header2
|
||||
* - Content
|
||||
- Content
|
||||
|
||||
.. rubric:: The rubric title with a reference to [AuthorYear]_
|
||||
|
||||
.. [AuthorYear] Author, Title, Year
|
||||
@@ -58,12 +58,12 @@ def test_build_all():
|
||||
"""))
|
||||
|
||||
master_doc = srcdir / 'contents.txt'
|
||||
master_doc.write_bytes((master_doc.text() + dedent("""
|
||||
master_doc.write_text(master_doc.text() + dedent(u"""
|
||||
.. toctree::
|
||||
|
||||
%(test_name)s/%(test_name)s
|
||||
""" % {'test_name': test_name})
|
||||
).encode('utf-8'))
|
||||
)
|
||||
|
||||
# note: no 'html' - if it's ok with dirhtml it's ok with html
|
||||
for buildername in ['dirhtml', 'singlehtml', 'latex', 'texinfo', 'pickle',
|
||||
|
||||
@@ -376,11 +376,8 @@ def test_html_output(app, status, warning):
|
||||
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:
|
||||
with (app.outdir / fname).open('rb') as fp:
|
||||
etree = ET.parse(fp, parser)
|
||||
finally:
|
||||
fp.close()
|
||||
for path, check in paths:
|
||||
yield check_xpath, etree, fname, path, check
|
||||
|
||||
@@ -429,11 +426,8 @@ def test_tocdepth(app, status, warning):
|
||||
for fname, paths in iteritems(expects):
|
||||
parser = NslessParser()
|
||||
parser.entity.update(html_entities.entitydefs)
|
||||
fp = open(os.path.join(app.outdir, fname), 'rb')
|
||||
try:
|
||||
with (app.outdir / fname).open('rb') as fp:
|
||||
etree = ET.parse(fp, parser)
|
||||
finally:
|
||||
fp.close()
|
||||
|
||||
for xpath, check, be_found in paths:
|
||||
yield check_xpath, etree, fname, xpath, check, be_found
|
||||
@@ -474,11 +468,8 @@ def test_tocdepth_singlehtml(app, status, warning):
|
||||
for fname, paths in iteritems(expects):
|
||||
parser = NslessParser()
|
||||
parser.entity.update(html_entities.entitydefs)
|
||||
fp = open(os.path.join(app.outdir, fname), 'rb')
|
||||
try:
|
||||
with (app.outdir / fname).open('rb') as fp:
|
||||
etree = ET.parse(fp, parser)
|
||||
finally:
|
||||
fp.close()
|
||||
|
||||
for xpath, check, be_found in paths:
|
||||
yield check_xpath, etree, fname, xpath, check, be_found
|
||||
@@ -531,11 +522,8 @@ def test_numfig_disabled(app, status, warning):
|
||||
for fname, paths in iteritems(expects):
|
||||
parser = NslessParser()
|
||||
parser.entity.update(html_entities.entitydefs)
|
||||
fp = open(os.path.join(app.outdir, fname), 'rb')
|
||||
try:
|
||||
with (app.outdir / fname).open('rb') as fp:
|
||||
etree = ET.parse(fp, parser)
|
||||
finally:
|
||||
fp.close()
|
||||
|
||||
for xpath, check, be_found in paths:
|
||||
yield check_xpath, etree, fname, xpath, check, be_found
|
||||
@@ -633,11 +621,8 @@ def test_numfig_without_numbered_toctree(app, status, warning):
|
||||
for fname, paths in iteritems(expects):
|
||||
parser = NslessParser()
|
||||
parser.entity.update(html_entities.entitydefs)
|
||||
fp = open(os.path.join(app.outdir, fname), 'rb')
|
||||
try:
|
||||
with (app.outdir / fname).open('rb') as fp:
|
||||
etree = ET.parse(fp, parser)
|
||||
finally:
|
||||
fp.close()
|
||||
|
||||
for xpath, check, be_found in paths:
|
||||
yield check_xpath, etree, fname, xpath, check, be_found
|
||||
@@ -731,11 +716,8 @@ def test_numfig_with_numbered_toctree(app, status, warning):
|
||||
for fname, paths in iteritems(expects):
|
||||
parser = NslessParser()
|
||||
parser.entity.update(html_entities.entitydefs)
|
||||
fp = open(os.path.join(app.outdir, fname), 'rb')
|
||||
try:
|
||||
with (app.outdir / fname).open('rb') as fp:
|
||||
etree = ET.parse(fp, parser)
|
||||
finally:
|
||||
fp.close()
|
||||
|
||||
for xpath, check, be_found in paths:
|
||||
yield check_xpath, etree, fname, xpath, check, be_found
|
||||
@@ -832,11 +814,8 @@ def test_numfig_with_prefix(app, status, warning):
|
||||
for fname, paths in iteritems(expects):
|
||||
parser = NslessParser()
|
||||
parser.entity.update(html_entities.entitydefs)
|
||||
fp = open(os.path.join(app.outdir, fname), 'rb')
|
||||
try:
|
||||
with (app.outdir / fname).open('rb') as fp:
|
||||
etree = ET.parse(fp, parser)
|
||||
finally:
|
||||
fp.close()
|
||||
|
||||
for xpath, check, be_found in paths:
|
||||
yield check_xpath, etree, fname, xpath, check, be_found
|
||||
@@ -930,11 +909,8 @@ def test_numfig_with_secnum_depth(app, status, warning):
|
||||
for fname, paths in iteritems(expects):
|
||||
parser = NslessParser()
|
||||
parser.entity.update(html_entities.entitydefs)
|
||||
fp = open(os.path.join(app.outdir, fname), 'rb')
|
||||
try:
|
||||
with (app.outdir / fname).open('rb') as fp:
|
||||
etree = ET.parse(fp, parser)
|
||||
finally:
|
||||
fp.close()
|
||||
|
||||
for xpath, check, be_found in paths:
|
||||
yield check_xpath, etree, fname, xpath, check, be_found
|
||||
|
||||
@@ -320,7 +320,7 @@ def test_footnote(app, status, warning):
|
||||
'\\footnotetext[5]{\nfootnotes in table\n}' in result)
|
||||
|
||||
|
||||
@with_app(buildername='latex', testroot='references-in-caption')
|
||||
@with_app(buildername='latex', testroot='footnotes')
|
||||
def test_reference_in_caption(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'Python.tex').text(encoding='utf8')
|
||||
@@ -332,3 +332,81 @@ def test_reference_in_caption(app, status, warning):
|
||||
assert '\\chapter{The section with a reference to {[}AuthorYear{]}}' in result
|
||||
assert '\\caption{The table title with a reference to {[}AuthorYear{]}}' in result
|
||||
assert '\\paragraph{The rubric title with a reference to {[}AuthorYear{]}}' in result
|
||||
|
||||
|
||||
@with_app(buildername='latex', testroot='footnotes',
|
||||
confoverrides={'latex_show_urls': 'inline'})
|
||||
def test_latex_show_urls_is_inline(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'Python.tex').text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
assert 'First footnote: \\footnote[2]{\nFirst\n}' in result
|
||||
assert 'Second footnote: \\footnote[1]{\nSecond\n}' in result
|
||||
assert '\\href{http://sphinx-doc.org/}{Sphinx} (http://sphinx-doc.org/)' in result
|
||||
assert 'Third footnote: \\footnote[3]{\nThird\n}' in result
|
||||
assert ('\\href{http://sphinx-doc.org/~test/}{URL including tilde} '
|
||||
'(http://sphinx-doc.org/\\textasciitilde{}test/)' in result)
|
||||
assert ('\\item[{\\href{http://sphinx-doc.org/}{URL in term} (http://sphinx-doc.org/)}] '
|
||||
'\\leavevmode\nDescription' in result)
|
||||
assert ('\\item[{Footnote in term \\footnotemark[4]}] '
|
||||
'\\leavevmode\\footnotetext[4]{\nFootnote in term\n}\nDescription' in result)
|
||||
assert ('\\item[{\\href{http://sphinx-doc.org/}{Term in deflist} '
|
||||
'(http://sphinx-doc.org/)}] \\leavevmode\nDescription' in result)
|
||||
assert ('\\href{https://github.com/sphinx-doc/sphinx}'
|
||||
'{https://github.com/sphinx-doc/sphinx}\n' in result)
|
||||
assert ('\\href{mailto:sphinx-dev@googlegroups.com}'
|
||||
'{sphinx-dev@googlegroups.com}' in result)
|
||||
|
||||
|
||||
@with_app(buildername='latex', testroot='footnotes',
|
||||
confoverrides={'latex_show_urls': 'footnote'})
|
||||
def test_latex_show_urls_is_footnote(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'Python.tex').text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
assert 'First footnote: \\footnote[2]{\nFirst\n}' in result
|
||||
assert 'Second footnote: \\footnote[1]{\nSecond\n}' in result
|
||||
assert ('\\href{http://sphinx-doc.org/}{Sphinx}'
|
||||
'\\footnote[3]{\nhttp://sphinx-doc.org/\n}' in result)
|
||||
assert 'Third footnote: \\footnote[5]{\nThird\n}' in result
|
||||
assert ('\\href{http://sphinx-doc.org/~test/}{URL including tilde}'
|
||||
'\\footnote[4]{\nhttp://sphinx-doc.org/\\textasciitilde{}test/\n}' in result)
|
||||
assert ('\\item[{\\href{http://sphinx-doc.org/}{URL in term}\\footnotemark[6]}] '
|
||||
'\\leavevmode\\footnotetext[6]{\nhttp://sphinx-doc.org/\n}\nDescription' in result)
|
||||
assert ('\\item[{Footnote in term \\footnotemark[8]}] '
|
||||
'\\leavevmode\\footnotetext[8]{\nFootnote in term\n}\nDescription' in result)
|
||||
assert ('\\item[{\\href{http://sphinx-doc.org/}{Term in deflist}\\footnotemark[7]}] '
|
||||
'\\leavevmode\\footnotetext[7]{\nhttp://sphinx-doc.org/\n}\nDescription' in result)
|
||||
assert ('\\href{https://github.com/sphinx-doc/sphinx}'
|
||||
'{https://github.com/sphinx-doc/sphinx}\n' in result)
|
||||
assert ('\\href{mailto:sphinx-dev@googlegroups.com}'
|
||||
'{sphinx-dev@googlegroups.com}\n' in result)
|
||||
|
||||
|
||||
@with_app(buildername='latex', testroot='footnotes',
|
||||
confoverrides={'latex_show_urls': 'no'})
|
||||
def test_latex_show_urls_is_no(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'Python.tex').text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
assert 'First footnote: \\footnote[2]{\nFirst\n}' in result
|
||||
assert 'Second footnote: \\footnote[1]{\nSecond\n}' in result
|
||||
assert '\\href{http://sphinx-doc.org/}{Sphinx}' in result
|
||||
assert 'Third footnote: \\footnote[3]{\nThird\n}' in result
|
||||
assert '\\href{http://sphinx-doc.org/~test/}{URL including tilde}' in result
|
||||
assert ('\\item[{\\href{http://sphinx-doc.org/}{URL in term}}] '
|
||||
'\\leavevmode\nDescription' in result)
|
||||
assert ('\\item[{Footnote in term \\footnotemark[4]}] '
|
||||
'\\leavevmode\\footnotetext[4]{\nFootnote in term\n}\nDescription' in result)
|
||||
assert ('\\item[{\\href{http://sphinx-doc.org/}{Term in deflist}}] '
|
||||
'\\leavevmode\nDescription' in result)
|
||||
assert ('\\href{https://github.com/sphinx-doc/sphinx}'
|
||||
'{https://github.com/sphinx-doc/sphinx}\n' in result)
|
||||
assert ('\\href{mailto:sphinx-dev@googlegroups.com}'
|
||||
'{sphinx-dev@googlegroups.com}\n' in result)
|
||||
|
||||
25
tests/test_util.py
Normal file
25
tests/test_util.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
test_util
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
Tests util functions.
|
||||
|
||||
:copyright: Copyright 2007-2015 by the Sphinx team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
from sphinx.util import encode_uri
|
||||
|
||||
|
||||
def test_encode_uri():
|
||||
expected = (u'https://ru.wikipedia.org/wiki/%D0%A1%D0%B8%D1%81%D1%82%D0%B5%D0%BC%D0%B0_'
|
||||
u'%D1%83%D0%BF%D1%80%D0%B0%D0%B2%D0%BB%D0%B5%D0%BD%D0%B8%D1%8F_'
|
||||
u'%D0%B1%D0%B0%D0%B7%D0%B0%D0%BC%D0%B8_%D0%B4%D0%B0%D0%BD%D0%BD%D1%8B%D1%85')
|
||||
uri = u'https://ru.wikipedia.org/wiki/Система_управления_базами_данных'
|
||||
assert expected, encode_uri(uri)
|
||||
|
||||
expected = (u'https://github.com/search?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+is%3A'
|
||||
u'sprint-friendly+user%3Ajupyter&type=Issues&ref=searchresults')
|
||||
uri = (u'https://github.com/search?utf8=✓&q=is%3Aissue+is%3Aopen+is%3A'
|
||||
u'sprint-friendly+user%3Ajupyter&type=Issues&ref=searchresults')
|
||||
assert expected, encode_uri(uri)
|
||||
Reference in New Issue
Block a user