17778a7ceadler# coding: utf-8
27778a7ceadler
37778a7ceadlerimport unittest
47778a7ceadler
57778a7ceadlerimport magic
67778a7ceadler
77778a7ceadler
87778a7ceadlerclass MagicTestCase(unittest.TestCase):
97778a7ceadler
107778a7ceadler    filename = 'magic.py'
117778a7ceadler    expected_mime_type = 'text/x-python'
127778a7ceadler    expected_encoding = 'us-ascii'
137778a7ceadler    expected_name = 'Python script, ASCII text executable'
147778a7ceadler
157778a7ceadler    def assert_result(self, result):
167778a7ceadler        self.assertEqual(result.mime_type, self.expected_mime_type)
177778a7ceadler        self.assertEqual(result.encoding, self.expected_encoding)
187778a7ceadler        self.assertEqual(result.name, self.expected_name)
197778a7ceadler
207778a7ceadler    def test_detect_from_filename(self):
217778a7ceadler        result = magic.detect_from_filename(self.filename)
227778a7ceadler        self.assert_result(result)
237778a7ceadler
247778a7ceadler    def test_detect_from_fobj(self):
257778a7ceadler        with open(self.filename) as fobj:
267778a7ceadler            result = magic.detect_from_fobj(fobj)
277778a7ceadler        self.assert_result(result)
287778a7ceadler
297778a7ceadler    def test_detect_from_content(self):
307778a7ceadler        with open(self.filename) as fobj:
317778a7ceadler            result = magic.detect_from_content(fobj.read(4096))
327778a7ceadler        self.assert_result(result)
33