diff options
author | Vinay Sharma <vinay04sharma@icloud.com> | 2020-07-19 13:35:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-19 13:35:52 (GMT) |
commit | bfd0fbdc1352534b3c91b46dbae4285f5220acf4 (patch) | |
tree | 955ae51b6ede69fa22a717072d7a80c4d08fa5c5 /Lib/test | |
parent | 10e466448f67850ed7bb2e2a4e7f017f2b050cad (diff) | |
download | cpython-bfd0fbdc1352534b3c91b46dbae4285f5220acf4.zip cpython-bfd0fbdc1352534b3c91b46dbae4285f5220acf4.tar.gz cpython-bfd0fbdc1352534b3c91b46dbae4285f5220acf4.tar.bz2 |
bpo-38169: Increase code coverage for SharedMemory and ShareableList (GH-16139)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/_test_multiprocessing.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py index 6b4679f..bde102a 100644 --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -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') |