Skip to content

Commit

Permalink
generate_image_file: don't hardcode the file format (#6538)
Browse files Browse the repository at this point in the history
It doesn't make much sense to encode the image as JPEG if the given file
name is "image.png". Instead, let PIL select the format based on the
requested file name.
  • Loading branch information
SpecLad authored Jul 23, 2023
1 parent 9659f82 commit 1bc7767
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tests/python/cli/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ def generate_images(dst_dir: Path, count: int) -> List[Path]:
dst_dir.mkdir(parents=True, exist_ok=True)
for i in range(count):
filename = dst_dir / f"img_{i}.jpg"
filename.write_bytes(generate_image_file().getvalue())
filename.write_bytes(generate_image_file(filename.name).getvalue())
filenames.append(filename)
return filenames
7 changes: 6 additions & 1 deletion tests/python/sdk/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,12 @@ def test_can_download_frames(self, fxt_new_task: Task, quality: str):
filename_pattern="frame-{frame_id}{frame_ext}",
)

assert (self.tmp_path / "frame-0.jpg").is_file()
if quality == "original":
expected_frame_ext = "png"
else:
expected_frame_ext = "jpg"

assert (self.tmp_path / f"frame-0.{expected_frame_ext}").is_file()
assert self.stdout.getvalue() == ""

def test_can_upload_annotations(self, fxt_new_task: Task, fxt_coco_file: Path):
Expand Down
7 changes: 6 additions & 1 deletion tests/python/sdk/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,12 @@ def test_can_download_frames(self, fxt_new_task: Task, quality: str):
filename_pattern="frame-{frame_id}{frame_ext}",
)

assert (self.tmp_path / "frame-0.jpg").is_file()
if quality == "original":
expected_frame_ext = "png"
else:
expected_frame_ext = "jpg"

assert (self.tmp_path / f"frame-0.{expected_frame_ext}").is_file()
assert self.stdout.getvalue() == ""

@pytest.mark.parametrize("quality", ("compressed", "original"))
Expand Down
4 changes: 2 additions & 2 deletions tests/python/shared/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

def generate_image_file(filename="image.png", size=(50, 50), color=(0, 0, 0)):
f = BytesIO()
image = Image.new("RGB", size=size, color=color)
image.save(f, "jpeg")
f.name = filename
image = Image.new("RGB", size=size, color=color)
image.save(f)
f.seek(0)

return f
Expand Down

0 comments on commit 1bc7767

Please sign in to comment.