Debian Codegraph @

tests/conftest.py

raw
1 from __future__ import annotations
2
3 from pathlib import Path
4
5 import pytest
6 import sphinx
7 from bs4 import BeautifulSoup
8
9 try:
10 import matplotlib as mpl
11 except ImportError:
12 pass
13 else:
14 mpl.rcParams['figure.max_open_warning'] = 0
15
16 pytest_plugins = ['sphinx.testing.fixtures']
17
18
19 @pytest.fixture(scope='session')
20 def rootdir():
21 if sphinx.version_info[:2] < (7, 2):
22 from sphinx.testing.path import path
23
24 return path(__file__).parent.abspath() / 'roots'
25
26 return Path(__file__).parent.resolve() / 'roots'
27
28
29 @pytest.fixture
30 def content(app):
31 app.build(force_all=True)
32 return app
33
34
35 def _meta_tags(content, subdir=None):
36 if subdir is None:
37 c = (content.outdir / 'index.html').read_text(encoding='utf-8')
38 else:
39 c = (content.outdir / subdir / 'index.html').read_text(encoding='utf-8')
40 return BeautifulSoup(c, 'html.parser').find_all('meta')
41
42
43 def _og_meta_tags(content):
44 return [
45 tag for tag in _meta_tags(content) if tag.get('property', '').startswith('og:')
46 ]
47
48
49 @pytest.fixture
50 def meta_tags(content):
51 return _meta_tags(content)
52
53
54 @pytest.fixture
55 def og_meta_tags(content):
56 return [
57 tag for tag in _meta_tags(content) if tag.get('property', '').startswith('og:')
58 ]
59
60
61 @pytest.fixture
62 def og_meta_tags_sub(content):
63 return [
64 tag
65 for tag in _meta_tags(content, 'sub')
66 if tag.get('property', '').startswith('og:')
67 ]
68
69
70 def pytest_configure(config):
71 config.addinivalue_line('markers', 'sphinx')