diff options
author | Fred Drake <fdrake@acm.org> | 2001-08-16 18:36:59 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2001-08-16 18:36:59 (GMT) |
commit | 3791838339f8c75cdce0bf9615817b1263234314 (patch) | |
tree | 5ad84e30df9ec90ba47ca3878bd2b52d13892c10 /Lib | |
parent | c81a06998f1de7e5f97a7c9599310c34214cec8f (diff) | |
download | cpython-3791838339f8c75cdce0bf9615817b1263234314.zip cpython-3791838339f8c75cdce0bf9615817b1263234314.tar.gz cpython-3791838339f8c75cdce0bf9615817b1263234314.tar.bz2 |
New unit test for the mimetypes module, to avoid future regressions.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_mimetypes.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Lib/test/test_mimetypes.py b/Lib/test/test_mimetypes.py new file mode 100644 index 0000000..9b9d339 --- /dev/null +++ b/Lib/test/test_mimetypes.py @@ -0,0 +1,42 @@ +import mimetypes +import StringIO +import unittest + +import test_support + +# Tell it we don't know about external files: +mimetypes.knownfiles = [] + + +class MimeTypesTestCase(unittest.TestCase): + def setUp(self): + self.db = mimetypes.MimeTypes() + + def test_default_data(self): + self.assertEqual(self.db.guess_type("foo.html"), + ("text/html", None)) + self.assertEqual(self.db.guess_type("foo.tgz"), + ("application/x-tar", "gzip")) + self.assertEqual(self.db.guess_type("foo.tar.gz"), + ("application/x-tar", "gzip")) + self.assertEqual(self.db.guess_type("foo.tar.Z"), + ("application/x-tar", "compress")) + + def test_data_urls(self): + self.assertEqual(self.db.guess_type("data:,thisIsTextPlain"), + ("text/plain", None)) + self.assertEqual(self.db.guess_type("data:;base64,thisIsTextPlain"), + ("text/plain", None)) + self.assertEqual(self.db.guess_type("data:text/x-foo,thisIsTextXFoo"), + ("text/x-foo", None)) + + def test_file_parsing(self): + sio = StringIO.StringIO("x-application/x-unittest pyunit\n") + self.db.readfp(sio) + self.assertEqual(self.db.guess_type("foo.pyunit"), + ("x-application/x-unittest", None)) + self.assertEqual(self.db.guess_extension("x-application/x-unittest"), + ".pyunit") + + +test_support.run_unittest(MimeTypesTestCase) |