| 
 | 1 | +from matplotlib.backend_bases import FigureCanvasBase  | 
1 | 2 | from matplotlib.backend_bases import RendererBase  | 
 | 3 | +from matplotlib.testing.decorators import image_comparison, cleanup  | 
 | 4 | + | 
 | 5 | +import matplotlib.pyplot as plt  | 
2 | 6 | import matplotlib.transforms as transforms  | 
3 | 7 | import matplotlib.path as path  | 
4 |  | -import numpy as np  | 
5 | 8 | 
 
  | 
 | 9 | +from nose.tools import assert_equal  | 
 | 10 | + | 
 | 11 | +import numpy as np  | 
 | 12 | +import tempfile  | 
 | 13 | +import os  | 
6 | 14 | 
 
  | 
7 | 15 | def test_uses_per_path():  | 
8 | 16 |     id = transforms.Affine2D()  | 
@@ -43,3 +51,30 @@ def check(master_transform, paths, all_transforms,  | 
43 | 51 |     check(id, paths, tforms, offsets, facecolors, [])  | 
44 | 52 |     check(id, paths, tforms, offsets, [], [])  | 
45 | 53 |     check(id, paths, tforms, offsets, facecolors[0:1], edgecolors)  | 
 | 54 | + | 
 | 55 | +@cleanup  | 
 | 56 | +def test_get_default_filename():  | 
 | 57 | +    test_dir = tempfile.mkdtemp()  | 
 | 58 | +    plt.rcParams['savefig.directory'] = test_dir  | 
 | 59 | +    fig = plt.figure()  | 
 | 60 | +    canvas = FigureCanvasBase(fig)  | 
 | 61 | +    filename = canvas.get_default_filename()  | 
 | 62 | +    assert_equal(filename, 'image.png')  | 
 | 63 | + | 
 | 64 | +@cleanup  | 
 | 65 | +def test_get_default_filename_already_existing():  | 
 | 66 | +    # From #3068: Suggest non-existing default filename  | 
 | 67 | +    test_dir = tempfile.mkdtemp()  | 
 | 68 | +    plt.rcParams['savefig.directory'] = test_dir  | 
 | 69 | +    fig = plt.figure()  | 
 | 70 | +    canvas = FigureCanvasBase(fig)  | 
 | 71 | + | 
 | 72 | +    # create 'image.png' in figure's save dir  | 
 | 73 | +    with open(os.path.join(test_dir, 'image.png'), 'a'):  | 
 | 74 | +        filename = canvas.get_default_filename()  | 
 | 75 | +        assert_equal(filename, 'image-1.png')  | 
 | 76 | + | 
 | 77 | + | 
 | 78 | +if __name__ == "__main__":  | 
 | 79 | +    import nose  | 
 | 80 | +    nose.runmodule(argv=['-s', '--with-doctest'], exit=False)  | 
0 commit comments