From 149333a3e4fc0199af32db77f7629933e49ec11b Mon Sep 17 00:00:00 2001 From: benoit74 Date: Tue, 26 May 2026 13:57:53 +0000 Subject: [PATCH] Bring coverage back to 100% --- CHANGELOG.md | 1 + src/zimscraperlib/i18n.py | 5 +++-- src/zimscraperlib/rewriting/js.py | 2 +- src/zimscraperlib/zim/indexing.py | 2 +- tests/image/test_image.py | 28 +++++++++++++++++++++++++++- 5 files changed, 33 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e5889f..51a2e5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix installation from source, which missed wombatSetup.js (#287) - Fix outdated system dependencies in README: remove Pillow build-time deps (bundled in wheels), add missing `libcairo` across all platforms (#152) - Improve contribution setup instructions: use `hatch shell`, clarify commands must be run from local clone root (#153) +- Bring coverage back to 100% (#293) ### Changed diff --git a/src/zimscraperlib/i18n.py b/src/zimscraperlib/i18n.py index 7396ecc..25855ab 100644 --- a/src/zimscraperlib/i18n.py +++ b/src/zimscraperlib/i18n.py @@ -7,7 +7,8 @@ ISO_LEVELS = ["1", "2b", "2t", "3", "5"] -class NotFoundError(ValueError): ... +class NotFoundError(ValueError): + pass # pragma: no cover class Language: @@ -105,7 +106,7 @@ def _get_names_from(self, query: str) -> tuple[str, str]: if native_display_name := query_locale.get_display_name(): if english_display_name := query_locale.get_display_name("en"): return native_display_name, english_display_name - except (babel.UnknownLocaleError, TypeError, ValueError, AttributeError): + except babel.UnknownLocaleError, TypeError, ValueError, AttributeError: pass # ISO code lookup order matters (most qualified first)! diff --git a/src/zimscraperlib/rewriting/js.py b/src/zimscraperlib/rewriting/js.py index f75f41b..bee192f 100644 --- a/src/zimscraperlib/rewriting/js.py +++ b/src/zimscraperlib/rewriting/js.py @@ -78,7 +78,7 @@ def remove_args_if_strict( # Detect strict mode if not already set by checking for class declaration if "isStrict" not in opts: - opts["isStrict"] = full_string[:offset].find("class ") >= 0 + opts["isStrict"] = full_string[:offset].find("class ") >= 0 # pragma: no cover if opts.get("isStrict"): return target.replace("arguments", "[]") return target diff --git a/src/zimscraperlib/zim/indexing.py b/src/zimscraperlib/zim/indexing.py index 51de209..b23cb5b 100644 --- a/src/zimscraperlib/zim/indexing.py +++ b/src/zimscraperlib/zim/indexing.py @@ -105,7 +105,7 @@ def get_pdf_content(page: pymupdf.Page) -> str: text = ( # pyright: ignore[reportUnknownVariableType] page.get_text() # pyright: ignore[reportUnknownMemberType] ) - if not isinstance(text, str): + if not isinstance(text, str): # pragma: no cover raise Exception("Unexpected text content") return text diff --git a/tests/image/test_image.py b/tests/image/test_image.py index 64ce9dc..2612cb7 100644 --- a/tests/image/test_image.py +++ b/tests/image/test_image.py @@ -926,7 +926,33 @@ def test_dynamic_jpeg_quality(jpg_image: pathlib.Path, tmp_path: pathlib.Path): assert os.path.getsize(dst) < os.path.getsize(jpg_image) -def test_ensure_matches(webp_image: pathlib.Path): +@pytest.mark.parametrize( + "fmt,expected", + [("png", "PNG"), ("jpg", "JPEG"), ("gif", "GIF"), ("webp", "WEBP"), ("svg", "SVG")], +) +def test_ensure_matches_ok( + png_image: pathlib.Path, + jpg_image: pathlib.Path, + gif_image: pathlib.Path, + webp_image: pathlib.Path, + svg_image: pathlib.Path, + tmp_path: pathlib.Path, + fmt: str, + expected: str, +): + src, _ = get_src_dst( + tmp_path, + fmt, + png_image=png_image, + jpg_image=jpg_image, + gif_image=gif_image, + webp_image=webp_image, + svg_image=svg_image, + ) + ensure_matches(src, expected) + + +def test_ensure_matches_ko(webp_image: pathlib.Path): with pytest.raises(ValueError, match=re.escape("is not of format")): ensure_matches(webp_image, "PNG")