merge birkenfeld/sphinx

This commit is contained in:
Robert Lehmann
2013-01-06 12:14:57 +01:00
69 changed files with 923 additions and 323 deletions

View File

@@ -27,9 +27,7 @@ Contents:
doctest
extensions
versioning/index
only
footnote
i18n/index
Python <http://python.org/>

View File

@@ -191,6 +191,10 @@ Figures
My caption of the figure
My description paragraph of the figure.
Description paragraph is wraped with legend node.
Version markup
--------------

View File

@@ -0,0 +1,12 @@
#, fuzzy
msgid ""
msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "File with UTF-8 BOM"
msgstr "Datei mit UTF-8"
msgid "This file has a UTF-8 \"BOM\"."
msgstr "This file has umlauts: äöü."

View File

@@ -0,0 +1,5 @@
File with UTF-8 BOM
===================
This file has a UTF-8 "BOM".

View File

@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
import sys, os
project = 'Sphinx intl <Tests>'
source_suffix = '.txt'
keep_warnings = True

View File

@@ -2,9 +2,13 @@
:maxdepth: 2
:numbered:
subdir/contents
bom
footnote
external_links
refs_inconsistency
literalblock
seealso
definition_terms
figure_caption
index_entries

View File

@@ -0,0 +1,29 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2012, foof
# This file is distributed under the same license as the foo package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: sphinx 1.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-01-04 7:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "i18n with figure caption"
msgstr "I18N WITH FIGURE CAPTION"
msgid "My caption of the figure"
msgstr "MY CAPTION OF THE FIGURE"
msgid "My description paragraph1 of the figure."
msgstr "MY DESCRIPTION PARAGRAPH1 OF THE FIGURE."
msgid "My description paragraph2 of the figure."
msgstr "MY DESCRIPTION PARAGRAPH2 OF THE FIGURE."

View File

@@ -0,0 +1,12 @@
:tocdepth: 2
i18n with figure caption
========================
.. figure:: i18n.png
My caption of the figure
My description paragraph1 of the figure.
My description paragraph2 of the figure.

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

View File

@@ -0,0 +1,77 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2013, foo
# This file is distributed under the same license as the foo package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: foo foo\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-01-05 18:10\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "i18n with index entries"
msgstr ""
msgid "index target section"
msgstr ""
msgid "this is :index:`Newsletter` target paragraph."
msgstr "THIS IS :index:`NEWSLETTER` TARGET PARAGRAPH."
msgid "various index entries"
msgstr ""
msgid "That's all."
msgstr ""
msgid "Mailing List"
msgstr "MAILING LIST"
msgid "Newsletter"
msgstr "NEWSLETTER"
msgid "Recipients List"
msgstr "RECIPIENTS LIST"
msgid "First"
msgstr "FIRST"
msgid "Second"
msgstr "SECOND"
msgid "Third"
msgstr "THIRD"
msgid "Entry"
msgstr "ENTRY"
msgid "See"
msgstr "SEE"
msgid "Module"
msgstr "MODULE"
msgid "Keyword"
msgstr "KEYWORD"
msgid "Operator"
msgstr "OPERATOR"
msgid "Object"
msgstr "OBJECT"
msgid "Exception"
msgstr "EXCEPTION"
msgid "Statement"
msgstr "STATEMENT"
msgid "Builtin"
msgstr "BUILTIN"

View File

@@ -0,0 +1,31 @@
:tocdepth: 2
i18n with index entries
=======================
.. index::
single: Mailing List
pair: Newsletter; Recipients List
index target section
--------------------
this is :index:`Newsletter` target paragraph.
various index entries
---------------------
.. index::
triple: First; Second; Third
see: Entry; Mailing List
seealso: See; Newsletter
module: Module
keyword: Keyword
operator: Operator
object: Object
exception: Exception
statement: Statement
builtin: Builtin
That's all.

View File

@@ -0,0 +1,2 @@
subdir contents
===============

View File

@@ -0,0 +1,2 @@
project = 'test-only-directive'

View File

@@ -0,0 +1,6 @@
test-only-directive
===================
.. toctree::
only

View File

@@ -386,10 +386,10 @@ def test_generate():
assert_warns("import for autodocumenting 'foobar'",
'function', 'foobar', more_content=None)
# importing
assert_warns("import/find module 'test_foobar'",
assert_warns("failed to import module 'test_foobar'",
'module', 'test_foobar', more_content=None)
# attributes missing
assert_warns("import/find function 'util.foobar'",
assert_warns("failed to import function 'foobar' from module 'util'",
'function', 'util.foobar', more_content=None)
# test auto and given content mixing

View File

@@ -11,6 +11,7 @@
import gettext
import os
import re
from subprocess import Popen, PIPE
from util import *
@@ -19,6 +20,7 @@ from util import SkipTest
def teardown_module():
(test_root / '_build').rmtree(True)
(test_roots / 'test-intl' / '_build').rmtree(True),
@with_app(buildername='gettext')
@@ -87,3 +89,51 @@ def test_gettext(app):
_ = gettext.translation('test_root', app.outdir, languages=['en']).gettext
assert _("Testing various markup") == u"Testing various markup"
@with_app(buildername='gettext',
srcdir=(test_roots / 'test-intl'),
doctreedir=(test_roots / 'test-intl' / '_build' / 'doctree'),
confoverrides={'gettext_compact': False})
def test_gettext_index_entries(app):
# regression test for #976
app.builder.build(['index_entries'])
_msgid_getter = re.compile(r'msgid "(.*)"').search
def msgid_getter(msgid):
m = _msgid_getter(msgid)
if m:
return m.groups()[0]
return None
pot = (app.outdir / 'index_entries.pot').text(encoding='utf-8')
msgids = filter(None, map(msgid_getter, pot.splitlines()))
expected_msgids = [
"i18n with index entries",
"index target section",
"this is :index:`Newsletter` target paragraph.",
"various index entries",
"That's all.",
"Mailing List",
"Newsletter",
"Recipients List",
"First",
"Second",
"Third",
"Entry",
"See",
"Module",
"Keyword",
"Operator",
"Object",
"Exception",
"Statement",
"Builtin",
]
for expect in expected_msgids:
assert expect in msgids
msgids.remove(expect)
# unexpected msgid existent
assert msgids == []

View File

@@ -35,7 +35,6 @@ ENV_WARNINGS = """\
%(root)s/autodoc_fodder.py:docstring of autodoc_fodder\\.MarkupError:2: \
WARNING: Explicit markup ends without a blank line; unexpected \
unindent\\.\\n?
%(root)s/i18n/literalblock.txt:13: WARNING: Literal block expected; none found.
%(root)s/images.txt:9: WARNING: image file not readable: foo.png
%(root)s/images.txt:23: WARNING: nonlocal image URI found: \
http://www.python.org/logo.png

View File

@@ -22,19 +22,34 @@ from util import SkipTest
warnfile = StringIO()
root = test_roots / 'test-intl'
doctreedir = root / '_build' / 'doctree'
def with_intl_app(*args, **kw):
default_kw = {
'srcdir': root,
'doctreedir': doctreedir,
'confoverrides': {
'language': 'xx', 'locale_dirs': ['.'],
'gettext_compact': False,
},
}
default_kw.update(kw)
return with_app(*args, **default_kw)
def setup_module():
# Delete remnants left over after failed build
(test_root / 'xx').rmtree(True)
(test_root / 'xx' / 'LC_MESSAGES').makedirs()
(root / 'xx').rmtree(True)
(root / 'xx' / 'LC_MESSAGES').makedirs()
# Compile all required catalogs into binary format (*.mo).
for dirpath, dirs, files in os.walk(test_root):
for dirpath, dirs, files in os.walk(root):
dirpath = path(dirpath)
for f in [f for f in files if f.endswith('.po')]:
po = dirpath / f
mo = test_root / 'xx' / 'LC_MESSAGES' / (
relpath(po[:-3], test_root) + '.mo')
mo = root / 'xx' / 'LC_MESSAGES' / (
relpath(po[:-3], root) + '.mo')
if not mo.parent.exists():
mo.parent.makedirs()
try:
@@ -52,12 +67,11 @@ def setup_module():
def teardown_module():
(test_root / '_build').rmtree(True)
(test_root / 'xx').rmtree(True)
(root / '_build').rmtree(True)
(root / 'xx').rmtree(True)
@with_app(buildername='text',
confoverrides={'language': 'xx', 'locale_dirs': ['.']})
@with_intl_app(buildername='text')
def test_simple(app):
app.builder.build(['bom'])
result = (app.outdir / 'bom.txt').text(encoding='utf-8')
@@ -67,31 +81,26 @@ def test_simple(app):
assert result == expect
@with_app(buildername='text',
confoverrides={'language': 'xx', 'locale_dirs': ['.']})
@with_intl_app(buildername='text')
def test_subdir(app):
app.builder.build(['subdir/includes'])
result = (app.outdir / 'subdir' / 'includes.txt').text(encoding='utf-8')
assert result.startswith(u"\ntranslation\n***********\n\n")
app.builder.build(['subdir/contents'])
result = (app.outdir / 'subdir' / 'contents.txt').text(encoding='utf-8')
assert result.startswith(u"\nsubdir contents\n***************\n")
@with_app(buildername='html', cleanenv=True,
confoverrides={'language': 'xx', 'locale_dirs': ['.'],
'gettext_compact': False})
@with_intl_app(buildername='html', cleanenv=True)
def test_i18n_footnote_break_refid(app):
"""test for #955 cant-build-html-with-footnotes-when-using"""
app.builder.build(['i18n/footnote'])
result = (app.outdir / 'i18n' / 'footnote.html').text(encoding='utf-8')
app.builder.build(['footnote'])
result = (app.outdir / 'footnote.html').text(encoding='utf-8')
# expect no error by build
@with_app(buildername='text', cleanenv=True,
confoverrides={'language': 'xx', 'locale_dirs': ['.'],
'gettext_compact': False})
@with_intl_app(buildername='text', cleanenv=True)
def test_i18n_footnote_regression(app):
"""regression test for fix #955"""
app.builder.build(['i18n/footnote'])
result = (app.outdir / 'i18n' / 'footnote.txt').text(encoding='utf-8')
app.builder.build(['footnote'])
result = (app.outdir / 'footnote.txt').text(encoding='utf-8')
expect = (u"\nI18N WITH FOOTNOTE"
u"\n******************\n" # underline matches new translation
u"\nI18N WITH FOOTNOTE INCLUDE THIS CONTENTS [ref] [1] [100]\n"
@@ -101,13 +110,11 @@ def test_i18n_footnote_regression(app):
assert result == expect
@with_app(buildername='html', cleanenv=True,
confoverrides={'language': 'xx', 'locale_dirs': ['.'],
'gettext_compact': False})
@with_intl_app(buildername='html', cleanenv=True)
def test_i18n_footnote_backlink(app):
"""i18n test for #1058"""
app.builder.build(['i18n/footnote'])
result = (app.outdir / 'i18n' / 'footnote.html').text(encoding='utf-8')
app.builder.build(['footnote'])
result = (app.outdir / 'footnote.html').text(encoding='utf-8')
expects = [
'<a class="footnote-reference" href="#id5" id="id1">[100]</a>',
'<a class="footnote-reference" href="#id4" id="id2">[1]</a>',
@@ -121,13 +128,11 @@ def test_i18n_footnote_backlink(app):
assert len(matches) == 1
@with_app(buildername='text', warning=warnfile, cleanenv=True,
confoverrides={'language': 'xx', 'locale_dirs': ['.'],
'gettext_compact': False})
@with_intl_app(buildername='text', warning=warnfile, cleanenv=True)
def test_i18n_warn_for_number_of_references_inconsistency(app):
app.builddir.rmtree(True)
app.builder.build(['i18n/refs_inconsistency'])
result = (app.outdir / 'i18n' / 'refs_inconsistency.txt').text(encoding='utf-8')
app.builder.build(['refs_inconsistency'])
result = (app.outdir / 'refs_inconsistency.txt').text(encoding='utf-8')
expect = (u"\nI18N WITH REFS INCONSISTENCY"
u"\n****************************\n"
u"\n* FOR FOOTNOTE [ref2].\n"
@@ -139,7 +144,7 @@ def test_i18n_warn_for_number_of_references_inconsistency(app):
assert result == expect
warnings = warnfile.getvalue().replace(os.sep, '/')
warning_fmt = u'.*/i18n/refs_inconsistency.txt:\\d+: ' \
warning_fmt = u'.*/refs_inconsistency.txt:\\d+: ' \
u'WARNING: inconsistent %s in translated message\n'
expected_warning_expr = (
warning_fmt % 'footnote references' +
@@ -148,12 +153,10 @@ def test_i18n_warn_for_number_of_references_inconsistency(app):
assert re.search(expected_warning_expr, warnings)
@with_app(buildername='html', cleanenv=True,
confoverrides={'language': 'xx', 'locale_dirs': ['.'],
'gettext_compact': False})
@with_intl_app(buildername='html', cleanenv=True)
def test_i18n_link_to_undefined_reference(app):
app.builder.build(['i18n/refs_inconsistency'])
result = (app.outdir / 'i18n' / 'refs_inconsistency.html').text(encoding='utf-8')
app.builder.build(['refs_inconsistency'])
result = (app.outdir / 'refs_inconsistency.html').text(encoding='utf-8')
expected_expr = """<a class="reference external" href="http://www.example.com">reference</a>"""
assert len(re.findall(expected_expr, result)) == 2
@@ -165,13 +168,11 @@ def test_i18n_link_to_undefined_reference(app):
assert len(re.findall(expected_expr, result)) == 1
@with_app(buildername='html', cleanenv=True,
confoverrides={'language': 'xx', 'locale_dirs': ['.'],
'gettext_compact': False})
@with_intl_app(buildername='html', cleanenv=True)
def test_i18n_keep_external_links(app):
"""regression test for #1044"""
app.builder.build(['i18n/external_links'])
result = (app.outdir / 'i18n' / 'external_links.html').text(encoding='utf-8')
app.builder.build(['external_links'])
result = (app.outdir / 'external_links.html').text(encoding='utf-8')
# external link check
expect_line = u"""<li>EXTERNAL LINK TO <a class="reference external" href="http://python.org">Python</a>.</li>"""
@@ -206,35 +207,31 @@ def test_i18n_keep_external_links(app):
assert expect_line == matched_line
@with_app(buildername='text', warning=warnfile, cleanenv=True,
confoverrides={'language': 'xx', 'locale_dirs': ['.'],
'gettext_compact': False})
@with_intl_app(buildername='text', warning=warnfile, cleanenv=True)
def test_i18n_literalblock_warning(app):
app.builddir.rmtree(True) #for warnings acceleration
app.builder.build(['i18n/literalblock'])
result = (app.outdir / 'i18n' / 'literalblock.txt').text(encoding='utf-8')
app.builder.build(['literalblock'])
result = (app.outdir / 'literalblock.txt').text(encoding='utf-8')
expect = (u"\nI18N WITH LITERAL BLOCK"
u"\n***********************\n"
u"\nCORRECT LITERAL BLOCK:\n"
u"\n this is"
u"\n literal block\n"
u"\nMISSING LITERAL BLOCK:\n"
u"\n<SYSTEM MESSAGE: ")
u"\n<SYSTEM MESSAGE:")
assert result.startswith(expect)
warnings = warnfile.getvalue().replace(os.sep, '/')
expected_warning_expr = u'.*/i18n/literalblock.txt:\\d+: ' \
expected_warning_expr = u'.*/literalblock.txt:\\d+: ' \
u'WARNING: Literal block expected; none found.'
assert re.search(expected_warning_expr, warnings)
@with_app(buildername='text',
confoverrides={'language': 'xx', 'locale_dirs': ['.'],
'gettext_compact': False})
@with_intl_app(buildername='text')
def test_i18n_definition_terms(app):
# regression test for #975
app.builder.build(['i18n/definition_terms'])
result = (app.outdir / 'i18n' / 'definition_terms.txt').text(encoding='utf-8')
app.builder.build(['definition_terms'])
result = (app.outdir / 'definition_terms.txt').text(encoding='utf-8')
expect = (u"\nI18N WITH DEFINITION TERMS"
u"\n**************************\n"
u"\nSOME TERM"
@@ -245,12 +242,10 @@ def test_i18n_definition_terms(app):
assert result == expect
@with_app(buildername='text', cleanenv=True,
confoverrides={'language': 'xx', 'locale_dirs': ['.'],
'gettext_compact': False})
@with_intl_app(buildername='text')
def test_seealso(app):
app.builder.build(['i18n/seealso'])
result = (app.outdir / 'i18n' / 'seealso.txt').text(encoding='utf-8')
app.builder.build(['seealso'])
result = (app.outdir / 'seealso.txt').text(encoding='utf-8')
expect = (u"\nI18N WITH SEEALSO"
u"\n*****************\n"
u"\nSee also: SHORT TEXT 1\n"
@@ -259,3 +254,48 @@ def test_seealso(app):
u"\n LONG TEXT 2\n")
assert result == expect
@with_intl_app(buildername='text')
def test_i18n_figure_caption(app):
# regression test for #940
app.builder.build(['figure_caption'])
result = (app.outdir / 'figure_caption.txt').text(encoding='utf-8')
expect = (u"\nI18N WITH FIGURE CAPTION"
u"\n************************\n"
u"\n [image]MY CAPTION OF THE FIGURE\n"
u"\n MY DESCRIPTION PARAGRAPH1 OF THE FIGURE.\n"
u"\n MY DESCRIPTION PARAGRAPH2 OF THE FIGURE.\n")
assert result == expect
@with_intl_app(buildername='html')
def test_i18n_index_entries(app):
# regression test for #976
app.builder.build(['index_entries'])
result = (app.outdir / 'genindex.html').text(encoding='utf-8')
def wrap(tag, keyword):
start_tag = "<%s[^>]*>" % tag
end_tag = "</%s>" % tag
return r"%s\s*%s\s*%s" % (start_tag, keyword, end_tag)
expected_exprs = [
wrap('a', 'NEWSLETTER'),
wrap('a', 'MAILING LIST'),
wrap('a', 'RECIPIENTS LIST'),
wrap('a', 'FIRST SECOND'),
wrap('a', 'SECOND THIRD'),
wrap('a', 'THIRD, FIRST'),
wrap('dt', 'ENTRY'),
wrap('dt', 'SEE'),
wrap('a', 'MODULE'),
wrap('a', 'KEYWORD'),
wrap('a', 'OPERATOR'),
wrap('a', 'OBJECT'),
wrap('a', 'EXCEPTION'),
wrap('a', 'STATEMENT'),
wrap('a', 'BUILTIN'),
]
for expr in expected_exprs:
assert re.search(expr, result, re.M)

View File

@@ -17,10 +17,10 @@ from util import *
def teardown_module():
(test_root / '_build').rmtree(True)
(test_roots / 'test-only-directive' / '_build').rmtree(True)
@with_app(buildername='text')
@with_app(buildername='text', srcdir=(test_roots / 'test-only-directive'))
def test_sectioning(app):
def getsects(section):

View File

@@ -36,7 +36,7 @@ def test_wordcollector():
doc['file'] = 'dummy'
parser.parse(FILE_CONTENTS, doc)
ix = IndexBuilder(None, 'en', {})
ix = IndexBuilder(None, 'en', {}, None)
ix.feed('filename', 'title', doc)
assert 'boson' not in ix._mapping
assert 'fermion' in ix._mapping

View File

@@ -30,7 +30,7 @@ from nose import tools, SkipTest
__all__ = [
'test_root', 'raises', 'raises_msg',
'test_root', 'test_roots', 'raises', 'raises_msg',
'skip_if', 'skip_unless', 'skip_unless_importable', 'Struct',
'ListOutput', 'TestApp', 'with_app', 'gen_with_app',
'path', 'with_tempdir', 'write_file',
@@ -39,6 +39,7 @@ __all__ = [
test_root = path(__file__).parent.joinpath('root').abspath()
test_roots = path(__file__).parent.joinpath('roots').abspath()
def _excstr(exc):
@@ -153,6 +154,8 @@ class TestApp(application.Sphinx):
self.cleanup_trees.insert(0, outdir)
if doctreedir is None:
doctreedir = srcdir.joinpath(srcdir, self.builddir, 'doctrees')
if not doctreedir.isdir():
doctreedir.makedirs()
if cleanenv:
self.cleanup_trees.insert(0, doctreedir)
if confoverrides is None: