Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(15)

Side by Side Diff: Lib/test/test_mimetypes.py

Issue 1043134: mimetypes.guess_extension('text/plain') == '.ksh' ???
Patch Set: Created 2 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/mimetypes.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import mimetypes 1 import mimetypes
2 import io 2 import io
3 import unittest 3 import unittest
4 import sys 4 import sys
5 5
6 from test import support 6 from test import support
7 7
8 # Tell it we don't know about external files: 8 # Tell it we don't know about external files:
9 mimetypes.knownfiles = [] 9 mimetypes.knownfiles = []
10 mimetypes.inited = False 10 mimetypes.inited = False
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 # such that the 'all' set will have more items in it. 54 # such that the 'all' set will have more items in it.
55 all = set(self.db.guess_all_extensions('text/plain', strict=True)) 55 all = set(self.db.guess_all_extensions('text/plain', strict=True))
56 unless(all >= set(['.bat', '.c', '.h', '.ksh', '.pl', '.txt'])) 56 unless(all >= set(['.bat', '.c', '.h', '.ksh', '.pl', '.txt']))
57 # And now non-strict 57 # And now non-strict
58 all = self.db.guess_all_extensions('image/jpg', strict=False) 58 all = self.db.guess_all_extensions('image/jpg', strict=False)
59 all.sort() 59 all.sort()
60 eq(all, ['.jpg']) 60 eq(all, ['.jpg'])
61 # And now for no hits 61 # And now for no hits
62 all = self.db.guess_all_extensions('image/jpg', strict=True) 62 all = self.db.guess_all_extensions('image/jpg', strict=True)
63 eq(all, []) 63 eq(all, [])
64
65 def test_guess_extension_all_types(self):
66 eq = self.assertEqual
67 unless = self.assertTrue
68 all_with_exts = set(self.db.guess_extension('text/plain', all_exts=True) )
69 all_without_exts = self.db.guess_extension('not_exits_type', all_exts=Tr ue)
70 unless(all_with_exts >= set(('.bat', '.c', '.h', '.ksh', '.pl', '.txt')) )
71 eq(all_without_exts, (None,))
64 72
65 73
66 @unittest.skipUnless(sys.platform.startswith("win"), "Windows only") 74 @unittest.skipUnless(sys.platform.startswith("win"), "Windows only")
67 class Win32MimeTypesTestCase(unittest.TestCase): 75 class Win32MimeTypesTestCase(unittest.TestCase):
68 def setUp(self): 76 def setUp(self):
69 # ensure all entries actually come from the Windows registry 77 # ensure all entries actually come from the Windows registry
70 self.original_types_map = mimetypes.types_map.copy() 78 self.original_types_map = mimetypes.types_map.copy()
71 mimetypes.types_map.clear() 79 mimetypes.types_map.clear()
72 mimetypes.init() 80 mimetypes.init()
73 self.db = mimetypes.MimeTypes() 81 self.db = mimetypes.MimeTypes()
(...skipping 12 matching lines...) Expand all
86 94
87 95
88 def test_main(): 96 def test_main():
89 support.run_unittest(MimeTypesTestCase, 97 support.run_unittest(MimeTypesTestCase,
90 Win32MimeTypesTestCase 98 Win32MimeTypesTestCase
91 ) 99 )
92 100
93 101
94 if __name__ == "__main__": 102 if __name__ == "__main__":
95 test_main() 103 test_main()
OLDNEW
« no previous file with comments | « Lib/mimetypes.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld cbc36f91f3f7