Skip to content

Commit

Permalink
assert: _diff_text: use repr() with line endings (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Mar 5, 2020
1 parent bc95201 commit b00435e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/_pytest/assertion/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ def _diff_text(left: str, right: str, verbose: int = 0) -> List[str]:
wcwidth(ch) <= 0
for ch in [ch for lines in left_lines + right_lines for ch in lines]
):
left_lines = [repr(x) for x in left_lines]
right_lines = [repr(x) for x in right_lines]
left_lines = [repr(x) for x in left.splitlines(True)]
right_lines = [repr(x) for x in right.splitlines(True)]
explanation += [
"NOTE: Strings contain non-printable characters. Escaping them using repr()."
]
Expand Down
6 changes: 4 additions & 2 deletions testing/test_assertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -1519,11 +1519,13 @@ def test_diff_different_line_endings():
r" line2",
]

# Only '\r' is considered non-printable
# Only '\r' is considered non-printable, repr() is used on original lines.
assert callequal("line1\r\nline2", "line1\nline2\r", verbose=2) == [
r"'line1\r\nline2' == 'line1\nline2\r'",
r"NOTE: Strings contain non-printable characters. Escaping them using repr().",
r" 'line1'",
r"- 'line1\n'",
r"+ 'line1\r\n'",
r"? ++",
r"- 'line2\r'",
r"? --",
r"+ 'line2'",
Expand Down

0 comments on commit b00435e

Please sign in to comment.