Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Remove figure from Gcf when it is closed #1683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Prev Previous commit
Next Next commit
test for issue #1683
  • Loading branch information
tacaswell committed Jan 19, 2013
commit 7a929cab359d2a7da513fc8a166b959ac4030c2d
19 changes: 17 additions & 2 deletions 19 lib/matplotlib/tests/test_backend_qt4.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
from matplotlib import rcParams
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you moved from rcParams to switch_backend, so you can remove this line.

from matplotlib import pyplot as plt
from matplotlib.testing.decorators import cleanup
from matplotlib._pylab_helpers import Gcf
import copy


@cleanup
def test_fig_close():
rcParams['backend'] = 'qt4agg'
# force switch to the Qt4 backend
plt.switch_backend('Qt4Agg')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably mark this test as knownfail or skip if Qt4/PySide are not installed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the correct way to test if Qt4/PySide is available?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like:

try:
    import Qt
    HAS_PYQT = True
except ImportError:
    HAS_PYQT = False

(And obviously extend to also check for PySide -- it should be good enough to have one or the other).


#save the state of Gcf.figs
init_figs = copy.copy(Gcf.figs)

# make a figure using pyplot interface
fig = plt.figure()
fig.close()

# simulate user clicking the close button by reaching in
# and calling close on the underlying Qt object
fig.canvas.manager.window.close()

# assert that we have removed the reference to the FigureManager
# that got added by plt.figure()
assert(init_figs == Gcf.figs)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.