|
4 | 4 |
|
5 | 5 | (c) Copyright CNRI, All Rights Reserved. NO WARRANTY. |
6 | 6 |
|
7 | | -"""#" |
8 | | -import unittest, test.test_support |
| 7 | +""" |
| 8 | + |
| 9 | +import sys |
| 10 | +import unittest |
9 | 11 | import hashlib |
| 12 | +import subprocess |
| 13 | +import test.test_support |
10 | 14 |
|
11 | 15 | encoding = 'utf-8' |
12 | 16 |
|
@@ -196,6 +200,25 @@ def test_east_asian_width(self): |
196 | 200 |
|
197 | 201 | class UnicodeMiscTest(UnicodeDatabaseTest): |
198 | 202 |
|
| 203 | + def test_failed_import_during_compiling(self): |
| 204 | + # Issue 4367 |
| 205 | + # Decoding \N escapes requires the unicodedata module. If it can't be |
| 206 | + # imported, we shouldn't segfault. |
| 207 | + |
| 208 | + # This program should raise a SyntaxError in the eval. |
| 209 | + code = "import sys;" \ |
| 210 | + "sys.modules['unicodedata'] = None;" \ |
| 211 | + """eval("u'\N{SOFT HYPHEN}'")""" |
| 212 | + args = [sys.executable, "-c", code] |
| 213 | + # We use a subprocess because the unicodedata module may already have |
| 214 | + # been loaded in this process. |
| 215 | + popen = subprocess.Popen(args, stderr=subprocess.PIPE) |
| 216 | + popen.wait() |
| 217 | + self.assertEqual(popen.returncode, 1) |
| 218 | + error = "SyntaxError: (unicode error) \N escapes not supported " \ |
| 219 | + "(can't load unicodedata module)" |
| 220 | + self.assertTrue(error in popen.stderr.read()) |
| 221 | + |
199 | 222 | def test_decimal_numeric_consistent(self): |
200 | 223 | # Test that decimal and numeric are consistent, |
201 | 224 | # i.e. if a character has a decimal value, |
|
0 commit comments