]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/file/python/tests.py
file: update to 5.34
[FreeBSD/FreeBSD.git] / contrib / file / python / tests.py
1 # coding: utf-8
2
3 import unittest
4
5 import magic
6
7
8 class MagicTestCase(unittest.TestCase):
9
10     filename = 'magic.py'
11     expected_mime_type = 'text/x-python'
12     expected_encoding = 'us-ascii'
13     expected_name = 'Python script, ASCII text executable'
14
15     def assert_result(self, result):
16         self.assertEqual(result.mime_type, self.expected_mime_type)
17         self.assertEqual(result.encoding, self.expected_encoding)
18         self.assertEqual(result.name, self.expected_name)
19
20     def test_detect_from_filename(self):
21         result = magic.detect_from_filename(self.filename)
22         self.assert_result(result)
23
24     def test_detect_from_fobj(self):
25         with open(self.filename) as fobj:
26             result = magic.detect_from_fobj(fobj)
27         self.assert_result(result)
28
29     def test_detect_from_content(self):
30         with open(self.filename) as fobj:
31             result = magic.detect_from_content(fobj.read(4096))
32         self.assert_result(result)