mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fixes #1785: Reduce output for test generators.
This commit is contained in:
parent
e2da583be8
commit
657c53b0f5
@ -12,7 +12,7 @@ import sys
|
|||||||
import shutil
|
import shutil
|
||||||
from codecs import open
|
from codecs import open
|
||||||
|
|
||||||
from six import PY2, text_type
|
from six import PY2, text_type, binary_type
|
||||||
|
|
||||||
|
|
||||||
FILESYSTEMENCODING = sys.getfilesystemencoding() or sys.getdefaultencoding()
|
FILESYSTEMENCODING = sys.getfilesystemencoding() or sys.getdefaultencoding()
|
||||||
@ -142,9 +142,11 @@ class path(text_type):
|
|||||||
"""
|
"""
|
||||||
f = open(self, mode='U', **kwargs)
|
f = open(self, mode='U', **kwargs)
|
||||||
try:
|
try:
|
||||||
return f.read()
|
text = f.read()
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
|
contents = repr_as(text, '<%s contents>' % self.basename())
|
||||||
|
return contents
|
||||||
|
|
||||||
def bytes(self):
|
def bytes(self):
|
||||||
"""
|
"""
|
||||||
@ -205,3 +207,18 @@ class path(text_type):
|
|||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '%s(%s)' % (self.__class__.__name__, text_type.__repr__(self))
|
return '%s(%s)' % (self.__class__.__name__, text_type.__repr__(self))
|
||||||
|
|
||||||
|
|
||||||
|
# Lives here only to avoid circular references; use it from util.py!
|
||||||
|
class _repr_text(text_type):
|
||||||
|
def __repr__(self):
|
||||||
|
return self._repr
|
||||||
|
class _repr_bin(binary_type):
|
||||||
|
def __repr__(self):
|
||||||
|
return self._repr
|
||||||
|
|
||||||
|
def repr_as(string, repr_):
|
||||||
|
wrapper = _repr_text if isinstance(string, text_type) else _repr_bin
|
||||||
|
proxy = wrapper(string)
|
||||||
|
proxy._repr = repr_
|
||||||
|
return proxy
|
||||||
|
@ -21,7 +21,7 @@ from six import string_types
|
|||||||
|
|
||||||
from util import tempdir, rootdir, path, gen_with_app, SkipTest, \
|
from util import tempdir, rootdir, path, gen_with_app, SkipTest, \
|
||||||
assert_re_search, assert_not_re_search, assert_in, assert_not_in, \
|
assert_re_search, assert_not_re_search, assert_in, assert_not_in, \
|
||||||
assert_startswith
|
assert_startswith, repr_as
|
||||||
|
|
||||||
|
|
||||||
root = tempdir / 'test-intl'
|
root = tempdir / 'test-intl'
|
||||||
@ -112,7 +112,7 @@ def test_text_builder(app, status, warning):
|
|||||||
|
|
||||||
# --- warnings in translation
|
# --- warnings in translation
|
||||||
|
|
||||||
warnings = warning.getvalue().replace(os.sep, '/')
|
warnings = getwarning(warning)
|
||||||
warning_expr = u'.*/warnings.txt:4: ' \
|
warning_expr = u'.*/warnings.txt:4: ' \
|
||||||
u'WARNING: Inline literal start-string without end-string.\n'
|
u'WARNING: Inline literal start-string without end-string.\n'
|
||||||
yield assert_re_search, warning_expr, warnings
|
yield assert_re_search, warning_expr, warnings
|
||||||
@ -149,7 +149,7 @@ def test_text_builder(app, status, warning):
|
|||||||
u"\n[100] THIS IS A NUMBERED FOOTNOTE.\n")
|
u"\n[100] THIS IS A NUMBERED FOOTNOTE.\n")
|
||||||
yield assert_equal, result, expect
|
yield assert_equal, result, expect
|
||||||
|
|
||||||
warnings = warning.getvalue().replace(os.sep, '/')
|
warnings = getwarning(warning)
|
||||||
warning_fmt = u'.*/refs_inconsistency.txt:\\d+: ' \
|
warning_fmt = u'.*/refs_inconsistency.txt:\\d+: ' \
|
||||||
u'WARNING: inconsistent %s in translated message\n'
|
u'WARNING: inconsistent %s in translated message\n'
|
||||||
expected_warning_expr = (
|
expected_warning_expr = (
|
||||||
@ -170,7 +170,7 @@ def test_text_builder(app, status, warning):
|
|||||||
u"\n<SYSTEM MESSAGE:")
|
u"\n<SYSTEM MESSAGE:")
|
||||||
yield assert_startswith, result, expect
|
yield assert_startswith, result, expect
|
||||||
|
|
||||||
warnings = warning.getvalue().replace(os.sep, '/')
|
warnings = getwarning(warning)
|
||||||
expected_warning_expr = u'.*/literalblock.txt:\\d+: ' \
|
expected_warning_expr = u'.*/literalblock.txt:\\d+: ' \
|
||||||
u'WARNING: Literal block expected; none found.'
|
u'WARNING: Literal block expected; none found.'
|
||||||
yield assert_re_search, expected_warning_expr, warnings
|
yield assert_re_search, expected_warning_expr, warnings
|
||||||
@ -197,7 +197,7 @@ def test_text_builder(app, status, warning):
|
|||||||
u"\n THE CORRESPONDING GLOSSARY #2\n"
|
u"\n THE CORRESPONDING GLOSSARY #2\n"
|
||||||
u"\nLINK TO *SOME NEW TERM*.\n")
|
u"\nLINK TO *SOME NEW TERM*.\n")
|
||||||
yield assert_equal, result, expect
|
yield assert_equal, result, expect
|
||||||
warnings = warning.getvalue().replace(os.sep, '/')
|
warnings = getwarning(warning)
|
||||||
yield assert_not_in, 'term not in glossary', warnings
|
yield assert_not_in, 'term not in glossary', warnings
|
||||||
|
|
||||||
# --- glossary term inconsistencies: regression test for #1090
|
# --- glossary term inconsistencies: regression test for #1090
|
||||||
@ -208,7 +208,7 @@ def test_text_builder(app, status, warning):
|
|||||||
u"\n1. LINK TO *SOME NEW TERM*.\n")
|
u"\n1. LINK TO *SOME NEW TERM*.\n")
|
||||||
yield assert_equal, result, expect
|
yield assert_equal, result, expect
|
||||||
|
|
||||||
warnings = warning.getvalue().replace(os.sep, '/')
|
warnings = getwarning(warning)
|
||||||
expected_warning_expr = (
|
expected_warning_expr = (
|
||||||
u'.*/glossary_terms_inconsistency.txt:\\d+: '
|
u'.*/glossary_terms_inconsistency.txt:\\d+: '
|
||||||
u'WARNING: inconsistent term references in translated message\n')
|
u'WARNING: inconsistent term references in translated message\n')
|
||||||
@ -449,7 +449,7 @@ def test_xml_builder(app, status, warning):
|
|||||||
None,
|
None,
|
||||||
['ref'])
|
['ref'])
|
||||||
|
|
||||||
warnings = warning.getvalue().replace(os.sep, '/')
|
warnings = getwarning(warning)
|
||||||
warning_expr = u'.*/footnote.xml:\\d*: SEVERE: Duplicate ID: ".*".\n'
|
warning_expr = u'.*/footnote.xml:\\d*: SEVERE: Duplicate ID: ".*".\n'
|
||||||
yield assert_not_re_search, warning_expr, warnings
|
yield assert_not_re_search, warning_expr, warnings
|
||||||
|
|
||||||
@ -580,7 +580,7 @@ def test_xml_builder(app, status, warning):
|
|||||||
['same-type-links', 'i18n-role-xref'])
|
['same-type-links', 'i18n-role-xref'])
|
||||||
|
|
||||||
# warnings
|
# warnings
|
||||||
warnings = warning.getvalue().replace(os.sep, '/')
|
warnings = getwarning(warning)
|
||||||
yield assert_not_in, 'term not in glossary', warnings
|
yield assert_not_in, 'term not in glossary', warnings
|
||||||
yield assert_not_in, 'undefined label', warnings
|
yield assert_not_in, 'undefined label', warnings
|
||||||
yield assert_not_in, 'unknown document', warnings
|
yield assert_not_in, 'unknown document', warnings
|
||||||
@ -748,3 +748,6 @@ def test_additional_targets_should_be_translated(app, status, warning):
|
|||||||
expected_expr = """<img alt="IMG -> I18N" src="_images/i18n.png" />"""
|
expected_expr = """<img alt="IMG -> I18N" src="_images/i18n.png" />"""
|
||||||
yield assert_count(expected_expr, result, 1)
|
yield assert_count(expected_expr, result, 1)
|
||||||
|
|
||||||
|
|
||||||
|
def getwarning(warnings):
|
||||||
|
return repr_as(warnings.getvalue().replace(os.sep, '/'), '<warnings>')
|
||||||
|
@ -23,7 +23,7 @@ from sphinx.theming import Theme
|
|||||||
from sphinx.ext.autodoc import AutoDirective
|
from sphinx.ext.autodoc import AutoDirective
|
||||||
from sphinx.pycode import ModuleAnalyzer
|
from sphinx.pycode import ModuleAnalyzer
|
||||||
|
|
||||||
from path import path
|
from path import path, repr_as
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Python >=3.3
|
# Python >=3.3
|
||||||
|
Loading…
Reference in New Issue
Block a user