Fix flake8 violations

This commit is contained in:
Takeshi KOMIYA 2017-01-26 01:13:17 +09:00
parent 2c91a52418
commit cf2061dfad
21 changed files with 71 additions and 68 deletions

View File

@ -26,4 +26,4 @@ universal = 1
[flake8]
max-line-length = 95
ignore = E116,E241,E251
exclude = .git,.tox,tests/*,build/*,sphinx/search/*,sphinx/pycode/pgen2/*,doc/ext/example*.py
exclude = .git,.tox,tests/*,build/*,sphinx/search/*,sphinx/pycode/pgen2/*,doc/ext/example*.py

View File

@ -59,8 +59,8 @@ ignore_paths = [
for sub in ('root', 'roots')
]
args = sys.argv[1:]
for path in ignore_paths:
args.extend(['--ignore', path])
for ignore_path in ignore_paths:
args.extend(['--ignore', ignore_path])
import pytest
import pytest # NOQA
sys.exit(pytest.main(args))

View File

@ -871,6 +871,7 @@ def test_generate():
assert_result_contains('.. py:function:: decoratedFunction()',
'module', 'autodoc_missing_imports')
# --- generate fodder ------------
__all__ = ['Class']
@ -909,6 +910,7 @@ class CustomDataDescriptor(object):
class CustomDataDescriptorMeta(type):
"""Descriptor metaclass docstring."""
@add_metaclass(CustomDataDescriptorMeta)
class CustomDataDescriptor2(CustomDataDescriptor):
"""Descriptor class with custom metaclass docstring."""

View File

@ -46,11 +46,10 @@ def nonascii_srcdir(request):
master_doc = srcdir / 'contents.txt'
master_doc.write_text(master_doc.text() + dedent(u"""
.. toctree::
.. toctree::
%(test_name)s/%(test_name)s
""" % {'test_name': test_name})
)
%(test_name)s/%(test_name)s
""" % {'test_name': test_name}))
return srcdir

View File

@ -52,6 +52,7 @@ if PY3:
etree_cache = {}
@pytest.fixture(scope='module')
def cached_etree_parse():
def parse(fname):

View File

@ -171,7 +171,7 @@ def test_latex_title_after_admonitions(app, status, warning):
@pytest.mark.sphinx('latex', testroot='numfig',
confoverrides={'numfig': True})
confoverrides={'numfig': True})
def test_numref(app, status, warning):
app.builder.build_all()
result = (app.outdir / 'Python.tex').text(encoding='utf8')
@ -548,12 +548,12 @@ def test_latex_show_urls_is_inline(app, status, warning):
'{\\hyperref[\\detokenize{index:the-section-with-a-reference-to}]'
'{\\sphinxcrossref{The section with a reference to }}}' in result)
assert ('First footnote: %\n\\begin{footnote}[2]\\sphinxAtStartFootnote\n'
'First\n%\n\\end{footnote}') in result
'First\n%\n\\end{footnote}') in result
assert ('Second footnote: %\n\\begin{footnote}[1]\\sphinxAtStartFootnote\n'
'Second\n%\n\\end{footnote}') in result
'Second\n%\n\\end{footnote}') in result
assert '\\href{http://sphinx-doc.org/}{Sphinx} (http://sphinx-doc.org/)' in result
assert ('Third footnote: %\n\\begin{footnote}[3]\\sphinxAtStartFootnote\n'
'Third\n%\n\\end{footnote}') in result
'Third\n%\n\\end{footnote}') 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} '
@ -591,9 +591,9 @@ def test_latex_show_urls_is_footnote(app, status, warning):
'{\\hyperref[\\detokenize{index:the-section-with-a-reference-to}]'
'{\\sphinxcrossref{The section with a reference to }}}') in result
assert ('First footnote: %\n\\begin{footnote}[3]\\sphinxAtStartFootnote\n'
'First\n%\n\\end{footnote}') in result
'First\n%\n\\end{footnote}') in result
assert ('Second footnote: %\n\\begin{footnote}[1]\\sphinxAtStartFootnote\n'
'Second\n%\n\\end{footnote}') in result
'Second\n%\n\\end{footnote}') in result
assert ('\\href{http://sphinx-doc.org/}{Sphinx}'
'%\n\\begin{footnote}[4]\\sphinxAtStartFootnote\n'
'\\nolinkurl{http://sphinx-doc.org/}\n%\n\\end{footnote}') in result
@ -615,7 +615,7 @@ def test_latex_show_urls_is_footnote(app, status, warning):
'\\leavevmode%\n\\begin{footnotetext}[9]\\sphinxAtStartFootnote\n'
'\\nolinkurl{http://sphinx-doc.org/}\n%\n'
'\\end{footnotetext}\nDescription') in result
assert '\\url{https://github.com/sphinx-doc/sphinx}\n' in result
assert ('\\url{https://github.com/sphinx-doc/sphinx}\n' in result)
assert ('\\href{mailto:sphinx-dev@googlegroups.com}'
'{sphinx-dev@googlegroups.com}\n') in result
@ -643,12 +643,12 @@ def test_latex_show_urls_is_no(app, status, warning):
'{\\hyperref[\\detokenize{index:the-section-with-a-reference-to}]'
'{\\sphinxcrossref{The section with a reference to }}}' in result)
assert ('First footnote: %\n\\begin{footnote}[2]\\sphinxAtStartFootnote\n'
'First\n%\n\\end{footnote}') in result
'First\n%\n\\end{footnote}') in result
assert ('Second footnote: %\n\\begin{footnote}[1]\\sphinxAtStartFootnote\n'
'Second\n%\n\\end{footnote}') in result
'Second\n%\n\\end{footnote}') in result
assert '\\href{http://sphinx-doc.org/}{Sphinx}' in result
assert ('Third footnote: %\n\\begin{footnote}[3]\\sphinxAtStartFootnote\n'
'Third\n%\n\\end{footnote}') in result
'Third\n%\n\\end{footnote}') 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
@ -688,10 +688,10 @@ def test_latex_logo_if_not_found(app, status, warning):
@pytest.mark.sphinx('latex', testroot='toctree-maxdepth',
confoverrides={'latex_documents': [
('index', 'SphinxTests.tex', 'Sphinx Tests Documentation',
'Georg Brandl', 'manual'),
]})
confoverrides={'latex_documents': [
('index', 'SphinxTests.tex', 'Sphinx Tests Documentation',
'Georg Brandl', 'manual'),
]})
def test_toctree_maxdepth_manual(app, status, warning):
app.builder.build_all()
result = (app.outdir / 'SphinxTests.tex').text(encoding='utf8')
@ -804,6 +804,7 @@ def test_latex_toplevel_sectioning_is_section(app, status, warning):
print(warning.getvalue())
assert '\\section{Foo}' in result
@skip_if_stylefiles_notfound
@pytest.mark.sphinx('latex', testroot='maxlistdepth')
def test_maxlistdepth_at_ten(app, status, warning):

View File

@ -102,7 +102,7 @@ def test_errors_warnings(tempdir):
u'# -*- coding: utf-8\n\nproject = u"Jägermeister"\n',
encoding='utf-8')
cfg = Config(tempdir, 'conf.py', {}, None)
cfg.init_values(lambda warning: 1/0)
cfg.init_values(lambda warning: 1 / 0)
assert cfg.project == u'Jägermeister'
# test the warning for bytestrings with non-ascii content
@ -163,13 +163,13 @@ def test_config_eol(tempdir):
for eol in (b'\n', b'\r\n'):
configfile.write_bytes(b'project = "spam"' + eol)
cfg = Config(tempdir, 'conf.py', {}, None)
cfg.init_values(lambda warning: 1/0)
cfg.init_values(lambda warning: 1 / 0)
assert cfg.project == u'spam'
@pytest.mark.sphinx(confoverrides={'master_doc': 123,
'language': 'foo',
'primary_domain': None})
'language': 'foo',
'primary_domain': None})
def test_builtin_conf(app, status, warning):
warnings = warning.getvalue()
assert 'master_doc' in warnings, (

View File

@ -67,8 +67,8 @@ def test_code_block_caption_latex(app, status, warning):
latex = (app.outdir / 'Python.tex').text(encoding='utf-8')
caption = '\\sphinxSetupCaptionForVerbatim{caption \\sphinxstyleemphasis{test} rb}'
label = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:id1}}}'
link = '\hyperref[\\detokenize{caption:name-test-rb}]' \
'{Listing \\ref{\\detokenize{caption:name-test-rb}}}'
link = '\hyperref[\\detokenize{caption:name-test-rb}]' \
'{Listing \\ref{\\detokenize{caption:name-test-rb}}}'
assert caption in latex
assert label in latex
assert link in latex
@ -79,12 +79,12 @@ def test_code_block_namedlink_latex(app, status, warning):
app.builder.build_all()
latex = (app.outdir / 'Python.tex').text(encoding='utf-8')
label1 = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:name-test-rb}}}'
link1 = '\\hyperref[\\detokenize{caption:name-test-rb}]'\
'{\\sphinxcrossref{\\DUrole{std,std-ref}{Ruby}}'
link1 = '\\hyperref[\\detokenize{caption:name-test-rb}]'\
'{\\sphinxcrossref{\\DUrole{std,std-ref}{Ruby}}'
label2 = ('\\def\\sphinxLiteralBlockLabel'
'{\\label{\\detokenize{namedblocks:some-ruby-code}}}')
link2 = '\\hyperref[\\detokenize{namedblocks:some-ruby-code}]'\
'{\\sphinxcrossref{\\DUrole{std,std-ref}{the ruby code}}}'
link2 = '\\hyperref[\\detokenize{namedblocks:some-ruby-code}]'\
'{\\sphinxcrossref{\\DUrole{std,std-ref}{the ruby code}}}'
assert label1 in latex
assert link1 in latex
assert label2 in latex
@ -263,8 +263,8 @@ def test_literalinclude_caption_latex(app, status, warning):
latex = (app.outdir / 'Python.tex').text(encoding='utf-8')
caption = '\\sphinxSetupCaptionForVerbatim{caption \\sphinxstylestrong{test} py}'
label = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:id2}}}'
link = '\hyperref[\\detokenize{caption:name-test-py}]' \
'{Listing \\ref{\\detokenize{caption:name-test-py}}}'
link = '\hyperref[\\detokenize{caption:name-test-py}]' \
'{Listing \\ref{\\detokenize{caption:name-test-py}}}'
assert caption in latex
assert label in latex
assert link in latex
@ -275,12 +275,12 @@ def test_literalinclude_namedlink_latex(app, status, warning):
app.builder.build('index')
latex = (app.outdir / 'Python.tex').text(encoding='utf-8')
label1 = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:name-test-py}}}'
link1 = '\\hyperref[\\detokenize{caption:name-test-py}]'\
'{\\sphinxcrossref{\\DUrole{std,std-ref}{Python}}'
link1 = '\\hyperref[\\detokenize{caption:name-test-py}]'\
'{\\sphinxcrossref{\\DUrole{std,std-ref}{Python}}'
label2 = ('\\def\\sphinxLiteralBlockLabel'
'{\\label{\\detokenize{namedblocks:some-python-code}}}')
link2 = '\\hyperref[\\detokenize{namedblocks:some-python-code}]'\
'{\\sphinxcrossref{\\DUrole{std,std-ref}{the python code}}}'
link2 = '\\hyperref[\\detokenize{namedblocks:some-python-code}]'\
'{\\sphinxcrossref{\\DUrole{std,std-ref}{the python code}}}'
assert label1 in latex
assert link1 in latex
assert label2 in latex

View File

@ -42,7 +42,7 @@ def test_sectioning(app, status, warning):
num = subsect[0].split()[0]
assert re.match('[0-9]+[.0-9]*[.]', num), \
'Unnumbered section: %r' % subsect[0]
testsects(prefix + str(i+1) + '.', subsect, indent+4)
testsects(prefix + str(i + 1) + '.', subsect, indent + 4)
app.builder.build(['only'])
doctree = app.env.get_doctree('only')
@ -51,6 +51,6 @@ def test_sectioning(app, status, warning):
parts = [getsects(n)
for n in [_n for _n in doctree.children if isinstance(_n, nodes.section)]]
for i, s in enumerate(parts):
testsects(str(i+1) + '.', s, 4)
testsects(str(i + 1) + '.', s, 4)
assert len(parts) == 4, 'Expected 4 document level headings, got:\n%s' % \
'\n'.join([p[0] for p in parts])

View File

@ -31,7 +31,7 @@ def parse(name, string):
if not parser.eof:
print("Parsing stopped at", parser.pos)
print(string)
print('-'*parser.pos + '^')
print('-' * parser.pos + '^')
raise DefinitionError("")
# The scopedness would usually have been set by CPPEnumObject
if name == "enum":
@ -495,7 +495,6 @@ def test_attributes():
output='__attribute__(()) static inline void f()')
# def test_print():
# # used for getting all the ids out for checking
# for a in ids:

View File

@ -20,7 +20,7 @@ import mock
from sphinx import addnodes
from sphinx.ext.intersphinx import setup as intersphinx_setup
from sphinx.ext.intersphinx import read_inventory, \
load_mappings, missing_reference, _strip_basic_auth, _read_from_url, \
load_mappings, missing_reference, _strip_basic_auth, \
_get_safe_url, fetch_inventory, INVENTORY_FILENAME

View File

@ -36,7 +36,7 @@ def test_jsmath(app, status, warning):
@pytest.mark.sphinx('html', testroot='ext-math-simple',
confoverrides = {'extensions': ['sphinx.ext.imgmath']})
confoverrides = {'extensions': ['sphinx.ext.imgmath']})
def test_imgmath_png(app, status, warning):
app.builder.build_all()
if "LaTeX command 'latex' cannot be run" in warning.getvalue():
@ -51,8 +51,8 @@ def test_imgmath_png(app, status, warning):
@pytest.mark.sphinx('html', testroot='ext-math-simple',
confoverrides={'extensions': ['sphinx.ext.imgmath'],
'imgmath_image_format': 'svg'})
confoverrides={'extensions': ['sphinx.ext.imgmath'],
'imgmath_image_format': 'svg'})
def test_imgmath_svg(app, status, warning):
app.builder.build_all()
if "LaTeX command 'latex' cannot be run" in warning.getvalue():
@ -67,7 +67,7 @@ def test_imgmath_svg(app, status, warning):
@pytest.mark.sphinx('html', testroot='ext-math',
confoverrides={'extensions': ['sphinx.ext.mathjax']})
confoverrides={'extensions': ['sphinx.ext.mathjax']})
def test_mathjax_align(app, status, warning):
app.builder.build_all()
@ -79,8 +79,8 @@ def test_mathjax_align(app, status, warning):
@pytest.mark.sphinx('html', testroot='ext-math',
confoverrides={'math_number_all': True,
'extensions': ['sphinx.ext.mathjax']})
confoverrides={'math_number_all': True,
'extensions': ['sphinx.ext.mathjax']})
def test_math_number_all_mathjax(app, status, warning):
app.builder.build_all()
@ -91,7 +91,7 @@ def test_math_number_all_mathjax(app, status, warning):
@pytest.mark.sphinx('latex', testroot='ext-math',
confoverrides={'extensions': ['sphinx.ext.mathjax']})
confoverrides={'extensions': ['sphinx.ext.mathjax']})
def test_math_number_all_latex(app, status, warning):
app.builder.build_all()

View File

@ -15,7 +15,7 @@ import pytest
@pytest.mark.sphinx('html', testroot='ext-todo', freshenv=True,
confoverrides={'todo_include_todos': True, 'todo_emit_warnings': True})
confoverrides={'todo_include_todos': True, 'todo_emit_warnings': True})
def test_todo(app, status, warning):
todos = []
@ -51,7 +51,7 @@ def test_todo(app, status, warning):
@pytest.mark.sphinx('html', testroot='ext-todo', freshenv=True,
confoverrides={'todo_include_todos': False, 'todo_emit_warnings': True})
confoverrides={'todo_include_todos': False, 'todo_emit_warnings': True})
def test_todo_not_included(app, status, warning):
todos = []

View File

@ -20,8 +20,9 @@ from babel.messages import pofile, mofile
from six import string_types
import pytest
from util import tempdir, rootdir, path, assert_re_search, \
assert_not_re_search, assert_startswith, assert_node, etree_parse
from util import (
path, assert_re_search, assert_not_re_search, assert_startswith, assert_node, etree_parse
)
sphinx_intl = pytest.mark.sphinx(
@ -559,6 +560,7 @@ def test_html_index_entries(app):
start_tag = "<%s[^>]*>" % tag
end_tag = "</%s>" % tag
return r"%s\s*%s\s*%s" % (start_tag, keyword, end_tag)
def wrap_nest(parenttag, childtag, keyword):
start_tag1 = "<%s[^>]*>" % parenttag
start_tag2 = "<%s[^>]*>" % childtag
@ -781,9 +783,9 @@ def test_xml_keep_external_links(app):
['http://example.com/external2',
'http://example.com/external1'])
assert_elem(
para1[1],
['LINK TO', 'THE PYTHON SITE', 'AND', 'THE SPHINX SITE', '.'],
['http://python.org', 'http://sphinx-doc.org'])
para1[1],
['LINK TO', 'THE PYTHON SITE', 'AND', 'THE SPHINX SITE', '.'],
['http://python.org', 'http://sphinx-doc.org'])
# multiple references in the same line
para2 = secs[2].findall('paragraph')

View File

@ -119,6 +119,7 @@ def get_verifier(verify, verify_re):
'verify': verify,
'verify_re': verify_re,
}
def get(name):
return v[name]
return get
@ -258,7 +259,7 @@ def test_keep_warnings_is_True(app, status, warning):
@pytest.mark.sphinx('dummy', testroot='keep_warnings',
confoverrides={'keep_warnings': False})
confoverrides={'keep_warnings': False})
def test_keep_warnings_is_False(app, status, warning):
app.builder.build_all()
doctree = pickle.loads((app.doctreedir / 'index.doctree').bytes())

View File

@ -8,7 +8,6 @@
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import os
from docutils import frontend, utils
from docutils.parsers import rst

View File

@ -83,11 +83,10 @@ def nonascii_srcdir(request, setup_command):
master_doc = srcdir / 'contents.txt'
master_doc.write_bytes((master_doc.text() + dedent("""
.. toctree::
.. toctree::
%(mb_name)s/%(mb_name)s
""" % locals())
).encode('utf-8'))
%(mb_name)s/%(mb_name)s
""" % locals())).encode('utf-8'))
@pytest.mark.usefixtures('nonascii_srcdir')

View File

@ -17,7 +17,7 @@ import pytest
from sphinx.theming import Theme, ThemeError
from util import with_app, path
from util import path
@pytest.mark.sphinx(

View File

@ -10,6 +10,7 @@
"""
import pytest
@pytest.mark.sphinx(testroot='toctree-glob')
def test_relations(app, status, warning):
app.builder.build_all()

View File

@ -161,8 +161,8 @@ def test_moderation(support):
session.close()
accepted = support.add_comment('Accepted Comment', node_id=node.id,
displayed=False)
deleted = support.add_comment('Comment to delete', node_id=node.id,
displayed=False)
deleted = support.add_comment('Comment to delete', node_id=node.id,
displayed=False)
# Make sure the moderation_callback is called.
assert called
# Make sure the user must be a moderator.

View File

@ -15,6 +15,7 @@ from functools import wraps
from xml.etree import ElementTree
from six import string_types
from six import StringIO
import pytest
@ -207,8 +208,6 @@ def strip_escseq(text):
# #############################################
# DEPRECATED implementations
from six import StringIO
def gen_with_app(*args, **kwargs):
"""