mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix flake8 violation under tests/
This commit is contained in:
@@ -25,5 +25,5 @@ universal = 1
|
||||
|
||||
[flake8]
|
||||
max-line-length=95
|
||||
ignore=E113,E116,E221,E226,E241,E251
|
||||
ignore=E113,E116,E221,E226,E241,E251,E901
|
||||
exclude=tests/*,build/*,sphinx/search/*,sphinx/pycode/pgen2/*
|
||||
|
||||
@@ -206,10 +206,13 @@ class path(text_type):
|
||||
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)
|
||||
|
||||
@@ -16,6 +16,7 @@ import sys
|
||||
import traceback
|
||||
|
||||
from path import path
|
||||
import nose
|
||||
|
||||
testroot = os.path.dirname(__file__) or '.'
|
||||
sys.path.insert(0, os.path.abspath(os.path.join(testroot, os.path.pardir)))
|
||||
@@ -47,5 +48,4 @@ tempdir.makedirs()
|
||||
print('Running Sphinx test suite (with Python %s)...' % sys.version.split()[0])
|
||||
sys.stdout.flush()
|
||||
|
||||
import nose
|
||||
nose.main()
|
||||
|
||||
@@ -67,7 +67,7 @@ def test_html_with_set_translator_for_html_and_html_translator_class(
|
||||
assert translator_class.__name__ == 'ConfHTMLTranslator'
|
||||
|
||||
|
||||
## this test break test_websupport.test_comments test. why?
|
||||
# this test break test_websupport.test_comments test. why?
|
||||
# @with_app(
|
||||
# buildername='dirhtml',
|
||||
# srcdir=(test_roots / 'test-api-set-translator'),
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"""
|
||||
|
||||
# "raises" imported for usage by autodoc
|
||||
from util import TestApp, Struct, raises, SkipTest
|
||||
from util import TestApp, Struct, raises, SkipTest # NOQA
|
||||
from nose.tools import with_setup, eq_
|
||||
|
||||
from six import StringIO
|
||||
@@ -22,6 +22,7 @@ from sphinx.ext.autodoc import AutoDirective, add_documenter, \
|
||||
|
||||
app = None
|
||||
|
||||
|
||||
def setup_module():
|
||||
global app
|
||||
app = TestApp()
|
||||
@@ -38,6 +39,7 @@ def teardown_module():
|
||||
|
||||
directive = options = None
|
||||
|
||||
|
||||
def setup_test():
|
||||
global options, directive
|
||||
global processed_docstrings, processed_signatures, _warnings
|
||||
@@ -73,19 +75,19 @@ def setup_test():
|
||||
|
||||
|
||||
_warnings = []
|
||||
processed_docstrings = []
|
||||
processed_signatures = []
|
||||
|
||||
|
||||
def warnfunc(msg):
|
||||
_warnings.append(msg)
|
||||
|
||||
|
||||
processed_docstrings = []
|
||||
|
||||
def process_docstring(app, what, name, obj, options, lines):
|
||||
processed_docstrings.append((what, name))
|
||||
if name == 'bar':
|
||||
lines.extend(['42', ''])
|
||||
|
||||
processed_signatures = []
|
||||
|
||||
def process_signature(app, what, name, obj, options, args, retann):
|
||||
processed_signatures.append((what, name))
|
||||
@@ -164,25 +166,28 @@ def test_format_signature():
|
||||
# test for functions
|
||||
def f(a, b, c=1, **d):
|
||||
pass
|
||||
|
||||
def g(a='\n'):
|
||||
pass
|
||||
assert formatsig('function', 'f', f, None, None) == '(a, b, c=1, **d)'
|
||||
assert formatsig('function', 'f', f, 'a, b, c, d', None) == '(a, b, c, d)'
|
||||
assert formatsig('function', 'f', f, None, 'None') == \
|
||||
'(a, b, c=1, **d) -> None'
|
||||
assert formatsig('function', 'f', f, None, 'None') == '(a, b, c=1, **d) -> None'
|
||||
assert formatsig('function', 'g', g, None, None) == r"(a='\\n')"
|
||||
|
||||
# test for classes
|
||||
class D:
|
||||
pass
|
||||
|
||||
class E(object):
|
||||
pass
|
||||
# no signature for classes without __init__
|
||||
for C in (D, E):
|
||||
assert formatsig('class', 'D', C, None, None) == ''
|
||||
|
||||
class F:
|
||||
def __init__(self, a, b=None):
|
||||
pass
|
||||
|
||||
class G(F, object):
|
||||
pass
|
||||
for C in (F, G):
|
||||
@@ -191,6 +196,7 @@ def test_format_signature():
|
||||
|
||||
# __init__ have signature at first line of docstring
|
||||
directive.env.config.autoclass_content = 'both'
|
||||
|
||||
class F2:
|
||||
'''some docstring for F2.'''
|
||||
def __init__(self, *args, **kw):
|
||||
@@ -211,8 +217,10 @@ def test_format_signature():
|
||||
class H:
|
||||
def foo1(self, b, *c):
|
||||
pass
|
||||
|
||||
def foo2(b, *c):
|
||||
pass
|
||||
|
||||
def foo3(self, d='\n'):
|
||||
pass
|
||||
assert formatsig('method', 'H.foo', H.foo1, None, None) == '(b, *c)'
|
||||
@@ -431,6 +439,7 @@ def test_docstring_processing():
|
||||
|
||||
lid = app.connect('autodoc-process-docstring',
|
||||
cut_lines(1, 1, ['function']))
|
||||
|
||||
def f():
|
||||
"""
|
||||
first line
|
||||
@@ -441,6 +450,7 @@ def test_docstring_processing():
|
||||
app.disconnect(lid)
|
||||
|
||||
lid = app.connect('autodoc-process-docstring', between('---', ['function']))
|
||||
|
||||
def g():
|
||||
"""
|
||||
first line
|
||||
@@ -452,8 +462,9 @@ def test_docstring_processing():
|
||||
assert process('function', 'g', g) == ['second line', '']
|
||||
app.disconnect(lid)
|
||||
|
||||
lid = app.connect('autodoc-process-docstring', between('---', ['function'],
|
||||
exclude=True))
|
||||
lid = app.connect('autodoc-process-docstring',
|
||||
between('---', ['function'], exclude=True))
|
||||
|
||||
def h():
|
||||
"""
|
||||
first line
|
||||
@@ -522,7 +533,7 @@ def test_new_documenter():
|
||||
def assert_result_contains(item, objtype, name, **kw):
|
||||
inst = AutoDirective._registry[objtype](directive, name)
|
||||
inst.generate(**kw)
|
||||
#print '\n'.join(directive.result)
|
||||
# print '\n'.join(directive.result)
|
||||
assert len(_warnings) == 0, _warnings
|
||||
assert item in directive.result
|
||||
del directive.result[:]
|
||||
@@ -535,6 +546,7 @@ def test_new_documenter():
|
||||
def test_attrgetter_using():
|
||||
def assert_getter_works(objtype, name, obj, attrs=[], **kw):
|
||||
getattr_spy = []
|
||||
|
||||
def special_getattr(obj, name, *defargs):
|
||||
if name in attrs:
|
||||
getattr_spy.append((obj, name))
|
||||
@@ -556,12 +568,10 @@ def test_attrgetter_using():
|
||||
|
||||
options.members = ALL
|
||||
options.inherited_members = False
|
||||
assert_getter_works('class', 'test_autodoc.Class', Class,
|
||||
['meth'])
|
||||
assert_getter_works('class', 'test_autodoc.Class', Class, ['meth'])
|
||||
|
||||
options.inherited_members = True
|
||||
assert_getter_works('class', 'test_autodoc.Class', Class,
|
||||
['meth', 'inheritedmeth'])
|
||||
assert_getter_works('class', 'test_autodoc.Class', Class, ['meth', 'inheritedmeth'])
|
||||
|
||||
|
||||
@with_setup(setup_test)
|
||||
@@ -578,7 +588,7 @@ def test_generate():
|
||||
inst = AutoDirective._registry[objtype](directive, name)
|
||||
inst.generate(**kw)
|
||||
assert directive.result
|
||||
#print '\n'.join(directive.result)
|
||||
# print '\n'.join(directive.result)
|
||||
assert len(_warnings) == 0, _warnings
|
||||
del directive.result[:]
|
||||
|
||||
@@ -586,13 +596,12 @@ def test_generate():
|
||||
del processed_docstrings[:]
|
||||
del processed_signatures[:]
|
||||
assert_works(objtype, name, **kw)
|
||||
assert set(processed_docstrings) | set(processed_signatures) == \
|
||||
set(items)
|
||||
assert set(processed_docstrings) | set(processed_signatures) == set(items)
|
||||
|
||||
def assert_result_contains(item, objtype, name, **kw):
|
||||
inst = AutoDirective._registry[objtype](directive, name)
|
||||
inst.generate(**kw)
|
||||
#print '\n'.join(directive.result)
|
||||
# print '\n'.join(directive.result)
|
||||
assert len(_warnings) == 0, _warnings
|
||||
assert item in directive.result
|
||||
del directive.result[:]
|
||||
@@ -604,17 +613,17 @@ def test_generate():
|
||||
assert len(_warnings) == 0, _warnings
|
||||
items = list(reversed(items))
|
||||
lineiter = iter(directive.result)
|
||||
#for line in directive.result:
|
||||
# if line.strip():
|
||||
# print repr(line)
|
||||
# for line in directive.result:
|
||||
# if line.strip():
|
||||
# print repr(line)
|
||||
while items:
|
||||
item = items.pop()
|
||||
for line in lineiter:
|
||||
if line == item:
|
||||
break
|
||||
else: # ran out of items!
|
||||
assert False, 'item %r not found in result or not in the ' \
|
||||
' correct order' % item
|
||||
assert False, ('item %r not found in result or not in the '
|
||||
' correct order' % item)
|
||||
del directive.result[:]
|
||||
|
||||
options.members = []
|
||||
@@ -824,19 +833,19 @@ def test_generate():
|
||||
'module', 'test_autodoc')
|
||||
|
||||
# --- generate fodder ------------
|
||||
import six, sys
|
||||
|
||||
__all__ = ['Class']
|
||||
|
||||
#: documentation for the integer
|
||||
integer = 1
|
||||
|
||||
|
||||
class CustomEx(Exception):
|
||||
"""My custom exception."""
|
||||
|
||||
def f(self):
|
||||
"""Exception method."""
|
||||
|
||||
|
||||
class CustomDataDescriptor(object):
|
||||
"""Descriptor class docstring."""
|
||||
|
||||
@@ -852,6 +861,7 @@ class CustomDataDescriptor(object):
|
||||
"""Function."""
|
||||
return "The Answer"
|
||||
|
||||
|
||||
def _funky_classmethod(name, b, c, d, docstring=None):
|
||||
"""Generates a classmethod for a class from a template by filling out
|
||||
some arguments."""
|
||||
@@ -863,6 +873,7 @@ def _funky_classmethod(name, b, c, d, docstring=None):
|
||||
function.__doc__ = docstring
|
||||
return classmethod(function)
|
||||
|
||||
|
||||
class Base(object):
|
||||
def inheritedmeth(self):
|
||||
"""Inherited function."""
|
||||
@@ -908,10 +919,10 @@ class Class(Base):
|
||||
roger = _funky_classmethod("roger", 2, 3, 4)
|
||||
|
||||
moore = _funky_classmethod("moore", 9, 8, 7,
|
||||
docstring="moore(a, e, f) -> happiness")
|
||||
docstring="moore(a, e, f) -> happiness")
|
||||
|
||||
def __init__(self, arg):
|
||||
self.inst_attr_inline = None #: an inline documented instance attr
|
||||
self.inst_attr_inline = None #: an inline documented instance attr
|
||||
#: a documented instance attribute
|
||||
self.inst_attr_comment = None
|
||||
self.inst_attr_string = None
|
||||
@@ -928,6 +939,7 @@ class Class(Base):
|
||||
class CustomDict(dict):
|
||||
"""Docstring."""
|
||||
|
||||
|
||||
def function(foo, *args, **kwds):
|
||||
"""
|
||||
Return spam.
|
||||
@@ -977,14 +989,17 @@ First line of docstring
|
||||
"""
|
||||
return 456
|
||||
|
||||
|
||||
class StrRepr(str):
|
||||
def __repr__(self):
|
||||
return self
|
||||
|
||||
|
||||
class AttCls(object):
|
||||
a1 = StrRepr('hello\nworld')
|
||||
a2 = None
|
||||
|
||||
|
||||
class InstAttCls(object):
|
||||
"""Class with documented class and instance attributes."""
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
"""
|
||||
|
||||
# "raises" imported for usage by autodoc
|
||||
import six
|
||||
import sys
|
||||
from util import TestApp, Struct, raises, SkipTest
|
||||
from nose.tools import with_setup, eq_
|
||||
|
||||
@@ -22,6 +24,7 @@ from sphinx.ext.autodoc import AutoDirective, add_documenter, \
|
||||
|
||||
app = None
|
||||
|
||||
|
||||
def setup_module():
|
||||
global app
|
||||
app = TestApp()
|
||||
@@ -38,6 +41,7 @@ def teardown_module():
|
||||
|
||||
directive = options = None
|
||||
|
||||
|
||||
def setup_test():
|
||||
global options, directive
|
||||
global processed_docstrings, processed_signatures, _warnings
|
||||
@@ -73,19 +77,19 @@ def setup_test():
|
||||
|
||||
|
||||
_warnings = []
|
||||
processed_docstrings = []
|
||||
processed_signatures = []
|
||||
|
||||
|
||||
def warnfunc(msg):
|
||||
_warnings.append(msg)
|
||||
|
||||
|
||||
processed_docstrings = []
|
||||
|
||||
def process_docstring(app, what, name, obj, options, lines):
|
||||
processed_docstrings.append((what, name))
|
||||
if name == 'bar':
|
||||
lines.extend(['42', ''])
|
||||
|
||||
processed_signatures = []
|
||||
|
||||
def process_signature(app, what, name, obj, options, args, retann):
|
||||
processed_signatures.append((what, name))
|
||||
@@ -116,7 +120,7 @@ def test_generate():
|
||||
inst = AutoDirective._registry[objtype](directive, name)
|
||||
inst.generate(**kw)
|
||||
assert directive.result
|
||||
#print '\n'.join(directive.result)
|
||||
# print '\n'.join(directive.result)
|
||||
assert len(_warnings) == 0, _warnings
|
||||
del directive.result[:]
|
||||
|
||||
@@ -124,13 +128,12 @@ def test_generate():
|
||||
del processed_docstrings[:]
|
||||
del processed_signatures[:]
|
||||
assert_works(objtype, name, **kw)
|
||||
assert set(processed_docstrings) | set(processed_signatures) == \
|
||||
set(items)
|
||||
assert set(processed_docstrings) | set(processed_signatures) == set(items)
|
||||
|
||||
def assert_result_contains(item, objtype, name, **kw):
|
||||
inst = AutoDirective._registry[objtype](directive, name)
|
||||
inst.generate(**kw)
|
||||
#print '\n'.join(directive.result)
|
||||
# print '\n'.join(directive.result)
|
||||
assert len(_warnings) == 0, _warnings
|
||||
assert item in directive.result
|
||||
del directive.result[:]
|
||||
@@ -142,17 +145,17 @@ def test_generate():
|
||||
assert len(_warnings) == 0, _warnings
|
||||
items = list(reversed(items))
|
||||
lineiter = iter(directive.result)
|
||||
#for line in directive.result:
|
||||
# if line.strip():
|
||||
# print repr(line)
|
||||
# for line in directive.result:
|
||||
# if line.strip():
|
||||
# print repr(line)
|
||||
while items:
|
||||
item = items.pop()
|
||||
for line in lineiter:
|
||||
if line == item:
|
||||
break
|
||||
else: # ran out of items!
|
||||
assert False, 'item %r not found in result or not in the ' \
|
||||
' correct order' % item
|
||||
assert False, ('item %r not found in result or not in the '
|
||||
' correct order' % item)
|
||||
del directive.result[:]
|
||||
|
||||
options.members = []
|
||||
@@ -233,19 +236,19 @@ def test_generate():
|
||||
|
||||
|
||||
# --- generate fodder ------------
|
||||
import six, sys
|
||||
|
||||
__all__ = ['Class']
|
||||
|
||||
#: documentation for the integer
|
||||
integer = 1
|
||||
|
||||
|
||||
class CustomEx(Exception):
|
||||
"""My custom exception."""
|
||||
|
||||
def f(self):
|
||||
"""Exception method."""
|
||||
|
||||
|
||||
class CustomDataDescriptor(object):
|
||||
"""Descriptor class docstring."""
|
||||
|
||||
@@ -261,6 +264,7 @@ class CustomDataDescriptor(object):
|
||||
"""Function."""
|
||||
return "The Answer"
|
||||
|
||||
|
||||
def _funky_classmethod(name, b, c, d, docstring=None):
|
||||
"""Generates a classmethod for a class from a template by filling out
|
||||
some arguments."""
|
||||
@@ -272,6 +276,7 @@ def _funky_classmethod(name, b, c, d, docstring=None):
|
||||
function.__doc__ = docstring
|
||||
return classmethod(function)
|
||||
|
||||
|
||||
class Base(object):
|
||||
def inheritedmeth(self):
|
||||
"""Inherited function."""
|
||||
@@ -322,10 +327,10 @@ class Class(Base):
|
||||
roger = _funky_classmethod("roger", 2, 3, 4)
|
||||
|
||||
moore = _funky_classmethod("moore", 9, 8, 7,
|
||||
docstring="moore(a, e, f) -> happiness")
|
||||
docstring="moore(a, e, f) -> happiness")
|
||||
|
||||
def __init__(self, arg):
|
||||
self.inst_attr_inline = None #: an inline documented instance attr
|
||||
self.inst_attr_inline = None #: an inline documented instance attr
|
||||
#: a documented instance attribute
|
||||
self.inst_attr_comment = None
|
||||
self.inst_attr_string = None
|
||||
|
||||
@@ -15,6 +15,7 @@ import pickle
|
||||
from docutils import nodes
|
||||
from textwrap import dedent
|
||||
from sphinx.errors import SphinxError
|
||||
import sphinx.builders.linkcheck
|
||||
|
||||
from util import with_app, rootdir, tempdir, SkipTest, TestApp
|
||||
|
||||
@@ -31,7 +32,6 @@ class MockOpener(object):
|
||||
url = req.url
|
||||
return result()
|
||||
|
||||
import sphinx.builders.linkcheck
|
||||
sphinx.builders.linkcheck.opener = MockOpener()
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
import os
|
||||
import plistlib
|
||||
|
||||
from util import with_app
|
||||
|
||||
@@ -114,7 +114,7 @@ def test_gettext_index_entries(app, status, warning):
|
||||
"Exception",
|
||||
"Statement",
|
||||
"Builtin",
|
||||
]
|
||||
]
|
||||
for expect in expected_msgids:
|
||||
assert expect in msgids
|
||||
msgids.remove(expect)
|
||||
|
||||
@@ -596,7 +596,7 @@ def test_numfig_without_numbered_toctree(app, status, warning):
|
||||
(".//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),
|
||||
@@ -622,7 +622,7 @@ def test_numfig_without_numbered_toctree(app, status, warning):
|
||||
"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),
|
||||
@@ -693,7 +693,7 @@ def test_numfig_with_numbered_toctree(app, status, warning):
|
||||
(".//li/a/span", '^Table:2.2$', True),
|
||||
(".//li/a/span", '^Listing 1$', True),
|
||||
(".//li/a/span", '^Code-2.2$', True),
|
||||
],
|
||||
],
|
||||
'foo.html': [
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig. 1.1 $', True),
|
||||
@@ -719,7 +719,7 @@ def test_numfig_with_numbered_toctree(app, status, warning):
|
||||
"span[@class='caption-number']", '^Listing 1.3 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^Listing 1.4 $', True),
|
||||
],
|
||||
],
|
||||
'bar.html': [
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig. 2.1 $', True),
|
||||
@@ -793,7 +793,7 @@ def test_numfig_with_prefix(app, status, warning):
|
||||
(".//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),
|
||||
@@ -819,7 +819,7 @@ def test_numfig_with_prefix(app, status, warning):
|
||||
"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),
|
||||
@@ -890,7 +890,7 @@ def test_numfig_with_secnum_depth(app, status, warning):
|
||||
(".//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),
|
||||
@@ -916,7 +916,7 @@ def test_numfig_with_secnum_depth(app, status, warning):
|
||||
"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),
|
||||
|
||||
@@ -45,8 +45,8 @@ def run_latex(outdir):
|
||||
try:
|
||||
os.mkdir(latex)
|
||||
p = Popen([latex, '--interaction=nonstopmode',
|
||||
'-output-directory=%s' % latex, 'SphinxTests.tex'],
|
||||
stdout=PIPE, stderr=PIPE)
|
||||
'-output-directory=%s' % latex, 'SphinxTests.tex'],
|
||||
stdout=PIPE, stderr=PIPE)
|
||||
except OSError: # most likely the latex executable was not found
|
||||
available_latexes -= 1
|
||||
else:
|
||||
@@ -59,9 +59,10 @@ def run_latex(outdir):
|
||||
finally:
|
||||
os.chdir(cwd)
|
||||
|
||||
if available_latexes == 0: # no latex is available, skip the test
|
||||
if available_latexes == 0: # no latex is available, skip the test
|
||||
raise SkipTest
|
||||
|
||||
|
||||
@with_app(buildername='latex', freshenv=True) # use freshenv to check warnings
|
||||
def test_latex(app, status, warning):
|
||||
LaTeXTranslator.ignore_missing_images = True
|
||||
|
||||
@@ -56,6 +56,7 @@ def test_compile_all_catalogs(app, status, warning):
|
||||
confoverrides={'language': 'en', 'locale_dirs': [locale_dir]})
|
||||
def test_compile_specific_catalogs(app, status, warning):
|
||||
catalog_dir = locale_dir / app.config.language / 'LC_MESSAGES'
|
||||
|
||||
def get_actual():
|
||||
return set(find_files(catalog_dir, '.mo'))
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
from six import PY2, PY3, StringIO, iteritems
|
||||
from six import PY3, iteritems
|
||||
from util import mock
|
||||
|
||||
from util import TestApp, with_app, gen_with_app, with_tempdir, \
|
||||
@@ -109,8 +109,10 @@ def test_errors_warnings(dir):
|
||||
u'# -*- coding: latin-1\nproject = "fooä"\n', encoding='latin-1')
|
||||
cfg = Config(dir, 'conf.py', {}, None)
|
||||
warned = [False]
|
||||
|
||||
def warn(msg):
|
||||
warned[0] = True
|
||||
|
||||
cfg.check_unicode(warn)
|
||||
assert warned[0]
|
||||
|
||||
@@ -160,18 +162,17 @@ def test_config_eol(tmpdir):
|
||||
assert cfg.project == u'spam'
|
||||
|
||||
|
||||
@with_app(confoverrides={
|
||||
'master_doc': 123,
|
||||
'language': 'foo',
|
||||
'primary_domain': None})
|
||||
@with_app(confoverrides={'master_doc': 123,
|
||||
'language': 'foo',
|
||||
'primary_domain': None})
|
||||
def test_builtin_conf(app, status, warning):
|
||||
warnings = warning.getvalue()
|
||||
assert_in('master_doc', warnings,
|
||||
'override on builtin "master_doc" should raise a type warning')
|
||||
'override on builtin "master_doc" should raise a type warning')
|
||||
assert_not_in('language', warnings, 'explicitly permitted '
|
||||
'override on builtin "language" should NOT raise a type warning')
|
||||
'override on builtin "language" should NOT raise a type warning')
|
||||
assert_not_in('primary_domain', warnings, 'override to None on builtin '
|
||||
'"primary_domain" should NOT raise a type warning')
|
||||
'"primary_domain" should NOT raise a type warning')
|
||||
|
||||
|
||||
# See roots/test-config/conf.py.
|
||||
@@ -193,12 +194,15 @@ TYPECHECK_WARNINGS = {
|
||||
'value15': False,
|
||||
'value16': False,
|
||||
}
|
||||
|
||||
|
||||
@gen_with_app(testroot='config')
|
||||
def test_gen_check_types(app, status, warning):
|
||||
if PY3:
|
||||
TYPECHECK_WARNINGS['value11'] = False
|
||||
|
||||
for key, should in iteritems(TYPECHECK_WARNINGS):
|
||||
yield assert_in if should else assert_not_in, key, warning.getvalue(), \
|
||||
'override on "%s" should%s raise a type warning' % \
|
||||
(key, '' if should else ' NOT')
|
||||
yield assert_in if should else assert_not_in, key, warning.getvalue(), (
|
||||
'override on "%s" should%s raise a type warning' %
|
||||
(key, '' if should else ' NOT')
|
||||
)
|
||||
|
||||
@@ -85,9 +85,9 @@ def test_code_block_namedlink_latex(app, status, warning):
|
||||
link2 = '\\hyperref[namedblocks:some\\string-ruby\\string-code]'\
|
||||
'{\\crossref{\\DUrole{std,std-ref}{the ruby code}}}'
|
||||
assert label1 in latex
|
||||
assert link1 in latex
|
||||
assert link1 in latex
|
||||
assert label2 in latex
|
||||
assert link2 in latex
|
||||
assert link2 in latex
|
||||
|
||||
|
||||
@with_app('xml', testroot='directive-code')
|
||||
@@ -272,9 +272,9 @@ def test_literalinclude_namedlink_latex(app, status, warning):
|
||||
link2 = '\\hyperref[namedblocks:some\\string-python\\string-code]'\
|
||||
'{\\crossref{\\DUrole{std,std-ref}{the python code}}}'
|
||||
assert label1 in latex
|
||||
assert link1 in latex
|
||||
assert link1 in latex
|
||||
assert label2 in latex
|
||||
assert link2 in latex
|
||||
assert link2 in latex
|
||||
|
||||
|
||||
@with_app('xml', testroot='directive-code')
|
||||
|
||||
@@ -77,7 +77,7 @@ def check(name, input, idv1output=None, idv2output=None, output=None):
|
||||
print(rootSymbol.dump(0))
|
||||
raise DefinitionError("")
|
||||
ids.append(ast.get_id_v2())
|
||||
#print ".. %s:: %s" % (name, input)
|
||||
# print ".. %s:: %s" % (name, input)
|
||||
|
||||
|
||||
def test_fundamental_types():
|
||||
@@ -397,11 +397,11 @@ def test_templates():
|
||||
"RK18c_string_view_baseIK4Char6TraitsE")
|
||||
|
||||
|
||||
#def test_print():
|
||||
# # used for getting all the ids out for checking
|
||||
# for a in ids:
|
||||
# print(a)
|
||||
# raise DefinitionError("")
|
||||
# def test_print():
|
||||
# # used for getting all the ids out for checking
|
||||
# for a in ids:
|
||||
# print(a)
|
||||
# raise DefinitionError("")
|
||||
|
||||
|
||||
@with_app(testroot='domain-cpp', confoverrides={'add_function_parentheses': True})
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
|
||||
from sphinx.domains.rst import parse_directive
|
||||
|
||||
def test_parse_directive():
|
||||
|
||||
def test_parse_directive():
|
||||
s = parse_directive(u' foö ')
|
||||
assert s == (u'foö', '')
|
||||
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
from util import with_app
|
||||
|
||||
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
from util import with_app
|
||||
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ def test_imgmath_png(app, status, warning):
|
||||
'\s*alt="a\^2\+b\^2=c\^2"/>\s*</p>\s*</div>')
|
||||
assert re.search(html, content, re.S)
|
||||
|
||||
|
||||
@with_app('html', testroot='ext-math',
|
||||
confoverrides={'extensions': ['sphinx.ext.imgmath'],
|
||||
'imgmath_image_format': 'svg'})
|
||||
@@ -43,6 +44,7 @@ def test_imgmath_svg(app, status, warning):
|
||||
'\s*alt="a\^2\+b\^2=c\^2"/>\s*</p>\s*</div>')
|
||||
assert re.search(html, content, re.S)
|
||||
|
||||
|
||||
@with_app('html', testroot='ext-math',
|
||||
confoverrides={'extensions': ['sphinx.ext.mathjax']})
|
||||
def test_mathjax_align(app, status, warning):
|
||||
@@ -54,6 +56,7 @@ def test_mathjax_align(app, status, warning):
|
||||
r'V \&= \\frac\{4\}\{3\} \\pi r\^3\\end\{aligned\}\\end\{align\} \\\]</div>')
|
||||
assert re.search(html, content, re.S)
|
||||
|
||||
|
||||
@with_app('html', testroot='ext-math',
|
||||
confoverrides={'math_number_all': True,
|
||||
'extensions': ['sphinx.ext.mathjax']})
|
||||
@@ -65,6 +68,7 @@ def test_math_number_all_mathjax(app, status, warning):
|
||||
r'<span class="eqno">\(1\)</span>\\\[a\^2\+b\^2=c\^2\\\]</div>')
|
||||
assert re.search(html, content, re.S)
|
||||
|
||||
|
||||
@with_app('latex', testroot='ext-math',
|
||||
confoverrides={'extensions': ['sphinx.ext.mathjax']})
|
||||
def test_math_number_all_latex(app, status, warning):
|
||||
|
||||
@@ -65,7 +65,7 @@ def test_detect_interactive():
|
||||
|
||||
def test_lexer_options():
|
||||
bridge = PygmentsBridge('html')
|
||||
ret = bridge.highlight_block('//comment', 'php', opts={'startinline' : True})
|
||||
ret = bridge.highlight_block('//comment', 'php', opts={'startinline': True})
|
||||
assert '<span class="c1">//comment</span>' in ret
|
||||
|
||||
|
||||
|
||||
@@ -680,7 +680,7 @@ def test_xml_builder(app, status, warning):
|
||||
def test_additional_targets_should_not_be_translated(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
## literalblock.txt
|
||||
# [literalblock.txt]
|
||||
result = (app.outdir / 'literalblock.html').text(encoding='utf-8')
|
||||
|
||||
# title should be translated
|
||||
@@ -707,7 +707,7 @@ def test_additional_targets_should_not_be_translated(app, status, warning):
|
||||
"""<span class="c1"># sys importing</span>""")
|
||||
yield assert_count(expected_expr, result, 1)
|
||||
|
||||
## raw.txt
|
||||
# [raw.txt]
|
||||
|
||||
result = (app.outdir / 'raw.html').text(encoding='utf-8')
|
||||
|
||||
@@ -715,7 +715,7 @@ def test_additional_targets_should_not_be_translated(app, status, warning):
|
||||
expected_expr = """<iframe src="http://sphinx-doc.org"></iframe></div>"""
|
||||
yield assert_count(expected_expr, result, 1)
|
||||
|
||||
## figure.txt
|
||||
# [figure.txt]
|
||||
|
||||
result = (app.outdir / 'figure.html').text(encoding='utf-8')
|
||||
|
||||
@@ -741,7 +741,7 @@ def test_additional_targets_should_not_be_translated(app, status, warning):
|
||||
def test_additional_targets_should_be_translated(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
## literalblock.txt
|
||||
# [literalblock.txt]
|
||||
result = (app.outdir / 'literalblock.html').text(encoding='utf-8')
|
||||
|
||||
# title should be translated
|
||||
@@ -768,7 +768,7 @@ def test_additional_targets_should_be_translated(app, status, warning):
|
||||
"""<span class="c1"># SYS IMPORTING</span>""")
|
||||
yield assert_count(expected_expr, result, 1)
|
||||
|
||||
## raw.txt
|
||||
# [raw.txt]
|
||||
|
||||
result = (app.outdir / 'raw.html').text(encoding='utf-8')
|
||||
|
||||
@@ -776,7 +776,7 @@ def test_additional_targets_should_be_translated(app, status, warning):
|
||||
expected_expr = """<iframe src="HTTP://SPHINX-DOC.ORG"></iframe></div>"""
|
||||
yield assert_count(expected_expr, result, 1)
|
||||
|
||||
## figure.txt
|
||||
# [figure.txt]
|
||||
|
||||
result = (app.outdir / 'figure.html').text(encoding='utf-8')
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ def setup_module():
|
||||
def teardown_module():
|
||||
app.cleanup()
|
||||
|
||||
|
||||
# since we're not resolving the markup afterwards, these nodes may remain
|
||||
class ForgivingTranslator:
|
||||
def visit_pending_xref(self, node):
|
||||
@@ -74,11 +75,12 @@ def verify_re(rst, html_expected, latex_expected):
|
||||
|
||||
if latex_expected:
|
||||
latex_translator = ForgivingLaTeXTranslator(document, app.builder)
|
||||
latex_translator.first_document = -1 # don't write \begin{document}
|
||||
latex_translator.first_document = -1 # don't write \begin{document}
|
||||
document.walkabout(latex_translator)
|
||||
latex_translated = ''.join(latex_translator.body).strip()
|
||||
assert re.match(latex_expected, latex_translated), 'from ' + repr(rst)
|
||||
|
||||
|
||||
def verify(rst, html_expected, latex_expected):
|
||||
if html_expected:
|
||||
html_expected = re.escape(html_expected) + '$'
|
||||
@@ -131,6 +133,7 @@ def test_inline():
|
||||
'<p><em class="manpage">mp(1)</em></p>',
|
||||
'\\emph{\\texttt{mp(1)}}')
|
||||
|
||||
|
||||
def test_latex_escaping():
|
||||
# correct escaping in normal mode
|
||||
yield (verify, u'Γ\\\\∞$', None,
|
||||
|
||||
@@ -20,6 +20,7 @@ from util import with_app
|
||||
|
||||
settings = parser = None
|
||||
|
||||
|
||||
def setup_module():
|
||||
global settings, parser
|
||||
optparser = frontend.OptionParser(components=(rst.Parser,))
|
||||
@@ -33,6 +34,7 @@ FILE_CONTENTS = '''\
|
||||
test that non-comments are indexed: fermion
|
||||
'''
|
||||
|
||||
|
||||
def test_wordcollector():
|
||||
doc = utils.new_document(b'test data', settings)
|
||||
doc['file'] = 'dummy'
|
||||
|
||||
@@ -47,7 +47,7 @@ def test_catalog_outdated(dir):
|
||||
mo_file.write_text('#')
|
||||
assert not cat.is_outdated() # if mo is exist and newer than po
|
||||
|
||||
os.utime(mo_file, (os.stat(mo_file).st_mtime - 10,) * 2) # to be outdate
|
||||
os.utime(mo_file, (os.stat(mo_file).st_mtime - 10,) * 2) # to be outdate
|
||||
assert cat.is_outdated() # if mo is exist and older than po
|
||||
|
||||
|
||||
@@ -213,6 +213,7 @@ def test_format_date():
|
||||
assert i18n.format_date(format, date=datet) == 'Feb 7, 2016, 5:11:17 AM'
|
||||
assert i18n.format_date(format, date=date) == 'Feb 7, 2016'
|
||||
|
||||
|
||||
def test_get_filename_for_language():
|
||||
app = TestApp()
|
||||
|
||||
|
||||
@@ -87,7 +87,6 @@ def test_extract_messages():
|
||||
nodes.rubric, 1,
|
||||
)
|
||||
|
||||
|
||||
text = dedent(
|
||||
"""
|
||||
| spam
|
||||
@@ -100,7 +99,6 @@ def test_extract_messages():
|
||||
nodes.line, 2,
|
||||
)
|
||||
|
||||
|
||||
text = dedent(
|
||||
"""
|
||||
section
|
||||
@@ -118,7 +116,6 @@ def test_extract_messages():
|
||||
nodes.line, 2,
|
||||
)
|
||||
|
||||
|
||||
text = dedent(
|
||||
"""
|
||||
* | **Title 1**
|
||||
|
||||
@@ -26,7 +26,7 @@ from sphinx.theming import Theme
|
||||
from sphinx.ext.autodoc import AutoDirective
|
||||
from sphinx.pycode import ModuleAnalyzer
|
||||
|
||||
from path import path, repr_as
|
||||
from path import path, repr_as # NOQA
|
||||
|
||||
try:
|
||||
# Python >=3.3
|
||||
@@ -110,6 +110,7 @@ except ImportError:
|
||||
def assert_in(x, thing, msg=''):
|
||||
if x not in thing:
|
||||
assert False, msg or '%r is not in %r' % (x, thing)
|
||||
|
||||
def assert_not_in(x, thing, msg=''):
|
||||
if x in thing:
|
||||
assert False, msg or '%r is in %r' % (x, thing)
|
||||
|
||||
Reference in New Issue
Block a user