From 4514350cc363fde103e96cf53576061c116d3b67 Mon Sep 17 00:00:00 2001 From: rmspeers Date: Thu, 20 Sep 2018 23:04:22 -0400 Subject: Updated constructor to accept the raw flag and pass it to the underlying library. Helpful for cases where unicode chars exist in match results. --- test/test.py | 19 +++++++++++++++++++ test/testdata/pgpunicode | 1 + 2 files changed, 20 insertions(+) create mode 100644 test/testdata/pgpunicode (limited to 'test') diff --git a/test/test.py b/test/test.py index ab29def..0f3aac2 100755 --- a/test/test.py +++ b/test/test.py @@ -84,6 +84,25 @@ class MagicTest(unittest.TestCase): finally: del os.environ['TZ'] + def test_unicode_result_nonraw(self): + m = magic.Magic(raw=False) + src = os.path.join(MagicTest.TESTDATA_DIR, 'pgpunicode') + result = m.from_file(src) + # NOTE: This check is added as otherwise some magic files don't identify the test case as a PGP key. + if 'PGP' in result: + assert r"PGP\011Secret Sub-key -" == result + else: + raise unittest.SkipTest("Magic file doesn't return expected type.") + + def test_unicode_result_raw(self): + m = magic.Magic(raw=True) + src = os.path.join(MagicTest.TESTDATA_DIR, 'pgpunicode') + result = m.from_file(src) + if 'PGP' in result: + assert b'PGP\tSecret Sub-key -' == result.encode('utf-8') + else: + raise unittest.SkipTest("Magic file doesn't return expected type.") + def test_mime_encodings(self): m = magic.Magic(mime_encoding=True) self.assert_values(m, { diff --git a/test/testdata/pgpunicode b/test/testdata/pgpunicode new file mode 100644 index 0000000..a44a36b --- /dev/null +++ b/test/testdata/pgpunicode @@ -0,0 +1 @@ +qʐ \ No newline at end of file -- cgit v1.2.1