summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_sys.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_sys.py')
-rw-r--r--Lib/test/test_sys.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 0b8529a..446dc53 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -15,6 +15,7 @@ from test.support import os_helper
from test.support.script_helper import assert_python_ok, assert_python_failure
from test.support import threading_helper
from test.support import import_helper
+from test.support import interpreters
import textwrap
import unittest
import warnings
@@ -699,6 +700,33 @@ class SysModuleTest(unittest.TestCase):
self.assertRaises(TypeError, sys.intern, S("abc"))
+ def test_subinterp_intern_dynamically_allocated(self):
+ s = "never interned before" + str(random.randrange(0, 10**9))
+ t = sys.intern(s)
+ self.assertIs(t, s)
+
+ interp = interpreters.create()
+ interp.run(textwrap.dedent(f'''
+ import sys
+ t = sys.intern({s!r})
+ assert id(t) != {id(s)}, (id(t), {id(s)})
+ assert id(t) != {id(t)}, (id(t), {id(t)})
+ '''))
+
+ def test_subinterp_intern_statically_allocated(self):
+ # See Tools/build/generate_global_objects.py for the list
+ # of strings that are always statically allocated.
+ s = '__init__'
+ t = sys.intern(s)
+
+ print('------------------------')
+ interp = interpreters.create()
+ interp.run(textwrap.dedent(f'''
+ import sys
+ t = sys.intern({s!r})
+ assert id(t) == {id(t)}, (id(t), {id(t)})
+ '''))
+
def test_sys_flags(self):
self.assertTrue(sys.flags)
attrs = ("debug",