8 class MagicTestCase(unittest.TestCase):
11 expected_mime_type = 'text/x-python'
12 expected_encoding = 'us-ascii'
13 expected_name = 'Python script, ASCII text executable'
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)
20 def test_detect_from_filename(self):
21 result = magic.detect_from_filename(self.filename)
22 self.assert_result(result)
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)
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)