Skip to content

Commit

Permalink
Implement assert_equal_annotation()
Browse files Browse the repository at this point in the history
This is basically assertEqual() but pretty prints the annotation in an
easier-to-read format.
  • Loading branch information
lieryan committed Nov 21, 2021
1 parent 9cd95e3 commit dfe82ba
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions ropetest/codeanalyzetest.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ def _annotation_char(offset):

return "".join([_annotation_char(offset) for offset in range(len(code))])

def assert_equal_annotation(self, code, expected, actual):
if expected != actual:
msg = ["Annotation does not match:\n"]
for line, line_exp, line_actual in zip(
code.splitlines(), expected.splitlines(), actual.splitlines()
):
msg.append(" " + line + "\n")
if line_exp != line_actual:
msg.append("e " + line_exp + "\n")
msg.append("a " + line_actual + "\n")
self.fail("".join(msg))

def test_keyword_before_parens(self):
code = dedent("""\
if (a_var).an_attr:
Expand Down Expand Up @@ -294,9 +306,10 @@ def test_is_import_statement(self):
"""))
word_finder = worder.Worder(code)
self.assertEqual(
self._make_offset_annotation(code, word_finder.is_import_statement),
self.assert_equal_annotation(
code,
annotations,
self._make_offset_annotation(code, word_finder.is_import_statement),
)

def test_is_import_statement_finding(self):
Expand Down Expand Up @@ -397,9 +410,10 @@ def test_is_from_statement(self):
"""))
word_finder = worder.Worder(code)
self.assertEqual(
self._make_offset_annotation(code, word_finder.is_from_statement),
self.assert_equal_annotation(
code,
annotations,
self._make_offset_annotation(code, word_finder.is_from_statement),
)

def test_is_from_with_from_import_and_multiline_parens(self):
Expand Down Expand Up @@ -428,9 +442,12 @@ def func(param=1):
"""))
word_finder = worder.Worder(code)
self.assertEqual(
self._make_offset_annotation(code, word_finder.is_function_keyword_parameter),
self.assert_equal_annotation(
code,
annotations,
self._make_offset_annotation(
code, word_finder.is_function_keyword_parameter
),
)

def test_one_letter_is_function_keyword_parameter(self):
Expand Down

0 comments on commit dfe82ba

Please sign in to comment.