mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
[3.12] gh-108963: using random to generate unique string in sys.intern test … (#110216)
gh-108963: using random to generate unique string in sys.intern test (#109491)
(cherry picked from commit 44b1e4ea48
)
Co-authored-by: AN Long <aisk@users.noreply.github.com>
This commit is contained in:
parent
b61a4da459
commit
f911d7ecd9
1 changed files with 2 additions and 7 deletions
|
@ -4,6 +4,7 @@ import gc
|
||||||
import locale
|
import locale
|
||||||
import operator
|
import operator
|
||||||
import os
|
import os
|
||||||
|
import random
|
||||||
import struct
|
import struct
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
@ -19,10 +20,6 @@ import unittest
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
|
|
||||||
# count the number of test runs, used to create unique
|
|
||||||
# strings to intern in test_intern()
|
|
||||||
INTERN_NUMRUNS = 0
|
|
||||||
|
|
||||||
DICT_KEY_STRUCT_FORMAT = 'n2BI2n'
|
DICT_KEY_STRUCT_FORMAT = 'n2BI2n'
|
||||||
|
|
||||||
class DisplayHookTest(unittest.TestCase):
|
class DisplayHookTest(unittest.TestCase):
|
||||||
|
@ -685,10 +682,8 @@ class SysModuleTest(unittest.TestCase):
|
||||||
self.assertEqual(sys.__stdout__.encoding, sys.__stderr__.encoding)
|
self.assertEqual(sys.__stdout__.encoding, sys.__stderr__.encoding)
|
||||||
|
|
||||||
def test_intern(self):
|
def test_intern(self):
|
||||||
global INTERN_NUMRUNS
|
|
||||||
INTERN_NUMRUNS += 1
|
|
||||||
self.assertRaises(TypeError, sys.intern)
|
self.assertRaises(TypeError, sys.intern)
|
||||||
s = "never interned before" + str(INTERN_NUMRUNS)
|
s = "never interned before" + str(random.randrange(0, 10**9))
|
||||||
self.assertTrue(sys.intern(s) is s)
|
self.assertTrue(sys.intern(s) is s)
|
||||||
s2 = s.swapcase().swapcase()
|
s2 = s.swapcase().swapcase()
|
||||||
self.assertTrue(sys.intern(s2) is s)
|
self.assertTrue(sys.intern(s2) is s)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue