From e3711fd1c60e417338f0518db846aa118db96f0b Mon Sep 17 00:00:00 2001 From: Raphael Boidol Date: Fri, 13 Oct 2023 21:06:46 +0200 Subject: [PATCH] fix: handling of `0` parameters for avif --- pre_commit_images/optimize_avif.py | 8 ++++---- tests/optimize_avif_test.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pre_commit_images/optimize_avif.py b/pre_commit_images/optimize_avif.py index 27d9f4d..b4efe77 100755 --- a/pre_commit_images/optimize_avif.py +++ b/pre_commit_images/optimize_avif.py @@ -51,20 +51,20 @@ def main(argv: Optional[Sequence[str]] = None) -> int: ) args = parser.parse_args(argv) - if not args.qmin and not args.qmax and not args.quality: + if args.qmin is None and args.qmax is None and args.quality is None: args.quality = 75 - if args.qmin and args.quality or args.qmax and args.quality: + if args.quality is not None and (args.qmin is not None or args.qmax is not None): sys.exit("Can not use both `qmin`/`qmax` and `quality`") - if args.qmin or args.qmax: + if args.qmin is not None or args.qmax is not None: warnings.warn( "`qmin`/`qmax` are deprecated, use `quality` instead" " - it will be the only option for future AVIF versions", category=DeprecationWarning, ) - options = {option: value for option, value in vars(args).items() if value} + options = {option: value for option, value in vars(args).items() if value is not None} def optimize(source: Path, target: IO[bytes]) -> None: im = Image.open(source) diff --git a/tests/optimize_avif_test.py b/tests/optimize_avif_test.py index 3eb4d00..9ef12e5 100644 --- a/tests/optimize_avif_test.py +++ b/tests/optimize_avif_test.py @@ -20,7 +20,7 @@ def image(tmpdir, original_image): def test_qmin_qmax_deprecated(image): with pytest.deprecated_call(): - assert main(("-min", "10", str(image))) == 0 + assert main(("-min", "0", str(image))) == 0 def test_qmin_qmax_and_quality(image):