@@ -135,19 +135,27 @@ def test_newempty(self):
135135 self .assertEqual (co .co_name , "funcname" )
136136 self .assertEqual (co .co_firstlineno , 15 )
137137
138+
139+ def isinterned (s ):
140+ return s is sys .intern (('_' + s + '_' )[1 :- 1 ])
141+
138142class CodeConstsTest (unittest .TestCase ):
139143
140144 def find_const (self , consts , value ):
141145 for v in consts :
142146 if v == value :
143147 return v
144- self .assertIn (value , consts ) # rises an exception
145- self .fail ('Should be never reached' )
148+ self .assertIn (value , consts ) # raises an exception
149+ self .fail ('Should never be reached' )
146150
147151 def assertIsInterned (self , s ):
148- if s is not sys . intern (s ):
152+ if not isinterned (s ):
149153 self .fail ('String %r is not interned' % (s ,))
150154
155+ def assertIsNotInterned (self , s ):
156+ if isinterned (s ):
157+ self .fail ('String %r is interned' % (s ,))
158+
151159 @cpython_only
152160 def test_interned_string (self ):
153161 co = compile ('res = "str_value"' , '?' , 'exec' )
@@ -172,6 +180,12 @@ def f(a='str_value'):
172180 return a
173181 self .assertIsInterned (f ())
174182
183+ @cpython_only
184+ def test_interned_string_with_null (self ):
185+ co = compile (r'res = "str\0value!"' , '?' , 'exec' )
186+ v = self .find_const (co .co_consts , 'str\0 value!' )
187+ self .assertIsNotInterned (v )
188+
175189
176190class CodeWeakRefTest (unittest .TestCase ):
177191
0 commit comments