@@ -36,20 +36,28 @@ def setUp(self):
36
36
37
37
def test_case_sensitivity (self ):
38
38
eq = self .assertEqual
39
- eq (self .db .guess_type ("foobar.HTML" ), self .db .guess_type ("foobar.html" ))
40
- eq (self .db .guess_type ("foobar.TGZ" ), self .db .guess_type ("foobar.tgz" ))
41
- eq (self .db .guess_type ("foobar.tar.Z" ), ("application/x-tar" , "compress" ))
42
- eq (self .db .guess_type ("foobar.tar.z" ), (None , None ))
39
+ eq (self .db .guess_file_type ("foobar.html" ), ("text/html" , None ))
40
+ eq (self .db .guess_type ("scheme:foobar.html" ), ("text/html" , None ))
41
+ eq (self .db .guess_file_type ("foobar.HTML" ), ("text/html" , None ))
42
+ eq (self .db .guess_type ("scheme:foobar.HTML" ), ("text/html" , None ))
43
+ eq (self .db .guess_file_type ("foobar.tgz" ), ("application/x-tar" , "gzip" ))
44
+ eq (self .db .guess_type ("scheme:foobar.tgz" ), ("application/x-tar" , "gzip" ))
45
+ eq (self .db .guess_file_type ("foobar.TGZ" ), ("application/x-tar" , "gzip" ))
46
+ eq (self .db .guess_type ("scheme:foobar.TGZ" ), ("application/x-tar" , "gzip" ))
47
+ eq (self .db .guess_file_type ("foobar.tar.Z" ), ("application/x-tar" , "compress" ))
48
+ eq (self .db .guess_type ("scheme:foobar.tar.Z" ), ("application/x-tar" , "compress" ))
49
+ eq (self .db .guess_file_type ("foobar.tar.z" ), (None , None ))
50
+ eq (self .db .guess_type ("scheme:foobar.tar.z" ), (None , None ))
43
51
44
52
def test_default_data (self ):
45
53
eq = self .assertEqual
46
- eq (self .db .guess_type ("foo.html" ), ("text/html" , None ))
47
- eq (self .db .guess_type ("foo.HTML" ), ("text/html" , None ))
48
- eq (self .db .guess_type ("foo.tgz" ), ("application/x-tar" , "gzip" ))
49
- eq (self .db .guess_type ("foo.tar.gz" ), ("application/x-tar" , "gzip" ))
50
- eq (self .db .guess_type ("foo.tar.Z" ), ("application/x-tar" , "compress" ))
51
- eq (self .db .guess_type ("foo.tar.bz2" ), ("application/x-tar" , "bzip2" ))
52
- eq (self .db .guess_type ("foo.tar.xz" ), ("application/x-tar" , "xz" ))
54
+ eq (self .db .guess_file_type ("foo.html" ), ("text/html" , None ))
55
+ eq (self .db .guess_file_type ("foo.HTML" ), ("text/html" , None ))
56
+ eq (self .db .guess_file_type ("foo.tgz" ), ("application/x-tar" , "gzip" ))
57
+ eq (self .db .guess_file_type ("foo.tar.gz" ), ("application/x-tar" , "gzip" ))
58
+ eq (self .db .guess_file_type ("foo.tar.Z" ), ("application/x-tar" , "compress" ))
59
+ eq (self .db .guess_file_type ("foo.tar.bz2" ), ("application/x-tar" , "bzip2" ))
60
+ eq (self .db .guess_file_type ("foo.tar.xz" ), ("application/x-tar" , "xz" ))
53
61
54
62
def test_data_urls (self ):
55
63
eq = self .assertEqual
@@ -63,7 +71,7 @@ def test_file_parsing(self):
63
71
eq = self .assertEqual
64
72
sio = io .StringIO ("x-application/x-unittest pyunit\n " )
65
73
self .db .readfp (sio )
66
- eq (self .db .guess_type ("foo.pyunit" ),
74
+ eq (self .db .guess_file_type ("foo.pyunit" ),
67
75
("x-application/x-unittest" , None ))
68
76
eq (self .db .guess_extension ("x-application/x-unittest" ), ".pyunit" )
69
77
@@ -95,12 +103,12 @@ def test_read_mime_types(self):
95
103
def test_non_standard_types (self ):
96
104
eq = self .assertEqual
97
105
# First try strict
98
- eq (self .db .guess_type ('foo.xul' , strict = True ), (None , None ))
106
+ eq (self .db .guess_file_type ('foo.xul' , strict = True ), (None , None ))
99
107
eq (self .db .guess_extension ('image/jpg' , strict = True ), None )
100
108
# And then non-strict
101
- eq (self .db .guess_type ('foo.xul' , strict = False ), ('text/xul' , None ))
102
- eq (self .db .guess_type ('foo.XUL' , strict = False ), ('text/xul' , None ))
103
- eq (self .db .guess_type ('foo.invalid' , strict = False ), (None , None ))
109
+ eq (self .db .guess_file_type ('foo.xul' , strict = False ), ('text/xul' , None ))
110
+ eq (self .db .guess_file_type ('foo.XUL' , strict = False ), ('text/xul' , None ))
111
+ eq (self .db .guess_file_type ('foo.invalid' , strict = False ), (None , None ))
104
112
eq (self .db .guess_extension ('image/jpg' , strict = False ), '.jpg' )
105
113
eq (self .db .guess_extension ('image/JPG' , strict = False ), '.jpg' )
106
114
@@ -124,15 +132,26 @@ def test_filename_with_url_delimiters(self):
124
132
'//share/server/' , '\\ \\ share\\ server\\ ' ):
125
133
path = prefix + name
126
134
with self .subTest (path = path ):
135
+ eq (self .db .guess_file_type (path ), gzip_expected )
127
136
eq (self .db .guess_type (path ), gzip_expected )
128
137
expected = (None , None ) if os .name == 'nt' else gzip_expected
129
138
for prefix in ('//' , '\\ \\ ' , '//share/' , '\\ \\ share\\ ' ):
130
139
path = prefix + name
131
140
with self .subTest (path = path ):
141
+ eq (self .db .guess_file_type (path ), expected )
132
142
eq (self .db .guess_type (path ), expected )
143
+ eq (self .db .guess_file_type (r" \"\`;b&b&c |.tar.gz" ), gzip_expected )
133
144
eq (self .db .guess_type (r" \"\`;b&b&c |.tar.gz" ), gzip_expected )
134
145
146
+ eq (self .db .guess_file_type (r'foo/.tar.gz' ), (None , 'gzip' ))
147
+ eq (self .db .guess_type (r'foo/.tar.gz' ), (None , 'gzip' ))
148
+ expected = (None , 'gzip' ) if os .name == 'nt' else gzip_expected
149
+ eq (self .db .guess_file_type (r'foo\.tar.gz' ), expected )
150
+ eq (self .db .guess_type (r'foo\.tar.gz' ), expected )
151
+ eq (self .db .guess_type (r'scheme:foo\.tar.gz' ), gzip_expected )
152
+
135
153
def test_url (self ):
154
+ result = self .db .guess_type ('http://example.com/host.html' )
136
155
result = self .db .guess_type ('http://host.html' )
137
156
msg = 'URL only has a host name, not a file'
138
157
self .assertSequenceEqual (result , (None , None ), msg )
@@ -240,22 +259,38 @@ def test_init_stability(self):
240
259
241
260
def test_path_like_ob (self ):
242
261
filename = "LICENSE.txt"
243
- filepath = pathlib . Path (filename )
244
- filepath_with_abs_dir = pathlib . Path ('/dir/' + filename )
245
- filepath_relative = pathlib . Path ('../dir/' + filename )
246
- path_dir = pathlib . Path ('./' )
262
+ filepath = os_helper . FakePath (filename )
263
+ filepath_with_abs_dir = os_helper . FakePath ('/dir/' + filename )
264
+ filepath_relative = os_helper . FakePath ('../dir/' + filename )
265
+ path_dir = os_helper . FakePath ('./' )
247
266
248
- expected = self .db .guess_type (filename )
267
+ expected = self .db .guess_file_type (filename )
249
268
269
+ self .assertEqual (self .db .guess_file_type (filepath ), expected )
250
270
self .assertEqual (self .db .guess_type (filepath ), expected )
271
+ self .assertEqual (self .db .guess_file_type (
272
+ filepath_with_abs_dir ), expected )
251
273
self .assertEqual (self .db .guess_type (
252
274
filepath_with_abs_dir ), expected )
275
+ self .assertEqual (self .db .guess_file_type (filepath_relative ), expected )
253
276
self .assertEqual (self .db .guess_type (filepath_relative ), expected )
277
+
278
+ self .assertEqual (self .db .guess_file_type (path_dir ), (None , None ))
254
279
self .assertEqual (self .db .guess_type (path_dir ), (None , None ))
255
280
281
+ def test_bytes_path (self ):
282
+ self .assertEqual (self .db .guess_file_type (b'foo.html' ),
283
+ self .db .guess_file_type ('foo.html' ))
284
+ self .assertEqual (self .db .guess_file_type (b'foo.tar.gz' ),
285
+ self .db .guess_file_type ('foo.tar.gz' ))
286
+ self .assertEqual (self .db .guess_file_type (b'foo.tgz' ),
287
+ self .db .guess_file_type ('foo.tgz' ))
288
+
256
289
def test_keywords_args_api (self ):
290
+ self .assertEqual (self .db .guess_file_type (
291
+ path = "foo.html" , strict = True ), ("text/html" , None ))
257
292
self .assertEqual (self .db .guess_type (
258
- url = "foo.html" , strict = True ), ("text/html" , None ))
293
+ url = "scheme: foo.html" , strict = True ), ("text/html" , None ))
259
294
self .assertEqual (self .db .guess_all_extensions (
260
295
type = 'image/jpg' , strict = True ), [])
261
296
self .assertEqual (self .db .guess_extension (
0 commit comments