MCPcopy Index your code
hub / github.com/python/cpython / test_subinterp_intern_singleton

Method test_subinterp_intern_singleton

Lib/test/test_sys.py:844–859  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

842 @support.cpython_only
843 @requires_subinterpreters
844 def test_subinterp_intern_singleton(self):
845 # Implementation detail: singletons are used for 0- and 1-character
846 # latin1 strings.
847 for s in '', '\n', '_', 'x', '\0', '\N{CEDILLA}', '\xff':
848 with self.subTest(s=s):
849 interp = interpreters.create()
850 interp.exec(textwrap.dedent(f'''
851 import sys
852
853 # set `s`, avoid parser interning & constant folding
854 s = str({s.encode()!r}, 'utf-8')
855
856 assert id(s) == {id(s)}
857 t = sys.intern(s)
858 '''))
859 self.assertTrue(sys._is_interned(s))
860
861 def test_sys_flags_indexable_attributes(self):
862 self.assertTrue(sys.flags)

Callers

nothing calls this directly

Calls 7

idFunction · 0.85
execMethod · 0.80
assertTrueMethod · 0.80
subTestMethod · 0.45
createMethod · 0.45
dedentMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected