sphinx/tests/test_builders/conftest.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

29 lines
639 B
Python
Raw Normal View History

2024-01-17 18:08:30 -06:00
from __future__ import annotations
2024-01-17 18:54:27 -06:00
from typing import TYPE_CHECKING
2024-01-17 18:08:30 -06:00
import pytest
from sphinx.testing.util import etree_parse
2024-01-17 18:08:30 -06:00
if TYPE_CHECKING:
from collections.abc import Callable, Iterator
2024-01-17 18:08:30 -06:00
from pathlib import Path
from xml.etree.ElementTree import ElementTree
_etree_cache: dict[Path, ElementTree] = {}
2024-01-17 18:08:30 -06:00
def _parse(path: Path) -> ElementTree:
if path in _etree_cache:
return _etree_cache[path]
2024-01-17 18:08:30 -06:00
_etree_cache[path] = tree = etree_parse(path)
return tree
2024-01-17 18:08:30 -06:00
@pytest.fixture(scope='package')
def cached_etree_parse() -> Iterator[Callable[[Path], ElementTree]]:
2024-01-17 18:08:30 -06:00
yield _parse
_etree_cache.clear()