@@ -67,9 +67,33 @@ def test_read_mime_types(self):
6767 with unittest .mock .patch .object (mimetypes , 'open' ,
6868 return_value = fp ) as mock_open :
6969 mime_dict = mimetypes .read_mime_types (filename )
70- mock_open .assert_called_with (filename , encoding = 'utf-8' )
70+ mock_open .assert_called_with (filename , encoding = 'utf-8' ,
71+ errors = 'replace' )
7172 eq (mime_dict [".Français" ], "application/no-mans-land" )
7273
74+ def test_read_mime_types_invalid_utf8_comment (self ):
75+ with os_helper .temp_dir () as directory :
76+ data = (b"# non-UTF-8 comment: \x83 \n "
77+ b"x-application/x-unittest pyunit\n " )
78+ file = os .path .join (directory , "sample.mimetype" )
79+ with open (file , "wb" ) as f :
80+ f .write (data )
81+
82+ mime_dict = mimetypes .read_mime_types (file )
83+ self .assertEqual (
84+ mime_dict [".pyunit" ], "x-application/x-unittest" )
85+
86+ db = mimetypes .MimeTypes ()
87+ db .read (file )
88+ self .assertEqual (
89+ db .guess_file_type ("sample.pyunit" )[0 ],
90+ "x-application/x-unittest" )
91+
92+ mimetypes .init (files = [file ])
93+ self .assertEqual (
94+ mimetypes .guess_file_type ("sample.pyunit" )[0 ],
95+ "x-application/x-unittest" )
96+
7397 def test_init_reinitializes (self ):
7498 # Issue 4936: make sure an init starts clean
7599 # First, put some poison into the types table
0 commit comments