Closes #15469: Correct __sizeof__ support for deque
diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py
index a0d30f1..595a0c4 100644
--- a/Lib/test/test_deque.py
+++ b/Lib/test/test_deque.py
@@ -6,6 +6,7 @@
import copy
import cPickle as pickle
import random
+import struct
BIG = 100000
@@ -517,6 +518,21 @@
gc.collect()
self.assertTrue(ref() is None, "Cycle was not collected")
+ check_sizeof = test_support.check_sizeof
+
+ @test_support.cpython_only
+ def test_sizeof(self):
+ BLOCKLEN = 62
+ basesize = test_support.calcobjsize('2P4PlP')
+ blocksize = struct.calcsize('2P%dP' % BLOCKLEN)
+ self.assertEqual(object.__sizeof__(deque()), basesize)
+ check = self.check_sizeof
+ check(deque(), basesize + blocksize)
+ check(deque('a'), basesize + blocksize)
+ check(deque('a' * (BLOCKLEN // 2)), basesize + blocksize)
+ check(deque('a' * (BLOCKLEN // 2 + 1)), basesize + 2 * blocksize)
+ check(deque('a' * (42 * BLOCKLEN)), basesize + 43 * blocksize)
+
class TestVariousIteratorArgs(unittest.TestCase):
def test_constructor(self):