1"""Access to examples of components."""
2
3from __future__ import annotations
4
5from pathlib import Path
6
7
8def get_example(component_directory: str, example_name: str) -> bytes:
9 """Return an example and raise an error if it is absent."""
10 here = Path(__file__).parent.parent
11 examples = here / "tests" / component_directory
12 if not example_name.endswith(".ics"):
13 example_name = example_name + ".ics"
14 example_file = examples / example_name
15 if not example_file.is_file():
16 raise ValueError(
17 f"Example {example_name} for {component_directory} not found. "
18 f"You can use one of {', '.join(p.name for p in examples.iterdir())}"
19 )
20 return Path(example_file).read_bytes()
21
22
23__all__ = ["get_example"]