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