Skip to content

Commit

Permalink
Merge branch 'master' into check_robot
Browse files Browse the repository at this point in the history
  • Loading branch information
JasperCraeghs authored Dec 16, 2024
2 parents eb4e94e + fd05e60 commit 1b1d3f6
Show file tree
Hide file tree
Showing 24 changed files with 1,161 additions and 761 deletions.
27 changes: 17 additions & 10 deletions docs/design.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Class Diagram
class "CoverityChecker" as mlx.warnings.regex_checker.CoverityChecker {
checkers : dict
count : int
counted_warnings
cq_default_path
cq_description_template
cq_findings
Expand All @@ -34,10 +33,14 @@ Class Diagram
classification
count
cq_description_template
logging_fmt : str
name : str
add_code_quality_finding(match)
check(content)
}
class "DebugOnlyFilter" as mlx.warnings.warnings_checker.DebugOnlyFilter {
filter(record: logging.LogRecord) -> bool
}
class "DoxyChecker" as mlx.warnings.regex_checker.DoxyChecker {
name : str
pattern
Expand All @@ -55,13 +58,13 @@ Class Diagram
class "JUnitChecker" as mlx.warnings.junit_checker.JUnitChecker {
count
name : str
name_repr
check(content)
prepare_tree(root_input)
}
class "PolyspaceChecker" as mlx.warnings.polyspace_checker.PolyspaceChecker {
checkers : list
count : int
counted_warnings
cq_default_path
cq_description_template
cq_findings
Expand All @@ -80,6 +83,7 @@ Class Diagram
count
cq_description_template
family_value
logging_fmt : str
name : str
add_code_quality_finding(row)
check(content)
Expand All @@ -95,7 +99,7 @@ Class Diagram
class "RobotChecker" as mlx.warnings.robot_checker.RobotChecker {
checkers : list
count : int
counted_warnings
logging_fmt : str
maximum
minimum
name : str
Expand All @@ -107,8 +111,10 @@ Class Diagram
class "RobotSuiteChecker" as mlx.warnings.robot_checker.RobotSuiteChecker {
check_suite_name : bool
is_valid_suite_name : bool
logging_fmt : str
name : str
suite_name
suite_name_repr
check(content)
}
class "SphinxChecker" as mlx.warnings.regex_checker.SphinxChecker {
Expand All @@ -120,21 +126,24 @@ Class Diagram
}
class "WarningsChecker" as mlx.warnings.warnings_checker.WarningsChecker {
count : int
counted_warnings
cq_default_path : str
cq_description_template
cq_enabled : bool
cq_findings
exclude_patterns : list
include_patterns : list
is_sub_checker
logger : LoggerAdapter, NoneType, RootLogger
logging_args : tuple
logging_fmt : str
maximum
minimum
name : str
verbose : bool
name_repr
add_patterns(regexes, pattern_container)
{abstract}check(content)
parse_config(config)
return_check_limits(extra)
return_check_limits()
return_count()
}
class "<color:red>WarningsConfigError</color>" as mlx.warnings.exceptions.WarningsConfigError {
Expand All @@ -144,9 +153,8 @@ Class Diagram
count : int
cq_enabled : bool
printout : bool
public_checkers : list
verbose : bool
activate_checker(checker)
public_checkers : tuple
activate_checker(checker_type)
activate_checker_name(name)
check(content)
check_logfile(file)
Expand All @@ -158,7 +166,6 @@ Class Diagram
return_count(name)
toggle_printout(printout)
write_code_quality_report(out_file)
write_counted_warnings(out_file)
}
class "XMLRunnerChecker" as mlx.warnings.regex_checker.XMLRunnerChecker {
name : str
Expand Down
30 changes: 15 additions & 15 deletions src/mlx/warnings/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
""" Melexis fork of warnings plugin """

__all__ = [
'CoverityChecker',
'DoxyChecker',
'Finding',
'JUnitChecker',
'PolyspaceChecker',
'PolyspaceFamilyChecker',
'RobotChecker',
'RobotSuiteChecker',
'SphinxChecker',
'WarningsChecker',
'WarningsPlugin',
'XMLRunnerChecker',
'__version__',
'warnings_wrapper',
'WarningsConfigError',
"CoverityChecker",
"DoxyChecker",
"Finding",
"JUnitChecker",
"PolyspaceChecker",
"PolyspaceFamilyChecker",
"RobotChecker",
"RobotSuiteChecker",
"SphinxChecker",
"WarningsChecker",
"WarningsPlugin",
"XMLRunnerChecker",
"__version__",
"warnings_wrapper",
"WarningsConfigError",
]


Expand Down
2 changes: 1 addition & 1 deletion src/mlx/warnings/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"""
from mlx.warnings.warnings import main

if __name__ == '__main__':
if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion src/mlx/warnings/code_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def fingerprint(self):
4. Step 3 is repeated until a unique hash is obtained.
"""
hashable_string = f"{self.severity}{self.path}{self.description}"
new_hash = hashlib.md5(str(hashable_string).encode('utf-8')).hexdigest()
new_hash = hashlib.md5(str(hashable_string).encode("utf-8")).hexdigest()
while new_hash in self.fingerprints and self.fingerprints[new_hash] != self:
new_hash = hashlib.md5(f"{hashable_string}{new_hash}".encode()).hexdigest()
type(self).fingerprints[new_hash] = self
Expand Down
28 changes: 14 additions & 14 deletions src/mlx/warnings/junit_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@


class JUnitChecker(WarningsChecker):
name = 'junit'
name = "junit"

def check(self, content):
''' Function for counting the number of JUnit failures in a specific text
"""Function for counting the number of JUnit failures in a specific text
Args:
content (str): The content to parse
'''
"""
try:
root_input = etree.fromstring(content.encode('utf-8'))
root_input = etree.fromstring(content.encode("utf-8"))
testsuites_root = self.prepare_tree(root_input)
suites = JUnitXml.fromelem(testsuites_root)
amount_to_exclude = 0
Expand All @@ -34,31 +34,31 @@ def check(self, content):

@property
def name_repr(self):
return "JUnit" if self.name == 'junit' else self.name.capitalize()
return "JUnit" if self.name == "junit" else super().name_repr

@staticmethod
def prepare_tree(root_input):
''' Prepares the tree element by adding a testsuites element as root when missing (to please JUnitXml)
"""Prepares the tree element by adding a testsuites element as root when missing (to please JUnitXml)
Args:
root_input (lxml.etree._Element/xml.etree.ElementTree.Element): Top-level XML element from input file
Returns:
lxml.etree._Element/xml.etree.ElementTree.Element: Top-level XML element with testsuites tag
'''
if root_input.tag.startswith('testsuite') and root_input.find('testcase') is None:
"""
if root_input.tag.startswith("testsuite") and root_input.find("testcase") is None:
testsuites_root = root_input
else:
testsuites_root = etree.Element("testsuites")
testsuites_root.append(root_input)
return testsuites_root

def _check_testcase(self, testcase, extra={}):
""" Handles the check of a test case element by checking if the result is a failure/error.
def _check_testcase(self, testcase):
"""Handles the check of a test case element by checking if the result is a failure/error.
If it is to be excluded by a configured regex, 1 is returned.
Otherwise, when in verbose/output mode, the suite name and test case name are printed/written along with the
failure/error message.
Otherwise, when in verbose/output mode, the suite name and test case name are printed/written
In output mode, the failure/error message is written additionally.
Args:
testcase (junitparser.TestCase): Test case element to check for failure or error
Expand All @@ -69,6 +69,6 @@ def _check_testcase(self, testcase, extra={}):
if isinstance(testcase.result, (Failure, Error)):
if self._is_excluded(testcase.result.message):
return 1
self.logger.info(f'{testcase.classname}.{testcase.name}')
self.logger.debug(f'{testcase.classname}.{testcase.name} | {testcase.result.message}')
self.logger.info(f"{testcase.classname}.{testcase.name}")
self.logger.debug(f"{testcase.classname}.{testcase.name} | {testcase.result.message}")
return 0
Loading

0 comments on commit 1b1d3f6

Please sign in to comment.