|
| 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
|
| 8 | + |
| 9 | +from nose.tools import assert_equal |
| 10 | + |
4 | 11 | import numpy as np
|
| 12 | +import os |
| 13 | +import shutil |
| 14 | +import tempfile |
5 | 15 |
|
6 | 16 |
|
7 | 17 | def test_uses_per_path():
|
@@ -43,3 +53,38 @@ def check(master_transform, paths, all_transforms,
|
43 | 53 | check(id, paths, tforms, offsets, facecolors, [])
|
44 | 54 | check(id, paths, tforms, offsets, [], [])
|
45 | 55 | check(id, paths, tforms, offsets, facecolors[0:1], edgecolors)
|
| 56 | + |
| 57 | + |
| 58 | +@cleanup |
| 59 | +def test_get_default_filename(): |
| 60 | + try: |
| 61 | + test_dir = tempfile.mkdtemp() |
| 62 | + plt.rcParams['savefig.directory'] = test_dir |
| 63 | + fig = plt.figure() |
| 64 | + canvas = FigureCanvasBase(fig) |
| 65 | + filename = canvas.get_default_filename() |
| 66 | + assert_equal(filename, 'image.png') |
| 67 | + finally: |
| 68 | + shutil.rmtree(test_dir) |
| 69 | + |
| 70 | + |
| 71 | +@cleanup |
| 72 | +def test_get_default_filename_already_exists(): |
| 73 | + # From #3068: Suggest non-existing default filename |
| 74 | + try: |
| 75 | + test_dir = tempfile.mkdtemp() |
| 76 | + plt.rcParams['savefig.directory'] = test_dir |
| 77 | + fig = plt.figure() |
| 78 | + canvas = FigureCanvasBase(fig) |
| 79 | + |
| 80 | + # create 'image.png' in figure's save dir |
| 81 | + open(os.path.join(test_dir, 'image.png'), 'w').close() |
| 82 | + |
| 83 | + filename = canvas.get_default_filename() |
| 84 | + assert_equal(filename, 'image-1.png') |
| 85 | + finally: |
| 86 | + shutil.rmtree(test_dir) |
| 87 | + |
| 88 | +if __name__ == "__main__": |
| 89 | + import nose |
| 90 | + nose.runmodule(argv=['-s', '--with-doctest'], exit=False) |
0 commit comments