@@ -3719,6 +3719,30 @@ def test_shared_memory_basics(self):
3719
3719
self .assertLess (same_sms .size , 20 * sms .size ) # Size was ignored.
3720
3720
same_sms .close ()
3721
3721
3722
+ # Creating Shared Memory Segment with -ve size
3723
+ with self .assertRaises (ValueError ):
3724
+ shared_memory .SharedMemory (create = True , size = - 2 )
3725
+
3726
+ # Attaching Shared Memory Segment without a name
3727
+ with self .assertRaises (ValueError ):
3728
+ shared_memory .SharedMemory (create = False )
3729
+
3730
+ # Test if shared memory segment is created properly,
3731
+ # when _make_filename returns an existing shared memory segment name
3732
+ with unittest .mock .patch (
3733
+ 'multiprocessing.shared_memory._make_filename' ) as mock_make_filename :
3734
+
3735
+ names = ['test01_fn' , 'test02_fn' ]
3736
+ mock_make_filename .side_effect = names
3737
+ shm1 = shared_memory .SharedMemory (create = True , size = 1 )
3738
+ self .addCleanup (shm1 .unlink )
3739
+ self .assertEqual (shm1 .name , names [0 ])
3740
+
3741
+ mock_make_filename .side_effect = names
3742
+ shm2 = shared_memory .SharedMemory (create = True , size = 1 )
3743
+ self .addCleanup (shm2 .unlink )
3744
+ self .assertEqual (shm2 .name , names [1 ])
3745
+
3722
3746
if shared_memory ._USE_POSIX :
3723
3747
# Posix Shared Memory can only be unlinked once. Here we
3724
3748
# test an implementation detail that is not observed across
0 commit comments