|
1 | 1 | import io
|
2 | 2 | import mimetypes
|
| 3 | +import os |
3 | 4 | import pathlib
|
4 | 5 | import sys
|
5 | 6 | import unittest.mock
|
@@ -111,15 +112,40 @@ def test_filename_with_url_delimiters(self):
|
111 | 112 | # compared to when interpreted as filename because of the semicolon.
|
112 | 113 | eq = self.assertEqual
|
113 | 114 | gzip_expected = ('application/x-tar', 'gzip')
|
114 |
| - eq(self.db.guess_type(";1.tar.gz"), gzip_expected) |
115 |
| - eq(self.db.guess_type("?1.tar.gz"), gzip_expected) |
116 |
| - eq(self.db.guess_type("#1.tar.gz"), gzip_expected) |
117 |
| - eq(self.db.guess_type("#1#.tar.gz"), gzip_expected) |
118 |
| - eq(self.db.guess_type(";1#.tar.gz"), gzip_expected) |
119 |
| - eq(self.db.guess_type(";&1=123;?.tar.gz"), gzip_expected) |
120 |
| - eq(self.db.guess_type("?k1=v1&k2=v2.tar.gz"), gzip_expected) |
| 115 | + for name in ( |
| 116 | + ';1.tar.gz', |
| 117 | + '?1.tar.gz', |
| 118 | + '#1.tar.gz', |
| 119 | + '#1#.tar.gz', |
| 120 | + ';1#.tar.gz', |
| 121 | + ';&1=123;?.tar.gz', |
| 122 | + '?k1=v1&k2=v2.tar.gz', |
| 123 | + ): |
| 124 | + for prefix in ('', '/', '\\', |
| 125 | + 'c:', 'c:/', 'c:\\', 'c:/d/', 'c:\\d\\', |
| 126 | + '//share/server/', '\\\\share\\server\\'): |
| 127 | + path = prefix + name |
| 128 | + with self.subTest(path=path): |
| 129 | + eq(self.db.guess_type(path), gzip_expected) |
| 130 | + expected = (None, None) if os.name == 'nt' else gzip_expected |
| 131 | + for prefix in ('//', '\\\\', '//share/', '\\\\share\\'): |
| 132 | + path = prefix + name |
| 133 | + with self.subTest(path=path): |
| 134 | + eq(self.db.guess_type(path), expected) |
121 | 135 | eq(self.db.guess_type(r" \"\`;b&b&c |.tar.gz"), gzip_expected)
|
122 | 136 |
|
| 137 | + def test_url(self): |
| 138 | + result = self.db.guess_type('http://host.html') |
| 139 | + msg = 'URL only has a host name, not a file' |
| 140 | + self.assertSequenceEqual(result, (None, None), msg) |
| 141 | + result = self.db.guess_type('http://example.com/host.html') |
| 142 | + msg = 'Should be text/html' |
| 143 | + self.assertSequenceEqual(result, ('text/html', None), msg) |
| 144 | + result = self.db.guess_type('http://example.com/host.html#x.tar') |
| 145 | + self.assertSequenceEqual(result, ('text/html', None)) |
| 146 | + result = self.db.guess_type('http://example.com/host.html?q=x.tar') |
| 147 | + self.assertSequenceEqual(result, ('text/html', None)) |
| 148 | + |
123 | 149 | def test_guess_all_types(self):
|
124 | 150 | # First try strict. Use a set here for testing the results because if
|
125 | 151 | # test_urllib2 is run before test_mimetypes, global state is modified
|
|
0 commit comments