dirty
This commit is contained in:
parent
19813d4d45
commit
5c2fb8c32b
20 changed files with 371 additions and 22 deletions
Binary file not shown.
|
|
@ -0,0 +1,117 @@
|
|||
from pathlib import Path
|
||||
import tarfile
|
||||
|
||||
import pytest
|
||||
|
||||
from byteb4rb1e.sphinxcontrib.testing.pytest.fixtures import (
|
||||
mock_sphinx_testapp,
|
||||
mock_sphinx_testsrc_dir
|
||||
)
|
||||
from byteb4rb1e.testing.pytest.decorators import run_in_subprocess_once
|
||||
from byteb4rb1e.testing.pytest.fixtures import mock_system_site_package_dir
|
||||
|
||||
|
||||
|
||||
@run_in_subprocess_once()
|
||||
def test_default(
|
||||
mock_sphinx_testapp,
|
||||
mock_sphinx_testsrc_dir,
|
||||
mock_system_site_package_dir,
|
||||
tmp_path,
|
||||
) -> None:
|
||||
"""
|
||||
"""
|
||||
pkg_dir = mock_system_site_package_dir('dummypkg')
|
||||
|
||||
mock_static_archive = tarfile.open(pkg_dir / 'data.tar', 'w')
|
||||
|
||||
(tmp_path / 'foobar.txt').write_text("Hello world!")
|
||||
|
||||
mock_static_archive.addfile(
|
||||
mock_static_archive.gettarinfo(
|
||||
arcname='foobar.txt',
|
||||
fileobj=(tmp_path / 'foobar.txt').open('r')
|
||||
)
|
||||
)
|
||||
|
||||
mock_static_archive.close()
|
||||
|
||||
app = mock_sphinx_testapp(srcdir=mock_sphinx_testsrc_dir())
|
||||
|
||||
app.setup_extension('byteb4rb1e.sphinxcontrib.ext.html_static_archive')
|
||||
|
||||
app.config['html_static_archive'] = f'pkg://dummypkg/data.tar'
|
||||
|
||||
app.build(force_all=True)
|
||||
|
||||
assert (Path(app.outdir) / '_static' / 'foobar.txt').exists()
|
||||
|
||||
|
||||
@run_in_subprocess_once()
|
||||
def test_compression(
|
||||
mock_sphinx_testapp,
|
||||
mock_sphinx_testsrc_dir,
|
||||
mock_system_site_package_dir,
|
||||
tmp_path,
|
||||
) -> None:
|
||||
"""
|
||||
"""
|
||||
pkg_dir = mock_system_site_package_dir('dummypkg')
|
||||
|
||||
mock_static_archive = tarfile.open(pkg_dir / 'data.tar.gz', 'w:gz')
|
||||
|
||||
(tmp_path / 'foobar.txt').write_text("Hello world!")
|
||||
|
||||
mock_static_archive.addfile(
|
||||
mock_static_archive.gettarinfo(
|
||||
arcname='foobar.txt',
|
||||
fileobj=(tmp_path / 'foobar.txt').open('r')
|
||||
)
|
||||
)
|
||||
|
||||
mock_static_archive.close()
|
||||
|
||||
app = mock_sphinx_testapp(srcdir=mock_sphinx_testsrc_dir())
|
||||
|
||||
app.setup_extension('byteb4rb1e.sphinxcontrib.ext.html_static_archive')
|
||||
|
||||
app.config['html_static_archive'] = f'pkg://dummypkg/data.tar.gz'
|
||||
|
||||
app.build(force_all=True)
|
||||
|
||||
assert (Path(app.outdir) / '_static' / 'foobar.txt').exists()
|
||||
|
||||
|
||||
@run_in_subprocess_once()
|
||||
def test_subdirs(
|
||||
mock_sphinx_testapp,
|
||||
mock_sphinx_testsrc_dir,
|
||||
mock_system_site_package_dir,
|
||||
tmp_path,
|
||||
) -> None:
|
||||
"""
|
||||
"""
|
||||
pkg_dir = mock_system_site_package_dir('dummypkg')
|
||||
|
||||
mock_static_archive = tarfile.open(pkg_dir / 'data.tar.gz', 'w:gz')
|
||||
|
||||
(tmp_path / 'foobar.txt').write_text("Hello world!")
|
||||
|
||||
mock_static_archive.addfile(
|
||||
mock_static_archive.gettarinfo(
|
||||
arcname='foo/bar/foobar.txt',
|
||||
fileobj=(tmp_path / 'foobar.txt').open('r')
|
||||
)
|
||||
)
|
||||
|
||||
mock_static_archive.close()
|
||||
|
||||
app = mock_sphinx_testapp(srcdir=mock_sphinx_testsrc_dir())
|
||||
|
||||
app.setup_extension('byteb4rb1e.sphinxcontrib.ext.html_static_archive')
|
||||
|
||||
app.config['html_static_archive'] = f'pkg://dummypkg/data.tar.gz'
|
||||
|
||||
app.build(force_all=True)
|
||||
|
||||
assert (Path(app.outdir) / '_static' / 'foo' / 'bar' / 'foobar.txt').exists()
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.pytest
|
||||
|
||||
from byteb4rb1e.sphinxcontrib.testing.pytest.fixtures import (
|
||||
mock_sphinx_testapp,
|
||||
mock_sphinx_testsrc_dir
|
||||
)
|
||||
|
||||
|
||||
def test_mock_sphinx_testsrc_dir(mock_sphinx_testsrc_dir):
|
||||
"""
|
||||
"""
|
||||
srcdir = mock_sphinx_testsrc_dir()
|
||||
|
||||
assert (srcdir / 'conf.py').exists()
|
||||
assert (srcdir / 'index.rst').exists()
|
||||
|
||||
|
||||
def test_mock_sphinx_testapp(mock_sphinx_testapp, mock_sphinx_testsrc_dir):
|
||||
"""
|
||||
"""
|
||||
srcdir = mock_sphinx_testsrc_dir()
|
||||
|
||||
app = mock_sphinx_testapp(srcdir=srcdir)
|
||||
|
||||
assert app.builder is not None
|
||||
assert app.srcdir.samefile(srcdir) is False # Should be copied to internal src
|
||||
|
||||
app.build(force_all=True)
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
def test_default() -> None:
|
||||
assert 1 == 1
|
||||
17
tests/integration/conftest.py
Normal file
17
tests/integration/conftest.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
pytest_plugins = ['byteb4rb1e.sphinxcontrib.testing.pytest.fixtures']
|
||||
|
||||
_TESTS_ROOT = Path(__file__).resolve().parent
|
||||
|
||||
def pytest_configure(config):
|
||||
# register an additional marker
|
||||
config.addinivalue_line(
|
||||
"markers", "pytest: test pytest integration"
|
||||
)
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def rootdir() -> Path:
|
||||
return _TESTS_ROOT
|
||||
Loading…
Add table
Add a link
Reference in a new issue