@@ -501,92 +501,7 @@ def test_keywords_args_api(self):
501501 type = 'image/jpeg' , strict = True ), ['.jpg' , '.jpe' , '.jpeg' ])
502502
503503
504- class GuessTypeDeprecationTestCase (unittest .TestCase ):
505- """Tests that guess_type() emits DeprecationWarning for file path inputs."""
506504
507- def setUp (self ):
508- self .db = mimetypes .MimeTypes ()
509-
510- # --- Module-level function tests ---
511-
512- def test_module_plain_string_path_warns (self ):
513- """Module-level guess_type() warns for a plain string with no URL scheme."""
514- with self .assertWarns (DeprecationWarning ) as cm :
515- mimetypes .guess_type ("file.txt" )
516- self .assertIn ("guess_file_type" , str (cm .warning ))
517- self .assertIn ("deprecated" , str (cm .warning ).lower ())
518-
519- def test_module_pathlike_warns (self ):
520- """Module-level guess_type() warns for a path-like object."""
521- with self .assertWarns (DeprecationWarning ):
522- mimetypes .guess_type (pathlib .Path ("file.txt" ))
523-
524- def test_module_bytes_path_warns (self ):
525- """Module-level guess_type() warns for a bytes path."""
526- with self .assertWarns (DeprecationWarning ):
527- mimetypes .guess_type (b"file.txt" )
528-
529- def test_module_url_with_scheme_no_warning (self ):
530- """Module-level guess_type() does NOT warn for a proper URL."""
531- with warnings .catch_warnings ():
532- warnings .simplefilter ("error" , DeprecationWarning )
533- # Should not raise -- http:// is a valid multi-char scheme.
534- mimetypes .guess_type ("http://example.com/file.html" )
535-
536- def test_module_data_url_no_warning (self ):
537- """Module-level guess_type() does NOT warn for data: URLs."""
538- with warnings .catch_warnings ():
539- warnings .simplefilter ("error" , DeprecationWarning )
540- mimetypes .guess_type ("data:text/plain,hello" )
541-
542- # --- MimeTypes class method tests ---
543-
544- def test_method_plain_string_path_warns (self ):
545- """MimeTypes.guess_type() warns for a plain string with no URL scheme."""
546- with self .assertWarns (DeprecationWarning ) as cm :
547- self .db .guess_type ("file.html" )
548- self .assertIn ("guess_file_type" , str (cm .warning ))
549-
550- def test_method_pathlike_warns (self ):
551- """MimeTypes.guess_type() warns for a path-like object."""
552- with self .assertWarns (DeprecationWarning ):
553- self .db .guess_type (pathlib .Path ("file.html" ))
554-
555- def test_method_bytes_path_warns (self ):
556- """MimeTypes.guess_type() warns for a bytes path."""
557- with self .assertWarns (DeprecationWarning ):
558- self .db .guess_type (b"file.html" )
559-
560- def test_method_url_with_scheme_no_warning (self ):
561- """MimeTypes.guess_type() does NOT warn for a proper URL."""
562- with warnings .catch_warnings ():
563- warnings .simplefilter ("error" , DeprecationWarning )
564- self .db .guess_type ("http://example.com/file.html" )
565-
566- def test_method_ftp_url_no_warning (self ):
567- """MimeTypes.guess_type() does NOT warn for an ftp: URL."""
568- with warnings .catch_warnings ():
569- warnings .simplefilter ("error" , DeprecationWarning )
570- self .db .guess_type ("ftp://example.com/file.tar.gz" )
571-
572- def test_result_unchanged (self ):
573- """guess_type() with a file path still returns the correct MIME type."""
574- with self .assertWarns (DeprecationWarning ):
575- result = mimetypes .guess_type ("file.html" )
576- expected = mimetypes .guess_file_type ("file.html" )
577- self .assertEqual (result , expected )
578-
579- def test_result_unchanged_pathlike (self ):
580- """guess_type() with a PathLike still returns the correct MIME type."""
581- with self .assertWarns (DeprecationWarning ):
582- result = self .db .guess_type (pathlib .Path ("file.tar.gz" ))
583- expected = self .db .guess_file_type (pathlib .Path ("file.tar.gz" ))
584- self .assertEqual (result , expected )
585-
586- def test_os_helper_fakepath_warns (self ):
587- """guess_type() warns for os_helper.FakePath (a path-like object)."""
588- with self .assertWarns (DeprecationWarning ):
589- self .db .guess_type (os_helper .FakePath ("file.tar.gz" ))
590505
591506
592507@unittest .skipUnless (sys .platform .startswith ("win" ), "Windows only" )
0 commit comments