Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3)

Delta Between Two Patch Sets: Lib/test/test_bytes.py

Issue 24467: bytearray pop and remove Buffer Over-read
Left Patch Set: Created 4 years, 7 months ago
Right Patch Set: Created 4 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | Objects/bytearrayobject.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 """Unit tests for the bytes and bytearray types. 1 """Unit tests for the bytes and bytearray types.
2 2
3 XXX This is a mess. Common tests should be moved to buffer_tests.py, 3 XXX This is a mess. Common tests should be moved to buffer_tests.py,
4 which itself ought to be unified with string_tests.py (and the latter 4 which itself ought to be unified with string_tests.py (and the latter
5 should be modernized). 5 should be modernized).
6 """ 6 """
7 7
8 import os 8 import os
9 import re 9 import re
10 import sys 10 import sys
(...skipping 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 self.assertTrue(b is b1) 1091 self.assertTrue(b is b1)
1092 1092
1093 def test_alloc(self): 1093 def test_alloc(self):
1094 b = bytearray() 1094 b = bytearray()
1095 alloc = b.__alloc__() 1095 alloc = b.__alloc__()
1096 self.assertTrue(alloc >= 0) 1096 self.assertTrue(alloc >= 0)
1097 seq = [alloc] 1097 seq = [alloc]
1098 for i in range(100): 1098 for i in range(100):
1099 b += b"x" 1099 b += b"x"
1100 alloc = b.__alloc__() 1100 alloc = b.__alloc__()
1101 self.assertTrue(alloc >= len(b)) 1101 self.assertGreater(alloc, len(b)) # including trailing null byte
1102 if alloc not in seq: 1102 if alloc not in seq:
1103 seq.append(alloc) 1103 seq.append(alloc)
1104 print(seq)
1105
1106 def test_init_alloc(self):
1107 b = bytearray()
1108 def g():
1109 for i in range(1, 100):
1110 yield i
1111 a = list(b)
1112 self.assertEqual(a, list(range(1, len(a)+1)))
1113 self.assertEqual(len(b), len(a))
1114 self.assertLessEqual(len(b), i)
1115 alloc = b.__alloc__()
1116 self.assertGreater(alloc, len(b)) # including trailing null byt e
1117 b.__init__(g())
1118 self.assertEqual(list(b), list(range(1, 100)))
1119 self.assertEqual(len(b), 99)
1120 alloc = b.__alloc__()
1121 self.assertGreater(alloc, len(b))
1104 1122
1105 def test_extend(self): 1123 def test_extend(self):
1106 orig = b'hello' 1124 orig = b'hello'
1107 a = bytearray(orig) 1125 a = bytearray(orig)
1108 a.extend(a) 1126 a.extend(a)
1109 self.assertEqual(a, orig + orig) 1127 self.assertEqual(a, orig + orig)
1110 self.assertEqual(a[5:], orig) 1128 self.assertEqual(a[5:], orig)
1111 a = bytearray(b'') 1129 a = bytearray(b'')
1112 # Test iterators that don't have a __length_hint__ 1130 # Test iterators that don't have a __length_hint__
1113 a.extend(map(int, orig * 25)) 1131 a.extend(map(int, orig * 25))
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
1550 self.assertEqual(x, b"abcd") 1568 self.assertEqual(x, b"abcd")
1551 1569
1552 1570
1553 class BytesSubclassTest(SubclassTest, unittest.TestCase): 1571 class BytesSubclassTest(SubclassTest, unittest.TestCase):
1554 type2test = bytes 1572 type2test = bytes
1555 subclass2test = BytesSubclass 1573 subclass2test = BytesSubclass
1556 1574
1557 1575
1558 if __name__ == "__main__": 1576 if __name__ == "__main__":
1559 unittest.main() 1577 unittest.main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+