diff options
| author | Eitan Adler <eadler@FreeBSD.org> | 2018-08-08 01:33:36 +0000 |
|---|---|---|
| committer | Eitan Adler <eadler@FreeBSD.org> | 2018-08-08 01:33:36 +0000 |
| commit | 2dc4dbb9673c9a3309c2dad59cb588c6f04beaea (patch) | |
| tree | efa730ff2430a75fdf2284e308776af5a440fcd0 /contrib/file/python/tests.py | |
| parent | a99020fbf3ffe31318986bb40b186f440983d71b (diff) | |
| parent | ad1ba6e1e032f79d03b9a6e2c714de84d1911b3a (diff) | |
Notes
Diffstat (limited to 'contrib/file/python/tests.py')
| -rw-r--r-- | contrib/file/python/tests.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/contrib/file/python/tests.py b/contrib/file/python/tests.py new file mode 100644 index 000000000000..197a8fc4b519 --- /dev/null +++ b/contrib/file/python/tests.py @@ -0,0 +1,32 @@ +# coding: utf-8 + +import unittest + +import magic + + +class MagicTestCase(unittest.TestCase): + + filename = 'magic.py' + expected_mime_type = 'text/x-python' + expected_encoding = 'us-ascii' + expected_name = 'Python script, ASCII text executable' + + def assert_result(self, result): + self.assertEqual(result.mime_type, self.expected_mime_type) + self.assertEqual(result.encoding, self.expected_encoding) + self.assertEqual(result.name, self.expected_name) + + def test_detect_from_filename(self): + result = magic.detect_from_filename(self.filename) + self.assert_result(result) + + def test_detect_from_fobj(self): + with open(self.filename) as fobj: + result = magic.detect_from_fobj(fobj) + self.assert_result(result) + + def test_detect_from_content(self): + with open(self.filename) as fobj: + result = magic.detect_from_content(fobj.read(4096)) + self.assert_result(result) |
