Changeset 391 for python/trunk/Lib/test/test_array.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/test/test_array.py
r2 r391 5 5 6 6 import unittest 7 import warnings 7 8 from test import test_support 8 9 from weakref import proxy … … 15 16 class ArraySubclassWithKwargs(array.array): 16 17 def __init__(self, typecode, newarg=None): 17 array.array.__init__( typecode)18 array.array.__init__(self, typecode) 18 19 19 20 tests = [] # list to accumulate all tests … … 49 50 a = array.array(self.typecode) 50 51 self.assertEqual(a.typecode, self.typecode) 51 self.assert _(a.itemsize>=self.minitemsize)52 self.assertTrue(a.itemsize>=self.minitemsize) 52 53 self.assertRaises(TypeError, array.array, self.typecode, None) 53 54 … … 64 65 self.assertRaises(TypeError, a.buffer_info, 42) 65 66 bi = a.buffer_info() 66 self.assert _(isinstance(bi, tuple))67 self.assertIsInstance(bi, tuple) 67 68 self.assertEqual(len(bi), 2) 68 self.assert _(isinstance(bi[0], (int, long)))69 self.assert _(isinstance(bi[1], int))69 self.assertIsInstance(bi[0], (int, long)) 70 self.assertIsInstance(bi[1], int) 70 71 self.assertEqual(bi[1], len(a)) 71 72 … … 189 190 test_support.unlink(test_support.TESTFN) 190 191 192 def test_fromfile_ioerror(self): 193 # Issue #5395: Check if fromfile raises a proper IOError 194 # instead of EOFError. 195 a = array.array(self.typecode) 196 f = open(test_support.TESTFN, 'wb') 197 try: 198 self.assertRaises(IOError, a.fromfile, f, len(self.example)) 199 finally: 200 f.close() 201 test_support.unlink(test_support.TESTFN) 202 203 def test_filewrite(self): 204 a = array.array(self.typecode, 2*self.example) 205 f = open(test_support.TESTFN, 'wb') 206 try: 207 f.write(a) 208 f.close() 209 b = array.array(self.typecode) 210 f = open(test_support.TESTFN, 'rb') 211 b.fromfile(f, len(self.example)) 212 self.assertEqual(b, array.array(self.typecode, self.example)) 213 self.assertNotEqual(a, b) 214 b.fromfile(f, len(self.example)) 215 self.assertEqual(a, b) 216 f.close() 217 finally: 218 if not f.closed: 219 f.close() 220 test_support.unlink(test_support.TESTFN) 221 191 222 def test_tofromlist(self): 192 223 a = array.array(self.typecode, 2*self.example) … … 223 254 def test_cmp(self): 224 255 a = array.array(self.typecode, self.example) 225 self.assert _((a == 42) is False)226 self.assert _((a != 42) is True)227 228 self.assert _((a == a) is True)229 self.assert _((a != a) is False)230 self.assert _((a < a) is False)231 self.assert _((a <= a) is True)232 self.assert _((a > a) is False)233 self.assert _((a >= a) is True)256 self.assertTrue((a == 42) is False) 257 self.assertTrue((a != 42) is True) 258 259 self.assertTrue((a == a) is True) 260 self.assertTrue((a != a) is False) 261 self.assertTrue((a < a) is False) 262 self.assertTrue((a <= a) is True) 263 self.assertTrue((a > a) is False) 264 self.assertTrue((a >= a) is True) 234 265 235 266 al = array.array(self.typecode, self.smallerexample) 236 267 ab = array.array(self.typecode, self.biggerexample) 237 268 238 self.assert _((a == 2*a) is False)239 self.assert _((a != 2*a) is True)240 self.assert _((a < 2*a) is True)241 self.assert _((a <= 2*a) is True)242 self.assert _((a > 2*a) is False)243 self.assert _((a >= 2*a) is False)244 245 self.assert _((a == al) is False)246 self.assert _((a != al) is True)247 self.assert _((a < al) is False)248 self.assert _((a <= al) is False)249 self.assert _((a > al) is True)250 self.assert _((a >= al) is True)251 252 self.assert _((a == ab) is False)253 self.assert _((a != ab) is True)254 self.assert _((a < ab) is True)255 self.assert _((a <= ab) is True)256 self.assert _((a > ab) is False)257 self.assert _((a >= ab) is False)269 self.assertTrue((a == 2*a) is False) 270 self.assertTrue((a != 2*a) is True) 271 self.assertTrue((a < 2*a) is True) 272 self.assertTrue((a <= 2*a) is True) 273 self.assertTrue((a > 2*a) is False) 274 self.assertTrue((a >= 2*a) is False) 275 276 self.assertTrue((a == al) is False) 277 self.assertTrue((a != al) is True) 278 self.assertTrue((a < al) is False) 279 self.assertTrue((a <= al) is False) 280 self.assertTrue((a > al) is True) 281 self.assertTrue((a >= al) is True) 282 283 self.assertTrue((a == ab) is False) 284 self.assertTrue((a != ab) is True) 285 self.assertTrue((a < ab) is True) 286 self.assertTrue((a <= ab) is True) 287 self.assertTrue((a > ab) is False) 288 self.assertTrue((a >= ab) is False) 258 289 259 290 def test_add(self): … … 274 305 b = a 275 306 a += array.array(self.typecode, 2*self.example) 276 self.assert _(a is b)307 self.assertTrue(a is b) 277 308 self.assertEqual( 278 309 a, 279 310 array.array(self.typecode, self.example[::-1]+2*self.example) 311 ) 312 a = array.array(self.typecode, self.example) 313 a += a 314 self.assertEqual( 315 a, 316 array.array(self.typecode, self.example + self.example) 280 317 ) 281 318 … … 317 354 318 355 a *= 5 319 self.assert _(a is b)356 self.assertTrue(a is b) 320 357 self.assertEqual( 321 358 a, … … 324 361 325 362 a *= 0 326 self.assert _(a is b)363 self.assertTrue(a is b) 327 364 self.assertEqual(a, array.array(self.typecode)) 328 365 329 366 a *= 1000 330 self.assert _(a is b)367 self.assertTrue(a is b) 331 368 self.assertEqual(a, array.array(self.typecode)) 332 369 333 370 a *= -1 334 self.assert _(a is b)371 self.assertTrue(a is b) 335 372 self.assertEqual(a, array.array(self.typecode)) 336 373 … … 593 630 L[start:stop:step] = data 594 631 a[start:stop:step] = array.array(self.typecode, data) 595 self.assertEqual s(a, array.array(self.typecode, L))632 self.assertEqual(a, array.array(self.typecode, L)) 596 633 597 634 del L[start:stop:step] 598 635 del a[start:stop:step] 599 self.assertEqual s(a, array.array(self.typecode, L))636 self.assertEqual(a, array.array(self.typecode, L)) 600 637 601 638 def test_index(self): … … 674 711 a, 675 712 array.array(self.typecode, self.example+self.example[::-1]) 713 ) 714 715 a = array.array(self.typecode, self.example) 716 a.extend(a) 717 self.assertEqual( 718 a, 719 array.array(self.typecode, self.example+self.example) 676 720 ) 677 721 … … 718 762 def test_buffer(self): 719 763 a = array.array(self.typecode, self.example) 720 b = buffer(a) 764 with test_support.check_py3k_warnings(): 765 b = buffer(a) 721 766 self.assertEqual(b[0], a.tostring()[0]) 722 767 … … 740 785 def test_subclass_with_kwargs(self): 741 786 # SF bug #1486663 -- this used to erroneously raise a TypeError 742 ArraySubclassWithKwargs('b', newarg=1) 787 with warnings.catch_warnings(): 788 warnings.filterwarnings("ignore", '', DeprecationWarning) 789 ArraySubclassWithKwargs('b', newarg=1) 743 790 744 791 … … 939 986 self.check_overflow(lower, upper) 940 987 988 @test_support.cpython_only 989 def test_sizeof_with_buffer(self): 990 a = array.array(self.typecode, self.example) 991 basesize = test_support.calcvobjsize('4P') 992 buffer_size = a.buffer_info()[1] * a.itemsize 993 test_support.check_sizeof(self, a, basesize + buffer_size) 994 995 @test_support.cpython_only 996 def test_sizeof_without_buffer(self): 997 a = array.array(self.typecode) 998 basesize = test_support.calcvobjsize('4P') 999 test_support.check_sizeof(self, a, basesize) 1000 941 1001 942 1002 class ByteTest(SignedNumberTest):
Note:
See TracChangeset
for help on using the changeset viewer.