Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/icalendar/cal/examples.py: 38%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

13 statements  

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"]