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
|
2024-03-25 05:03:44 -05:00
|
|
|
|
|
|
|
from sphinx.testing.util import etree_parse
|
2024-01-17 18:08:30 -06:00
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
2024-04-08 21:26:44 -05:00
|
|
|
from collections.abc import Callable, Iterator
|
2024-01-17 18:08:30 -06:00
|
|
|
from pathlib import Path
|
2024-03-25 05:03:44 -05:00
|
|
|
from xml.etree.ElementTree import ElementTree
|
|
|
|
|
|
|
|
_etree_cache: dict[Path, ElementTree] = {}
|
2024-01-17 18:08:30 -06:00
|
|
|
|
|
|
|
|
2024-03-25 05:03:44 -05:00
|
|
|
def _parse(path: Path) -> ElementTree:
|
|
|
|
if path in _etree_cache:
|
|
|
|
return _etree_cache[path]
|
2024-01-17 18:08:30 -06:00
|
|
|
|
2024-03-25 05:03:44 -05:00
|
|
|
_etree_cache[path] = tree = etree_parse(path)
|
|
|
|
return tree
|
2024-01-17 18:08:30 -06:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='package')
|
2024-04-08 21:26:44 -05:00
|
|
|
def cached_etree_parse() -> Iterator[Callable[[Path], ElementTree]]:
|
2024-01-17 18:08:30 -06:00
|
|
|
yield _parse
|
2024-03-25 05:03:44 -05:00
|
|
|
_etree_cache.clear()
|