Skip to content

Commit

Permalink
tests: Handle Sphinx < 7.2
Browse files Browse the repository at this point in the history
Sphinx 7.2 only supports Python 3.9. We want to support 3.8 for a tad
longer.

Signed-off-by: Stephen Finucane <[email protected]>
  • Loading branch information
stephenfin committed Sep 4, 2023
1 parent 42e2359 commit 9985d6e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
30 changes: 25 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import tempfile

import pytest
from pathlib import Path
import sphinx

pytest_plugins = 'sphinx.testing.fixtures'

Expand All @@ -19,10 +19,30 @@

@pytest.fixture(scope='session')
def sphinx_test_tempdir():
return Path(
os.environ.get('SPHINX_TEST_TEMPDIR',
tempfile.mkdtemp(prefix='apidoc-'))).resolve()
if sphinx.version_info >= (7, 2, 0):
from pathlib import Path

return Path(
os.environ.get(
'SPHINX_TEST_TEMPDIR', tempfile.mkdtemp(prefix='apidoc-'),
)
).resolve()
else:
from sphinx.testing.path import path

return path(
os.environ.get(
'SPHINX_TEST_TEMPDIR', tempfile.mkdtemp(prefix='apidoc-'),
)
).abspath()


@pytest.fixture(scope='session')
def rootdir():
return Path(os.path.dirname(__file__) or '.').resolve() / 'roots'
if sphinx.version_info >= (7, 2, 0):
from pathlib import Path
return Path(os.path.dirname(__file__) or '.').resolve() / 'roots'
else:
from sphinx.testing.path import path

return path(os.path.dirname(__file__) or '.').abspath() / 'roots'
19 changes: 13 additions & 6 deletions tests/test_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,24 @@
from sphinx.util import logging


def is_dir(path):
if sphinx.version_info >= (7, 2, 0):
return path.is_dir()
else:
return path.isdir()


@pytest.mark.sphinx('html', testroot='basics')
def test_basics(app, status, warning):
logging.setup(app, status, warning)
app.builder.build_all()

assert (app.srcdir / 'api').is_dir()
assert is_dir(app.srcdir / 'api')
assert (app.srcdir / 'api' / 'modules.rst').exists()
assert (app.srcdir / 'api' / 'apidoc_dummy_module.rst').exists()
assert not (app.srcdir / 'api' / 'conf.rst').exists()

assert (app.outdir / 'api').is_dir()
assert is_dir(app.outdir / 'api')
assert (app.outdir / 'api' / 'modules.html').exists()
assert (app.outdir / 'api' / 'apidoc_dummy_module.html').exists()
assert not (app.outdir / 'api' / 'conf.html').exists()
Expand All @@ -40,7 +47,7 @@ def test_advanced(app, status, warning):
logging.setup(app, status, warning)
app.builder.build_all()

assert (app.srcdir / 'api').is_dir()
assert is_dir(app.srcdir / 'api')
assert (app.srcdir / 'api' / 'custom.rst').exists()
for module in [
'apidoc_dummy_module.rst',
Expand All @@ -58,7 +65,7 @@ def test_advanced(app, status, warning):
# The 'Module contents' header isn't present if '--module-first' used
assert 'Module contents' not in package_doc

assert (app.outdir / 'api').is_dir()
assert is_dir(app.outdir / 'api')
assert (app.outdir / 'api' / 'custom.html').exists()
for module in [
'apidoc_dummy_module.html',
Expand All @@ -79,7 +86,7 @@ def test_advanced_negative(app, status, warning):
logging.setup(app, status, warning)
app.builder.build_all()

assert (app.srcdir / 'api').is_dir()
assert is_dir(app.srcdir / 'api')
for module in [
'apidoc_dummy_module.rst',
]:
Expand All @@ -94,7 +101,7 @@ def test_advanced_negative(app, status, warning):
# The 'Module contents' header is present if '--module-first' isn't used
assert 'Module contents' in package_doc

assert (app.outdir / 'api').is_dir()
assert is_dir(app.outdir / 'api')
for module in [
'apidoc_dummy_module.html',
]:
Expand Down

0 comments on commit 9985d6e

Please sign in to comment.