Skip to content

Commit ff65d77

Browse files
authored
Merge pull request #302 from openzim/test_coverage
Bring coverage back to 100%
2 parents 3adcd39 + 149333a commit ff65d77

5 files changed

Lines changed: 33 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
- Fix installation from source, which missed wombatSetup.js (#287)
2121
- Fix outdated system dependencies in README: remove Pillow build-time deps (bundled in wheels), add missing `libcairo` across all platforms (#152)
2222
- Improve contribution setup instructions: use `hatch shell`, clarify commands must be run from local clone root (#153)
23+
- Bring coverage back to 100% (#293)
2324

2425
### Changed
2526

src/zimscraperlib/i18n.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
ISO_LEVELS = ["1", "2b", "2t", "3", "5"]
88

99

10-
class NotFoundError(ValueError): ...
10+
class NotFoundError(ValueError):
11+
pass # pragma: no cover
1112

1213

1314
class Language:
@@ -105,7 +106,7 @@ def _get_names_from(self, query: str) -> tuple[str, str]:
105106
if native_display_name := query_locale.get_display_name():
106107
if english_display_name := query_locale.get_display_name("en"):
107108
return native_display_name, english_display_name
108-
except (babel.UnknownLocaleError, TypeError, ValueError, AttributeError):
109+
except babel.UnknownLocaleError, TypeError, ValueError, AttributeError:
109110
pass
110111

111112
# ISO code lookup order matters (most qualified first)!

src/zimscraperlib/rewriting/js.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def remove_args_if_strict(
7878

7979
# Detect strict mode if not already set by checking for class declaration
8080
if "isStrict" not in opts:
81-
opts["isStrict"] = full_string[:offset].find("class ") >= 0
81+
opts["isStrict"] = full_string[:offset].find("class ") >= 0 # pragma: no cover
8282
if opts.get("isStrict"):
8383
return target.replace("arguments", "[]")
8484
return target

src/zimscraperlib/zim/indexing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def get_pdf_content(page: pymupdf.Page) -> str:
105105
text = ( # pyright: ignore[reportUnknownVariableType]
106106
page.get_text() # pyright: ignore[reportUnknownMemberType]
107107
)
108-
if not isinstance(text, str):
108+
if not isinstance(text, str): # pragma: no cover
109109
raise Exception("Unexpected text content")
110110
return text
111111

tests/image/test_image.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,33 @@ def test_dynamic_jpeg_quality(jpg_image: pathlib.Path, tmp_path: pathlib.Path):
926926
assert os.path.getsize(dst) < os.path.getsize(jpg_image)
927927

928928

929-
def test_ensure_matches(webp_image: pathlib.Path):
929+
@pytest.mark.parametrize(
930+
"fmt,expected",
931+
[("png", "PNG"), ("jpg", "JPEG"), ("gif", "GIF"), ("webp", "WEBP"), ("svg", "SVG")],
932+
)
933+
def test_ensure_matches_ok(
934+
png_image: pathlib.Path,
935+
jpg_image: pathlib.Path,
936+
gif_image: pathlib.Path,
937+
webp_image: pathlib.Path,
938+
svg_image: pathlib.Path,
939+
tmp_path: pathlib.Path,
940+
fmt: str,
941+
expected: str,
942+
):
943+
src, _ = get_src_dst(
944+
tmp_path,
945+
fmt,
946+
png_image=png_image,
947+
jpg_image=jpg_image,
948+
gif_image=gif_image,
949+
webp_image=webp_image,
950+
svg_image=svg_image,
951+
)
952+
ensure_matches(src, expected)
953+
954+
955+
def test_ensure_matches_ko(webp_image: pathlib.Path):
930956
with pytest.raises(ValueError, match=re.escape("is not of format")):
931957
ensure_matches(webp_image, "PNG")
932958

0 commit comments

Comments
 (0)