diff options
author | Benjamin Peterson <benjamin@python.org> | 2008-11-21 22:27:24 +0000 |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2008-11-21 22:27:24 +0000 |
commit | c078f929cb20f3e48fc1636ae8c211bc4f91a483 (patch) | |
tree | ccf028e901cb764d739a57cd1c28ba79f2bcd41c /Lib/test/test_unicodedata.py | |
parent | d42941751c52e4e077e3d94bef6f4a3e545444ee (diff) | |
download | cpython-git-c078f929cb20f3e48fc1636ae8c211bc4f91a483.tar.gz |
don't segfault when \N escapes are used and unicodedata fails to load
Fixes #4367
Diffstat (limited to 'Lib/test/test_unicodedata.py')
-rw-r--r-- | Lib/test/test_unicodedata.py | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/Lib/test/test_unicodedata.py b/Lib/test/test_unicodedata.py index b24e8f7981..84999e57b3 100644 --- a/Lib/test/test_unicodedata.py +++ b/Lib/test/test_unicodedata.py @@ -4,9 +4,13 @@ (c) Copyright CNRI, All Rights Reserved. NO WARRANTY. -"""#" -import unittest, test.test_support +""" + +import sys +import unittest import hashlib +import subprocess +import test.test_support encoding = 'utf-8' @@ -196,6 +200,25 @@ class UnicodeFunctionsTest(UnicodeDatabaseTest): class UnicodeMiscTest(UnicodeDatabaseTest): + def test_failed_import_during_compiling(self): + # Issue 4367 + # Decoding \N escapes requires the unicodedata module. If it can't be + # imported, we shouldn't segfault. + + # This program should raise a SyntaxError in the eval. + code = "import sys;" \ + "sys.modules['unicodedata'] = None;" \ + """eval("u'\N{SOFT HYPHEN}'")""" + args = [sys.executable, "-c", code] + # We use a subprocess because the unicodedata module may already have + # been loaded in this process. + popen = subprocess.Popen(args, stderr=subprocess.PIPE) + popen.wait() + self.assertEqual(popen.returncode, 1) + error = "SyntaxError: (unicode error) \N escapes not supported " \ + "(can't load unicodedata module)" + self.assertTrue(error in popen.stderr.read()) + def test_decimal_numeric_consistent(self): # Test that decimal and numeric are consistent, # i.e. if a character has a decimal value, |