From 419e145e36a4f12e4dff112f8c4e2dbba2d65995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Freitag?= Date: Fri, 20 Nov 2020 19:04:26 +0100 Subject: [PATCH] Make tests/ a Python package Allows relative imports. --- tests/__init__.py | 0 tests/roots/test-ext-doctest-skipif/conf.py | 2 +- tests/roots/test-ext-doctest/doctest.txt | 2 +- tests/test_build_latex.py | 3 +- tests/test_build_linkcheck.py | 2 +- tests/test_build_texinfo.py | 3 +- tests/test_ext_autodoc_autoattribute.py | 3 +- tests/test_ext_autodoc_autoclass.py | 3 +- tests/test_ext_autodoc_autodata.py | 3 +- tests/test_ext_autodoc_autofunction.py | 3 +- tests/test_ext_autodoc_configs.py | 3 +- tests/test_ext_autodoc_events.py | 3 +- tests/test_ext_autodoc_private_members.py | 3 +- tests/test_ext_intersphinx.py | 5 ++-- tests/test_util_inspect.py | 8 +++--- tests/test_util_typing.py | 32 ++++++++++----------- 16 files changed, 44 insertions(+), 34 deletions(-) create mode 100644 tests/__init__.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/roots/test-ext-doctest-skipif/conf.py b/tests/roots/test-ext-doctest-skipif/conf.py index dfbc06f05..c863dbc01 100644 --- a/tests/roots/test-ext-doctest-skipif/conf.py +++ b/tests/roots/test-ext-doctest-skipif/conf.py @@ -6,7 +6,7 @@ source_suffix = '.txt' 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) ''' diff --git a/tests/roots/test-ext-doctest/doctest.txt b/tests/roots/test-ext-doctest/doctest.txt index e45bc2721..04780cfbb 100644 --- a/tests/roots/test-ext-doctest/doctest.txt +++ b/tests/roots/test-ext-doctest/doctest.txt @@ -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 diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 864f8b37c..69ffa36e0 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -16,7 +16,6 @@ from shutil import copyfile 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 @@ -26,6 +25,8 @@ from sphinx.util import docutils 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', diff --git a/tests/test_build_linkcheck.py b/tests/test_build_linkcheck.py index 965a8576d..c09c81fe0 100644 --- a/tests/test_build_linkcheck.py +++ b/tests/test_build_linkcheck.py @@ -15,7 +15,7 @@ import textwrap 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) diff --git a/tests/test_build_texinfo.py b/tests/test_build_texinfo.py index 18cb42eb5..a18c8c6bf 100644 --- a/tests/test_build_texinfo.py +++ b/tests/test_build_texinfo.py @@ -15,7 +15,6 @@ from subprocess import PIPE, CalledProcessError 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 @@ -23,6 +22,8 @@ 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 diff --git a/tests/test_ext_autodoc_autoattribute.py b/tests/test_ext_autodoc_autoattribute.py index 31dccbd03..8cbabfe5f 100644 --- a/tests/test_ext_autodoc_autoattribute.py +++ b/tests/test_ext_autodoc_autoattribute.py @@ -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') diff --git a/tests/test_ext_autodoc_autoclass.py b/tests/test_ext_autodoc_autoclass.py index f71ffd679..17c7f8944 100644 --- a/tests/test_ext_autodoc_autoclass.py +++ b/tests/test_ext_autodoc_autoclass.py @@ -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') diff --git a/tests/test_ext_autodoc_autodata.py b/tests/test_ext_autodoc_autodata.py index 72665cdba..a4f8ca78a 100644 --- a/tests/test_ext_autodoc_autodata.py +++ b/tests/test_ext_autodoc_autodata.py @@ -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') diff --git a/tests/test_ext_autodoc_autofunction.py b/tests/test_ext_autodoc_autofunction.py index c6a7af7c9..4010e7cee 100644 --- a/tests/test_ext_autodoc_autofunction.py +++ b/tests/test_ext_autodoc_autofunction.py @@ -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') diff --git a/tests/test_ext_autodoc_configs.py b/tests/test_ext_autodoc_configs.py index 4dff7c3db..496059b7c 100644 --- a/tests/test_ext_autodoc_configs.py +++ b/tests/test_ext_autodoc_configs.py @@ -12,10 +12,11 @@ import platform 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' diff --git a/tests/test_ext_autodoc_events.py b/tests/test_ext_autodoc_events.py index 193d6e87b..ad6a81129 100644 --- a/tests/test_ext_autodoc_events.py +++ b/tests/test_ext_autodoc_events.py @@ -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): diff --git a/tests/test_ext_autodoc_private_members.py b/tests/test_ext_autodoc_private_members.py index 88cceefed..6bce5ce78 100644 --- a/tests/test_ext_autodoc_private_members.py +++ b/tests/test_ext_autodoc_private_members.py @@ -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') diff --git a/tests/test_ext_intersphinx.py b/tests/test_ext_intersphinx.py index 63a62aeab..d32970c8b 100644 --- a/tests/test_ext_intersphinx.py +++ b/tests/test_ext_intersphinx.py @@ -15,14 +15,15 @@ from unittest import mock 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): diff --git a/tests/test_util_inspect.py b/tests/test_util_inspect.py index 9243c030d..17070f4d6 100644 --- a/tests/test_util_inspect.py +++ b/tests/test_util_inspect.py @@ -129,8 +129,8 @@ def test_signature_partialmethod(): 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) @@ -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) diff --git a/tests/test_util_typing.py b/tests/test_util_typing.py index 73b4aca53..c81cdaba2 100644 --- a/tests/test_util_typing.py +++ b/tests/test_util_typing.py @@ -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`]" @@ -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.`]") + ":obj:`Union`\\ [:class:`tests.test_util_typing.MyClass1`, :class:`tests.test_util_typing.`]") 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.') @@ -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.`" + assert restify(MyClass1) == ":class:`tests.test_util_typing.MyClass1`" + assert restify(MyClass2) == ":class:`tests.test_util_typing.`" def test_restify_type_hints_alias(): @@ -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(): @@ -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]" @@ -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.]") + "Union[tests.test_util_typing.MyClass1, tests.test_util_typing.]") 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(): @@ -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." + assert stringify(MyClass1) == "tests.test_util_typing.MyClass1" + assert stringify(MyClass2) == "tests.test_util_typing." def test_stringify_type_hints_alias(): @@ -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'