Separate the various parts of the error report with newlines (#11659)
Previously the error report would have all sections glued together: - The assertion representation - The error explanation - The full diff This makes it hard to see at a glance where which one starts and ends. One of the representation (dataclasses, tuples, attrs) does display a newlines at the start already. Let's add a newlines before the error explanation and before the full diff, so we get an easier to read report. This has one disadvantage: we get one line less in the least verbose mode, where the output gets truncated.
This commit is contained in:
committed by
GitHub
parent
cd269f0e6d
commit
a536f49d91
@@ -99,6 +99,7 @@ class TestApprox:
|
||||
2.0,
|
||||
1.0,
|
||||
[
|
||||
"",
|
||||
" comparison failed",
|
||||
f" Obtained: {SOME_FLOAT}",
|
||||
f" Expected: {SOME_FLOAT} ± {SOME_FLOAT}",
|
||||
@@ -113,6 +114,7 @@ class TestApprox:
|
||||
"c": 3000000.0,
|
||||
},
|
||||
[
|
||||
r"",
|
||||
r" comparison failed. Mismatched elements: 2 / 3:",
|
||||
rf" Max absolute difference: {SOME_FLOAT}",
|
||||
rf" Max relative difference: {SOME_FLOAT}",
|
||||
@@ -130,6 +132,7 @@ class TestApprox:
|
||||
"c": None,
|
||||
},
|
||||
[
|
||||
r"",
|
||||
r" comparison failed. Mismatched elements: 2 / 3:",
|
||||
r" Max absolute difference: -inf",
|
||||
r" Max relative difference: -inf",
|
||||
@@ -143,6 +146,7 @@ class TestApprox:
|
||||
[1.0, 2.0, 3.0, 4.0],
|
||||
[1.0, 3.0, 3.0, 5.0],
|
||||
[
|
||||
r"",
|
||||
r" comparison failed. Mismatched elements: 2 / 4:",
|
||||
rf" Max absolute difference: {SOME_FLOAT}",
|
||||
rf" Max relative difference: {SOME_FLOAT}",
|
||||
@@ -156,6 +160,7 @@ class TestApprox:
|
||||
(1, 2.2, 4),
|
||||
(1, 3.2, 4),
|
||||
[
|
||||
r"",
|
||||
r" comparison failed. Mismatched elements: 1 / 3:",
|
||||
rf" Max absolute difference: {SOME_FLOAT}",
|
||||
rf" Max relative difference: {SOME_FLOAT}",
|
||||
@@ -169,6 +174,7 @@ class TestApprox:
|
||||
[0.0],
|
||||
[1.0],
|
||||
[
|
||||
r"",
|
||||
r" comparison failed. Mismatched elements: 1 / 1:",
|
||||
rf" Max absolute difference: {SOME_FLOAT}",
|
||||
r" Max relative difference: inf",
|
||||
@@ -187,6 +193,7 @@ class TestApprox:
|
||||
a,
|
||||
b,
|
||||
[
|
||||
r"",
|
||||
r" comparison failed. Mismatched elements: 1 / 20:",
|
||||
rf" Max absolute difference: {SOME_FLOAT}",
|
||||
rf" Max relative difference: {SOME_FLOAT}",
|
||||
@@ -209,6 +216,7 @@ class TestApprox:
|
||||
]
|
||||
),
|
||||
[
|
||||
r"",
|
||||
r" comparison failed. Mismatched elements: 3 / 8:",
|
||||
rf" Max absolute difference: {SOME_FLOAT}",
|
||||
rf" Max relative difference: {SOME_FLOAT}",
|
||||
@@ -224,6 +232,7 @@ class TestApprox:
|
||||
np.array([0.0]),
|
||||
np.array([1.0]),
|
||||
[
|
||||
r"",
|
||||
r" comparison failed. Mismatched elements: 1 / 1:",
|
||||
rf" Max absolute difference: {SOME_FLOAT}",
|
||||
r" Max relative difference: inf",
|
||||
@@ -241,6 +250,7 @@ class TestApprox:
|
||||
message = "\n".join(str(e.value).split("\n")[1:])
|
||||
assert message == "\n".join(
|
||||
[
|
||||
" ",
|
||||
" Impossible to compare arrays with different shapes.",
|
||||
" Shapes: (2, 1) and (2, 2)",
|
||||
]
|
||||
@@ -251,6 +261,7 @@ class TestApprox:
|
||||
message = "\n".join(str(e.value).split("\n")[1:])
|
||||
assert message == "\n".join(
|
||||
[
|
||||
" ",
|
||||
" Impossible to compare lists with different sizes.",
|
||||
" Lengths: 2 and 3",
|
||||
]
|
||||
@@ -264,6 +275,7 @@ class TestApprox:
|
||||
2.0,
|
||||
1.0,
|
||||
[
|
||||
"",
|
||||
" comparison failed",
|
||||
f" Obtained: {SOME_FLOAT}",
|
||||
f" Expected: {SOME_FLOAT} ± {SOME_FLOAT}",
|
||||
@@ -277,15 +289,15 @@ class TestApprox:
|
||||
a,
|
||||
b,
|
||||
[
|
||||
r" comparison failed. Mismatched elements: 20 / 20:",
|
||||
rf" Max absolute difference: {SOME_FLOAT}",
|
||||
rf" Max relative difference: {SOME_FLOAT}",
|
||||
r" Index \| Obtained\s+\| Expected",
|
||||
rf" \(0,\)\s+\| {SOME_FLOAT} \| {SOME_FLOAT} ± {SOME_FLOAT}",
|
||||
rf" \(1,\)\s+\| {SOME_FLOAT} \| {SOME_FLOAT} ± {SOME_FLOAT}",
|
||||
rf" \(2,\)\s+\| {SOME_FLOAT} \| {SOME_FLOAT} ± {SOME_FLOAT}...",
|
||||
"",
|
||||
rf"\s*...Full output truncated \({SOME_INT} lines hidden\), use '-vv' to show",
|
||||
r"^ $",
|
||||
r"^ comparison failed. Mismatched elements: 20 / 20:$",
|
||||
rf"^ Max absolute difference: {SOME_FLOAT}$",
|
||||
rf"^ Max relative difference: {SOME_FLOAT}$",
|
||||
r"^ Index \| Obtained\s+\| Expected\s+$",
|
||||
rf"^ \(0,\)\s+\| {SOME_FLOAT} \| {SOME_FLOAT} ± {SOME_FLOAT}e-{SOME_INT}$",
|
||||
rf"^ \(1,\)\s+\| {SOME_FLOAT} \| {SOME_FLOAT} ± {SOME_FLOAT}e-{SOME_INT}\.\.\.$",
|
||||
"^ $",
|
||||
rf"^ ...Full output truncated \({SOME_INT} lines hidden\), use '-vv' to show$",
|
||||
],
|
||||
verbosity_level=0,
|
||||
)
|
||||
@@ -294,6 +306,7 @@ class TestApprox:
|
||||
a,
|
||||
b,
|
||||
[
|
||||
r" ",
|
||||
r" comparison failed. Mismatched elements: 20 / 20:",
|
||||
rf" Max absolute difference: {SOME_FLOAT}",
|
||||
rf" Max relative difference: {SOME_FLOAT}",
|
||||
@@ -652,6 +665,7 @@ class TestApprox:
|
||||
{"foo": 42.0},
|
||||
{"foo": 0.0},
|
||||
[
|
||||
r"",
|
||||
r" comparison failed. Mismatched elements: 1 / 1:",
|
||||
rf" Max absolute difference: {SOME_FLOAT}",
|
||||
r" Max relative difference: inf",
|
||||
|
||||
Reference in New Issue
Block a user