# Path: test/fake_time_util.py
# @contextlib.contextmanager
# def fake_time(fake_clock=None):
#     fake_clock = fake_clock or FakeClock()
#     stack_sampler.get_stack_sampler().timer_func = fake_clock.get_time
# 
#     try:
#         with mock.patch("time.sleep", new=fake_clock.sleep):
#             yield fake_clock
#     finally:
#         stack_sampler.get_stack_sampler().timer_func = None


from test.fake_time_util import fake_time
    from IPython.utils.io import capture_output as capture_ipython_output
    from IPython.testing.globalipapp import start_ipython
import pytest
    function_e()

def function_e():
    time.sleep(0.1)

function_a()
"""

# Tests #


@pytest.mark.ipythonmagic
def test_magics(ip):

    with fake_time():
        with capture_ipython_output() as captured:
            ip.run_cell_magic("pyinstrument", line="", cell=cell_code)

    assert len(captured.outputs) == 1
    output = captured.outputs[0]
    assert "text/html" in output.data
    assert "text/plain" in output.data

    assert "function_a" in output.data["text/html"]
    assert "<iframe" in output.data["text/html"]
    assert "function_a" in output.data["text/plain"]

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


# Path: test/fake_time_util.py
# @contextlib.contextmanager
# def fake_time(fake_clock=None):
#     fake_clock = fake_clock or FakeClock()
#     stack_sampler.get_stack_sampler().timer_func = fake_clock.get_time
# 
#     try:
#         with mock.patch("time.sleep", new=fake_clock.sleep):
#             yield fake_clock
#     finally:
#         stack_sampler.get_stack_sampler().timer_func = None


# Path: test/test_ipython_magic.py
from test.fake_time_util import fake_time
    from IPython.utils.io import capture_output as capture_ipython_output
    from IPython.testing.globalipapp import start_ipython
import pytest

    function_e()

def function_e():
    time.sleep(0.1)

function_a()
"""

# Tests #


@pytest.mark.ipythonmagic
def test_magics(ip):

    with fake_time():
        with capture_ipython_output() as captured:
            ip.run_cell_magic("pyinstrument", line="", cell=cell_code)

    assert len(captured.outputs) == 1
    output = captured.outputs[0]
    assert "text/html" in output.data
    assert "text/plain" in output.data

    assert "function_a" in output.data["text/html"]
    assert "<iframe" in output.data["text/html"]
    assert "function_a" in output.data["text/plain"]

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


    with fake_time():