Coverage for visailu/verify.py: 100.00%

13 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2024-02-05 19:49:28 +00:00

1"""Verify the YAML file for quiz data.""" 

2 

3import pathlib 

4from typing import Any, no_type_check 

5 

6import yaml 

7 

8from visailu import slugify 

9 

10 

11@no_type_check 

12def verify_path(path: str, options=None) -> tuple[int, str, Any]: 

13 """Verify the path points to a valid YAML file.""" 

14 try: 

15 with pathlib.Path(path).open('rt', encoding='utf-8') as handle: 

16 data = yaml.safe_load(handle) 

17 except (RuntimeError, yaml.scanner.ScannerError) as err: 

18 message = f'path{path} is not a valid YAML file. Details: {slugify(str(err))}' 

19 return 1, message, {} 

20 return 0, '', data