| 1 |
"""Test the images generated from building the documentation.""" |
| 2 |
|
| 3 |
from __future__ import annotations |
| 4 |
|
| 5 |
from pathlib import Path |
| 6 |
from xml.etree.ElementTree import parse |
| 7 |
|
| 8 |
import pytest |
| 9 |
|
| 10 |
ROOT_DIR = str(Path(__file__).parent.parent.parent) |
| 11 |
BUILD_DIR = str(Path(ROOT_DIR) / 'doc' / '_build') |
| 12 |
HTML_DIR = str(Path(BUILD_DIR) / 'html') |
| 13 |
|
| 14 |
|
| 15 |
# Same value as `sphinx_gallery_conf['junit']` in `conf.py` |
| 16 |
SPHINX_GALLERY_CONF_JUNIT = Path('sphinx-gallery') / 'junit-results.xml' |
| 17 |
SPHINX_GALLERY_EXAMPLE_MAX_TIME = 150.0 # Measured in seconds |
| 18 |
XML_FILE = HTML_DIR / SPHINX_GALLERY_CONF_JUNIT |
| 19 |
assert XML_FILE.is_file() |
| 20 |
|
| 21 |
|
| 22 |
xml_root = parse(XML_FILE).getroot() |
| 23 |
test_cases = [dict(case.attrib) for case in xml_root.iterfind('testcase')] |
| 24 |
test_ids = [case['classname'] for case in test_cases] |
| 25 |
|
| 26 |
|
| 27 |
@pytest.mark.parametrize('testcase', test_cases, ids=test_ids) |
| 28 |
def test_sphinx_gallery_execution_times(testcase): |
| 29 |
if float(testcase['time']) > SPHINX_GALLERY_EXAMPLE_MAX_TIME: |
| 30 |
pytest.fail( |
| 31 |
f'Gallery example {testcase["name"]!r} from {testcase["file"]!r}\n' |
| 32 |
f'Took too long to run: ' |
| 33 |
f'Duration {testcase["time"]}s > {SPHINX_GALLERY_EXAMPLE_MAX_TIME}s', |
| 34 |
) |