mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
27 lines
543 B
Python
27 lines
543 B
Python
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
import pytest
|
|
from html5lib import HTMLParser
|
|
|
|
if TYPE_CHECKING:
|
|
from pathlib import Path
|
|
|
|
etree_cache = {}
|
|
|
|
|
|
def _parse(fname: Path) -> HTMLParser:
|
|
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():
|
|
yield _parse
|
|
etree_cache.clear()
|