Coverage for src/castep_linter/error_logging/xml_writer.py: 23%
16 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-23 18:07 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-23 18:07 +0000
1"""Module to write code linting errors in JUnit XML format"""
2from pathlib import Path
3from typing import Dict
5from junitparser import Error, JUnitXml, Skipped, TestCase, TestSuite # type: ignore
7from castep_linter.error_logging.logger import ErrorLogger
10def 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)
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)
24 xml.add_testsuite(suite)
26 xml.write(file)