Skip to content

Commit bab7151

Browse files
committed
Add tests around alloc and getsizeof that show clearing isn't working which is resulting in threading failure
1 parent 451c302 commit bab7151

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Lib/test/test_bytes.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,15 @@ def test_clear(self):
13901390
b.append(ord('p'))
13911391
self.assertEqual(b, b'p')
13921392

1393+
# Cleared object should be empty.
1394+
b = bytearray(b'abc')
1395+
b.clear()
1396+
self.assertEqual(b.__alloc__(), 0)
1397+
self.assertEqual(sys.getsizeof(b), 0)
1398+
c = b.copy()
1399+
self.assertEqual(c.__alloc__(), 0)
1400+
self.assertEqual(sys.getsizeof(c), 0)
1401+
13931402
def test_copy(self):
13941403
b = bytearray(b'abc')
13951404
bb = b.copy()
@@ -1456,6 +1465,8 @@ def test_take_bytes(self):
14561465
self.assertEqual(ba.take_bytes(), b'ab')
14571466
self.assertEqual(len(ba), 0)
14581467
self.assertEqual(ba, bytearray(b''))
1468+
self.assertEqual(ba.__alloc__(), 0)
1469+
self.assertEqual(sys.getsizeof(ba), 0)
14591470

14601471
# Positive and negative slicing.
14611472
ba = bytearray(b'abcdef')

0 commit comments

Comments
 (0)