diff options
| author | Mayank Asthana <mayankasthana1993@gmail.com> | 2018-10-10 14:46:44 (GMT) |
|---|---|---|
| committer | Antoine Pitrou <pitrou@free.fr> | 2018-10-10 14:46:44 (GMT) |
| commit | 7e18deef652a9d413d5dbd19d61073ba7eb5460e (patch) | |
| tree | 3f40e32bd110a4454934d01eb3796f65af9ea7ca /Lib/test | |
| parent | 3058b7d85697f95573fa042d6b9e4d6e2a9e739c (diff) | |
| download | cpython-7e18deef652a9d413d5dbd19d61073ba7eb5460e.zip cpython-7e18deef652a9d413d5dbd19d61073ba7eb5460e.tar.gz cpython-7e18deef652a9d413d5dbd19d61073ba7eb5460e.tar.bz2 | |
bpo-34926: Make mimetypes.guess_type accept os.PathLike objects (GH-9777)
:meth:`mimetypes.MimeTypes.guess_type` now accepts :term:`path-like object` in addition to url strings.
Diffstat (limited to 'Lib/test')
| -rw-r--r-- | Lib/test/test_mimetypes.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_mimetypes.py b/Lib/test/test_mimetypes.py index 4e2c908..554d3d5 100644 --- a/Lib/test/test_mimetypes.py +++ b/Lib/test/test_mimetypes.py @@ -1,6 +1,7 @@ import io import locale import mimetypes +import pathlib import sys import unittest @@ -77,6 +78,29 @@ class MimeTypesTestCase(unittest.TestCase): strict=True) self.assertEqual(exts, ['.g3', '.g\xb3']) + def test_path_like_ob(self): + filename = "LICENSE.txt" + filepath = pathlib.Path(filename) + filepath_with_abs_dir = pathlib.Path('/dir/'+filename) + filepath_relative = pathlib.Path('../dir/'+filename) + path_dir = pathlib.Path('./') + + expected = self.db.guess_type(filename) + + self.assertEqual(self.db.guess_type(filepath), expected) + self.assertEqual(self.db.guess_type( + filepath_with_abs_dir), expected) + self.assertEqual(self.db.guess_type(filepath_relative), expected) + self.assertEqual(self.db.guess_type(path_dir), (None, None)) + + def test_keywords_args_api(self): + self.assertEqual(self.db.guess_type( + url="foo.html", strict=True), ("text/html", None)) + self.assertEqual(self.db.guess_all_extensions( + type='image/jpg', strict=True), []) + self.assertEqual(self.db.guess_extension( + type='image/jpg', strict=False), '.jpg') + @unittest.skipUnless(sys.platform.startswith("win"), "Windows only") class Win32MimeTypesTestCase(unittest.TestCase): |
