Skip to content

Commit

Permalink
Use double quotes; Adapt strings to line lenght = 120
Browse files Browse the repository at this point in the history
  • Loading branch information
JokeWaumans committed Dec 16, 2024
1 parent d94412a commit 6fde428
Show file tree
Hide file tree
Showing 20 changed files with 816 additions and 737 deletions.
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
22 changes: 11 additions & 11 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,27 +34,27 @@ 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 self.name.capitalize()

@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.
"""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
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
48 changes: 24 additions & 24 deletions src/mlx/warnings/polyspace_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@


class PolyspaceChecker(WarningsChecker):
name = 'polyspace'
name = "polyspace"
checkers = []

def __init__(self, *logging_args):
'''Constructor to set the default code quality description template to "Polyspace: $check"'''
super().__init__(*logging_args)
self._cq_description_template = Template('Polyspace: $check')
self._cq_description_template = Template("Polyspace: $check")

@property
def cq_findings(self):
''' List[dict]: list of code quality findings'''
"""List[dict]: list of code quality findings"""
for checker in self.checkers:
self._cq_findings.extend(checker.cq_findings)
return self._cq_findings

@property
def cq_description_template(self):
''' Template: string.Template instance based on the configured template string '''
"""Template: string.Template instance based on the configured template string"""
return self._cq_description_template

@cq_description_template.setter
Expand All @@ -37,11 +37,11 @@ def cq_description_template(self, template_obj):

@property
def minimum(self):
''' Gets the lowest minimum amount of warnings
"""Gets the lowest minimum amount of warnings
Returns:
int: the lowest minimum for warnings
'''
"""
if self.checkers:
return min(x.minimum for x in self.checkers)
return 0
Expand All @@ -53,11 +53,11 @@ def minimum(self, minimum):

@property
def maximum(self):
''' Gets the highest minimum amount of warnings
"""Gets the highest minimum amount of warnings
Returns:
int: the highest maximum for warnings
'''
"""
if self.checkers:
return max(x.maximum for x in self.checkers)
return 0
Expand All @@ -68,43 +68,43 @@ def maximum(self, maximum):
checker.maximum = maximum

def check(self, content):
'''
"""
Function for counting the number of failures in a TSV file exported by Polyspace
Args:
content (_io.TextIOWrapper): The open file to parse
'''
"""
if not isinstance(content, TextIOWrapper):
raise TypeError(
f"{self.__class__.__name__} can't handle this type; expected {type(TextIOWrapper)}; got {type(content)}"
)
reader = csv.DictReader(content, dialect='excel-tab')
reader = csv.DictReader(content, dialect="excel-tab")
# set column names to lowercase
reader.fieldnames = [name.lower() for name in reader.fieldnames]

for row in reader:
for checker in self.checkers:
if row['family'].lower() == checker.family_value:
if row["family"].lower() == checker.family_value:
checker.check(row)

def return_count(self):
''' Getter function for the amount of warnings found
"""Getter function for the amount of warnings found
Returns:
int: Number of warnings found
'''
"""
self.count = 0
for checker in self.checkers:
self.count += checker.return_count()
return self.count

def return_check_limits(self):
''' Function for checking whether the warning count is within the configured limits
"""Function for checking whether the warning count is within the configured limits
Returns:
int: 0 if the amount of warnings is within limits, the count of warnings otherwise
(or 1 in case of a count of 0 warnings)
'''
"""
count = 0
for checker in self.checkers:
count += checker.return_check_limits()
Expand All @@ -130,10 +130,10 @@ def parse_config(self, config):
if family_value == "enabled":
continue
if family_value == "cq_description_template":
self.cq_description_template = Template(config['cq_description_template'])
self.cq_description_template = Template(config["cq_description_template"])
continue
if family_value == "cq_default_path":
self.cq_default_path = config['cq_default_path']
self.cq_default_path = config["cq_default_path"]
continue
if family_value == "exclude":
self.add_patterns(config.get("exclude"), self.exclude_patterns)
Expand Down Expand Up @@ -164,7 +164,7 @@ def parse_config(self, config):


class PolyspaceFamilyChecker(WarningsChecker):
name = 'polyspace_sub'
name = "polyspace_sub"
subchecker = True
code_quality_severity = {
"impact: high": "critical",
Expand All @@ -190,19 +190,19 @@ def __init__(self, family_value, column_name, check_value, *logging_args):

@property
def cq_description_template(self):
''' Template: string.Template instance based on the configured template string '''
"""Template: string.Template instance based on the configured template string"""
return self._cq_description_template

@cq_description_template.setter
def cq_description_template(self, template_obj):
self._cq_description_template = template_obj

def add_code_quality_finding(self, row):
'''Add code quality finding
"""Add code quality finding
Args:
row (dict): The row of the warning with the corresponding colomn names
'''
"""
try:
description = self.cq_description_template.substitute(os.environ, **row)
except KeyError as err:
Expand All @@ -222,12 +222,12 @@ def add_code_quality_finding(self, row):
self.cq_findings.append(finding.to_dict())

def check(self, content):
'''
"""
Function for counting the number of failures in a TSV/CSV file exported by Polyspace
Args:
content (dict): The row of the TSV file
'''
"""
if content[self.column_name].lower() == self.check_value:
if content["status"].lower() in ["not a defect", "justified"]:
self.logger.info(f"Excluded defect with ID {content.get('id', None)!r} because the status is "
Expand Down
Loading

0 comments on commit 6fde428

Please sign in to comment.