Improved MIME test

This commit is contained in:
Bastian Kleineidam 2010-03-03 20:10:10 +01:00
parent 8f33b01cbf
commit 9f8c941e2a
1 changed files with 16 additions and 12 deletions

View File

@ -24,7 +24,9 @@ class TestMime (unittest.TestCase):
def mime_test (self, filename, mime, encoding): def mime_test (self, filename, mime, encoding):
"""Test that file has given mime and encoding.""" """Test that file has given mime and encoding."""
archive = os.path.join(datadir, filename) archive = os.path.join(datadir, filename)
self.assertEqual(patoolib.util.guess_mime(filename), (mime, encoding)) res = patoolib.util.guess_mime(archive)
fail_msg = "MIME type for archive `%s' should be (%s, %s), but was %s" % (filename, mime, encoding, res)
self.assertEqual(res, (mime, encoding), fail_msg)
@needs_program('file') @needs_program('file')
def test_mime (self): def test_mime (self):
@ -42,10 +44,11 @@ class TestMime (unittest.TestCase):
self.mime_test("t.deb.foo", "application/x-debian-package", None) self.mime_test("t.deb.foo", "application/x-debian-package", None)
self.mime_test("t.gz", "application/x-gzip", None) self.mime_test("t.gz", "application/x-gzip", None)
self.mime_test("t.gz.foo", "application/x-gzip", None) self.mime_test("t.gz.foo", "application/x-gzip", None)
self.mime_test("t.jar", "application/java-archive", None) self.mime_test("t.jar", "application/zip", None)
self.mime_test("t.jar.foo", "application/java-archive", None) self.mime_test("t.jar.foo", "application/zip", None)
self.mime_test("t.lzma", "application/x-lzma", None) self.mime_test("t.lzma", "application/x-lzma", None)
self.mime_test("t.lzma.foo", "application/x-lzma", None) # file(1) does not recognize .lzma files
#self.mime_test("t.lzma.foo", "application/x-lzma", None)
self.mime_test("t.lzo", "application/x-lzop", None) self.mime_test("t.lzo", "application/x-lzop", None)
self.mime_test("t.lzo.foo", "application/x-lzop", None) self.mime_test("t.lzo.foo", "application/x-lzop", None)
self.mime_test("t.rar", "application/x-rar", None) self.mime_test("t.rar", "application/x-rar", None)
@ -55,21 +58,22 @@ class TestMime (unittest.TestCase):
self.mime_test("t.tar", "application/x-tar", None) self.mime_test("t.tar", "application/x-tar", None)
self.mime_test("t.tar.foo", "application/x-tar", None) self.mime_test("t.tar.foo", "application/x-tar", None)
self.mime_test("t.tar.bz2", "application/x-tar", "bzip2") self.mime_test("t.tar.bz2", "application/x-tar", "bzip2")
self.mime_test("t.tar.bz2.foo", "application/x-bzip2", None) self.mime_test("t.tar.bz2.foo", "application/x-tar", "bzip2")
self.mime_test("t.tar.gz", "application/x-tar", "gzip") self.mime_test("t.tar.gz", "application/x-tar", "gzip")
self.mime_test("t.tar.gz.foo", "application/x-gzip", None) self.mime_test("t.tar.gz.foo", "application/x-tar", "gzip")
self.mime_test("t.tar.lzma", "application/x-tar", "lzma") self.mime_test("t.tar.lzma", "application/x-tar", "lzma")
self.mime_test("t.tar.lzma.foo", "application/x-lzma", None) # file(1) does not recognize .lzma files
#self.mime_test("t.tar.lzma.foo", "application/x-tar", "lzma")
self.mime_test("t.tar.xz", "application/x-tar", "xz") self.mime_test("t.tar.xz", "application/x-tar", "xz")
self.mime_test("t.tar.xz.foo", "application/x-xz", None) self.mime_test("t.tar.xz.foo", "application/x-tar", "xz")
self.mime_test("t.tar.Z", "application/x-tar", "compress") self.mime_test("t.tar.Z", "application/x-tar", "compress")
self.mime_test("t.tar.Z.foo", "application/x-compress", None) self.mime_test("t.tar.Z.foo", "application/x-tar", "compress")
self.mime_test("t.taz", "application/x-tar", "compress") self.mime_test("t.taz", "application/x-tar", "compress")
self.mime_test("t.taz.foo", "application/x-compress", None) self.mime_test("t.taz.foo", "application/x-tar", "compress")
self.mime_test("t.tbz2", "application/x-tar", "bzip2") self.mime_test("t.tbz2", "application/x-tar", "bzip2")
self.mime_test("t.tbz2.foo", "application/x-bzip2", None) self.mime_test("t.tbz2.foo", "application/x-tar", "bzip2")
self.mime_test("t.tgz", "application/x-tar", "gzip") self.mime_test("t.tgz", "application/x-tar", "gzip")
self.mime_test("t.tgz.foo", "application/x-gzip", None) self.mime_test("t.tgz.foo", "application/x-tar", "gzip")
self.mime_test("t.txt.gz", "application/x-gzip", None) self.mime_test("t.txt.gz", "application/x-gzip", None)
self.mime_test("t.txt.gz.foo", "application/x-gzip", None) self.mime_test("t.txt.gz.foo", "application/x-gzip", None)
self.mime_test("t.xz", "application/x-xz", None) self.mime_test("t.xz", "application/x-xz", None)