7 # Tell it we don't know about external files:
8 mimetypes
.knownfiles
= []
11 class MimeTypesTestCase(unittest
.TestCase
):
13 self
.db
= mimetypes
.MimeTypes()
15 def test_default_data(self
):
16 self
.assertEqual(self
.db
.guess_type("foo.html"),
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"),
28 self
.assertEqual(self
.db
.guess_type("data:;base64,thisIsTextPlain"),
30 self
.assertEqual(self
.db
.guess_type("data:text/x-foo,thisIsTextXFoo"),
33 def test_file_parsing(self
):
34 sio
= StringIO
.StringIO("x-application/x-unittest pyunit\n")
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"),
41 def test_non_standard_types(self
):
43 self
.assertEqual(self
.db
.guess_type('foo.xul', strict
=1),
45 self
.assertEqual(self
.db
.guess_extension('image/jpg', strict
=1),
48 self
.assertEqual(self
.db
.guess_type('foo.xul', strict
=0),
50 self
.assertEqual(self
.db
.guess_extension('image/jpg', strict
=0),
55 test_support
.run_unittest(MimeTypesTestCase
)
58 if __name__
== "__main__":