-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: switch to
quality
setting for AVIF & deprecate qmin
/qmax
- Loading branch information
Showing
5 changed files
with
61 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,53 @@ | ||
import shutil | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from pre_commit_images.optimize_avif import main | ||
|
||
|
||
def test_compress_avif(tmpdir): | ||
image = "test.avif" | ||
path = Path(tmpdir) / image | ||
test_file = Path(__file__).parent / image | ||
shutil.copy(test_file, path) | ||
@pytest.fixture | ||
def original_image(tmpdir): | ||
return Path(__file__).parent / "test.avif" | ||
|
||
|
||
@pytest.fixture | ||
def image(tmpdir, original_image): | ||
path = Path(tmpdir) / "test.avif" | ||
shutil.copy(original_image, path) | ||
return path | ||
|
||
|
||
assert main(("-min", "63", "-max", "63", "-e", "0", str(path))) == 0 | ||
assert test_file.stat().st_size > path.stat().st_size | ||
def test_qmin_qmax_deprecated(image): | ||
with pytest.deprecated_call(): | ||
assert main(("-min", "10", str(image))) == 0 | ||
|
||
|
||
def test_compress_avif_below_threshold(tmpdir): | ||
image = "test.avif" | ||
path = Path(tmpdir) / image | ||
test_file = Path(__file__).parent / image | ||
shutil.copy(test_file, path) | ||
def test_qmin_qmax_and_quality(image): | ||
with pytest.raises(SystemExit) as wrapped_exit: | ||
assert main(("-min", "10", "--quality", "20", str(image))) == 1 | ||
assert wrapped_exit.type == SystemExit | ||
assert wrapped_exit.value.code == 1 | ||
|
||
|
||
def test_compress_avif(original_image, image): | ||
assert main(("--quality", "75", "-e", "0", str(image))) == 0 | ||
assert original_image.stat().st_size > image.stat().st_size | ||
|
||
|
||
def test_compress_avif_below_threshold(original_image, image): | ||
assert ( | ||
main( | ||
( | ||
"-min", | ||
"10", | ||
"-max", | ||
"20", | ||
"--quality", | ||
"90", | ||
"-e", | ||
"10", | ||
"-t", | ||
"6144", | ||
str(path), | ||
str(image), | ||
) | ||
) | ||
== 0 | ||
) | ||
assert test_file.stat().st_size == path.stat().st_size | ||
assert original_image.stat().st_size == image.stat().st_size |