@@ -45,7 +45,7 @@ def get_contentprovider(self):
4545 return FileLikeProvider (self .fileobj )
4646
4747
48- def test_zim_creator (tmp_path , png_image , html_file , html_str ):
48+ def test_zim_creator (tmp_path , png_image , html_file , html_str : str , html_str_cn : str ):
4949 fpath = tmp_path / "test.zim"
5050 main_path = "welcome"
5151 tags = ";" .join (["toto" , "tata" ])
@@ -56,6 +56,13 @@ def test_zim_creator(tmp_path, png_image, html_file, html_str):
5656 ) as creator :
5757 # verbatim HTML from string
5858 creator .add_item_for ("welcome" , "wel" , content = html_str , is_front = True )
59+ # verbatim HTML from bytes
60+ creator .add_item_for (
61+ "welcome1" , "wel1" , content = html_str .encode (), is_front = True
62+ )
63+ creator .add_item_for (
64+ "welcome2" , "wel2" , content = html_str_cn .encode ("gb2312" ), is_front = True
65+ )
5966 # verbatim HTML from file
6067 creator .add_item_for ("welcome3" , "wel3" , fpath = html_file )
6168 creator .add_item_for ("welcome4" , "wel4" , fpath = html_file )
@@ -98,6 +105,8 @@ def test_zim_creator(tmp_path, png_image, html_file, html_str):
98105
99106 # ensure non-rewritten articles have not been rewritten
100107 assert bytes (reader .get_item ("welcome" ).content ).decode (UTF8 ) == html_str
108+ assert bytes (reader .get_item ("welcome1" ).content ).decode (UTF8 ) == html_str
109+ assert bytes (reader .get_item ("welcome2" ).content ).decode ("gb2312" ) == html_str_cn
101110 assert bytes (reader .get_item ("welcome3" ).content ).decode (UTF8 ) == html_str
102111
103112 # ensure illustration is present and corrext
@@ -180,6 +189,30 @@ def test_add_item_for_delete_fail(tmp_path, png_image):
180189 assert reader .get_item ("index" )
181190
182191
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+
203+ def test_add_item_for_unsupported_content_type (tmp_path ):
204+ fpath = tmp_path / "test.zim"
205+ # test with incorrect content type
206+ with Creator (fpath , "welcome" ).config_dev_metadata () as creator :
207+ with pytest .raises (RuntimeError ):
208+ creator .add_item_for (
209+ path = "welcome" ,
210+ title = "hello" ,
211+ mimetype = "text/plain" ,
212+ content = 123 , # pyright: ignore[reportArgumentType]
213+ )
214+
215+
183216def test_compression (tmp_path ):
184217 fpath = tmp_path / "test.zim"
185218 with Creator (
@@ -508,7 +541,7 @@ def test_check_metadata(tmp_path):
508541
509542
510543def test_relax_metadata (tmp_path ):
511- Creator (tmp_path , "" , disable_metadata_checks = False ).config_dev_metadata (
544+ Creator (tmp_path , "" , disable_metadata_checks = True ).config_dev_metadata (
512545 Description = "T" * 90
513546 ).start ()
514547
0 commit comments