Skip to content

Commit

Permalink
Testing: Test that "%matplotlib qt" is working
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 committed Sep 20, 2018
1 parent 694da5b commit 8644285
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions spyder_kernels/ipdb/tests/test_matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,33 @@ def test_matplotlib_inline(qtconsole, qtbot):

# Assert that there's a plot in the console
assert shell._control.toHtml().count('img src') == 1


def test_matplotlib_qt(qtconsole, qtbot):
"""Test that %matplotlib qt is working."""
window = qtconsole.window
shell = window.active_frontend

# Wait until the console is fully up
qtbot.waitUntil(lambda: shell._prompt_html is not None,
timeout=SHELL_TIMEOUT)

# Set qt backend
with qtbot.waitSignal(shell.executed):
shell.execute("%matplotlib qt")

# Make a plot
with qtbot.waitSignal(shell.executed):
shell.execute("import matplotlib.pyplot as plt; plt.plot(range(10))")

# Assert we have three prompts in the console, meaning that the
# previous plot command was non-blocking
assert '3' in shell._prompt_html

# Running QApplication.instance() should return a QApplication
# object because "%matplotlib qt" creates one
with qtbot.waitSignal(shell.executed):
shell.execute("from PyQt5.QtWidgets import QApplication; QApplication.instance()")

# Assert the previous command returns the object
assert 'PyQt5.QtWidgets.QApplication object' in shell._control.toPlainText()

0 comments on commit 8644285

Please sign in to comment.