diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2009-11-15 14:10:48 +0000 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2009-11-15 14:10:48 +0000 |
commit | d5b34d4597a7163edf20f831db620b0a4fe57d5d (patch) | |
tree | 59f31e437e8495b6a19835fb217288b89e0c69b6 /Lib/test | |
parent | a548deeb29badee88dc6fc7a2853b6f56558347f (diff) | |
download | cpython-git-d5b34d4597a7163edf20f831db620b0a4fe57d5d.tar.gz |
Issue #4969: The mimetypes module now reads the MIME database from
the registry under Windows. Patch by Gabriel Genellina.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_mimetypes.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/Lib/test/test_mimetypes.py b/Lib/test/test_mimetypes.py index cc1790e0df..3508b56056 100644 --- a/Lib/test/test_mimetypes.py +++ b/Lib/test/test_mimetypes.py @@ -1,6 +1,7 @@ import mimetypes import StringIO import unittest +import sys from test import test_support @@ -62,8 +63,31 @@ class MimeTypesTestCase(unittest.TestCase): eq(all, []) +@unittest.skipUnless(sys.platform.startswith("win"), "Windows only") +class Win32MimeTypesTestCase(unittest.TestCase): + def setUp(self): + # ensure all entries actually come from the Windows registry + self.original_types_map = mimetypes.types_map.copy() + mimetypes.types_map.clear() + mimetypes.init() + self.db = mimetypes.MimeTypes() + + def tearDown(self): + # restore default settings + mimetypes.types_map.clear() + mimetypes.types_map.update(self.original_types_map) + + def test_registry_parsing(self): + # the original, minimum contents of the MIME database in the + # Windows registry is undocumented AFAIK. + # Use file types that should *always* exist: + eq = self.assertEqual + eq(self.db.guess_type("foo.txt"), ("text/plain", None)) + def test_main(): - test_support.run_unittest(MimeTypesTestCase) + test_support.run_unittest(MimeTypesTestCase, + Win32MimeTypesTestCase + ) if __name__ == "__main__": |