Skip to content
Open
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
47 changes: 47 additions & 0 deletions tests/test_libzim_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,3 +894,50 @@ def test_accented_search_from_libzim(fpath):
accented_search = accented_searcher.search(accented_query)
assert accented_search.getEstimatedMatches() == zim.article_count
assert list(accented_search.getResults(0, zim.article_count)) == ["path0", "path1"]


def test_get_entry_by_title_utf8(fpath):
"""Test get_entry_by_title on a ZIM with title index and distinct title and path."""
with Creator(fpath) as creator:
creator.add_item(
StaticItem(
path="articles/song.html",
title="A Song for You",
content="Standard English content",
)
)
creator.add_item(
StaticItem(
path="articles/utf8.html",
title="Spécial: 日本語 & हिन्दी — 🚀 ★",
content="UTF-8 multilingual content",
)
)

zim = Archive(fpath)
assert zim.has_title_index is True

assert zim.has_entry_by_title("A Song for You") is True
entry1 = zim.get_entry_by_title("A Song for You")
assert entry1.path == "articles/song.html"
assert entry1.title == "A Song for You"

utf8_title = "Spécial: 日本語 & हिन्दी — 🚀 ★"
assert zim.has_entry_by_title(utf8_title) is True
entry2 = zim.get_entry_by_title(utf8_title)
assert entry2.path == "articles/utf8.html"
assert entry2.title == utf8_title

assert zim.has_entry_by_title("articles/song.html") is False
with pytest.raises(KeyError):
zim.get_entry_by_title("articles/song.html")

assert zim.has_entry_by_title("articles/utf8.html") is False
with pytest.raises(KeyError):
zim.get_entry_by_title("articles/utf8.html")

assert zim.has_entry_by_title("Non Existent Title 🔍") is False
with pytest.raises(KeyError):
zim.get_entry_by_title("Non Existent Title 🔍")


Loading