]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-38169: Increase code coverage for SharedMemory and ShareableList (GH-16139)
authorVinay Sharma <vinay04sharma@icloud.com>
Sun, 19 Jul 2020 13:35:52 +0000 (19:05 +0530)
committerGitHub <noreply@github.com>
Sun, 19 Jul 2020 13:35:52 +0000 (22:35 +0900)
Lib/test/_test_multiprocessing.py
Misc/NEWS.d/next/Tests/2019-09-14-13-20-27.bpo-38169.hurq4B.rst [new file with mode: 0644]

index 6b4679f82da735ade6f3b2eb3522db5c4dd5ca22..bde102ae2e0518d002e487b38d0f2362078a6b1d 100644 (file)
@@ -3768,6 +3768,18 @@ class _TestSharedMemory(BaseTestCase):
         self.assertGreaterEqual(sms.size, 512)
         self.assertGreaterEqual(len(sms.buf), sms.size)
 
+        # Verify __repr__
+        self.assertIn(sms.name, str(sms))
+        self.assertIn(str(sms.size), str(sms))
+
+        # Test pickling
+        sms.buf[0:6] = b'pickle'
+        pickled_sms = pickle.dumps(sms)
+        sms2 = pickle.loads(pickled_sms)
+        self.assertEqual(sms.name, sms2.name)
+        self.assertEqual(sms.size, sms2.size)
+        self.assertEqual(bytes(sms.buf[0:6]), bytes(sms2.buf[0:6]), b'pickle')
+
         # Modify contents of shared memory segment through memoryview.
         sms.buf[0] = 42
         self.assertEqual(sms.buf[0], 42)
@@ -3975,6 +3987,23 @@ class _TestSharedMemory(BaseTestCase):
         )
         self.addCleanup(sl.shm.unlink)
 
+        # Verify __repr__
+        self.assertIn(sl.shm.name, str(sl))
+        self.assertIn(str(list(sl)), str(sl))
+
+        # Index Out of Range (get)
+        with self.assertRaises(IndexError):
+            sl[7]
+
+        # Index Out of Range (set)
+        with self.assertRaises(IndexError):
+            sl[7] = 2
+
+        # Assign value without format change (str -> str)
+        current_format = sl._get_packing_format(0)
+        sl[0] = 'howdy'
+        self.assertEqual(current_format, sl._get_packing_format(0))
+
         # Verify attributes are readable.
         self.assertEqual(sl.format, '8s8sdqxxxxxx?xxxxxxxx?q')
 
diff --git a/Misc/NEWS.d/next/Tests/2019-09-14-13-20-27.bpo-38169.hurq4B.rst b/Misc/NEWS.d/next/Tests/2019-09-14-13-20-27.bpo-38169.hurq4B.rst
new file mode 100644 (file)
index 0000000..3972b9d
--- /dev/null
@@ -0,0 +1 @@
+Increase code coverage for SharedMemory and ShareableList