summaryrefslogtreecommitdiff
path: root/test/test.py
diff options
context:
space:
mode:
authorAdam Hupp <adam@hupp.org>2017-11-20 09:21:00 -0800
committerAdam Hupp <adam@hupp.org>2017-11-20 09:23:19 -0800
commitbec0d4428f6de11ffd90d19dfddb5af9c72d9c63 (patch)
tree52e177a31a1a2d5b55ecc3516ddcf55810c2c3dc /test/test.py
parent72c27fa8bfa4b8a53c09cdd42dd72f4c61d20504 (diff)
downloadpython-magic-bec0d4428f6de11ffd90d19dfddb5af9c72d9c63.tar.gz
python3 str handling
In python3 ctypes, a str is passed to ctypes as wchar*. This means the layout of the string magic looks like [ascii, null, ascii, null, etc]. For some reason, magic handles this just fine most of the time, but it's clearly wrong and I'm amazed it worked at all.
Diffstat (limited to 'test/test.py')
-rwxr-xr-xtest/test.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/test/test.py b/test/test.py
index 6ae5c07..78ddb2b 100755
--- a/test/test.py
+++ b/test/test.py
@@ -30,6 +30,13 @@ class MagicTest(unittest.TestCase):
break
else:
self.assertTrue(False, "no match for " + repr(expected_value))
+
+ def test_from_buffer_str_and_bytes(self):
+ m = magic.Magic(mime=True)
+ s = '#!/usr/bin/env python\nprint("foo")'
+ self.assertEqual("text/x-python", m.from_buffer(s))
+ b = b'#!/usr/bin/env python\nprint("foo")'
+ self.assertEqual("text/x-python", m.from_buffer(b))
def test_mime_types(self):
dest = os.path.join(MagicTest.TESTDATA_DIR, b'\xce\xbb'.decode('utf-8'))