Add support to display field names in namedtuple diffs.
This commit is contained in:
committed by
Ran Benita
parent
5913cd20ec
commit
9a0f4e57ee
@@ -1,3 +1,4 @@
|
||||
import collections
|
||||
import sys
|
||||
import textwrap
|
||||
from typing import Any
|
||||
@@ -987,6 +988,44 @@ class TestAssert_reprcompare_attrsclass:
|
||||
assert lines is None
|
||||
|
||||
|
||||
class TestAssert_reprcompare_namedtuple:
|
||||
def test_namedtuple(self) -> None:
|
||||
NT = collections.namedtuple("NT", ["a", "b"])
|
||||
|
||||
left = NT(1, "b")
|
||||
right = NT(1, "c")
|
||||
|
||||
lines = callequal(left, right)
|
||||
assert lines == [
|
||||
"NT(a=1, b='b') == NT(a=1, b='c')",
|
||||
"",
|
||||
"Omitting 1 identical items, use -vv to show",
|
||||
"Differing attributes:",
|
||||
"['b']",
|
||||
"",
|
||||
"Drill down into differing attribute b:",
|
||||
" b: 'b' != 'c'",
|
||||
" - c",
|
||||
" + b",
|
||||
"Use -v to get the full diff",
|
||||
]
|
||||
|
||||
def test_comparing_two_different_namedtuple(self) -> None:
|
||||
NT1 = collections.namedtuple("NT1", ["a", "b"])
|
||||
NT2 = collections.namedtuple("NT2", ["a", "b"])
|
||||
|
||||
left = NT1(1, "b")
|
||||
right = NT2(2, "b")
|
||||
|
||||
lines = callequal(left, right)
|
||||
# Because the types are different, uses the generic sequence matcher.
|
||||
assert lines == [
|
||||
"NT1(a=1, b='b') == NT2(a=2, b='b')",
|
||||
"At index 0 diff: 1 != 2",
|
||||
"Use -v to get the full diff",
|
||||
]
|
||||
|
||||
|
||||
class TestFormatExplanation:
|
||||
def test_special_chars_full(self, pytester: Pytester) -> None:
|
||||
# Issue 453, for the bug this would raise IndexError
|
||||
|
||||
Reference in New Issue
Block a user