Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8aae9a3

Browse files
committed
strip ansi for comparison
1 parent e1aadc2 commit 8aae9a3

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

tests/test_magic.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,8 +1094,21 @@ def test_notebook_export_json_with_output():
10941094
expected = expected_nb["cells"][i]
10951095
assert expected["source"] == command
10961096
assert actual["source"] == expected["source"]
1097-
assert (
1098-
actual["outputs"] == expected["outputs"]
1097+
_strip_ansi = re.compile(r"\x1b\[[0-9;]*m").sub
1098+
1099+
def strip_ansi_from_outputs(outputs):
1100+
result = []
1101+
for out in outputs:
1102+
out = dict(out)
1103+
if "traceback" in out:
1104+
out["traceback"] = [
1105+
_strip_ansi("", line) for line in out["traceback"]
1106+
]
1107+
result.append(out)
1108+
return result
1109+
1110+
assert strip_ansi_from_outputs(actual["outputs"]) == strip_ansi_from_outputs(
1111+
expected["outputs"]
10991112
), f"Outputs do not match for cell {i+1} with source {command!r}"
11001113
finally:
11011114
_ip.colors = "nocolor"

0 commit comments

Comments
 (0)