Skip to content

Commit

Permalink
panlint: Improve variable naming in _assert_lint_line
Browse files Browse the repository at this point in the history
  • Loading branch information
jrha committed Dec 10, 2024
1 parent ed85b7d commit 8d308f5
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions panc/src/main/scripts/panlint/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,40 +31,40 @@ def setUp(self):
self.maxDiff = None
self.longMessage = True

def _assert_lint_line(self, line, diagnoses, messages, problems, first_line=False):
def _assert_lint_line(self, input_line, input_diagnoses, input_messages, input_problems, input_first_line=False):
"""For a given line of code, assert that the full lint output matches expectations
Parameters:
line (panlint.Line): Line of source code to be linted
diagnoses (list of str): Expected lines of diagnosis markers
messages (list of str): Expected problem descriptions
problems (int): Expected number of problems
first_line (bool): Whether this line should be considered the first line of a file (defaults to False)
input_line (panlint.Line): Line of source code to be linted
input_diagnoses (list of str): Expected lines of diagnosis markers
input_messages (list of str): Expected problem descriptions
input_problems (int): Expected number of problems
input_first_line (bool): Whether this line should be considered the first line of a file (defaults to False)
"""
diagnoses.sort()
input_diagnoses.sort()

r_line, r_first_line = panlint.lint_line(line, [], first_line)
self.assertEqual(len(r_line.problems), problems)
result_line, result_first_line = panlint.lint_line(input_line, [], input_first_line)
self.assertEqual(len(result_line.problems), input_problems)

r_diagnoses = [p.diagnose() for p in r_line.problems]
r_diagnoses.sort()
result_diagnoses = [p.diagnose() for p in result_line.problems]
result_diagnoses.sort()

for d1, d2 in zip(diagnoses, r_diagnoses):
for d1, d2 in zip(input_diagnoses, result_diagnoses):
self.assertEqual(d1, d2)

# If messages is set to None, ignore the contents and just check that is not an empty set
if messages is None:
for p in r_line.problems:
if input_messages is None:
for p in result_line.problems:
self.assertNotEqual(p.message.text, '')
else:
messages.sort()
r_messages = [p.message.text for p in r_line.problems]
r_messages.sort()
for m1, m2 in zip(messages, r_messages):
input_messages.sort()
result_messages = [p.message.text for p in result_line.problems]
result_messages.sort()
for m1, m2 in zip(input_messages, result_messages):
self.assertEqual(m1, m2)

# first_line must ALWAYS be False when returned
self.assertEqual(r_first_line, False)
self.assertEqual(result_first_line, False)

def test_message_ids(self):
line_pattern_ids = [m.id for m in panlint.LINE_PATTERNS.keys()]
Expand Down

0 comments on commit 8d308f5

Please sign in to comment.