Skip to content

Commit 50721d5

Browse files
committed
Fixed #127: added getMetadataItem support
added `get_metadata_item()` on Archive to match `getMetadataItem()`. Improved existing tests to test it. Added a new ZIM from zim-testing-suite to test for Illustration's mimetype
1 parent ba62b0a commit 50721d5

7 files changed

Lines changed: 61 additions & 5 deletions

File tree

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- v*
77

88
env:
9-
LIBZIM_VERSION: 7.0.0
9+
LIBZIM_VERSION: 7.1.0
1010
LIBZIM_INCLUDE_PATH: include/zim
1111
TWINE_USERNAME: __token__
1212
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: test
22
on: [push]
33

44
env:
5-
LIBZIM_VERSION: 7.0.0
5+
LIBZIM_VERSION: 7.1.0
66
LIBZIM_INCLUDE_PATH: include/zim
77
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
88
PROFILE: 1
@@ -56,7 +56,7 @@ jobs:
5656
run: |
5757
echo LIBZIM_EXT=so >> $GITHUB_ENV
5858
echo LIBZIM_RELEASE=libzim_linux-x86_64-$LIBZIM_VERSION >> $GITHUB_ENV
59-
echo LIBZIM_LIBRARY_PATH=lib/x86_64-linux-gnu/libzim.so.7.0.0 >> $GITHUB_ENV
59+
echo LIBZIM_LIBRARY_PATH=lib/x86_64-linux-gnu/libzim.so.7.1.0 >> $GITHUB_ENV
6060
6161
- name: Cache libzim dylib & headers
6262
uses: actions/cache@master

libzim/libwrapper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ class Archive : public Wrapper<zim::Archive>
153153
}
154154
FORWARD(zim::size_type, getFilesize)
155155
FORWARD(std::string, getMetadata)
156+
FORWARD(wrapper::Item, getMetadataItem)
156157
FORWARD(std::vector<std::string>, getMetadataKeys)
157158
FORWARD(zim::size_type, getEntryCount)
158159
FORWARD(zim::size_type, getAllEntryCount)

libzim/libzim.pyx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,11 @@ cdef class Archive:
799799
"""List of Metadata keys present in this archive"""
800800
return [key.decode("UTF-8", "strict") for key in self.c_archive.getMetadataKeys()]
801801

802+
def get_metadata_item(self, name: str) -> Item:
803+
"""A Metadata's Item"""
804+
cdef zim.Item item = move(self.c_archive.getMetadataItem(name.encode('UTF-8')))
805+
return Item.from_item(move(item))
806+
802807
def get_metadata(self, name: str) -> bytes:
803808
"""A Metadata's content -> bytes
804809

libzim/zim.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ cdef extern from "libwrapper.h" namespace "wrapper":
138138
Entry getEntryByTitle(string title) except +
139139

140140
string getMetadata(string name) except +
141+
Item getMetadataItem(string name) except +
141142
vector[string] getMetadataKeys() except +
142143

143144
Entry getMainEntry() except +

tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
@task
17-
def download_libzim(c, version="7.0.0"):
17+
def download_libzim(c, version="7.1.0"):
1818
"""download C++ libzim binary"""
1919

2020
if platform.machine() != "x86_64" or platform.system() not in ("Linux", "Darwin"):

tests/test_libzim_reader.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,50 @@
190190
"test_redirect": "-/favicon",
191191
"test_redirect_to": "I/empty.png",
192192
},
193+
"small.zim": {
194+
"filename": "small.zim",
195+
"filesize": 41155,
196+
"new_ns": True,
197+
"mutlipart": False,
198+
"zim_uuid": "3581ae7eedd57e6cd2f1c0cab073643f",
199+
"metadata_keys": [
200+
"Counter",
201+
"Creator",
202+
"Date",
203+
"Description",
204+
"Illustration_48x48@1",
205+
"Language",
206+
"Publisher",
207+
"Scraper",
208+
"Tags",
209+
"Title",
210+
],
211+
"test_metadata": "Title",
212+
"test_metadata_value": "Test ZIM file",
213+
"has_main_entry": True,
214+
"has_favicon_entry": True,
215+
"has_fulltext_index": False,
216+
"has_title_index": True,
217+
"has_checksum": True,
218+
"checksum": None,
219+
"is_valid": True,
220+
"entry_count": 2,
221+
"all_entry_count": 16,
222+
"article_count": 1,
223+
"suggestion_string": None,
224+
"suggestion_count": None,
225+
"suggestion_result": None,
226+
"search_string": None,
227+
"search_count": None,
228+
"search_result": None,
229+
"test_path": "main.html",
230+
"test_title": "Test ZIM file",
231+
"test_mimetype": "text/html",
232+
"test_size": 207,
233+
"test_content_includes": "Test ZIM file",
234+
"test_redirect": None,
235+
"test_redirect_to": None,
236+
},
193237
}
194238

195239

@@ -220,7 +264,7 @@ def all_zims(tmpdir_factory):
220264
libzim_urls = [
221265
f"https://github.com/kiwix/kiwix-lib/raw/master/test/data/{name}"
222266
for name in ("zimfile.zim", "example.zim", "corner_cases.zim")
223-
]
267+
] + ["https://github.com/openzim/zim-testing-suite/raw/main/data/nons/small.zim"]
224268

225269
# download libzim tests
226270
for url in libzim_urls:
@@ -313,6 +357,9 @@ def test_reader_metadata(
313357
assert zim.metadata_keys == metadata_keys
314358
if test_metadata:
315359
assert zim.get_metadata(test_metadata).decode("UTF-8") == test_metadata_value
360+
item = zim.get_metadata_item(test_metadata)
361+
assert item.mimetype == "text/plain"
362+
assert item.size > 1
316363

317364

318365
@pytest.mark.parametrize(
@@ -347,6 +394,8 @@ def test_reader_main_favicon_entries(
347394
assert zim.get_illustration_item().path == "Illustration_48x48@1"
348395
assert zim.get_illustration_sizes() == {48}
349396

397+
assert zim.get_metadata_item("Illustration_48x48@1").mimetype == "image/png"
398+
350399

351400
@pytest.mark.parametrize(
352401
*parametrize_for(["filename", "has_fulltext_index", "has_title_index"])

0 commit comments

Comments
 (0)