Coverage for src/castep_linter/error_logging/xml_writer.py: 23%

1"""Module to write code linting errors in JUnit XML format"""

2 from pathlib import Path

3 from typing import Dict

4

5 from junitparser import Error, JUnitXml, Skipped, TestCase, TestSuite # type: ignore

6

7 from castep_linter.error_logging.logger import ErrorLogger

8

9

10 def write_xml(file: Path, error_logs: Dict[str, ErrorLogger], error_level: int):

11 """write code linting errors in JUnit XML format"""

12 xml = JUnitXml()

13 for scanned_file, log in error_logs.items():

14 suite = TestSuite(scanned_file)

15

16 for error in log.errors:

17 case = TestCase(str(error))

18 if error.ERROR_SEVERITY >= error_level:

19 case.result = [Error(error.context(scanned_file, underline=True))]

20 else:

21 case.result = [Skipped(error.context(scanned_file, underline=True))]

22 suite.add_testcase(case)

23

24 xml.add_testsuite(suite)

25

26 xml.write(file)