|
4 | 4 | import numpy as np |
5 | 5 | import pytest |
6 | 6 |
|
| 7 | +import matplotlib as mpl |
7 | 8 | from matplotlib import cm |
8 | | -from matplotlib.testing.decorators import image_comparison |
| 9 | +from matplotlib.testing.decorators import check_figures_equal |
9 | 10 | from matplotlib.dates import rrulewrapper |
10 | 11 | import matplotlib.pyplot as plt |
11 | 12 | import matplotlib.transforms as mtransforms |
@@ -40,13 +41,11 @@ def test_simple(): |
40 | 41 | pickle.dump(fig, BytesIO(), pickle.HIGHEST_PROTOCOL) |
41 | 42 |
|
42 | 43 |
|
43 | | -@image_comparison( |
44 | | - ['multi_pickle.png'], remove_text=True, style='mpl20', tol=0.082) |
45 | | -def test_complete(): |
46 | | - # Remove this line when this test image is regenerated. |
47 | | - plt.rcParams['pcolormesh.snap'] = False |
48 | | - |
49 | | - fig = plt.figure('Figure with a label?', figsize=(10, 6)) |
| 44 | +@mpl.style.context("default") |
| 45 | +@check_figures_equal(extensions=["png"]) |
| 46 | +def test_complete(fig_test, fig_ref): |
| 47 | + fig_ref.set_size_inches((10, 6)) |
| 48 | + plt.figure(fig_ref) |
50 | 49 |
|
51 | 50 | plt.suptitle('Can you fit any more in a figure?') |
52 | 51 |
|
@@ -89,25 +88,27 @@ def test_complete(): |
89 | 88 | plt.subplot(3, 3, 9) |
90 | 89 | plt.errorbar(x, x * -0.5, xerr=0.2, yerr=0.4) |
91 | 90 |
|
92 | | - # |
93 | 91 | # plotting is done, now test its pickle-ability |
94 | | - # |
95 | | - result_fh = BytesIO() |
96 | | - pickle.dump(fig, result_fh, pickle.HIGHEST_PROTOCOL) |
97 | | - |
98 | | - plt.close('all') |
99 | | - |
100 | | - # make doubly sure that there are no figures left |
101 | | - assert plt._pylab_helpers.Gcf.figs == {} |
102 | | - |
103 | | - # wind back the fh and load in the figure |
104 | | - result_fh.seek(0) |
105 | | - fig = pickle.load(result_fh) |
106 | | - |
107 | | - # make sure there is now a figure manager |
108 | | - assert plt._pylab_helpers.Gcf.figs != {} |
109 | | - |
110 | | - assert fig.get_label() == 'Figure with a label?' |
| 92 | + pkl = BytesIO() |
| 93 | + pickle.dump(fig_ref, pkl, pickle.HIGHEST_PROTOCOL) |
| 94 | + loaded = pickle.loads(pkl.getbuffer()) |
| 95 | + loaded.canvas.draw() |
| 96 | + |
| 97 | + fig_test.set_size_inches(loaded.get_size_inches()) |
| 98 | + fig_test.figimage(loaded.canvas.renderer.buffer_rgba()) |
| 99 | + |
| 100 | + plt.close(loaded) |
| 101 | + |
| 102 | + |
| 103 | +def test_gcf(): |
| 104 | + fig = plt.figure("a label") |
| 105 | + buf = BytesIO() |
| 106 | + pickle.dump(fig, buf, pickle.HIGHEST_PROTOCOL) |
| 107 | + plt.close("all") |
| 108 | + assert plt._pylab_helpers.Gcf.figs == {} # No figures must be left. |
| 109 | + fig = pickle.loads(buf.getbuffer()) |
| 110 | + assert plt._pylab_helpers.Gcf.figs != {} # A manager is there again. |
| 111 | + assert fig.get_label() == "a label" |
111 | 112 |
|
112 | 113 |
|
113 | 114 | def test_no_pyplot(): |
|
0 commit comments