Skip to content

Commit

Permalink
Add missing test in PR#178 to remain at 100% coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit74 committed Jul 30, 2024
1 parent 6eb77a5 commit 1583e4f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/zim/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
8 changes: 8 additions & 0 deletions tests/zim/test_zim_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()
Expand All @@ -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(
Expand Down

0 comments on commit 1583e4f

Please sign in to comment.