Skip to content

Commit

Permalink
Read the file once; loop over checkers
Browse files Browse the repository at this point in the history
  • Loading branch information
JokeWaumans committed Jun 25, 2024
1 parent 5e29ef3 commit 0a0004e
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions src/mlx/warnings/polyspace_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ def check(self, content, **kwargs):
# set colomn names to lowercase
reader.fieldnames = [name.lower() for name in reader.fieldnames]

for checker in self.checkers:
checker.check(reader)
for row in reader:
for checker in self.checkers:
if row['family'].lower() == checker.family_value:
if row[checker.colomn_name].lower() == checker.check_value:
checker.count = checker.count + 1

def return_count(self):
''' Getter function for the amount of warnings found
Expand All @@ -42,7 +45,8 @@ def return_count(self):
'''
self.count = 0
for checker in self.checkers:
self.count += checker.return_count()
print("{0.count} warnings found for '{0.colomn_name}: {0.check_value}'".format(checker))
self.count += checker.count
return self.count

def return_check_limits(self):
Expand All @@ -67,6 +71,9 @@ def return_check_limits(self):
else:
print("Number of warnings ({0.count}) is between limits {0.warn_min} and {0.warn_max}. Well done."
.format(self))
self.warn_min = 0
self.warn_max = 0
self.count = check_failures
return check_failures

def parse_config(self, config):
Expand Down Expand Up @@ -125,19 +132,6 @@ def __init__(self, family_value, colomn_name, check_value, minimum, maximum):
self.maximum = maximum
self.count = 0

def check(self, reader):
""" Function for counting the number the specified value to be checked in a specified colomn of the
TSV/CSV file.
Args:
reader (csv.DictReader): The DictReader class of csv library
"""
for row in reader:
if row['family'] == self.family_value:

if row[self.colomn_name].lower() == self.check_value:
self.count += 1

def get_minimum(self):
''' Gets the lowest minimum amount of warnings
Expand All @@ -153,11 +147,3 @@ def get_maximum(self):
int: the highest maximum for warnings
'''
return self.maximum

def return_count(self):
''' Getter function for the amount of warnings found
Returns:
int: Number of warnings found
'''
return self.count

0 comments on commit 0a0004e

Please sign in to comment.