github.com/grumpyhome/grumpy@v0.3.1-0.20201208125205-7b775405bdf1/grumpy-runtime-src/third_party/stdlib/test/test_list.py (about) 1 import sys 2 import unittest 3 from test import test_support, list_tests 4 5 class ListTest(list_tests.CommonTest): 6 type2test = list 7 8 def test_basic(self): 9 self.assertEqual(list([]), []) 10 l0_3 = [0, 1, 2, 3] 11 l0_3_bis = list(l0_3) 12 self.assertEqual(l0_3, l0_3_bis) 13 self.assertTrue(l0_3 is not l0_3_bis) 14 self.assertEqual(list(()), []) 15 self.assertEqual(list((0, 1, 2, 3)), [0, 1, 2, 3]) 16 self.assertEqual(list(''), []) 17 self.assertEqual(list('spam'), ['s', 'p', 'a', 'm']) 18 19 if sys.maxsize == 0x7fffffff: 20 # This test can currently only work on 32-bit machines. 21 # XXX If/when PySequence_Length() returns a ssize_t, it should be 22 # XXX re-enabled. 23 # Verify clearing of bug #556025. 24 # This assumes that the max data size (sys.maxint) == max 25 # address size this also assumes that the address size is at 26 # least 4 bytes with 8 byte addresses, the bug is not well 27 # tested 28 # 29 # Note: This test is expected to SEGV under Cygwin 1.3.12 or 30 # earlier due to a newlib bug. See the following mailing list 31 # thread for the details: 32 33 # http://sources.redhat.com/ml/newlib/2002/msg00369.html 34 self.assertRaises(MemoryError, list, xrange(sys.maxint // 2)) 35 36 # This code used to segfault in Py2.4a3 37 x = [] 38 x.extend(-y for y in x) 39 self.assertEqual(x, []) 40 41 def test_truth(self): 42 super(ListTest, self).test_truth() 43 self.assertTrue(not []) 44 self.assertTrue([42]) 45 46 def test_identity(self): 47 self.assertTrue([] is not []) 48 49 def test_len(self): 50 super(ListTest, self).test_len() 51 self.assertEqual(len([]), 0) 52 self.assertEqual(len([0]), 1) 53 self.assertEqual(len([0, 1, 2]), 3) 54 55 @unittest.expectedFailure 56 def test_overflow(self): 57 lst = [4, 5, 6, 7] 58 n = int((sys.maxsize*2+2) // len(lst)) 59 def mul(a, b): return a * b 60 def imul(a, b): a *= b 61 self.assertRaises((MemoryError, OverflowError), mul, lst, n) 62 self.assertRaises((MemoryError, OverflowError), imul, lst, n) 63 64 def test_main(verbose=None): 65 test_support.run_unittest(ListTest) 66 67 # verify reference counting 68 # import sys 69 # if verbose and hasattr(sys, "gettotalrefcount"): 70 # import gc 71 # counts = [None] * 5 72 # for i in xrange(len(counts)): 73 # test_support.run_unittest(ListTest) 74 # gc.collect() 75 # counts[i] = sys.gettotalrefcount() 76 # print counts 77 78 79 if __name__ == "__main__": 80 test_main(verbose=True)