From 18d181fa7776ced81249e18805c91c53c739834c Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sun, 3 Nov 2019 17:31:07 +0200 Subject: [PATCH] Remove dead code in _pytest.assertion.util._diff_text The function handles bytes input, however that is never used. The function has two callers: 1) ``` if istext(left) and istext(right): explanation = _diff_text(left, right, verbose ``` `istext` checks `isinstance(str)`. 2) ``` def _notin_text(term: str, text: str, verbose: int = 0) -> List[str]: ... diff = _diff_text(correct_text, text, verbose ``` and `_notin_text` is called once: ``` if istext(left) and istext(right): explanation = _notin_text(left, right, verbose ``` --- src/_pytest/assertion/util.py | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/src/_pytest/assertion/util.py b/src/_pytest/assertion/util.py index ce29553d5..1d9fffd34 100644 --- a/src/_pytest/assertion/util.py +++ b/src/_pytest/assertion/util.py @@ -181,32 +181,15 @@ def assertrepr_compare(config, op, left, right): def _diff_text(left, right, verbose=0): - """Return the explanation for the diff between text or bytes. + """Return the explanation for the diff between text. Unless --verbose is used this will skip leading and trailing characters which are identical to keep the diff minimal. - - If the input are bytes they will be safely converted to text. """ from difflib import ndiff explanation = [] # type: List[str] - def escape_for_readable_diff(binary_text): - """ - Ensures that the internal string is always valid unicode, converting any bytes safely to valid unicode. - This is done using repr() which then needs post-processing to fix the encompassing quotes and un-escape - newlines and carriage returns (#429). - """ - r = str(repr(binary_text)[1:-1]) - r = r.replace(r"\n", "\n") - r = r.replace(r"\r", "\r") - return r - - if isinstance(left, bytes): - left = escape_for_readable_diff(left) - if isinstance(right, bytes): - right = escape_for_readable_diff(right) if verbose < 1: i = 0 # just in case left or right has zero length for i in range(min(len(left), len(right))):