"Fossies" - the Fresh Open Source Software Archive

Member "file-5.35/python/tests.py" (23 Nov 2015, 964 Bytes) of package /linux/misc/file-5.35.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "tests.py" see the Fossies "Dox" file reference documentation.

    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)