Skip to content

Commit

Permalink
Refactor test case
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Nov 4, 2024
1 parent 3ead9ac commit b0bfee2
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions Lib/test/test_mimetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,29 +223,32 @@ def test_guess_known_extensions(self):

def test_preferred_extension(self):
def check_extensions():
self.assertEqual(mimetypes.guess_extension('application/octet-stream'), '.bin')
self.assertEqual(mimetypes.guess_extension('application/postscript'), '.ps')
self.assertEqual(mimetypes.guess_extension('application/vnd.apple.mpegurl'), '.m3u')
self.assertEqual(mimetypes.guess_extension('application/vnd.ms-excel'), '.xls')
self.assertEqual(mimetypes.guess_extension('application/vnd.ms-powerpoint'), '.ppt')
self.assertEqual(mimetypes.guess_extension('application/x-texinfo'), '.texi')
self.assertEqual(mimetypes.guess_extension('application/x-troff'), '.roff')
self.assertEqual(mimetypes.guess_extension('application/xml'), '.xsl')
self.assertEqual(mimetypes.guess_extension('audio/matroska'), '.mka')
self.assertEqual(mimetypes.guess_extension('audio/mpeg'), '.mp3')
self.assertEqual(mimetypes.guess_extension('image/avif'), '.avif')
self.assertEqual(mimetypes.guess_extension('image/webp'), '.webp')
self.assertEqual(mimetypes.guess_extension('image/jpeg'), '.jpg')
self.assertEqual(mimetypes.guess_extension('image/tiff'), '.tiff')
self.assertEqual(mimetypes.guess_extension('message/rfc822'), '.eml')
self.assertEqual(mimetypes.guess_extension('text/html'), '.html')
self.assertEqual(mimetypes.guess_extension('text/plain'), '.txt')
self.assertEqual(mimetypes.guess_extension('text/rtf'), '.rtf')
self.assertEqual(mimetypes.guess_extension('text/x-rst'), '.rst')
self.assertEqual(mimetypes.guess_extension('video/matroska'), '.mkv')
self.assertEqual(mimetypes.guess_extension('video/matroska-3d'), '.mk3d')
self.assertEqual(mimetypes.guess_extension('video/mpeg'), '.mpeg')
self.assertEqual(mimetypes.guess_extension('video/quicktime'), '.mov')
for mime_type, ext in (
("application/octet-stream", ".bin"),
("application/postscript", ".ps"),
("application/vnd.apple.mpegurl", ".m3u"),
("application/vnd.ms-excel", ".xls"),
("application/vnd.ms-powerpoint", ".ppt"),
("application/x-texinfo", ".texi"),
("application/x-troff", ".roff"),
("application/xml", ".xsl"),
("audio/matroska", ".mka"),
("audio/mpeg", ".mp3"),
("image/avif", ".avif"),
("image/webp", ".webp"),
("image/jpeg", ".jpg"),
("image/tiff", ".tiff"),
("message/rfc822", ".eml"),
("text/html", ".html"),
("text/plain", ".txt"),
("text/rtf", ".rtf"),
("text/x-rst", ".rst"),
("video/matroska", ".mkv"),
("video/matroska-3d", ".mk3d"),
("video/mpeg", ".mpeg"),
("video/quicktime", ".mov"),
):
self.assertEqual(mimetypes.guess_extension(mime_type), ext)

check_extensions()
mimetypes.init()
Expand Down

0 comments on commit b0bfee2

Please sign in to comment.