diff options
| author | Adam Hupp <adam@hupp.org> | 2017-12-04 11:55:27 -0800 |
|---|---|---|
| committer | Adam Hupp <adam@hupp.org> | 2017-12-04 11:55:27 -0800 |
| commit | a0b9f316fda16b21923bb57e1de9a98789befbba (patch) | |
| tree | bdd5da3016316b3c0d788939258aaf60f4135c7b /test | |
| parent | 10e20995b5f4b8f8131b7e69912882bb81393cb2 (diff) | |
| download | python-magic-a0b9f316fda16b21923bb57e1de9a98789befbba.tar.gz | |
Merge in compatability mode with libmagic
The libmagic distribution uses the same package name `magic` as
python-magic, but has an incompatible API. This change merges in a
copy of libmagic's bindings, wrapped to give deprecation warnings.
This is intended to a) mitigate the short-term pain to users and
packagers who need to figure out which to use, and b) give us a path
to merging the two sets of bindings.
I'd be happy for libmagic to take over this package if we could find a
path to it.
Diffstat (limited to 'test')
| -rw-r--r-- | test/libmagic_test.py | 35 | ||||
| -rw-r--r-- | test/run.py | 1 |
2 files changed, 36 insertions, 0 deletions
diff --git a/test/libmagic_test.py b/test/libmagic_test.py new file mode 100644 index 0000000..5a0a290 --- /dev/null +++ b/test/libmagic_test.py @@ -0,0 +1,35 @@ +# coding: utf-8 + +import unittest + +import magic + + +class MagicTestCase(unittest.TestCase): + + filename = 'test/testdata/test.pdf' + expected_mime_type = 'application/pdf' + expected_encoding = 'us-ascii' + expected_name = 'PDF document, version 1.2' + + 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) + +if __name__ == '__main__': + unittest.main() diff --git a/test/run.py b/test/run.py index c10c11f..6b37555 100644 --- a/test/run.py +++ b/test/run.py @@ -24,6 +24,7 @@ def run_test(versions): found = True print("Testing %s" % i) subprocess.run([i, os.path.join(this_dir, "test.py")], env=new_env, check=True) + subprocess.run([i, os.path.join(this_dir, "libmagic_test.py")], env=new_env, check=True) if not found: sys.exit("No versions found: " + str(versions)) |
