summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVinay Sharma <vinay04sharma@icloud.com>2019-09-09 16:48:55 (GMT)
committerDavin Potts <applio@users.noreply.github.com>2019-09-09 16:48:55 (GMT)
commitd14e39c8d9a9b525c7dcd83b2a260e2707fa85c1 (patch)
tree5aabc7eef491db06440c84527e71584cd764d8f8
parent64c6ac74e254d31f93fcc74bf02b3daa7d3e3f25 (diff)
downloadcpython-d14e39c8d9a9b525c7dcd83b2a260e2707fa85c1.zip
cpython-d14e39c8d9a9b525c7dcd83b2a260e2707fa85c1.tar.gz
cpython-d14e39c8d9a9b525c7dcd83b2a260e2707fa85c1.tar.bz2
bpo-38018: Increase code coverage for multiprocessing.shared_memory (GH-15662)
-rw-r--r--Lib/test/_test_multiprocessing.py24
-rw-r--r--Misc/NEWS.d/next/Tests/2019-09-03-19-33-10.bpo-38018.zTrMu7.rst1
2 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py
index 2fe0def..8269b87 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -3719,6 +3719,30 @@ class _TestSharedMemory(BaseTestCase):
self.assertLess(same_sms.size, 20*sms.size) # Size was ignored.
same_sms.close()
+ # Creating Shared Memory Segment with -ve size
+ with self.assertRaises(ValueError):
+ shared_memory.SharedMemory(create=True, size=-2)
+
+ # Attaching Shared Memory Segment without a name
+ with self.assertRaises(ValueError):
+ shared_memory.SharedMemory(create=False)
+
+ # Test if shared memory segment is created properly,
+ # when _make_filename returns an existing shared memory segment name
+ with unittest.mock.patch(
+ 'multiprocessing.shared_memory._make_filename') as mock_make_filename:
+
+ names = ['test01_fn', 'test02_fn']
+ mock_make_filename.side_effect = names
+ shm1 = shared_memory.SharedMemory(create=True, size=1)
+ self.addCleanup(shm1.unlink)
+ self.assertEqual(shm1.name, names[0])
+
+ mock_make_filename.side_effect = names
+ shm2 = shared_memory.SharedMemory(create=True, size=1)
+ self.addCleanup(shm2.unlink)
+ self.assertEqual(shm2.name, names[1])
+
if shared_memory._USE_POSIX:
# Posix Shared Memory can only be unlinked once. Here we
# test an implementation detail that is not observed across
diff --git a/Misc/NEWS.d/next/Tests/2019-09-03-19-33-10.bpo-38018.zTrMu7.rst b/Misc/NEWS.d/next/Tests/2019-09-03-19-33-10.bpo-38018.zTrMu7.rst
new file mode 100644
index 0000000..3646404
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2019-09-03-19-33-10.bpo-38018.zTrMu7.rst
@@ -0,0 +1 @@
+Increase code coverage for multiprocessing.shared_memory.