Skip to content

Commit

Permalink
Merge pull request sphinx-doc#8461 from francoisfreitag/flake8-linkcheck
Browse files Browse the repository at this point in the history
Make tests/ a Python package
  • Loading branch information
tk0miya committed Nov 21, 2020
2 parents 13a986b + 419e145 commit a440270
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 34 deletions.
Empty file added tests/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion tests/roots/test-ext-doctest-skipif/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
exclude_patterns = ['_build']

doctest_global_setup = '''
from test_ext_doctest import record
from tests.test_ext_doctest import record
record('doctest_global_setup', 'body', True)
'''
Expand Down
2 changes: 1 addition & 1 deletion tests/roots/test-ext-doctest/doctest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Special directives

.. testcleanup:: *

import test_ext_doctest
from tests import test_ext_doctest
test_ext_doctest.cleanup_call()

non-ASCII result
Expand Down
3 changes: 2 additions & 1 deletion tests/test_build_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from subprocess import PIPE, CalledProcessError

import pytest
from test_build_html import ENV_WARNINGS

from sphinx.builders.latex import default_latex_documents
from sphinx.config import Config
Expand All @@ -26,6 +25,8 @@
from sphinx.util.osutil import cd, ensuredir
from sphinx.writers.latex import LaTeXTranslator

from .test_build_html import ENV_WARNINGS

LATEX_ENGINES = ['pdflatex', 'lualatex', 'xelatex']
DOCCLASSES = ['howto', 'manual']
STYLEFILES = ['article.cls', 'fancyhdr.sty', 'titlesec.sty', 'amsmath.sty',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_build_linkcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import pytest
import requests

from utils import CERT_FILE, http_server, https_server, modify_env
from .utils import CERT_FILE, http_server, https_server, modify_env


@pytest.mark.sphinx('linkcheck', testroot='linkcheck', freshenv=True)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_build_texinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
from unittest.mock import Mock

import pytest
from test_build_html import ENV_WARNINGS

from sphinx.builders.texinfo import default_texinfo_documents
from sphinx.config import Config
from sphinx.testing.util import strip_escseq
from sphinx.util.docutils import new_document
from sphinx.writers.texinfo import TexinfoTranslator

from .test_build_html import ENV_WARNINGS

TEXINFO_WARNINGS = ENV_WARNINGS + """\
%(root)s/index.rst:\\d+: WARNING: unknown option: &option
%(root)s/index.rst:\\d+: WARNING: citation not found: missing
Expand Down
3 changes: 2 additions & 1 deletion tests/test_ext_autodoc_autoattribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import sys

import pytest
from test_ext_autodoc import do_autodoc

from .test_ext_autodoc import do_autodoc


@pytest.mark.sphinx('html', testroot='ext-autodoc')
Expand Down
3 changes: 2 additions & 1 deletion tests/test_ext_autodoc_autoclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import sys

import pytest
from test_ext_autodoc import do_autodoc

from .test_ext_autodoc import do_autodoc


@pytest.mark.sphinx('html', testroot='ext-autodoc')
Expand Down
3 changes: 2 additions & 1 deletion tests/test_ext_autodoc_autodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import sys

import pytest
from test_ext_autodoc import do_autodoc

from .test_ext_autodoc import do_autodoc


@pytest.mark.sphinx('html', testroot='ext-autodoc')
Expand Down
3 changes: 2 additions & 1 deletion tests/test_ext_autodoc_autofunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import sys

import pytest
from test_ext_autodoc import do_autodoc

from .test_ext_autodoc import do_autodoc


@pytest.mark.sphinx('html', testroot='ext-autodoc')
Expand Down
3 changes: 2 additions & 1 deletion tests/test_ext_autodoc_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
import sys

import pytest
from test_ext_autodoc import do_autodoc

from sphinx.testing import restructuredtext

from .test_ext_autodoc import do_autodoc

IS_PYPY = platform.python_implementation() == 'PyPy'


Expand Down
3 changes: 2 additions & 1 deletion tests/test_ext_autodoc_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
"""

import pytest
from test_ext_autodoc import do_autodoc

from sphinx.ext.autodoc import between, cut_lines

from .test_ext_autodoc import do_autodoc


@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_process_docstring(app):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_ext_autodoc_private_members.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"""

import pytest
from test_ext_autodoc import do_autodoc

from .test_ext_autodoc import do_autodoc


@pytest.mark.sphinx('html', testroot='ext-autodoc')
Expand Down
5 changes: 3 additions & 2 deletions tests/test_ext_intersphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@

import pytest
from docutils import nodes
from test_util_inventory import inventory_v2, inventory_v2_not_having_version

from sphinx import addnodes
from sphinx.ext.intersphinx import (INVENTORY_FILENAME, _get_safe_url, _strip_basic_auth,
fetch_inventory, inspect_main, load_mappings,
missing_reference, normalize_intersphinx_mapping)
from sphinx.ext.intersphinx import setup as intersphinx_setup
from utils import http_server

from .test_util_inventory import inventory_v2, inventory_v2_not_having_version
from .utils import http_server


def fake_node(domain, type, target, content, **attrs):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_util_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ def meth2(self, arg1, arg2):


def test_signature_annotations():
from typing_test_data import (Node, f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12,
f13, f14, f15, f16, f17, f18, f19, f20, f21)
from .typing_test_data import (Node, f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12,
f13, f14, f15, f16, f17, f18, f19, f20, f21)

# Class annotations
sig = inspect.signature(f0)
Expand Down Expand Up @@ -226,10 +226,10 @@ def test_signature_annotations():
if (3, 5, 0) <= sys.version_info < (3, 5, 3):
assert stringify_signature(sig) == '(self) -> List[Node]'
else:
assert stringify_signature(sig) == '(self) -> List[typing_test_data.Node]'
assert stringify_signature(sig) == '(self) -> List[tests.typing_test_data.Node]'

sig = inspect.signature(Node.__init__)
assert stringify_signature(sig) == '(self, parent: Optional[typing_test_data.Node]) -> None'
assert stringify_signature(sig) == '(self, parent: Optional[tests.typing_test_data.Node]) -> None'

# show_annotation is False
sig = inspect.signature(f7)
Expand Down
32 changes: 16 additions & 16 deletions tests/test_util_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_restify_type_hints_containers():
assert restify(Tuple[str, str, str]) == ":class:`Tuple`\\ [:class:`str`, :class:`str`, :class:`str`]"
assert restify(Tuple[str, ...]) == ":class:`Tuple`\\ [:class:`str`, ...]"
assert restify(List[Dict[str, Tuple]]) == ":class:`List`\\ [:class:`Dict`\\ [:class:`str`, :class:`Tuple`]]"
assert restify(MyList[Tuple[int, int]]) == ":class:`test_util_typing.MyList`\\ [:class:`Tuple`\\ [:class:`int`, :class:`int`]]"
assert restify(MyList[Tuple[int, int]]) == ":class:`tests.test_util_typing.MyList`\\ [:class:`Tuple`\\ [:class:`int`, :class:`int`]]"
assert restify(Generator[None, None, None]) == ":class:`Generator`\\ [:obj:`None`, :obj:`None`, :obj:`None`]"


Expand All @@ -76,10 +76,10 @@ def test_restify_type_hints_Union():
if sys.version_info >= (3, 7):
assert restify(Union[int, Integral]) == ":obj:`Union`\\ [:class:`int`, :class:`numbers.Integral`]"
assert (restify(Union[MyClass1, MyClass2]) ==
":obj:`Union`\\ [:class:`test_util_typing.MyClass1`, :class:`test_util_typing.<MyClass2>`]")
":obj:`Union`\\ [:class:`tests.test_util_typing.MyClass1`, :class:`tests.test_util_typing.<MyClass2>`]")
else:
assert restify(Union[int, Integral]) == ":class:`numbers.Integral`"
assert restify(Union[MyClass1, MyClass2]) == ":class:`test_util_typing.MyClass1`"
assert restify(Union[MyClass1, MyClass2]) == ":class:`tests.test_util_typing.MyClass1`"


@pytest.mark.skipif(sys.version_info < (3, 7), reason='python 3.7+ is required.')
Expand All @@ -88,15 +88,15 @@ def test_restify_type_hints_typevars():
T_co = TypeVar('T_co', covariant=True)
T_contra = TypeVar('T_contra', contravariant=True)

assert restify(T) == ":obj:`test_util_typing.T`"
assert restify(T_co) == ":obj:`test_util_typing.T_co`"
assert restify(T_contra) == ":obj:`test_util_typing.T_contra`"
assert restify(List[T]) == ":class:`List`\\ [:obj:`test_util_typing.T`]"
assert restify(T) == ":obj:`tests.test_util_typing.T`"
assert restify(T_co) == ":obj:`tests.test_util_typing.T_co`"
assert restify(T_contra) == ":obj:`tests.test_util_typing.T_contra`"
assert restify(List[T]) == ":class:`List`\\ [:obj:`tests.test_util_typing.T`]"


def test_restify_type_hints_custom_class():
assert restify(MyClass1) == ":class:`test_util_typing.MyClass1`"
assert restify(MyClass2) == ":class:`test_util_typing.<MyClass2>`"
assert restify(MyClass1) == ":class:`tests.test_util_typing.MyClass1`"
assert restify(MyClass2) == ":class:`tests.test_util_typing.<MyClass2>`"


def test_restify_type_hints_alias():
Expand All @@ -107,7 +107,7 @@ def test_restify_type_hints_alias():


def test_restify_broken_type_hints():
assert restify(BrokenType) == ':class:`test_util_typing.BrokenType`'
assert restify(BrokenType) == ':class:`tests.test_util_typing.BrokenType`'


def test_stringify():
Expand All @@ -127,7 +127,7 @@ def test_stringify_type_hints_containers():
assert stringify(Tuple[str, str, str]) == "Tuple[str, str, str]"
assert stringify(Tuple[str, ...]) == "Tuple[str, ...]"
assert stringify(List[Dict[str, Tuple]]) == "List[Dict[str, Tuple]]"
assert stringify(MyList[Tuple[int, int]]) == "test_util_typing.MyList[Tuple[int, int]]"
assert stringify(MyList[Tuple[int, int]]) == "tests.test_util_typing.MyList[Tuple[int, int]]"
assert stringify(Generator[None, None, None]) == "Generator[None, None, None]"


Expand Down Expand Up @@ -164,10 +164,10 @@ def test_stringify_type_hints_Union():
if sys.version_info >= (3, 7):
assert stringify(Union[int, Integral]) == "Union[int, numbers.Integral]"
assert (stringify(Union[MyClass1, MyClass2]) ==
"Union[test_util_typing.MyClass1, test_util_typing.<MyClass2>]")
"Union[tests.test_util_typing.MyClass1, tests.test_util_typing.<MyClass2>]")
else:
assert stringify(Union[int, Integral]) == "numbers.Integral"
assert stringify(Union[MyClass1, MyClass2]) == "test_util_typing.MyClass1"
assert stringify(Union[MyClass1, MyClass2]) == "tests.test_util_typing.MyClass1"


def test_stringify_type_hints_typevars():
Expand All @@ -182,8 +182,8 @@ def test_stringify_type_hints_typevars():


def test_stringify_type_hints_custom_class():
assert stringify(MyClass1) == "test_util_typing.MyClass1"
assert stringify(MyClass2) == "test_util_typing.<MyClass2>"
assert stringify(MyClass1) == "tests.test_util_typing.MyClass1"
assert stringify(MyClass2) == "tests.test_util_typing.<MyClass2>"


def test_stringify_type_hints_alias():
Expand All @@ -194,4 +194,4 @@ def test_stringify_type_hints_alias():


def test_stringify_broken_type_hints():
assert stringify(BrokenType) == 'test_util_typing.BrokenType'
assert stringify(BrokenType) == 'tests.test_util_typing.BrokenType'

0 comments on commit a440270

Please sign in to comment.