[Python-checkins] CVS: python/dist/src/Lib/test test_mimetypes.py,NONE,1.1

Fred L. Drake fdrake@users.sourceforge.net
Thu, 16 Aug 2001 11:37:01 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv16639

Added Files:
	test_mimetypes.py 
Log Message:

New unit test for the mimetypes module, to avoid future regressions.


--- NEW FILE: test_mimetypes.py ---
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)