mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
29 lines
711 B
Python
29 lines
711 B
Python
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
import pytest
|
|
from html5lib import HTMLParser
|
|
|
|
if TYPE_CHECKING:
|
|
from collections.abc import Callable, Generator
|
|
from pathlib import Path
|
|
from xml.etree.ElementTree import Element
|
|
|
|
etree_cache: dict[Path, Element] = {}
|
|
|
|
|
|
def _parse(fname: Path) -> Element:
|
|
if fname in etree_cache:
|
|
return etree_cache[fname]
|
|
with fname.open('rb') as fp:
|
|
etree = HTMLParser(namespaceHTMLElements=False).parse(fp)
|
|
etree_cache[fname] = etree
|
|
return etree
|
|
|
|
|
|
@pytest.fixture(scope='package')
|
|
def cached_etree_parse() -> Generator[Callable[[Path], Element], None, None]:
|
|
yield _parse
|
|
etree_cache.clear()
|