Skip to content

Commit

Permalink
Normalise sys.path manipulation in tests (#12665)
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner authored Jul 23, 2024
1 parent a69ca67 commit 7c4db26
Show file tree
Hide file tree
Showing 37 changed files with 87 additions and 85 deletions.
4 changes: 2 additions & 2 deletions tests/js/roots/titles/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, str(Path.cwd().resolve()))

extensions = ['sphinx.ext.autodoc']
5 changes: 3 additions & 2 deletions tests/roots/test-add_enumerable_node/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, str(Path.cwd().resolve()))

sys.path.insert(0, os.path.abspath('.'))
extensions = ['enumerable_node']

numfig = True
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os
import sys
from pathlib import Path

from docutils.parsers import Parser
sys.path.insert(0, str(Path.cwd().resolve()))

sys.path.insert(0, os.path.abspath('.'))
from docutils.parsers import Parser


class DummyTestParser(Parser):
Expand Down
5 changes: 2 additions & 3 deletions tests/roots/test-add_source_parser/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, os.path.abspath('.'))

sys.path.insert(0, str(Path.cwd().resolve()))

extensions = ['source_parser']
4 changes: 2 additions & 2 deletions tests/roots/test-api-set-translator/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# set this by test
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
# from pathlib import Path
# sys.path.insert(0, str(Path.cwd().resolve()))

from docutils.writers.docutils_xml import XMLTranslator

Expand Down
4 changes: 2 additions & 2 deletions tests/roots/test-api-set-translator/nonext/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, os.path.dirname(os.path.abspath('.')))
sys.path.insert(0, str(Path.cwd().resolve()))

project = 'test'
4 changes: 2 additions & 2 deletions tests/roots/test-autosummary/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, str(Path.cwd().resolve()))

extensions = ['sphinx.ext.autosummary']

Expand Down
5 changes: 3 additions & 2 deletions tests/roots/test-environment-record-dependencies/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, str(Path.cwd().resolve()))

sys.path.insert(0, os.path.abspath('.'))
extensions = ['sphinx.ext.autodoc']
4 changes: 2 additions & 2 deletions tests/roots/test-ext-autodoc/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, str(Path.cwd().resolve()))

extensions = ['sphinx.ext.autodoc']

Expand Down
4 changes: 2 additions & 2 deletions tests/roots/test-ext-autosummary-filename-map/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, str(Path.cwd().resolve()))

extensions = ['sphinx.ext.autosummary']
autosummary_generate = True
Expand Down
4 changes: 2 additions & 2 deletions tests/roots/test-ext-autosummary-import_cycle/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, str(Path.cwd().resolve()))

extensions = ['sphinx.ext.autosummary']
autosummary_generate = False
4 changes: 2 additions & 2 deletions tests/roots/test-ext-autosummary-imported_members/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, str(Path.cwd().resolve()))

extensions = ['sphinx.ext.autosummary']
autosummary_generate = True
Expand Down
4 changes: 2 additions & 2 deletions tests/roots/test-ext-autosummary-mock_imports/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, str(Path.cwd().resolve()))

extensions = ['sphinx.ext.autosummary']
autosummary_generate = True
Expand Down
4 changes: 2 additions & 2 deletions tests/roots/test-ext-autosummary-module_all/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, str(Path.cwd().resolve()))

extensions = ['sphinx.ext.autosummary']
autosummary_generate = True
Expand Down
4 changes: 2 additions & 2 deletions tests/roots/test-ext-autosummary-module_prefix/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, str(Path.cwd().resolve()))

extensions = [
'sphinx.ext.autosummary',
Expand Down
4 changes: 2 additions & 2 deletions tests/roots/test-ext-autosummary-recursive/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, str(Path.cwd().resolve()))

extensions = ['sphinx.ext.autosummary']
autosummary_generate = True
5 changes: 2 additions & 3 deletions tests/roots/test-ext-autosummary-skip-member/conf.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, os.path.abspath('.'))

sys.path.insert(0, str(Path.cwd().resolve()))

extensions = ['sphinx.ext.autosummary']
autosummary_generate = True
Expand Down
5 changes: 2 additions & 3 deletions tests/roots/test-ext-autosummary-template/conf.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, os.path.abspath('.'))

sys.path.insert(0, str(Path.cwd().resolve()))

extensions = ['sphinx.ext.autosummary']
autosummary_generate = True
Expand Down
4 changes: 2 additions & 2 deletions tests/roots/test-ext-autosummary/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, str(Path.cwd().resolve()))

extensions = ['sphinx.ext.autosummary']
autosummary_generate = True
4 changes: 2 additions & 2 deletions tests/roots/test-ext-coverage/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, str(Path.cwd().resolve()))

extensions = ['sphinx.ext.autodoc', 'sphinx.ext.coverage']

Expand Down
4 changes: 2 additions & 2 deletions tests/roots/test-ext-doctest-with-autodoc/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
from os import path
from pathlib import Path

sys.path.insert(0, path.abspath(path.dirname(__file__)))
sys.path.insert(0, str(Path.cwd().resolve()))

project = 'test project for doctest + autodoc reporting'
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest']
5 changes: 3 additions & 2 deletions tests/roots/test-ext-imgmockconverter/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, str(Path.cwd().resolve()))

sys.path.insert(0, os.path.abspath('.'))
extensions = ['mocksvgconverter']
4 changes: 2 additions & 2 deletions tests/roots/test-ext-inheritance_diagram/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, str(Path.cwd().resolve()))

extensions = ['sphinx.ext.inheritance_diagram', 'sphinx.ext.intersphinx']
7 changes: 4 additions & 3 deletions tests/roots/test-ext-napoleon-paramtype/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, str(Path.cwd().resolve()))

sys.path.insert(0, os.path.abspath('.'))
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
Expand All @@ -12,4 +13,4 @@
# in order to avoid creating a real HTTP connection
intersphinx_mapping = {}
intersphinx_cache_limit = 0
intersphinx_disabled_reftypes = []
intersphinx_disabled_reftypes = []
5 changes: 3 additions & 2 deletions tests/roots/test-ext-napoleon/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, str(Path.cwd().resolve()))

sys.path.insert(0, os.path.abspath('.'))
extensions = ['sphinx.ext.napoleon']
7 changes: 3 additions & 4 deletions tests/roots/test-ext-viewcode/conf.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, str(Path.cwd().resolve()))

source_dir = os.path.abspath('.')
if source_dir not in sys.path:
sys.path.insert(0, source_dir)
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode']
exclude_patterns = ['_build']

Expand Down
4 changes: 2 additions & 2 deletions tests/roots/test-extensions/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, str(Path.cwd().resolve()))
4 changes: 2 additions & 2 deletions tests/roots/test-inheritance/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, str(Path.cwd().resolve()))

extensions = ['sphinx.ext.inheritance_diagram']
4 changes: 2 additions & 2 deletions tests/roots/test-latex-labels-before-module/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, str(Path.cwd().resolve()))

extensions = ['sphinx.ext.autodoc']

Expand Down
5 changes: 2 additions & 3 deletions tests/roots/test-prolog/conf.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, os.path.abspath('.'))

sys.path.insert(0, str(Path.cwd().resolve()))

extensions = ['prolog_markdown_parser']

Expand Down
6 changes: 3 additions & 3 deletions tests/roots/test-root/conf.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import os
import sys
from pathlib import Path

sys.path.insert(0, str(Path.cwd().resolve()))

from docutils import nodes
from docutils.parsers.rst import Directive

from sphinx import addnodes

sys.path.append(os.path.abspath('.'))

extensions = ['sphinx.ext.autodoc',
'sphinx.ext.todo',
'sphinx.ext.coverage',
Expand Down
5 changes: 3 additions & 2 deletions tests/roots/test-util-copyasset_overwrite/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import sys
sys.path.insert(0, os.path.abspath('.'))
from pathlib import Path

sys.path.insert(0, str(Path.cwd().resolve()))

extensions = ['myext']
html_static_path = ['user_static']
Expand Down
4 changes: 2 additions & 2 deletions tests/roots/test-warnings/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import sys
from pathlib import Path

sys.path.append(os.path.abspath('.'))
sys.path.insert(0, str(Path.cwd().resolve()))

extensions = ['sphinx.ext.autodoc']
4 changes: 2 additions & 2 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ def test_instantiation(
if rootdir and not src_dir.exists():
shutil.copytree(Path(str(rootdir)) / 'test-root', src_dir)

syspath = sys.path[:]
saved_path = sys.path.copy()

# When
app_ = SphinxTestApp(
srcdir=src_dir,
status=StringIO(),
warning=StringIO(),
)
sys.path[:] = syspath
sys.path[:] = saved_path
app_.cleanup()

# Then
Expand Down
5 changes: 3 additions & 2 deletions tests/test_extensions/test_ext_inheritance_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,9 @@ def test_import_classes(rootdir):
from sphinx.parsers import Parser, RSTParser
from sphinx.util.i18n import CatalogInfo

saved_path = sys.path.copy()
sys.path.insert(0, str(rootdir / 'test-ext-inheritance_diagram'))
try:
sys.path.append(str(rootdir / 'test-ext-inheritance_diagram'))
from example.sphinx import DummyClass

# got exception for unknown class or module
Expand Down Expand Up @@ -339,4 +340,4 @@ def test_import_classes(rootdir):
classes = import_classes('sphinx', 'example')
assert classes == [DummyClass]
finally:
sys.path.pop()
sys.path[:] = saved_path
6 changes: 3 additions & 3 deletions tests/test_pycode/test_pycode.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ def test_ModuleAnalyzer_for_module(rootdir):
assert analyzer.srcname in (SPHINX_MODULE_PATH,
os.path.abspath(SPHINX_MODULE_PATH))

path = str(rootdir / 'test-pycode')
sys.path.insert(0, path)
saved_path = sys.path.copy()
sys.path.insert(0, str(rootdir / 'test-pycode'))
try:
analyzer = ModuleAnalyzer.for_module('cp_1251_coded')
docs = analyzer.find_attr_docs()
assert docs == {('', 'X'): ['It MUST look like X="\u0425"', '']}
finally:
sys.path.pop(0)
sys.path[:] = saved_path


def test_ModuleAnalyzer_find_tags():
Expand Down
Loading

0 comments on commit 7c4db26

Please sign in to comment.