Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions src/zimscraperlib/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
ISO_LEVELS = ["1", "2b", "2t", "3", "5"]


class NotFoundError(ValueError): ...
class NotFoundError(ValueError):
pass # pragma: no cover


class Language:
Expand Down Expand Up @@ -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)!
Expand Down
2 changes: 1 addition & 1 deletion src/zimscraperlib/rewriting/js.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/zimscraperlib/zim/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 27 additions & 1 deletion tests/image/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
Loading