Coverage for conflog/loaders/xml_loader.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.2.4, created at 2024-01-14 05:52 +0000

1"""XML configuration loader. 

2""" 

3import xml.etree.ElementTree as ET 

4from . import PARAMS 

5 

6def load(conf_file: str) -> dict: 

7 """Get configuration values from XML file. 

8 """ 

9 conf = {} 

10 with open(conf_file, 'r', encoding='utf-8') as stream: 

11 xml_tree = ET.ElementTree(ET.fromstring(stream.read())) 

12 conf_xml = xml_tree.getroot() 

13 for param in PARAMS: 

14 xml_elem = conf_xml.find(param) 

15 if xml_elem is not None: 

16 conf[param] = xml_elem.text 

17 return conf