Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyinstrument/magic/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def _silent_exception_handler(self, etype, value, tb, tb_offset=None):
)

text_config = compute_render_options(
args, renderer_class=HTMLRenderer, unicode_support=True, color_support=True
args, renderer_class=ConsoleRenderer, unicode_support=True, color_support=True
)

html_renderer = renderers.HTMLRenderer(show_all=args.show_all, timeline=args.timeline)
Expand Down
14 changes: 9 additions & 5 deletions test/test_ipython_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import pytest

from .util import strip_ansi

# note: IPython should be imported within each test. Importing it in our tests
# seems to cause problems with subsequent tests.

Expand Down Expand Up @@ -49,10 +51,11 @@ def test_magics(ip):

assert "function_a" in output.data["text/html"]
assert "<iframe" in output.data["text/html"]
assert "function_a" in output.data["text/plain"]
plain_text = strip_ansi(output.data["text/plain"])
assert "function_a" in plain_text

assert "- 0.200 function_a" in output.data["text/plain"]
assert "- 0.100 FakeClock.sleep" in output.data["text/plain"]
assert "0.200 function_a" in plain_text
assert "0.100 FakeClock.sleep" in plain_text

with fake_time():
with capture_ipython_output() as captured:
Expand All @@ -62,8 +65,9 @@ def test_magics(ip):
assert len(captured.outputs) == 1
output = captured.outputs[0]

assert "function_a" in output.data["text/plain"]
assert "- 0.100 FakeClock.sleep" in output.data["text/plain"]
plain_text = strip_ansi(output.data["text/plain"])
assert "function_a" in plain_text
assert "0.100 FakeClock.sleep" in plain_text


@pytest.mark.ipythonmagic
Expand Down
5 changes: 5 additions & 0 deletions test/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import os
import re
import sys
import time
from typing import Callable, Generator, Generic, Iterable, Iterator, NoReturn, Optional, TypeVar
Expand All @@ -23,6 +24,10 @@ def assert_never(x: NoReturn) -> NoReturn:
raise AssertionError(f"Invalid value: {x!r}")


def strip_ansi(value: str) -> str:
return re.sub(r"\x1b\[[0-9;]*m", "", value)


def do_nothing():
pass

Expand Down
Loading