diff --git a/tests/zim/test_indexing.py b/tests/zim/test_indexing.py index 378a0e47..3e77dd9a 100644 --- a/tests/zim/test_indexing.py +++ b/tests/zim/test_indexing.py @@ -332,3 +332,23 @@ def test_indexing_item_pdf_custom_title(tmp_path, encrypted_pdf_file): assert reader.get_search_results_count("the") == 1 assert reader.get_search_results_count("microsoft") == 1 assert reader.get_search_results_count("c8clark") == 1 + + +@pytest.mark.parametrize( + "content, wordcount, expected_wordcount", + [ + ("foo", None, 1), + ("foo bar", None, 2), + (" foo bar ", None, 2), + ( + "foo bar", + 123, + 123, + ), # wordcount is passed so it is not automatically computed + ], +) +def test_index_data_wordcount(content, wordcount, expected_wordcount): + assert ( + IndexData(title="foo", content=content, wordcount=wordcount).get_wordcount() + == expected_wordcount + ) diff --git a/tests/zim/test_zim_creator.py b/tests/zim/test_zim_creator.py index a60d907f..5436c020 100644 --- a/tests/zim/test_zim_creator.py +++ b/tests/zim/test_zim_creator.py @@ -535,6 +535,9 @@ def test_check_metadata(tmp_path): with pytest.raises(ValueError, match="Counter cannot be set"): Creator(tmp_path, "").config_dev_metadata(Counter=1).start() + with pytest.raises(ValueError, match="Invalid type for Foo"): + Creator(tmp_path, "").config_dev_metadata(Foo=1).start() + with pytest.raises(ValueError, match="Description is too long."): Creator(tmp_path, "").config_dev_metadata(Description="T" * 90).start() @@ -750,6 +753,10 @@ def test_config_metadata_control_characters(tmp_path): "Creator_1", " A creator ", ) + creator.add_metadata( + "Binary1", + bytes.fromhex("01FA"), + ) pass assert fpath.exists() @@ -773,6 +780,7 @@ def test_config_metadata_control_characters(tmp_path): == "A description \rwith \ncontrol characters\tsss" ) assert reader.get_text_metadata("Creator_1") == "A creator" + assert bytes.hex(reader.get_metadata("Binary1")) == "01fa" @pytest.mark.parametrize(