Exemple #1
0
def disable_ipython():
    """Disable output of IPython HTML objects."""
    try:
        from IPython.core.interactiveshell import InteractiveShell
        InteractiveShell.clear_instance()
    except Exception:
        pass
def test_helpful_error():
    """If you're not in Fil, you get an error message."""
    results = []
    sys.excepthook = results.append
    InteractiveShell.clear_instance()
    shell = InteractiveShell.instance()
    with capture_output() as results:
        shell.run_cell("%load_ext filprofiler")
    assert "UsageError" in results.stderr
    assert "Fil kernel" in results.stderr
    assert "Change Kernel" in results.stderr
    InteractiveShell.clear_instance()
Exemple #3
0
def run_in_ipython_shell(code_cells):
    """Run a list of strings in IPython.

    Returns parsed allocations.
    """
    InteractiveShell.clear_instance()

    shell = InteractiveShell.instance(
        display_pub_class=CapturingDisplayPublisher)
    for code in code_cells:
        shell.run_cell(code)
    InteractiveShell.clear_instance()
    html = shell.display_pub.outputs[-1]["data"]["text/html"]
    assert "<iframe" in html
    [svg_path] = re.findall('src="([^"]*)"', html)
    assert svg_path.endswith("peak-memory.svg")
    resultdir = Path(svg_path).parent.parent

    return get_allocations(resultdir)
Exemple #4
0
def mock_ipython():
    shell = InteractiveShell.instance()  # type: InteractiveShell
    shell.display_pub = MockDisplayPublisher()
    yield shell.display_pub
    InteractiveShell.clear_instance()