-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathconftest.py
64 lines (44 loc) · 1.35 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from __future__ import annotations
from pathlib import Path
import pytest
import sphinx
from bs4 import BeautifulSoup
pytest_plugins = ["sphinx.testing.fixtures"]
@pytest.fixture(scope="session")
def rootdir():
if sphinx.version_info[:2] >= (7, 0):
return Path(__file__).parent.resolve() / "roots"
else:
from sphinx.testing.path import path
return path(__file__).parent.abspath() / "roots"
@pytest.fixture
def content(app):
app.build(force_all=True)
return app
def _meta_tags(content, subdir=None):
if subdir is None:
c = (content.outdir / "index.html").read_text()
else:
c = (content.outdir / subdir / "index.html").read_text()
return BeautifulSoup(c, "html.parser").find_all("meta")
def _og_meta_tags(content):
return [
tag for tag in _meta_tags(content) if tag.get("property", "").startswith("og:")
]
@pytest.fixture
def meta_tags(content):
return _meta_tags(content)
@pytest.fixture
def og_meta_tags(content):
return [
tag for tag in _meta_tags(content) if tag.get("property", "").startswith("og:")
]
@pytest.fixture
def og_meta_tags_sub(content):
return [
tag
for tag in _meta_tags(content, "sub")
if tag.get("property", "").startswith("og:")
]
def pytest_configure(config):
config.addinivalue_line("markers", "sphinx")