diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-10-04 15:17:08 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-10-04 15:17:08 (GMT) |
commit | ab8b75a56e771eb410f74a8432bc88e5937398cf (patch) | |
tree | e73545300807fffbe09c968fa02882d44736ac0b /Lib/test/test_code.py | |
parent | 317d350f9c535fff36f15e4d3b8adb3be222eebd (diff) | |
download | cpython-ab8b75a56e771eb410f74a8432bc88e5937398cf.zip cpython-ab8b75a56e771eb410f74a8432bc88e5937398cf.tar.gz cpython-ab8b75a56e771eb410f74a8432bc88e5937398cf.tar.bz2 |
Issue #28350: String constants with null character no longer interned.
Diffstat (limited to 'Lib/test/test_code.py')
-rw-r--r-- | Lib/test/test_code.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/Lib/test/test_code.py b/Lib/test/test_code.py index 9268baf..142261e 100644 --- a/Lib/test/test_code.py +++ b/Lib/test/test_code.py @@ -112,19 +112,27 @@ class CodeTest(unittest.TestCase): self.assertEqual(co.co_name, "funcname") self.assertEqual(co.co_firstlineno, 15) + +def isinterned(s): + return s is intern(('_' + s + '_')[1:-1]) + class CodeConstsTest(unittest.TestCase): def find_const(self, consts, value): for v in consts: if v == value: return v - self.assertIn(value, consts) # rises an exception - self.fail('Should be never reached') + self.assertIn(value, consts) # raises an exception + self.fail('Should never be reached') def assertIsInterned(self, s): - if s is not intern(s): + if not isinterned(s): self.fail('String %r is not interned' % (s,)) + def assertIsNotInterned(self, s): + if isinterned(s): + self.fail('String %r is interned' % (s,)) + @cpython_only def test_interned_string(self): co = compile('res = "str_value"', '?', 'exec') @@ -143,6 +151,12 @@ class CodeConstsTest(unittest.TestCase): return a self.assertIsInterned(f()) + @cpython_only + def test_interned_string_with_null(self): + co = compile(r'res = "str\0value!"', '?', 'exec') + v = self.find_const(co.co_consts, 'str\0value!') + self.assertIsNotInterned(v) + class CodeWeakRefTest(unittest.TestCase): |