LOG = logging.getLogger(APPNAME)
-
# =============================================================================
class MagicTest(LogtraceTestcase):
expected_value = (expected_value,)
LOG.debug("Testing {!r}, expecting {!r}.".format(filename, expected_value))
-
+
for i in expected_value:
with open(filename, 'rb') as f:
buf_value = m.from_buffer(f.read())
break
else:
self.assertTrue(False, "no match for " + repr(expected_value))
-
+
# -------------------------------------------------------------------------
def test_mime_types(self):
self.assert_values(m, {
'magic.pyc': 'application/octet-stream',
'test.pdf': 'application/pdf',
- 'test.gz': 'application/gzip',
+ 'test.gz': ('application/gzip', 'application/x-gzip'),
'text.txt': 'text/plain',
b'\xce\xbb'.decode('utf-8'): 'text/plain',
b'\xce\xbb': 'text/plain',
os.environ['TZ'] = 'UTC' # To get the last modified date of test.gz in UTC
try:
self.assert_values(m, {
- 'magic.pyc': 'python 2.4 byte-compiled',
+ 'magic.pyc': 'python 2.7 byte-compiled',
'test.pdf': 'PDF document, version 1.2',
'test.gz':
('gzip compressed data, was "test", from Unix, last modified: Sun Jun 29 01:32:52 2008',
LOG.debug("Testing {!r} - expecting {!r} - got {!r}.".format(
filename, 'image/jpeg', result))
self.assertEqual(result, 'image/jpeg')
-
+
m = magic.Magic(mime=True, keep_going=True)
expected = ['image/jpeg', 'application/octet-stream']
result = m.from_file(filename)
def t(x,y):
raise magic.MagicException("passthrough")
magic.magic_buffer = t
-
+
self.assertRaises(magic.MagicException, magic.from_buffer, "hello", True)
finally:
magic.magic_buffer = old