mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
refactor: Fix flake8 violations under tests/ directory
This commit is contained in:
parent
5a42348fd7
commit
21a3bd4127
@ -20,7 +20,7 @@ from test_build_html import ENV_WARNINGS
|
|||||||
|
|
||||||
from sphinx.builders.latex import default_latex_documents
|
from sphinx.builders.latex import default_latex_documents
|
||||||
from sphinx.config import Config
|
from sphinx.config import Config
|
||||||
from sphinx.errors import SphinxError, ThemeError
|
from sphinx.errors import SphinxError
|
||||||
from sphinx.testing.util import strip_escseq
|
from sphinx.testing.util import strip_escseq
|
||||||
from sphinx.util import docutils
|
from sphinx.util import docutils
|
||||||
from sphinx.util.osutil import cd, ensuredir
|
from sphinx.util.osutil import cd, ensuredir
|
||||||
|
@ -10,9 +10,7 @@
|
|||||||
|
|
||||||
import http.server
|
import http.server
|
||||||
import json
|
import json
|
||||||
import re
|
|
||||||
import textwrap
|
import textwrap
|
||||||
from unittest import mock
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
@ -112,6 +110,7 @@ def test_anchors_ignored(app):
|
|||||||
# expect all ok when excluding #top
|
# expect all ok when excluding #top
|
||||||
assert not content
|
assert not content
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver-anchor', freshenv=True)
|
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver-anchor', freshenv=True)
|
||||||
def test_raises_for_invalid_status(app):
|
def test_raises_for_invalid_status(app):
|
||||||
class InternalServerErrorHandler(http.server.BaseHTTPRequestHandler):
|
class InternalServerErrorHandler(http.server.BaseHTTPRequestHandler):
|
||||||
@ -137,6 +136,7 @@ class HeadersDumperHandler(http.server.BaseHTTPRequestHandler):
|
|||||||
self.end_headers()
|
self.end_headers()
|
||||||
print(self.headers.as_string())
|
print(self.headers.as_string())
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx(
|
@pytest.mark.sphinx(
|
||||||
'linkcheck', testroot='linkcheck-localserver', freshenv=True,
|
'linkcheck', testroot='linkcheck-localserver', freshenv=True,
|
||||||
confoverrides={'linkcheck_auth': [
|
confoverrides={'linkcheck_auth': [
|
||||||
@ -212,6 +212,7 @@ def test_linkcheck_request_headers_default(app, capsys):
|
|||||||
assert "Accepts: application/json\n" not in stdout
|
assert "Accepts: application/json\n" not in stdout
|
||||||
assert "X-Secret: open sesami\n" in stdout
|
assert "X-Secret: open sesami\n" in stdout
|
||||||
|
|
||||||
|
|
||||||
def make_redirect_handler(*, support_head):
|
def make_redirect_handler(*, support_head):
|
||||||
class RedirectOnceHandler(http.server.BaseHTTPRequestHandler):
|
class RedirectOnceHandler(http.server.BaseHTTPRequestHandler):
|
||||||
def do_HEAD(self):
|
def do_HEAD(self):
|
||||||
@ -235,6 +236,7 @@ def make_redirect_handler(*, support_head):
|
|||||||
|
|
||||||
return RedirectOnceHandler
|
return RedirectOnceHandler
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver', freshenv=True)
|
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver', freshenv=True)
|
||||||
def test_follows_redirects_on_HEAD(app, capsys):
|
def test_follows_redirects_on_HEAD(app, capsys):
|
||||||
with http_server(make_redirect_handler(support_head=True)):
|
with http_server(make_redirect_handler(support_head=True)):
|
||||||
@ -252,6 +254,7 @@ def test_follows_redirects_on_HEAD(app, capsys):
|
|||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver', freshenv=True)
|
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver', freshenv=True)
|
||||||
def test_follows_redirects_on_GET(app, capsys):
|
def test_follows_redirects_on_GET(app, capsys):
|
||||||
with http_server(make_redirect_handler(support_head=False)):
|
with http_server(make_redirect_handler(support_head=False)):
|
||||||
@ -280,6 +283,7 @@ class OKHandler(http.server.BaseHTTPRequestHandler):
|
|||||||
self.do_HEAD()
|
self.do_HEAD()
|
||||||
self.wfile.write(b"ok\n")
|
self.wfile.write(b"ok\n")
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver-https', freshenv=True)
|
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver-https', freshenv=True)
|
||||||
def test_invalid_ssl(app):
|
def test_invalid_ssl(app):
|
||||||
# Link indicates SSL should be used (https) but the server does not handle it.
|
# Link indicates SSL should be used (https) but the server does not handle it.
|
||||||
@ -294,6 +298,7 @@ def test_invalid_ssl(app):
|
|||||||
assert content["uri"] == "https://localhost:7777/"
|
assert content["uri"] == "https://localhost:7777/"
|
||||||
assert "SSLError" in content["info"]
|
assert "SSLError" in content["info"]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver-https', freshenv=True)
|
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver-https', freshenv=True)
|
||||||
def test_connect_to_selfsigned_fails(app):
|
def test_connect_to_selfsigned_fails(app):
|
||||||
with https_server(OKHandler):
|
with https_server(OKHandler):
|
||||||
@ -307,6 +312,7 @@ def test_connect_to_selfsigned_fails(app):
|
|||||||
assert content["uri"] == "https://localhost:7777/"
|
assert content["uri"] == "https://localhost:7777/"
|
||||||
assert "[SSL: CERTIFICATE_VERIFY_FAILED]" in content["info"]
|
assert "[SSL: CERTIFICATE_VERIFY_FAILED]" in content["info"]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver-https', freshenv=True)
|
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver-https', freshenv=True)
|
||||||
def test_connect_to_selfsigned_with_tls_verify_false(app):
|
def test_connect_to_selfsigned_with_tls_verify_false(app):
|
||||||
app.config.tls_verify = False
|
app.config.tls_verify = False
|
||||||
@ -324,6 +330,7 @@ def test_connect_to_selfsigned_with_tls_verify_false(app):
|
|||||||
"info": "",
|
"info": "",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver-https', freshenv=True)
|
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver-https', freshenv=True)
|
||||||
def test_connect_to_selfsigned_with_tls_cacerts(app):
|
def test_connect_to_selfsigned_with_tls_cacerts(app):
|
||||||
app.config.tls_cacerts = CERT_FILE
|
app.config.tls_cacerts = CERT_FILE
|
||||||
@ -341,6 +348,7 @@ def test_connect_to_selfsigned_with_tls_cacerts(app):
|
|||||||
"info": "",
|
"info": "",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver-https', freshenv=True)
|
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver-https', freshenv=True)
|
||||||
def test_connect_to_selfsigned_with_requests_env_var(app):
|
def test_connect_to_selfsigned_with_requests_env_var(app):
|
||||||
with modify_env(REQUESTS_CA_BUNDLE=CERT_FILE), https_server(OKHandler):
|
with modify_env(REQUESTS_CA_BUNDLE=CERT_FILE), https_server(OKHandler):
|
||||||
@ -357,6 +365,7 @@ def test_connect_to_selfsigned_with_requests_env_var(app):
|
|||||||
"info": "",
|
"info": "",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver-https', freshenv=True)
|
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver-https', freshenv=True)
|
||||||
def test_connect_to_selfsigned_nonexistent_cert_file(app):
|
def test_connect_to_selfsigned_nonexistent_cert_file(app):
|
||||||
app.config.tls_cacerts = "does/not/exist"
|
app.config.tls_cacerts = "does/not/exist"
|
||||||
|
@ -521,7 +521,7 @@ def test_attributes():
|
|||||||
|
|
||||||
|
|
||||||
def filter_warnings(warning, file):
|
def filter_warnings(warning, file):
|
||||||
lines = warning.getvalue().split("\n");
|
lines = warning.getvalue().split("\n")
|
||||||
res = [l for l in lines if "domain-c" in l and "{}.rst".format(file) in l and
|
res = [l for l in lines if "domain-c" in l and "{}.rst".format(file) in l and
|
||||||
"WARNING: document isn't included in any toctree" not in l]
|
"WARNING: document isn't included in any toctree" not in l]
|
||||||
print("Filtered warnings for file '{}':".format(file))
|
print("Filtered warnings for file '{}':".format(file))
|
||||||
@ -602,6 +602,7 @@ def _get_obj(app, queryName):
|
|||||||
return (docname, anchor, objectType)
|
return (docname, anchor, objectType)
|
||||||
return (queryName, "not", "found")
|
return (queryName, "not", "found")
|
||||||
|
|
||||||
|
|
||||||
def test_cfunction(app):
|
def test_cfunction(app):
|
||||||
text = (".. c:function:: PyObject* "
|
text = (".. c:function:: PyObject* "
|
||||||
"PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)")
|
"PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)")
|
||||||
|
@ -707,7 +707,6 @@ def test_class_definitions():
|
|||||||
check('class', 'template<class T> {key}has_var<T, std::void_t<decltype(&T::var)>>',
|
check('class', 'template<class T> {key}has_var<T, std::void_t<decltype(&T::var)>>',
|
||||||
{2: 'I0E7has_varI1TNSt6void_tIDTadN1T3varEEEEE'})
|
{2: 'I0E7has_varI1TNSt6void_tIDTadN1T3varEEEEE'})
|
||||||
|
|
||||||
|
|
||||||
check('class', 'template<typename ...Ts> {key}T<int (*)(Ts)...>',
|
check('class', 'template<typename ...Ts> {key}T<int (*)(Ts)...>',
|
||||||
{2: 'IDpE1TIJPFi2TsEEE'})
|
{2: 'IDpE1TIJPFi2TsEEE'})
|
||||||
check('class', 'template<int... Is> {key}T<(Is)...>',
|
check('class', 'template<int... Is> {key}T<(Is)...>',
|
||||||
|
@ -333,7 +333,7 @@ def test_multiple_cmdoptions(app):
|
|||||||
def test_productionlist(app, status, warning):
|
def test_productionlist(app, status, warning):
|
||||||
app.builder.build_all()
|
app.builder.build_all()
|
||||||
|
|
||||||
warnings = warning.getvalue().split("\n");
|
warnings = warning.getvalue().split("\n")
|
||||||
assert len(warnings) == 2
|
assert len(warnings) == 2
|
||||||
assert warnings[-1] == ''
|
assert warnings[-1] == ''
|
||||||
assert "Dup2.rst:4: WARNING: duplicate token description of Dup, other instance in Dup1" in warnings[0]
|
assert "Dup2.rst:4: WARNING: duplicate token description of Dup, other instance in Dup1" in warnings[0]
|
||||||
|
@ -177,7 +177,6 @@ def test_format_signature(app):
|
|||||||
for C in (D, E):
|
for C in (D, E):
|
||||||
assert formatsig('class', 'D', C, None, None) == '()'
|
assert formatsig('class', 'D', C, None, None) == '()'
|
||||||
|
|
||||||
|
|
||||||
class SomeMeta(type):
|
class SomeMeta(type):
|
||||||
def __call__(cls, a, b=None):
|
def __call__(cls, a, b=None):
|
||||||
return type.__call__(cls, a, b)
|
return type.__call__(cls, a, b)
|
||||||
@ -209,7 +208,6 @@ def test_format_signature(app):
|
|||||||
assert formatsig('class', 'C', C, None, None) == '(a, b=None)'
|
assert formatsig('class', 'C', C, None, None) == '(a, b=None)'
|
||||||
assert formatsig('class', 'C', D, 'a, b', 'X') == '(a, b) -> X'
|
assert formatsig('class', 'C', D, 'a, b', 'X') == '(a, b) -> X'
|
||||||
|
|
||||||
|
|
||||||
class ListSubclass(list):
|
class ListSubclass(list):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -219,7 +217,6 @@ def test_format_signature(app):
|
|||||||
else:
|
else:
|
||||||
assert formatsig('class', 'C', ListSubclass, None, None) == ''
|
assert formatsig('class', 'C', ListSubclass, None, None) == ''
|
||||||
|
|
||||||
|
|
||||||
class ExceptionSubclass(Exception):
|
class ExceptionSubclass(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -227,7 +224,6 @@ def test_format_signature(app):
|
|||||||
if getattr(Exception, '__text_signature__', None) is None:
|
if getattr(Exception, '__text_signature__', None) is None:
|
||||||
assert formatsig('class', 'C', ExceptionSubclass, None, None) == ''
|
assert formatsig('class', 'C', ExceptionSubclass, None, None) == ''
|
||||||
|
|
||||||
|
|
||||||
# __init__ have signature at first line of docstring
|
# __init__ have signature at first line of docstring
|
||||||
directive.env.config.autoclass_content = 'both'
|
directive.env.config.autoclass_content = 'both'
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
import http.server
|
import http.server
|
||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
from io import BytesIO
|
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -1070,7 +1070,7 @@ Methods:
|
|||||||
|
|
||||||
|
|
||||||
description
|
description
|
||||||
"""
|
""" # NOQA
|
||||||
config = Config()
|
config = Config()
|
||||||
actual = str(GoogleDocstring(docstring, config=config, app=None, what='module',
|
actual = str(GoogleDocstring(docstring, config=config, app=None, what='module',
|
||||||
options={'noindex': True}))
|
options={'noindex': True}))
|
||||||
|
@ -17,7 +17,6 @@ from docutils.parsers.rst import Parser as RstParser
|
|||||||
from sphinx import addnodes
|
from sphinx import addnodes
|
||||||
from sphinx.builders.html.transforms import KeyboardTransform
|
from sphinx.builders.html.transforms import KeyboardTransform
|
||||||
from sphinx.builders.latex import LaTeXBuilder
|
from sphinx.builders.latex import LaTeXBuilder
|
||||||
from sphinx.builders.latex.theming import ThemeFactory
|
|
||||||
from sphinx.roles import XRefRole
|
from sphinx.roles import XRefRole
|
||||||
from sphinx.testing.util import Struct, assert_node
|
from sphinx.testing.util import Struct, assert_node
|
||||||
from sphinx.transforms import SphinxSmartQuotes
|
from sphinx.transforms import SphinxSmartQuotes
|
||||||
|
@ -13,7 +13,6 @@ from collections import OrderedDict
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from sphinx.project import Project
|
from sphinx.project import Project
|
||||||
from sphinx.testing.comparer import PathComparer
|
|
||||||
|
|
||||||
|
|
||||||
def test_project_discover(rootdir):
|
def test_project_discover(rootdir):
|
||||||
|
@ -19,6 +19,7 @@ from sphinx.pycode import ModuleAnalyzer
|
|||||||
|
|
||||||
SPHINX_MODULE_PATH = os.path.splitext(sphinx.__file__)[0] + '.py'
|
SPHINX_MODULE_PATH = os.path.splitext(sphinx.__file__)[0] + '.py'
|
||||||
|
|
||||||
|
|
||||||
def test_ModuleAnalyzer_get_module_source():
|
def test_ModuleAnalyzer_get_module_source():
|
||||||
assert ModuleAnalyzer.get_module_source('sphinx') == (sphinx.__file__, sphinx.__loader__.get_source('sphinx'))
|
assert ModuleAnalyzer.get_module_source('sphinx') == (sphinx.__file__, sphinx.__loader__.get_source('sphinx'))
|
||||||
|
|
||||||
|
@ -14,8 +14,7 @@ from unittest.mock import patch
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import sphinx
|
from sphinx.errors import ExtensionError
|
||||||
from sphinx.errors import ExtensionError, PycodeError
|
|
||||||
from sphinx.testing.util import strip_escseq
|
from sphinx.testing.util import strip_escseq
|
||||||
from sphinx.util import (SkipProgressMessage, display_chunk, encode_uri, ensuredir,
|
from sphinx.util import (SkipProgressMessage, display_chunk, encode_uri, ensuredir,
|
||||||
import_object, logging, parselinenos, progress_message,
|
import_object, logging, parselinenos, progress_message,
|
||||||
|
@ -19,7 +19,7 @@ import _testcapi
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from sphinx.util import inspect
|
from sphinx.util import inspect
|
||||||
from sphinx.util.inspect import is_builtin_class_method, stringify_signature
|
from sphinx.util.inspect import stringify_signature
|
||||||
|
|
||||||
|
|
||||||
def test_signature():
|
def test_signature():
|
||||||
|
@ -10,8 +10,7 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
from numbers import Integral
|
from numbers import Integral
|
||||||
from typing import (Any, Callable, Dict, Generator, Generic, List, Optional, Tuple, TypeVar,
|
from typing import Any, Callable, Dict, Generator, List, Optional, Tuple, TypeVar, Union
|
||||||
Union)
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -25,8 +24,10 @@ class MyClass1:
|
|||||||
class MyClass2(MyClass1):
|
class MyClass2(MyClass1):
|
||||||
__qualname__ = '<MyClass2>'
|
__qualname__ = '<MyClass2>'
|
||||||
|
|
||||||
|
|
||||||
T = TypeVar('T')
|
T = TypeVar('T')
|
||||||
|
|
||||||
|
|
||||||
class MyList(List[T]):
|
class MyList(List[T]):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -132,8 +133,8 @@ def test_stringify_type_hints_containers():
|
|||||||
|
|
||||||
@pytest.mark.skipif(sys.version_info < (3, 9), reason='python 3.9+ is required.')
|
@pytest.mark.skipif(sys.version_info < (3, 9), reason='python 3.9+ is required.')
|
||||||
def test_stringify_Annotated():
|
def test_stringify_Annotated():
|
||||||
from typing import Annotated
|
from typing import Annotated # type: ignore
|
||||||
assert stringify(Annotated[str, "foo", "bar"]) == "str"
|
assert stringify(Annotated[str, "foo", "bar"]) == "str" # NOQA
|
||||||
|
|
||||||
|
|
||||||
def test_stringify_type_hints_string():
|
def test_stringify_type_hints_string():
|
||||||
|
@ -77,7 +77,7 @@ def f14() -> Any:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def f15(x: "Unknown", y: "int") -> Any:
|
def f15(x: "Unknown", y: "int") -> Any: # type: ignore # NOQA
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user