'
) in html
@pytest.mark.sphinx('epub', testroot='html_assets')
def test_epub_assets(app):
app.build(force_all=True)
# epub_sytlesheets (same as html_css_files)
content = (app.outdir / 'index.xhtml').read_text(encoding='utf8')
assert (
''
) in content
assert (
''
) in content
@pytest.mark.sphinx(
'epub',
testroot='html_assets',
confoverrides={'epub_css_files': ['css/epub.css']},
)
def test_epub_css_files(app):
app.build(force_all=True)
# epub_css_files
content = (app.outdir / 'index.xhtml').read_text(encoding='utf8')
assert (
''
) in content
# files in html_css_files are not outputted
assert (
''
) not in content
assert (
''
) not in content
@pytest.mark.sphinx('epub', testroot='roles-download')
def test_html_download_role(app):
app.build()
assert not (app.outdir / '_downloads' / 'dummy.dat').exists()
content = (app.outdir / 'index.xhtml').read_text(encoding='utf8')
assert (
''
'dummy.dat
'
) in content
assert (
''
'not_found.dat
'
) in content
assert (
''
'Sphinx logo
'
' [https://www.sphinx-doc.org/en/master'
'/_static/sphinx-logo.svg]
'
) in content
@pytest.mark.sphinx('epub', testroot='toctree-duplicated')
def test_duplicated_toctree_entry(app):
app.build(force_all=True)
assert 'WARNING: duplicated ToC entry found: foo.xhtml' in app.warning.getvalue()
@pytest.mark.skipif(
'DO_EPUBCHECK' not in os.environ,
reason='Skipped because DO_EPUBCHECK is not set',
)
@pytest.mark.sphinx('epub', testroot='root')
def test_run_epubcheck(app):
app.build()
if not runnable(['java', '-version']):
pytest.skip('Unable to run Java; skipping test')
epubcheck = Path(os.environ.get('EPUBCHECK_PATH', '/usr/share/java/epubcheck.jar'))
if not epubcheck.exists():
pytest.skip('Could not find epubcheck; skipping test')
try:
subprocess.run(
['java', '-jar', epubcheck, app.outdir / 'SphinxTests.epub'], # NoQA: S607
capture_output=True,
check=True,
)
except CalledProcessError as exc:
print(exc.stdout.decode('utf-8'))
print(exc.stderr.decode('utf-8'))
msg = f'epubcheck exited with return code {exc.returncode}'
raise AssertionError(msg) from exc
def test_xml_name_pattern_check():
assert _XML_NAME_PATTERN.match('id-pub')
assert _XML_NAME_PATTERN.match('webpage')
assert not _XML_NAME_PATTERN.match('1bfda21')
@pytest.mark.usefixtures('_http_teapot')
@pytest.mark.sphinx('epub', testroot='images')
def test_copy_images(app):
app.build()
images_dir = Path(app.outdir) / '_images'
images = {image.name for image in images_dir.rglob('*')}
images.discard('python-logo.png')
assert images == {
# 'ba30773957c3fe046897111afd65a80b81cad089.png', # epub: image from data:image/png URI in source
'img.png',
'rimg.png',
'rimg1.png',
'svgimg.svg',
'testimäge.png',
}