test_whitespace_eater_unicode(): Make this test Python 2.1 compatible.
[python/dscho.git] / Lib / test / test_mimetypes.py
blob69539663ca6fa3e1717119d3fdf596cf9d0d61d0
1 import mimetypes
2 import StringIO
3 import unittest
5 from test import test_support
7 # Tell it we don't know about external files:
8 mimetypes.knownfiles = []
11 class MimeTypesTestCase(unittest.TestCase):
12 def setUp(self):
13 self.db = mimetypes.MimeTypes()
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"))
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))
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")
41 def test_non_standard_types(self):
42 # First try strict
43 self.assertEqual(self.db.guess_type('foo.xul', strict=1),
44 (None, None))
45 self.assertEqual(self.db.guess_extension('image/jpg', strict=1),
46 None)
47 # And then non-strict
48 self.assertEqual(self.db.guess_type('foo.xul', strict=0),
49 ('text/xul', None))
50 self.assertEqual(self.db.guess_extension('image/jpg', strict=0),
51 '.jpg')
54 def test_main():
55 test_support.run_unittest(MimeTypesTestCase)
58 if __name__ == "__main__":
59 test_main()