diff --git a/tests/conftest.py b/tests/conftest.py index a6d1ff9..07e8a78 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -10,7 +10,7 @@ import tempfile import pytest -from pathlib import Path +import sphinx pytest_plugins = 'sphinx.testing.fixtures' @@ -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' diff --git a/tests/test_ext.py b/tests/test_ext.py index 8275c0a..afd9ba5 100644 --- a/tests/test_ext.py +++ b/tests/test_ext.py @@ -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() @@ -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', @@ -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', @@ -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', ]: @@ -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', ]: