Corrected pathlib.Path detection when saving

This commit is contained in:
Andrew Murray 2021-07-24 14:21:33 +10:00
parent 68c5f2dce1
commit 4038a287ee
2 changed files with 9 additions and 8 deletions

View File

@ -149,10 +149,11 @@ class TestImage:
assert im.mode == "RGB" assert im.mode == "RGB"
assert im.size == (128, 128) assert im.size == (128, 128)
temp_file = str(tmp_path / "temp.jpg") for ext in (".jpg", ".jp2"):
if os.path.exists(temp_file): temp_file = str(tmp_path / ("temp." + ext))
os.remove(temp_file) if os.path.exists(temp_file):
im.save(Path(temp_file)) os.remove(temp_file)
im.save(Path(temp_file))
def test_fp_name(self, tmp_path): def test_fp_name(self, tmp_path):
temp_file = str(tmp_path / "temp.jpg") temp_file = str(tmp_path / "temp.jpg")

View File

@ -2180,12 +2180,12 @@ class Image:
filename = "" filename = ""
open_fp = False open_fp = False
if isPath(fp): if isinstance(fp, Path):
filename = fp
open_fp = True
elif isinstance(fp, Path):
filename = str(fp) filename = str(fp)
open_fp = True open_fp = True
elif isPath(fp):
filename = fp
open_fp = True
elif fp == sys.stdout: elif fp == sys.stdout:
try: try:
fp = sys.stdout.buffer fp = sys.stdout.buffer