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

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

Issue 20547: Use specific asserts in bigmem tests
Left Patch Set: Created 5 years, 11 months ago
Right Patch Set: Created 2 years, 9 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 """Bigmem tests - tests for the 32-bit boundary in containers. 1 """Bigmem tests - tests for the 32-bit boundary in containers.
2 2
3 These tests try to exercise the 32-bit boundary that is sometimes, if 3 These tests try to exercise the 32-bit boundary that is sometimes, if
4 rarely, exceeded in practice, but almost never tested. They are really only 4 rarely, exceeded in practice, but almost never tested. They are really only
5 meaningful on 64-bit builds on machines with a *lot* of memory, but the 5 meaningful on 64-bit builds on machines with a *lot* of memory, but the
6 tests are always run, usually with very low memory limits to make sure the 6 tests are always run, usually with very low memory limits to make sure the
7 tests themselves don't suffer from bitrot. To run them for real, pass a 7 tests themselves don't suffer from bitrot. To run them for real, pass a
8 high memory limit to regrtest, with the -M option. 8 high memory limit to regrtest, with the -M option.
9 """ 9 """
10 10
11 from test import support 11 from test import support
12 from test.support import bigmemtest, _1G, _2G, _4G 12 from test.support import bigmemtest, _1G, _2G, _4G
13 13
14 import unittest 14 import unittest
15 import operator 15 import operator
16 import sys 16 import sys
17 import functools
18 17
19 # These tests all use one of the bigmemtest decorators to indicate how much 18 # These tests all use one of the bigmemtest decorators to indicate how much
20 # memory they use and how much memory they need to be even meaningful. The 19 # memory they use and how much memory they need to be even meaningful. The
21 # decorators take two arguments: a 'memuse' indicator declaring 20 # decorators take two arguments: a 'memuse' indicator declaring
22 # (approximate) bytes per size-unit the test will use (at peak usage), and a 21 # (approximate) bytes per size-unit the test will use (at peak usage), and a
23 # 'minsize' indicator declaring a minimum *useful* size. A test that 22 # 'minsize' indicator declaring a minimum *useful* size. A test that
24 # allocates a bytestring to test various operations near the end will have a 23 # allocates a bytestring to test various operations near the end will have a
25 # minsize of at least 2Gb (or it wouldn't reach the 32-bit limit, so the 24 # minsize of at least 2Gb (or it wouldn't reach the 32-bit limit, so the
26 # test wouldn't be very useful) and a memuse of 1 (one byte per size-unit, 25 # test wouldn't be very useful) and a memuse of 1 (one byte per size-unit,
27 # if it allocates only one big string at a time.) 26 # if it allocates only one big string at a time.)
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 s2 = _('...') + s 110 s2 = _('...') + s
112 self.assertTrue(s2.endswith(s)) 111 self.assertTrue(s2.endswith(s))
113 self.assertFalse(s.endswith(_('a') + SUBSTR)) 112 self.assertFalse(s.endswith(_('a') + SUBSTR))
114 self.assertFalse(SUBSTR.endswith(s)) 113 self.assertFalse(SUBSTR.endswith(s))
115 114
116 @bigmemtest(size=_2G + 10, memuse=2) 115 @bigmemtest(size=_2G + 10, memuse=2)
117 def test_expandtabs(self, size): 116 def test_expandtabs(self, size):
118 _ = self.from_latin1 117 _ = self.from_latin1
119 s = _('-') * size 118 s = _('-') * size
120 tabsize = 8 119 tabsize = 8
121 self.assertEqual(s.expandtabs(), s) 120 self.assertTrue(s.expandtabs() == s)
122 del s 121 del s
123 slen, remainder = divmod(size, tabsize) 122 slen, remainder = divmod(size, tabsize)
124 s = _(' \t') * slen 123 s = _(' \t') * slen
125 s = s.expandtabs(tabsize) 124 s = s.expandtabs(tabsize)
126 self.assertEqual(len(s), size - remainder) 125 self.assertEqual(len(s), size - remainder)
127 self.assertEqual(len(s.strip(_(' '))), 0) 126 self.assertEqual(len(s.strip(_(' '))), 0)
128 127
129 @bigmemtest(size=_2G, memuse=2) 128 @bigmemtest(size=_2G, memuse=2)
130 def test_find(self, size): 129 def test_find(self, size):
131 _ = self.from_latin1 130 _ = self.from_latin1
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 SUBSTR = _('abc def ghi') 262 SUBSTR = _('abc def ghi')
264 s = SUBSTR.rjust(size) 263 s = SUBSTR.rjust(size)
265 self.assertEqual(len(s), size) 264 self.assertEqual(len(s), size)
266 self.assertEqual(s.lstrip(), SUBSTR.lstrip()) 265 self.assertEqual(s.lstrip(), SUBSTR.lstrip())
267 del s 266 del s
268 s = SUBSTR.ljust(size) 267 s = SUBSTR.ljust(size)
269 self.assertEqual(len(s), size) 268 self.assertEqual(len(s), size)
270 # Type-specific optimization 269 # Type-specific optimization
271 if isinstance(s, (str, bytes)): 270 if isinstance(s, (str, bytes)):
272 stripped = s.lstrip() 271 stripped = s.lstrip()
273 self.assertIs(stripped, s) 272 self.assertTrue(stripped is s)
274 273
275 @bigmemtest(size=_2G + 10, memuse=2) 274 @bigmemtest(size=_2G + 10, memuse=2)
276 def test_replace(self, size): 275 def test_replace(self, size):
277 _ = self.from_latin1 276 _ = self.from_latin1
278 replacement = _('a') 277 replacement = _('a')
279 s = _(' ') * size 278 s = _(' ') * size
280 s = s.replace(_(' '), replacement) 279 s = s.replace(_(' '), replacement)
281 self.assertEqual(len(s), size) 280 self.assertEqual(len(s), size)
282 self.assertEqual(s.count(replacement), size) 281 self.assertEqual(s.count(replacement), size)
283 s = s.replace(replacement, _(' '), size - 4) 282 s = s.replace(replacement, _(' '), size - 4)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 SUBSTR = _(' abc def ghi') 334 SUBSTR = _(' abc def ghi')
336 s = SUBSTR.ljust(size) 335 s = SUBSTR.ljust(size)
337 self.assertEqual(len(s), size) 336 self.assertEqual(len(s), size)
338 self.assertEqual(s.rstrip(), SUBSTR.rstrip()) 337 self.assertEqual(s.rstrip(), SUBSTR.rstrip())
339 del s 338 del s
340 s = SUBSTR.rjust(size) 339 s = SUBSTR.rjust(size)
341 self.assertEqual(len(s), size) 340 self.assertEqual(len(s), size)
342 # Type-specific optimization 341 # Type-specific optimization
343 if isinstance(s, (str, bytes)): 342 if isinstance(s, (str, bytes)):
344 stripped = s.rstrip() 343 stripped = s.rstrip()
345 self.assertIs(stripped, s) 344 self.assertTrue(stripped is s)
346 345
347 # The test takes about size bytes to build a string, and then about 346 # The test takes about size bytes to build a string, and then about
348 # sqrt(size) substrings of sqrt(size) in size and a list to 347 # sqrt(size) substrings of sqrt(size) in size and a list to
349 # hold sqrt(size) items. It's close but just over 2x size. 348 # hold sqrt(size) items. It's close but just over 2x size.
350 @bigmemtest(size=_2G, memuse=2.1) 349 @bigmemtest(size=_2G, memuse=2.1)
351 def test_split_small(self, size): 350 def test_split_small(self, size):
352 _ = self.from_latin1 351 _ = self.from_latin1
353 # Crudely calculate an estimate so that the result of s.split won't 352 # Crudely calculate an estimate so that the result of s.split won't
354 # take up an inordinate amount of memory 353 # take up an inordinate amount of memory
355 chunksize = int(size ** 0.5 + 2) 354 chunksize = int(size ** 0.5 + 2)
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 self.assertRaises(IndexError, operator.getitem, s, len(s) + 1) 528 self.assertRaises(IndexError, operator.getitem, s, len(s) + 1)
530 self.assertRaises(IndexError, operator.getitem, s, len(s) + 1<<31) 529 self.assertRaises(IndexError, operator.getitem, s, len(s) + 1<<31)
531 530
532 @bigmemtest(size=_2G, memuse=2) 531 @bigmemtest(size=_2G, memuse=2)
533 def test_contains(self, size): 532 def test_contains(self, size):
534 _ = self.from_latin1 533 _ = self.from_latin1
535 SUBSTR = _('0123456789') 534 SUBSTR = _('0123456789')
536 edge = _('-') * (size // 2) 535 edge = _('-') * (size // 2)
537 s = _('').join([edge, SUBSTR, edge]) 536 s = _('').join([edge, SUBSTR, edge])
538 del edge 537 del edge
539 self.assertIn(SUBSTR, s) 538 self.assertTrue(SUBSTR in s)
540 self.assertNotIn(SUBSTR * 2, s) 539 self.assertFalse(SUBSTR * 2 in s)
541 self.assertIn(_('-'), s) 540 self.assertTrue(_('-') in s)
542 self.assertNotIn(_('a'), s) 541 self.assertFalse(_('a') in s)
543 s += _('a') 542 s += _('a')
544 self.assertIn(_('a'), s) 543 self.assertTrue(_('a') in s)
545 544
546 @bigmemtest(size=_2G + 10, memuse=2) 545 @bigmemtest(size=_2G + 10, memuse=2)
547 def test_compare(self, size): 546 def test_compare(self, size):
548 _ = self.from_latin1 547 _ = self.from_latin1
549 s1 = _('-') * size 548 s1 = _('-') * size
550 s2 = _('-') * size 549 s2 = _('-') * size
551 self.assertTrue(s1 == s2) 550 self.assertTrue(s1 == s2)
552 del s2 551 del s2
553 s2 = s1 + _('a') 552 s2 = s1 + _('a')
554 self.assertFalse(s1 == s2) 553 self.assertFalse(s1 == s2)
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 @bigmemtest(size=_2G - 1, memuse=ascii_char_size + 1) 647 @bigmemtest(size=_2G - 1, memuse=ascii_char_size + 1)
649 def test_encode_ascii(self, size): 648 def test_encode_ascii(self, size):
650 return self.basic_encode_test(size, 'ascii', c='A') 649 return self.basic_encode_test(size, 'ascii', c='A')
651 650
652 # str % (...) uses a Py_UCS4 intermediate representation 651 # str % (...) uses a Py_UCS4 intermediate representation
653 652
654 @bigmemtest(size=_2G + 10, memuse=ascii_char_size * 2 + ucs4_char_size) 653 @bigmemtest(size=_2G + 10, memuse=ascii_char_size * 2 + ucs4_char_size)
655 def test_format(self, size): 654 def test_format(self, size):
656 s = '-' * size 655 s = '-' * size
657 sf = '%s' % (s,) 656 sf = '%s' % (s,)
658 self.assertEqual(s, sf) 657 self.assertTrue(s == sf)
659 del sf 658 del sf
660 sf = '..%s..' % (s,) 659 sf = '..%s..' % (s,)
661 self.assertEqual(len(sf), len(s) + 4) 660 self.assertEqual(len(sf), len(s) + 4)
662 self.assertTrue(sf.startswith('..-')) 661 self.assertTrue(sf.startswith('..-'))
663 self.assertTrue(sf.endswith('-..')) 662 self.assertTrue(sf.endswith('-..'))
664 del s, sf 663 del s, sf
665 664
666 size //= 2 665 size //= 2
667 edge = '-' * size 666 edge = '-' * size
668 s = ''.join([edge, '%s', edge]) 667 s = ''.join([edge, '%s', edge])
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 s = char * size 729 s = char * size
731 try: 730 try:
732 for f in (repr, ascii): 731 for f in (repr, ascii):
733 r = f(s) 732 r = f(s)
734 self.assertEqual(len(r), 2 + (len(f(char)) - 2) * size) 733 self.assertEqual(len(r), 2 + (len(f(char)) - 2) * size)
735 self.assertTrue(r.endswith(r"\U0001dcba'"), r[-12:]) 734 self.assertTrue(r.endswith(r"\U0001dcba'"), r[-12:])
736 r = None 735 r = None
737 finally: 736 finally:
738 r = s = None 737 r = s = None
739 738
740 # The original test_translate is overriden here, so as to get the 739 # The original test_translate is overridden here, so as to get the
741 # correct size estimate: str.translate() uses an intermediate Py_UCS4 740 # correct size estimate: str.translate() uses an intermediate Py_UCS4
742 # representation. 741 # representation.
743 742
744 @bigmemtest(size=_2G, memuse=ascii_char_size * 2 + ucs4_char_size) 743 @bigmemtest(size=_2G, memuse=ascii_char_size * 2 + ucs4_char_size)
745 def test_translate(self, size): 744 def test_translate(self, size):
746 _ = self.from_latin1 745 _ = self.from_latin1
747 SUBSTR = _('aZz.z.Aaz.') 746 SUBSTR = _('aZz.z.Aaz.')
748 trans = { 747 trans = {
749 ord(_('.')): _('-'), 748 ord(_('.')): _('-'),
750 ord(_('a')): _('!'), 749 ord(_('a')): _('!'),
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 return self.basic_concat_test(size) 848 return self.basic_concat_test(size)
850 849
851 @bigmemtest(size=_2G + 2, memuse=24) 850 @bigmemtest(size=_2G + 2, memuse=24)
852 def test_concat_large(self, size): 851 def test_concat_large(self, size):
853 return self.basic_concat_test(size) 852 return self.basic_concat_test(size)
854 853
855 @bigmemtest(size=_2G // 5 + 10, memuse=8 * 5) 854 @bigmemtest(size=_2G // 5 + 10, memuse=8 * 5)
856 def test_contains(self, size): 855 def test_contains(self, size):
857 t = (1, 2, 3, 4, 5) * size 856 t = (1, 2, 3, 4, 5) * size
858 self.assertEqual(len(t), size * 5) 857 self.assertEqual(len(t), size * 5)
859 self.assertIn(5, t) 858 self.assertTrue(5 in t)
860 self.assertNotIn((1, 2, 3, 4, 5), t) 859 self.assertFalse((1, 2, 3, 4, 5) in t)
861 self.assertNotIn(0, t) 860 self.assertFalse(0 in t)
862 861
863 @bigmemtest(size=_2G + 10, memuse=8) 862 @bigmemtest(size=_2G + 10, memuse=8)
864 def test_hash(self, size): 863 def test_hash(self, size):
865 t1 = (0,) * size 864 t1 = (0,) * size
866 h1 = hash(t1) 865 h1 = hash(t1)
867 del t1 866 del t1
868 t2 = (0,) * (size + 1) 867 t2 = (0,) * (size + 1)
869 self.assertNotEqual(h1, hash(t2)) 868 self.assertNotEqual(h1, hash(t2))
870 869
871 @bigmemtest(size=_2G + 10, memuse=8) 870 @bigmemtest(size=_2G + 10, memuse=8)
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 return self.basic_test_inplace_concat(size) 999 return self.basic_test_inplace_concat(size)
1001 1000
1002 @bigmemtest(size=_2G + 2, memuse=24) 1001 @bigmemtest(size=_2G + 2, memuse=24)
1003 def test_inplace_concat_large(self, size): 1002 def test_inplace_concat_large(self, size):
1004 return self.basic_test_inplace_concat(size) 1003 return self.basic_test_inplace_concat(size)
1005 1004
1006 @bigmemtest(size=_2G // 5 + 10, memuse=8 * 5) 1005 @bigmemtest(size=_2G // 5 + 10, memuse=8 * 5)
1007 def test_contains(self, size): 1006 def test_contains(self, size):
1008 l = [1, 2, 3, 4, 5] * size 1007 l = [1, 2, 3, 4, 5] * size
1009 self.assertEqual(len(l), size * 5) 1008 self.assertEqual(len(l), size * 5)
1010 self.assertIn(5, l) 1009 self.assertTrue(5 in l)
1011 self.assertNotIn([1, 2, 3, 4, 5], l) 1010 self.assertFalse([1, 2, 3, 4, 5] in l)
1012 self.assertNotIn(0, l) 1011 self.assertFalse(0 in l)
1013 1012
1014 @bigmemtest(size=_2G + 10, memuse=8) 1013 @bigmemtest(size=_2G + 10, memuse=8)
1015 def test_hash(self, size): 1014 def test_hash(self, size):
1016 l = [0] * size 1015 l = [0] * size
1017 self.assertRaises(TypeError, hash, l) 1016 self.assertRaises(TypeError, hash, l)
1018 1017
1019 @bigmemtest(size=_2G + 10, memuse=8) 1018 @bigmemtest(size=_2G + 10, memuse=8)
1020 def test_index_and_slice(self, size): 1019 def test_index_and_slice(self, size):
1021 l = [None] * size 1020 l = [None] * size
1022 self.assertEqual(len(l), size) 1021 self.assertEqual(len(l), size)
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 self.assertEqual(l[-10:], [5] * 10) 1247 self.assertEqual(l[-10:], [5] * 10)
1249 1248
1250 def test_main(): 1249 def test_main():
1251 support.run_unittest(StrTest, BytesTest, BytearrayTest, 1250 support.run_unittest(StrTest, BytesTest, BytearrayTest,
1252 TupleTest, ListTest) 1251 TupleTest, ListTest)
1253 1252
1254 if __name__ == '__main__': 1253 if __name__ == '__main__':
1255 if len(sys.argv) > 1: 1254 if len(sys.argv) > 1:
1256 support.set_memlimit(sys.argv[1]) 1255 support.set_memlimit(sys.argv[1])
1257 test_main() 1256 test_main()
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

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