fix(test): retrofit deprecations
pathlib support and sphinx.testing.path deprecation in Sphinx ver. 9 was announced in Sphinx ver. 6 and enabled in Sphinx ver. 7, hence there are three different environment states to support in regards to paths in Sphinx testing environments.
This commit is contained in:
parent
a4fd97b55a
commit
6321c3f11b
2 changed files with 20 additions and 3 deletions
|
|
@ -5,10 +5,25 @@ import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import shutil
|
import shutil
|
||||||
from typing import Any, Tuple, Callable, Iterator, Dict
|
from typing import Any, Tuple, Callable, Iterator, Dict
|
||||||
|
import warnings
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
try:
|
||||||
|
from sphinx.deprecation import RemovedInSphinx90Warning
|
||||||
|
except ImportError:
|
||||||
|
RemovedInSphinx90Warning = None
|
||||||
|
|
||||||
from sphinx.testing.util import SphinxTestApp
|
from sphinx.testing.util import SphinxTestApp
|
||||||
from sphinx.testing.fixtures import make_app, test_params
|
from sphinx.testing.fixtures import make_app, test_params
|
||||||
|
USE_PATHLIB = True
|
||||||
|
with warnings.catch_warnings(record=True) as w:
|
||||||
|
warnings.simplefilter('always')
|
||||||
|
from sphinx.testing.path import path as sphinxtesting_path
|
||||||
|
if w and issubclass(w[-1].message.__class__, RemovedInSphinx90Warning):
|
||||||
|
USE_PATHLIB = True
|
||||||
|
else:
|
||||||
|
USE_PATHLIB = False
|
||||||
|
|
||||||
from byteb4rb1e.testing.pytest.fixtures import current_test
|
from byteb4rb1e.testing.pytest.fixtures import current_test
|
||||||
|
|
||||||
|
|
@ -75,9 +90,10 @@ def mock_sphinx_testapp(
|
||||||
builddir = basedir / 'build'
|
builddir = basedir / 'build'
|
||||||
|
|
||||||
shutil.copytree(kwargs['srcdir'], srcdir, dirs_exist_ok=True)
|
shutil.copytree(kwargs['srcdir'], srcdir, dirs_exist_ok=True)
|
||||||
kwargs['srcdir'] = srcdir
|
|
||||||
|
|
||||||
kwargs.setdefault('builddir', builddir)
|
kwargs['srcdir'] = sphinxtesting_path(srcdir) if not USE_PATHLIB else srcdir
|
||||||
|
|
||||||
|
kwargs.setdefault('builddir', sphinxtesting_path(builddir) if not USE_PATHLIB else builddir)
|
||||||
|
|
||||||
app_ = make_app(*args, **kwargs)
|
app_ = make_app(*args, **kwargs)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
@ -26,6 +27,6 @@ def test_mock_sphinx_testapp(mock_sphinx_testapp, mock_sphinx_testsrc_dir):
|
||||||
app = mock_sphinx_testapp(srcdir=srcdir)
|
app = mock_sphinx_testapp(srcdir=srcdir)
|
||||||
|
|
||||||
assert app.builder is not None
|
assert app.builder is not None
|
||||||
assert app.srcdir.samefile(srcdir) is False # Should be copied to internal src
|
assert Path(app.srcdir).samefile(srcdir) is False # Should be copied to internal src
|
||||||
|
|
||||||
app.build(force_all=True)
|
app.build(force_all=True)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue