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

Commit 28d9f53

Browse filesBrowse files
author
Umair Idris
committed
Add tests for FigureCanvasBase.get_default_filename()
1 parent 4da2db8 commit 28d9f53
Copy full SHA for 28d9f53

File tree

Expand file treeCollapse file tree

1 file changed

+36
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+36
-1
lines changed

‎lib/matplotlib/tests/test_backend_bases.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_bases.py
+36-1Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
from matplotlib.backend_bases import FigureCanvasBase
12
from matplotlib.backend_bases import RendererBase
3+
from matplotlib.testing.decorators import image_comparison, cleanup
4+
5+
import matplotlib.pyplot as plt
26
import matplotlib.transforms as transforms
37
import matplotlib.path as path
4-
import numpy as np
58

9+
from nose.tools import assert_equal
10+
11+
import numpy as np
12+
import tempfile
13+
import os
614

715
def test_uses_per_path():
816
id = transforms.Affine2D()
@@ -43,3 +51,30 @@ def check(master_transform, paths, all_transforms,
4351
check(id, paths, tforms, offsets, facecolors, [])
4452
check(id, paths, tforms, offsets, [], [])
4553
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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.