diff options
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)) |
