summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-10-04 15:21:25 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-10-04 15:21:25 (GMT)
commite81b0d335b13bc1f26a08b292807ac17c8670b1c (patch)
tree2cbe866587ea5a3ff86501efc7ae29f2234e5ae5 /Lib/test
parent804480912c8328df7d042c6e5201cfe4abf21742 (diff)
parent09f3d080fe0cadab0db6380c58dd4968db20287d (diff)
downloadcpython-e81b0d335b13bc1f26a08b292807ac17c8670b1c.zip
cpython-e81b0d335b13bc1f26a08b292807ac17c8670b1c.tar.gz
cpython-e81b0d335b13bc1f26a08b292807ac17c8670b1c.tar.bz2
Issue #28350: String constants with null character no longer interned.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_code.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/Lib/test/test_code.py b/Lib/test/test_code.py
index 2be17a2..7975ea0 100644
--- a/Lib/test/test_code.py
+++ b/Lib/test/test_code.py
@@ -135,19 +135,27 @@ class CodeTest(unittest.TestCase):
self.assertEqual(co.co_name, "funcname")
self.assertEqual(co.co_firstlineno, 15)
+
+def isinterned(s):
+ return s is sys.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 sys.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')
@@ -172,6 +180,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):