blob: f4d8c80b725cd359b8290a42f18d8ec49f1dc607 (
plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
|
"""Snapshot suite for every public library validator.
Each :class:`edify.Pattern` exposed by :mod:`edify.library` has a committed
``.to_regex_string()`` snapshot under ``tests/snapshots/library/<name>.regex``.
Set ``EDIFY_UPDATE_SNAPSHOTS=1`` to regenerate the corpus in one pytest run
after an intentional compile-path change.
"""
from collections.abc import Iterator
from pathlib import Path
import pytest
import edify.library as library_module
from edify import Pattern
from edify.testing import assert_snapshot
_SNAPSHOT_ROOT = Path(__file__).parent.parent / "snapshots" / "library"
def _registered_patterns() -> Iterator[tuple[str, Pattern]]:
for name in sorted(dir(library_module)):
if name.startswith("_"):
continue
value = getattr(library_module, name)
if isinstance(value, Pattern):
yield name, value
REGISTERED_PATTERNS: list[tuple[str, Pattern]] = list(_registered_patterns())
@pytest.mark.parametrize(
("name", "pattern"),
REGISTERED_PATTERNS,
ids=[registered_name for registered_name, _ in REGISTERED_PATTERNS],
)
def test_library_pattern_emits_the_snapshotted_regex(name: str, pattern: Pattern):
snapshot_path = _SNAPSHOT_ROOT / f"{name}.regex"
emitted = pattern.to_regex_string()
assert_snapshot(emitted, snapshot_path)
|