Skip to content

Commit

Permalink
Compatibility with IPython 8 where tracebacks are different
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzymadness committed Jan 5, 2022
1 parent 612a9e8 commit ddcf154
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions nbclient/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@
from .base import NBClientTestsBase

addr_pat = re.compile(r'0x[0-9a-f]{7,9}')
ipython_input_pat = re.compile(r'<ipython-input-\d+-[0-9a-f]+>')
current_dir = os.path.dirname(__file__)
ipython_input_pat = re.compile(r'<ipython-input-\d+-[0-9a-f]+>')
# Tracebacks look different in IPython 8,
# see: https://github.com/ipython/ipython/blob/master/docs/source/whatsnew/version8.rst#traceback-improvements # noqa
ipython8_input_pat = re.compile(r'Input In \[\d+\],')


class AsyncMock(Mock):
Expand Down Expand Up @@ -201,10 +204,10 @@ def normalize_output(output):
if isinstance(value, string_types):
output['data'][key] = normalize_base64(value)
if 'traceback' in output:
tb = [
re.sub(ipython_input_pat, '<IPY-INPUT>', strip_ansi(line))
for line in output['traceback']
]
tb = []
for line in output["traceback"]:
line = re.sub(ipython_input_pat, '<IPY-INPUT>', strip_ansi(line))
line = re.sub(ipython8_input_pat, '<IPY-INPUT>', strip_ansi(line))
output['traceback'] = tb

return output
Expand Down

0 comments on commit ddcf154

Please sign in to comment.