Skip to content

Commit d180e35

Browse files
committed
Always set item attributes when passed, even if 'False'/empty/whatever
1 parent dab7b11 commit d180e35

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/zimscraperlib/zim/items.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ def __init__(
3434
**kwargs: Any,
3535
):
3636
super().__init__()
37-
if path:
37+
if path is not None:
3838
kwargs["path"] = path
39-
if title:
39+
if title is not None:
4040
kwargs["title"] = title
41-
if mimetype:
41+
if mimetype is not None:
4242
kwargs["mimetype"] = mimetype
43-
if hints:
43+
if hints is not None:
4444
kwargs["hints"] = hints
4545
for k, v in kwargs.items():
4646
setattr(self, k, v)
@@ -81,11 +81,11 @@ def __init__(
8181
hints: Optional[dict] = None,
8282
**kwargs: Any,
8383
):
84-
if content:
84+
if content is not None:
8585
kwargs["content"] = content
86-
if fileobj:
86+
if fileobj is not None:
8787
kwargs["fileobj"] = fileobj
88-
if filepath:
88+
if filepath is not None:
8989
kwargs["filepath"] = filepath
9090
super().__init__(
9191
path=path, title=title, mimetype=mimetype, hints=hints, **kwargs
@@ -155,7 +155,7 @@ def __init__(
155155
use_disk: Optional[bool] = None,
156156
**kwargs: Any,
157157
):
158-
if use_disk:
158+
if use_disk is not None:
159159
kwargs["use_disk"] = use_disk
160160
super().__init__(
161161
path=path, title=title, mimetype=mimetype, hints=hints, **kwargs

tests/zim/test_zim_creator.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,17 @@ def test_add_item_for_delete_fail(tmp_path, png_image):
189189
assert reader.get_item("index")
190190

191191

192+
def test_add_item_empty_content(tmp_path):
193+
fpath = tmp_path / "test.zim"
194+
# test with incorrect content type
195+
with Creator(fpath, "welcome").config_dev_metadata() as creator:
196+
creator.add_item_for(
197+
path="welcome",
198+
title="hello",
199+
content="",
200+
)
201+
202+
192203
def test_add_item_for_unsupported_content_type(tmp_path):
193204
fpath = tmp_path / "test.zim"
194205
# test with incorrect content type

0 commit comments

Comments
 (0)