Added conditional to check if left or right is an empty list. Added modifications to the formatting to fix strings that were created with implicit string concatenation.
This commit is contained in:
parent
eb38e69e86
commit
3a513ac6bd
|
@ -12,6 +12,7 @@ from typing import Mapping
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from typing import Protocol
|
from typing import Protocol
|
||||||
from typing import Sequence
|
from typing import Sequence
|
||||||
|
from typing import Tuple
|
||||||
from unicodedata import normalize
|
from unicodedata import normalize
|
||||||
|
|
||||||
import _pytest._code
|
import _pytest._code
|
||||||
|
@ -341,12 +342,16 @@ def _compare_eq_iterable(
|
||||||
# dynamic import to speedup pytest
|
# dynamic import to speedup pytest
|
||||||
import difflib
|
import difflib
|
||||||
|
|
||||||
|
if _is_empty_vs_non_empty(left, right):
|
||||||
|
left_formatting, right_formatting = _format_for_empty_and_non_empty(left, right)
|
||||||
|
else:
|
||||||
left_formatting = pprint.pformat(left).splitlines()
|
left_formatting = pprint.pformat(left).splitlines()
|
||||||
right_formatting = pprint.pformat(right).splitlines()
|
right_formatting = pprint.pformat(right).splitlines()
|
||||||
|
|
||||||
# Re-format for different output lengths.
|
# Re-format for different output lengths.
|
||||||
lines_left = len(left_formatting)
|
lines_left = len(left_formatting)
|
||||||
lines_right = len(right_formatting)
|
lines_right = len(right_formatting)
|
||||||
|
|
||||||
if lines_left != lines_right:
|
if lines_left != lines_right:
|
||||||
printer = PrettyPrinter()
|
printer = PrettyPrinter()
|
||||||
left_formatting = printer.pformat(left).splitlines()
|
left_formatting = printer.pformat(left).splitlines()
|
||||||
|
@ -371,6 +376,32 @@ def _compare_eq_iterable(
|
||||||
return explanation
|
return explanation
|
||||||
|
|
||||||
|
|
||||||
|
def _is_empty_vs_non_empty(left: Iterable[Any], right: Iterable[Any]) -> bool:
|
||||||
|
is_left_empty = not any(left) if isinstance(left, Iterable) else not left
|
||||||
|
is_right_empty = not any(right) if isinstance(right, Iterable) else not right
|
||||||
|
return (is_left_empty and not is_right_empty) or (
|
||||||
|
not is_left_empty and is_right_empty
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _format_for_empty_and_non_empty(
|
||||||
|
left: Iterable[Any], right: Iterable[Any]
|
||||||
|
) -> Tuple[List[str], List[str]]:
|
||||||
|
if isinstance(left, (list, tuple)) and isinstance(right, (list, tuple)):
|
||||||
|
if not left:
|
||||||
|
right_width = len(right[0]) + 4 if right else 80
|
||||||
|
right_formatting = pprint.pformat(right, width=right_width).splitlines()
|
||||||
|
left_formatting = pprint.pformat(left).splitlines()
|
||||||
|
else:
|
||||||
|
left_width = len(left[0]) + 4 if left else 80
|
||||||
|
left_formatting = pprint.pformat(left, width=left_width).splitlines()
|
||||||
|
right_formatting = pprint.pformat(right).splitlines()
|
||||||
|
return left_formatting, right_formatting
|
||||||
|
else:
|
||||||
|
# Fall back to default formatting
|
||||||
|
return pprint.pformat(left).splitlines(), pprint.pformat(right).splitlines()
|
||||||
|
|
||||||
|
|
||||||
def _compare_eq_sequence(
|
def _compare_eq_sequence(
|
||||||
left: Sequence[Any], right: Sequence[Any], verbose: int = 0
|
left: Sequence[Any], right: Sequence[Any], verbose: int = 0
|
||||||
) -> List[str]:
|
) -> List[str]:
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
def test_():
|
|
||||||
m = [
|
|
||||||
"This is some dummy test which shows the strange way in which Pycharm"
|
|
||||||
" displays the full diff."
|
|
||||||
]
|
|
||||||
assert m == []
|
|
Loading…
Reference in New Issue