Skip to content

Commit b718c06

Browse files
committed
Last fix?
1 parent c424b41 commit b718c06

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

tests/zim/test_zim_creator.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,59 @@ def test_blank_metadata(tmp_path):
10081008
reader.get_text_metadata("None")
10091009

10101010

1011+
@pytest.mark.parametrize(
1012+
"name,value,expected_value",
1013+
[
1014+
pytest.param(
1015+
"X-Test",
1016+
DEFAULT_DEV_ZIM_METADATA.Title + "Foo",
1017+
DEFAULT_DEV_ZIM_METADATA.Title + "Foo",
1018+
id="simple_str",
1019+
),
1020+
pytest.param("X-Test", None, None, id="empty"),
1021+
pytest.param("Tags", ["tag1", "tag2"], "tag1;tag2", id="tags"),
1022+
pytest.param(
1023+
"LongDescription",
1024+
"Long \r\adescription",
1025+
"Long \rdescription",
1026+
id="long_description",
1027+
),
1028+
],
1029+
)
1030+
def test_add_metadata(tmp_path, name, value, expected_value):
1031+
fpath = tmp_path / "test_blank.zim"
1032+
with Creator(fpath, "").config_dev_metadata() as creator:
1033+
creator.add_metadata(name, value)
1034+
assert fpath.exists()
1035+
reader = Archive(fpath)
1036+
if value:
1037+
assert reader.get_text_metadata(name) == expected_value
1038+
else:
1039+
with pytest.raises(RuntimeError, match="Cannot find metadata"):
1040+
reader.get_text_metadata(name)
1041+
1042+
1043+
@pytest.mark.parametrize(
1044+
"name",
1045+
[
1046+
pytest.param(
1047+
"Illustration_96x96@1",
1048+
id="illustration_@",
1049+
),
1050+
pytest.param(
1051+
"Illustration_96x96_at_1", # must be renamed to Illustration_96x96@1
1052+
id="illustration_at",
1053+
),
1054+
],
1055+
)
1056+
def test_add_bad_illustration(tmp_path, name):
1057+
with pytest.raises(
1058+
ValueError, match="Illustration_96x96@1 is not a 96x96 PNG Image"
1059+
):
1060+
with Creator(tmp_path / "_.zim", "").config_dev_metadata() as creator:
1061+
creator.add_metadata(name, DEFAULT_DEV_ZIM_METADATA.Illustration_48x48_at_1)
1062+
1063+
10111064
@pytest.mark.parametrize(
10121065
"name,metadata_type,default_value,expected_value,expected_error",
10131066
[

0 commit comments

Comments
 (0)