Skip to content

Commit f33a3e8

Browse files
vinay0410websurfer5
authored andcommitted
bpo-38018: Increase code coverage for multiprocessing.shared_memory (pythonGH-15662)
1 parent 2bc1dd4 commit f33a3e8

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Lib/test/_test_multiprocessing.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3719,6 +3719,30 @@ def test_shared_memory_basics(self):
37193719
self.assertLess(same_sms.size, 20*sms.size) # Size was ignored.
37203720
same_sms.close()
37213721

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+
37223746
if shared_memory._USE_POSIX:
37233747
# Posix Shared Memory can only be unlinked once. Here we
37243748
# test an implementation detail that is not observed across
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Increase code coverage for multiprocessing.shared_memory.

0 commit comments

Comments
 (0)