Fred Drake | 3791838 | 2001-08-16 18:36:59 +0000 | [diff] [blame] | 1 | import mimetypes |
| 2 | import StringIO |
| 3 | import unittest |
| 4 | |
| 5 | import test_support |
| 6 | |
| 7 | # Tell it we don't know about external files: |
| 8 | mimetypes.knownfiles = [] |
| 9 | |
| 10 | |
| 11 | class MimeTypesTestCase(unittest.TestCase): |
| 12 | def setUp(self): |
| 13 | self.db = mimetypes.MimeTypes() |
| 14 | |
| 15 | def test_default_data(self): |
| 16 | self.assertEqual(self.db.guess_type("foo.html"), |
| 17 | ("text/html", None)) |
| 18 | self.assertEqual(self.db.guess_type("foo.tgz"), |
| 19 | ("application/x-tar", "gzip")) |
| 20 | self.assertEqual(self.db.guess_type("foo.tar.gz"), |
| 21 | ("application/x-tar", "gzip")) |
| 22 | self.assertEqual(self.db.guess_type("foo.tar.Z"), |
| 23 | ("application/x-tar", "compress")) |
| 24 | |
| 25 | def test_data_urls(self): |
| 26 | self.assertEqual(self.db.guess_type("data:,thisIsTextPlain"), |
| 27 | ("text/plain", None)) |
| 28 | self.assertEqual(self.db.guess_type("data:;base64,thisIsTextPlain"), |
| 29 | ("text/plain", None)) |
| 30 | self.assertEqual(self.db.guess_type("data:text/x-foo,thisIsTextXFoo"), |
| 31 | ("text/x-foo", None)) |
| 32 | |
| 33 | def test_file_parsing(self): |
| 34 | sio = StringIO.StringIO("x-application/x-unittest pyunit\n") |
| 35 | self.db.readfp(sio) |
| 36 | self.assertEqual(self.db.guess_type("foo.pyunit"), |
| 37 | ("x-application/x-unittest", None)) |
| 38 | self.assertEqual(self.db.guess_extension("x-application/x-unittest"), |
| 39 | ".pyunit") |
| 40 | |
| 41 | |
Fred Drake | 2e2be37 | 2001-09-20 21:33:42 +0000 | [diff] [blame] | 42 | def test_main(): |
| 43 | test_support.run_unittest(MimeTypesTestCase) |
| 44 | |
| 45 | |
| 46 | if __name__ == "__main__": |
| 47 | test_main() |