Skip to content

Commit dbb7534

Browse files
authored
Merge pull request #400 from mcwanza/fix-258
Re-enable test_indexing_item_not_front and cover non-front items
2 parents d1deb81 + 63d16ff commit dbb7534

2 files changed

Lines changed: 65 additions & 9 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
- Patch vendored `wombat.js` so `retrieveWBOSRCAsURL` (the helper behind the above element-property fix) resolves a recorded original against the frame's true original URL (`wb_info.url`) instead of its replay-time `ownerDocument`, fixing it returning/using a URL under the wrong host for a page whose own URL was changed by a fuzzy rule (e.g. YouTube embeds), which broke playback (#398)
1919
- Add a host-gated `SITE_JS_PATCHES` mechanism to `JsRewriter`, fixing MDN's `<interactive-example>` widget missing a deterministic `permalink` attribute (#394)
2020

21+
### Changed
22+
23+
- Re-enable `test_indexing_item_not_front` and test libzim's current indexing behavior for non-front items, including non-front `text/html` ones (#400)
24+
2125
## [5.5.2] - 2026-11-06
2226

2327
### Fixed

‎tests/zim/test_indexing.py‎

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ def test_indexing_item_is_front(tmp_path: pathlib.Path, png_image: pathlib.Path)
119119
assert reader.get_search_results_count("food") == 0
120120

121121

122-
@pytest.mark.skip # see https://github.com/openzim/python-scraperlib/issues/258
123122
def test_indexing_item_not_front(tmp_path: pathlib.Path, png_image: pathlib.Path):
123+
"""Create a ZIM with a non-front item with custom title and content for indexing"""
124124
fpath = tmp_path / "test.zim"
125125
main_path = "welcome"
126126
with Creator(fpath, main_path).config_dev_metadata() as creator:
@@ -139,21 +139,73 @@ def test_indexing_item_not_front(tmp_path: pathlib.Path, png_image: pathlib.Path
139139
assert fpath.exists()
140140

141141
reader = Archive(fpath)
142-
# "brain" works as a suggestion but "food" doesn't work because since no front
143-
# article is present in the zim file, libzim doesn't create a title xapian index.
144-
# so, when searching suggestion, libzim is fallback to a binary search on the title
145-
# and return only article starting by the query.
146-
# see https://github.com/openzim/libzim/issues/902#issuecomment-2223050129
147-
assert "welcome" in list(reader.get_suggestions("brain"))
142+
# libzim 3.13 yields no suggestions for a non-front item.
143+
# This test documents libzim's current behaviour.
144+
assert "welcome" not in list(reader.get_suggestions("brain"))
148145
assert "welcome" not in list(reader.get_suggestions("food"))
149146
assert "welcome" not in list(reader.get_suggestions("screen"))
150147
assert "welcome" not in list(reader.get_suggestions("car"))
151-
assert reader.get_search_results_count("screen") >= 1
152-
assert reader.get_search_results_count("car") >= 1
148+
assert reader.get_search_results_count("screen") == 1
149+
assert reader.get_search_results_count("car") == 1
153150
assert reader.get_search_results_count("brain") == 0
154151
assert reader.get_search_results_count("food") == 0
155152

156153

154+
def test_indexing_html_not_front_custom(tmp_path: pathlib.Path):
155+
"""A non-front HTML item has custom indexing data"""
156+
fpath = tmp_path / "test.zim"
157+
main_path = "welcome"
158+
with Creator(fpath, main_path).config_dev_metadata() as creator:
159+
creator.add_item(
160+
StaticItem(
161+
content="<html><body>car</body></html>",
162+
path="welcome",
163+
title="brain food",
164+
mimetype="text/html",
165+
index_data=IndexData(title="screen", content="car"),
166+
hints={libzim.writer.Hint.FRONT_ARTICLE: False},
167+
)
168+
)
169+
assert fpath.exists()
170+
171+
reader = Archive(fpath)
172+
assert "welcome" not in list(reader.get_suggestions("brain"))
173+
assert "welcome" not in list(reader.get_suggestions("food"))
174+
assert "welcome" not in list(reader.get_suggestions("screen"))
175+
assert "welcome" not in list(reader.get_suggestions("car"))
176+
assert reader.get_search_results_count("screen") == 1
177+
assert reader.get_search_results_count("car") == 1
178+
assert reader.get_search_results_count("brain") == 0
179+
assert reader.get_search_results_count("food") == 0
180+
181+
182+
def test_indexing_html_not_front_with_libzim(tmp_path: pathlib.Path):
183+
"""A non-front HTML item is automatically indexed by libzim"""
184+
fpath = tmp_path / "test.zim"
185+
main_path = "welcome"
186+
with Creator(fpath, main_path).config_dev_metadata() as creator:
187+
creator.add_item(
188+
StaticItem(
189+
content="<html><title>screen</title><body>car</body></html>",
190+
path="welcome",
191+
title="brain food",
192+
mimetype="text/html",
193+
hints={libzim.writer.Hint.FRONT_ARTICLE: False},
194+
)
195+
)
196+
assert fpath.exists()
197+
198+
reader = Archive(fpath)
199+
assert "welcome" not in list(reader.get_suggestions("brain"))
200+
assert "welcome" not in list(reader.get_suggestions("food"))
201+
assert "welcome" not in list(reader.get_suggestions("screen"))
202+
assert "welcome" not in list(reader.get_suggestions("car"))
203+
assert reader.get_search_results_count("brain") == 1
204+
assert reader.get_search_results_count("food") == 1
205+
assert reader.get_search_results_count("car") == 1
206+
assert reader.get_search_results_count("screen") == 0
207+
208+
157209
def _assert_pdf_zim(fpath: pathlib.Path):
158210
assert fpath.exists()
159211

0 commit comments

Comments
 (0)