Skip to content

Commit 1792aac

Browse files
committed
add test for ePub
1 parent d838dd5 commit 1792aac

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

tests/conftest.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ def content(app):
3232
return app
3333

3434

35-
def _meta_tags(content, subdir=None):
35+
def _meta_tags(content, subdir=None, target='index.html'):
3636
if subdir is None:
37-
c = (content.outdir / 'index.html').read_text(encoding='utf-8')
37+
c = (content.outdir / target).read_text(encoding='utf-8')
3838
else:
39-
c = (content.outdir / subdir / 'index.html').read_text(encoding='utf-8')
39+
c = (content.outdir / subdir / target).read_text(encoding='utf-8')
4040
return BeautifulSoup(c, 'html.parser').find_all('meta')
4141

4242

@@ -53,9 +53,7 @@ def meta_tags(content):
5353

5454
@pytest.fixture
5555
def og_meta_tags(content):
56-
return [
57-
tag for tag in _meta_tags(content) if tag.get('property', '').startswith('og:')
58-
]
56+
return _og_meta_tags(content)
5957

6058

6159
@pytest.fixture

tests/roots/test-simple/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@
88
html_theme = 'basic'
99

1010
ogp_site_url = 'http://example.org/en/latest/'
11+
12+
# needed for ePub build
13+
epub_copyright = 'sphinxext.opengraph team'
14+
version = '1.0'

tests/test_options.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ def test_simple(og_meta_tags):
4242
)
4343

4444

45+
@pytest.mark.sphinx('epub', testroot='simple')
46+
def test_epub(content: Sphinx):
47+
"""ogp tags are disabled for ePub build"""
48+
meta_tags = conftest._meta_tags(content, target='index.xhtml')
49+
og_meta_tags = [tag for tag in meta_tags if tag.get('property', '').startswith('og:')]
50+
assert len(og_meta_tags) == 0
51+
52+
4553
@pytest.mark.sphinx('html', testroot='meta-name-description')
4654
def test_meta_name_description(meta_tags):
4755
og_description = get_tag_content(meta_tags, 'description')

0 commit comments

Comments
 (0)