File: conftest.py

package info (click to toggle)
sphinx 8.2.3-12
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 26,960 kB
  • sloc: python: 105,864; javascript: 6,474; perl: 449; makefile: 178; sh: 37; xml: 19; ansic: 2
file content (28 lines) | stat: -rw-r--r-- 639 bytes parent folder | download | duplicates (18)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from __future__ import annotations

from typing import TYPE_CHECKING

import pytest

from sphinx.testing.util import etree_parse

if TYPE_CHECKING:
    from collections.abc import Callable, Iterator
    from pathlib import Path
    from xml.etree.ElementTree import ElementTree

_etree_cache: dict[Path, ElementTree] = {}


def _parse(path: Path) -> ElementTree:
    if path in _etree_cache:
        return _etree_cache[path]

    _etree_cache[path] = tree = etree_parse(path)
    return tree


@pytest.fixture(scope='package')
def cached_etree_parse() -> Iterator[Callable[[Path], ElementTree]]:
    yield _parse
    _etree_cache.clear()