Coverage for src/susi/utils/yaml.py: 77%

13 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2025-06-13 14:15 +0000

1import os 

2import yaml 

3from ..base.logging import Logging 

4 

5log = Logging.get_logger() 

6 

7 

8def read_yaml(file_path: str) -> dict: 

9 if not os.path.isfile(file_path): 

10 raise RuntimeError('Given file path "{}" is not a file.'.format(file_path)) 

11 

12 with open(file_path, "r") as stream: 

13 return yaml.safe_load(stream) 

14 

15 

16def write(file_path: str, data: dict) -> None: 

17 log.info("Dumping to YAML file: '%s'", file_path) 

18 with open(file_path, 'w') as f: 

19 yaml.safe_dump(data, f)