-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Suggest non-existing default filename (Implement #3608) #4221
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
Conversation
i = 1 | ||
while os.path.isfile(os.path.join(save_dir, default_filename)): | ||
# attach numerical value to basename | ||
default_filename = '{}-{}.{}'.format(default_basename, i, default_filetype) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't use this type of string formatting. It was introduced in py2.7 and we support py2.6. You will need "{0}-{1}.{2}" instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the catch! It has been fixed via 4da2db8.
Can you also add a test? I would suggest something like import tempfile
@cleanup
def test_filename():
test_dir = tempfile.mkdtemp()
rcParams['saving.directory'] = test_dir
target_name = os.path.join(test_dir, 'figure_1.png')
target_name2 = os.path.join(test_dir, 'figure_1-1.png')
fig = plt.figure()
fn = fig.get_default_filename()
assert_equal(fn, target_name)
fig.save_fig(fn)
fn2 = fig.get_default_filename()
assert_equal(fn2, target_name2) |
Done. Should the created temp directories/files be cleaned up after the test? From Python docs: "The user of mkdtemp() is responsible for deleting the temporary directory and its contents when done with it." |
Yes please to cleaning up the temp directory. On Mon, Mar 16, 2015, 05:13 Umair Idris [email protected] wrote:
|
Done. |
ENH : Suggest non-existing default filename in gui save window closes #3608
Thanks! |
No description provided.