summaryrefslogtreecommitdiffstats
path: root/python/tests.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 17:00:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 17:00:10 +0000
commit1ebbd027274333758fc3517685d81847601db676 (patch)
tree5259d053d3e3066e0745150805fa4b20184eef98 /python/tests.py
parentInitial commit. (diff)
downloadfile-1ebbd027274333758fc3517685d81847601db676.tar.xz
file-1ebbd027274333758fc3517685d81847601db676.zip
Adding upstream version 1:5.45.upstream/1%5.45upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--python/tests.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/python/tests.py b/python/tests.py
new file mode 100644
index 0000000..3fc73c6
--- /dev/null
+++ b/python/tests.py
@@ -0,0 +1,32 @@
+# coding: utf-8
+
+import unittest
+
+import magic
+
+
+class MagicTestCase(unittest.TestCase):
+
+ filename = 'magic.py'
+ expected_mime_type = 'text/x-script.python'
+ expected_encoding = 'us-ascii'
+ expected_name = 'Python script, ASCII text executable'
+
+ 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, "rb") as fobj:
+ result = magic.detect_from_fobj(fobj)
+ self.assert_result(result)
+
+ def test_detect_from_content(self):
+ with open(self.filename, "rb") as fobj:
+ result = magic.detect_from_content(fobj.read(8192))
+ self.assert_result(result)