77import itertools
88import random
99import socket
10+ import string
1011import sys
1112import weakref
1213
1516
1617PAGESIZE = mmap .PAGESIZE
1718
19+ tagname_prefix = f'python_{ os .getpid ()} _test_mmap'
20+ def random_tagname (length = 10 ):
21+ suffix = '' .join (random .choices (string .ascii_uppercase , k = length ))
22+ return f'{ tagname_prefix } _{ suffix } '
1823
1924class MmapTests (unittest .TestCase ):
2025
@@ -610,21 +615,23 @@ def test_tagname(self):
610615 data1 = b"0123456789"
611616 data2 = b"abcdefghij"
612617 assert len (data1 ) == len (data2 )
618+ tagname1 = random_tagname ()
619+ tagname2 = random_tagname ()
613620
614621 # Test same tag
615- m1 = mmap .mmap (- 1 , len (data1 ), tagname = "foo" )
622+ m1 = mmap .mmap (- 1 , len (data1 ), tagname = tagname1 )
616623 m1 [:] = data1
617- m2 = mmap .mmap (- 1 , len (data2 ), tagname = "foo" )
624+ m2 = mmap .mmap (- 1 , len (data2 ), tagname = tagname1 )
618625 m2 [:] = data2
619626 self .assertEqual (m1 [:], data2 )
620627 self .assertEqual (m2 [:], data2 )
621628 m2 .close ()
622629 m1 .close ()
623630
624631 # Test different tag
625- m1 = mmap .mmap (- 1 , len (data1 ), tagname = "foo" )
632+ m1 = mmap .mmap (- 1 , len (data1 ), tagname = tagname1 )
626633 m1 [:] = data1
627- m2 = mmap .mmap (- 1 , len (data2 ), tagname = "boo" )
634+ m2 = mmap .mmap (- 1 , len (data2 ), tagname = tagname2 )
628635 m2 [:] = data2
629636 self .assertEqual (m1 [:], data1 )
630637 self .assertEqual (m2 [:], data2 )
@@ -635,17 +642,18 @@ def test_tagname(self):
635642 @unittest .skipUnless (os .name == 'nt' , 'requires Windows' )
636643 def test_sizeof (self ):
637644 m1 = mmap .mmap (- 1 , 100 )
638- tagname = "foo"
645+ tagname = random_tagname ()
639646 m2 = mmap .mmap (- 1 , 100 , tagname = tagname )
640647 self .assertEqual (sys .getsizeof (m2 ),
641648 sys .getsizeof (m1 ) + len (tagname ) + 1 )
642649
643650 @unittest .skipUnless (os .name == 'nt' , 'requires Windows' )
644651 def test_crasher_on_windows (self ):
645652 # Should not crash (Issue 1733986)
646- m = mmap .mmap (- 1 , 1000 , tagname = "foo" )
653+ tagname = random_tagname ()
654+ m = mmap .mmap (- 1 , 1000 , tagname = tagname )
647655 try :
648- mmap .mmap (- 1 , 5000 , tagname = "foo" )[:] # same tagname, but larger size
656+ mmap .mmap (- 1 , 5000 , tagname = tagname )[:] # same tagname, but larger size
649657 except :
650658 pass
651659 m .close ()
@@ -857,7 +865,7 @@ def test_resize_succeeds_with_error_for_second_named_mapping(self):
857865 """
858866 start_size = 2 * PAGESIZE
859867 reduced_size = PAGESIZE
860- tagname = "TEST"
868+ tagname = random_tagname ()
861869 data_length = 8
862870 data = bytes (random .getrandbits (8 ) for _ in range (data_length ))
863871
0 commit comments