Closed adl1995 closed 6 years ago
@adl1995 - Thanks!
Well ideally, this option would work the same for FITS, PNG and JPEG. I guess if Pillow doesn't offer the equivalent you have to do something like:
from pathlib import Path
if Path(filename).exits():
raise ...
Concerning test: yes, would be nice and shouldn't be hard to write (using with pytest.raises
), but I'd also merge without since the code is simple.
@cdeil - Please see the updated code.
For FITS files, astropy.io.fits.writeto raises the OSError
exception by default. However, for JPG and PNG files I have manually raised the FileExistsError
exception, as it seems more appropriate.
Is this fine, or should all formats raise the same exception for consistency?
I think if you move the code that checks and raises FileExistsError at the top, it will be nicer for the user, and already for you in the test, because it behaves the same.
Note that you should create an FileExistsError
instance with the filename mentioned in the raise statement, as explained here:
https://stackoverflow.com/questions/36077266/how-do-i-raise-a-filenotfounderror-properly
This seems better. The FileExistsError
is now raised for all file formats (FITS, JPG, PNG).
Looks good. Thanks!
Following issue #127, this PR adds the
overwrite
parameter towrite_image
function, which defaults toFalse
. For now, this parameter only works with FITS files, I'm not sure what's the default behavior of PIL for JPG and PNG files.@cdeil - Should I include a test case for this by writing a same file twice?