@@ -13,42 +13,49 @@ def setUp(self):
1313 self .db = mimetypes .MimeTypes ()
1414
1515 def test_default_data (self ):
16- self .assertEqual (self .db .guess_type ("foo.html" ),
17- ("text/html" , None ))
18- self .assertEqual (self .db .guess_type ("foo.tgz" ),
19- ("application/x-tar" , "gzip" ))
20- self .assertEqual (self .db .guess_type ("foo.tar.gz" ),
21- ("application/x-tar" , "gzip" ))
22- self .assertEqual (self .db .guess_type ("foo.tar.Z" ),
23- ("application/x-tar" , "compress" ))
16+ eq = self .assertEqual
17+ eq (self .db .guess_type ("foo.html" ), ("text/html" , None ))
18+ eq (self .db .guess_type ("foo.tgz" ), ("application/x-tar" , "gzip" ))
19+ eq (self .db .guess_type ("foo.tar.gz" ), ("application/x-tar" , "gzip" ))
20+ eq (self .db .guess_type ("foo.tar.Z" ), ("application/x-tar" , "compress" ))
2421
2522 def test_data_urls (self ):
26- self .assertEqual (self .db .guess_type ("data:,thisIsTextPlain" ),
27- ("text/plain" , None ))
28- self .assertEqual (self .db .guess_type ("data:;base64,thisIsTextPlain" ),
29- ("text/plain" , None ))
30- self .assertEqual (self .db .guess_type ("data:text/x-foo,thisIsTextXFoo" ),
31- ("text/x-foo" , None ))
23+ eq = self .assertEqual
24+ guess_type = self .db .guess_type
25+ eq (guess_type ("data:,thisIsTextPlain" ), ("text/plain" , None ))
26+ eq (guess_type ("data:;base64,thisIsTextPlain" ), ("text/plain" , None ))
27+ eq (guess_type ("data:text/x-foo,thisIsTextXFoo" ), ("text/x-foo" , None ))
3228
3329 def test_file_parsing (self ):
30+ eq = self .assertEqual
3431 sio = StringIO .StringIO ("x-application/x-unittest pyunit\n " )
3532 self .db .readfp (sio )
36- self .assertEqual (self .db .guess_type ("foo.pyunit" ),
37- ("x-application/x-unittest" , None ))
38- self .assertEqual (self .db .guess_extension ("x-application/x-unittest" ),
39- ".pyunit" )
33+ eq (self .db .guess_type ("foo.pyunit" ),
34+ ("x-application/x-unittest" , None ))
35+ eq (self .db .guess_extension ("x-application/x-unittest" ), ".pyunit" )
4036
4137 def test_non_standard_types (self ):
38+ eq = self .assertEqual
4239 # First try strict
43- self .assertEqual (self .db .guess_type ('foo.xul' , strict = 1 ),
44- (None , None ))
45- self .assertEqual (self .db .guess_extension ('image/jpg' , strict = 1 ),
46- None )
40+ eq (self .db .guess_type ('foo.xul' , strict = True ), (None , None ))
41+ eq (self .db .guess_extension ('image/jpg' , strict = True ), None )
4742 # And then non-strict
48- self .assertEqual (self .db .guess_type ('foo.xul' , strict = 0 ),
49- ('text/xul' , None ))
50- self .assertEqual (self .db .guess_extension ('image/jpg' , strict = 0 ),
51- '.jpg' )
43+ eq (self .db .guess_type ('foo.xul' , strict = False ), ('text/xul' , None ))
44+ eq (self .db .guess_extension ('image/jpg' , strict = False ), '.jpg' )
45+
46+ def test_guess_all_types (self ):
47+ eq = self .assertEqual
48+ # First try strict
49+ all = self .db .guess_all_extensions ('text/plain' , strict = True )
50+ all .sort ()
51+ eq (all , ['.bat' , '.c' , '.h' , '.ksh' , '.pl' , '.txt' ])
52+ # And now non-strict
53+ all = self .db .guess_all_extensions ('image/jpg' , strict = False )
54+ all .sort ()
55+ eq (all , ['.jpg' ])
56+ # And now for no hits
57+ all = self .db .guess_all_extensions ('image/jpg' , strict = True )
58+ eq (all , [])
5259
5360
5461def test_main ():
0 commit comments