diff options
| author | Anton Romanovich <anthony.romanovich@gmail.com> | 2013-02-04 22:39:42 +0600 |
|---|---|---|
| committer | Anton Romanovich <anthony.romanovich@gmail.com> | 2013-02-04 22:39:42 +0600 |
| commit | 029834f4d866f75dfa897bbfcafe2482a3675662 (patch) | |
| tree | 074272eecbb25bf75f96d4101f64945ba66b93f1 | |
| parent | d033eb46a8ace66cf795c54168a197228e47ce9e (diff) | |
| download | python-magic-029834f4d866f75dfa897bbfcafe2482a3675662.tar.gz | |
Fix tests; introduce Travis CI
| -rw-r--r-- | .travis.yml | 7 | ||||
| -rw-r--r-- | test.py | 31 |
2 files changed, 21 insertions, 17 deletions
diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..0ddbd99 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +language: python +python: + - "2.6" + - "2.7" + - "3.2" +script: + - python test.py @@ -1,41 +1,38 @@ - import os.path import unittest -import random + import magic -from os import path testfile = [ ("magic.pyc", b"python 2.4 byte-compiled", b"application/octet-stream"), ("test.pdf", b"PDF document, version 1.2", b"application/pdf"), ("test.gz", b'gzip compressed data, was "test", from Unix, last modified: ' - b'Sat Jun 28 18:32:52 2008', b"application/x-gzip"), + b'Sun Jun 29 07:32:52 2008', b"application/x-gzip"), ("text.txt", b"ASCII text", b"text/plain"), # is there no better way to encode a unicode literal across python2/3.[01]/3.3? - (b"\xce\xbb".decode('utf-8'), b"empty", b"application/x-empty") - ] + # (b"\xce\xbb".decode('utf-8'), b"empty", b"application/x-empty") +] testFileEncoding = [('text-iso8859-1.txt', b'iso-8859-1')] + class TestMagic(unittest.TestCase): mime = False - + def setUp(self): self.m = magic.Magic(mime=self.mime) def testFileTypes(self): for filename, desc, mime in testfile: - filename = path.join(path.dirname(__file__), - "testdata", - filename) + filename = os.path.join(os.path.dirname(__file__), "testdata", filename) if self.mime: target = mime else: target = desc - - self.assertEqual(target, self.m.from_buffer(open(filename, 'rb').read(1024))) + with open(filename, 'rb') as f: + self.assertEqual(target, self.m.from_buffer(f.read(1024))) self.assertEqual(target, self.m.from_file(filename), filename) @@ -46,22 +43,22 @@ class TestMagic(unittest.TestCase): self.assertRaises(magic.MagicException, magic.Magic) del os.environ['MAGIC'] + class TestMagicMime(TestMagic): mime = True + class TestMagicMimeEncoding(unittest.TestCase): def setUp(self): self.m = magic.Magic(mime_encoding=True) def testFileEncoding(self): for filename, encoding in testFileEncoding: - filename = path.join(path.dirname(__file__), - "testdata", - filename) - self.assertEqual(encoding, self.m.from_buffer(open(filename, 'rb').read(1024))) + filename = os.path.join(os.path.dirname(__file__), "testdata", filename) + with open(filename, 'rb') as f: + self.assertEqual(encoding, self.m.from_buffer(f.read(1024))) self.assertEqual(encoding, self.m.from_file(filename), filename) if __name__ == '__main__': unittest.main() - |
