Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
test.test_array.FloatTest Class Reference
Inheritance diagram for test.test_array.FloatTest:
Inheritance graph
[legend]
Collaboration diagram for test.test_array.FloatTest:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def assertEntryEqual
def test_byteswap
def test_extslice
def test_delslice
def test_assignment
def test_iterationcontains
def check_overflow
def test_subclassing
def test_frombytearray
def badtypecode
def test_constructor
def test_len
def test_buffer_info
def test_copy
def test_deepcopy
def test_reduce_ex
def test_pickle
def test_pickle_for_empty_array
def test_insert
def test_tofromfile
def test_fromfile_ioerror
def test_filewrite
def test_tofromlist
def test_tofromstring
def test_tofrombytes
def test_fromarray
def test_repr
def test_str
def test_cmp
def test_add
def test_iadd
def test_mul
def test_imul
def test_getitem
def test_setitem
def test_delitem
def test_getslice
def test_extended_getslice
def test_setslice
def test_extended_set_del_slice
def test_index
def test_count
def test_remove
def test_pop
def test_reverse
def test_extend
def test_constructor_with_iterable_argument
def test_coveritertraverse
def test_buffer
def test_weakref
def test_bug_782369
def test_subclass_with_kwargs
def test_create_from_bytes

Public Attributes

 offset

Static Public Attributes

string typecode = 'f'
int minitemsize = 4
list example = [-42.0, 0, 42, 1e5, -1e10]
list smallerexample = [-42.0, 0, 42, 1e5, -2e10]
list biggerexample = [-42.0, 0, 42, 1e5, 1e10]
int outside = 23

Detailed Description

Definition at line 1233 of file test_array.py.


Member Function Documentation

def test.test_array.FPTest.assertEntryEqual (   self,
  entry1,
  entry2 
) [inherited]

Reimplemented from test.test_array.BaseTest.

Definition at line 1214 of file test_array.py.

01214 
01215     def assertEntryEqual(self, entry1, entry2):
01216         self.assertAlmostEqual(entry1, entry2)

Here is the call graph for this function:

def test.test_array.BaseTest.badtypecode (   self) [inherited]

Definition at line 183 of file test_array.py.

00183 
00184     def badtypecode(self):
00185         # Return a typecode that is different from our own
00186         return typecodes[(typecodes.index(self.typecode)+1) % len(typecodes)]

Here is the caller graph for this function:

def test.test_array.NumberTest.check_overflow (   self,
  lower,
  upper 
) [inherited]

Definition at line 1086 of file test_array.py.

01086 
01087     def check_overflow(self, lower, upper):
01088         # method to be used by subclasses
01089 
01090         # should not overflow assigning lower limit
01091         a = array.array(self.typecode, [lower])
01092         a[0] = lower
01093         # should overflow assigning less than lower limit
01094         self.assertRaises(OverflowError, array.array, self.typecode, [lower-1])
01095         self.assertRaises(OverflowError, a.__setitem__, 0, lower-1)
01096         # should not overflow assigning upper limit
01097         a = array.array(self.typecode, [upper])
01098         a[0] = upper
01099         # should overflow assigning more than upper limit
01100         self.assertRaises(OverflowError, array.array, self.typecode, [upper+1])
01101         self.assertRaises(OverflowError, a.__setitem__, 0, upper+1)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_array.BaseTest.test_add (   self) [inherited]

Definition at line 453 of file test_array.py.

00453 
00454     def test_add(self):
00455         a = array.array(self.typecode, self.example) \
00456             + array.array(self.typecode, self.example[::-1])
00457         self.assertEqual(
00458             a,
00459             array.array(self.typecode, self.example + self.example[::-1])
00460         )
00461 
00462         b = array.array(self.badtypecode())
00463         self.assertRaises(TypeError, a.__add__, b)
00464 
00465         self.assertRaises(TypeError, a.__add__, "bad")

Here is the call graph for this function:

def test.test_array.NumberTest.test_assignment (   self) [inherited]

Definition at line 1061 of file test_array.py.

01061 
01062     def test_assignment(self):
01063         a = array.array(self.typecode, range(10))
01064         a[::2] = array.array(self.typecode, [42]*5)
01065         self.assertEqual(a, array.array(self.typecode, [42, 1, 42, 3, 42, 5, 42, 7, 42, 9]))
01066         a = array.array(self.typecode, range(10))
01067         a[::-4] = array.array(self.typecode, [10]*3)
01068         self.assertEqual(a, array.array(self.typecode, [0, 10, 2, 3, 4, 10, 6, 7, 8 ,10]))
01069         a = array.array(self.typecode, range(4))
01070         a[::-1] = a
01071         self.assertEqual(a, array.array(self.typecode, [3, 2, 1, 0]))
01072         a = array.array(self.typecode, range(10))
01073         b = a[:]
01074         c = a[:]
01075         ins = array.array(self.typecode, range(2))
01076         a[2:3] = ins
01077         b[slice(2,3)] = ins
01078         c[2:3:] = ins

Here is the call graph for this function:

def test.test_array.BaseTest.test_buffer (   self) [inherited]

Definition at line 929 of file test_array.py.

00929 
00930     def test_buffer(self):
00931         a = array.array(self.typecode, self.example)
00932         m = memoryview(a)
00933         expected = m.tobytes()
00934         self.assertEqual(a.tobytes(), expected)
00935         self.assertEqual(a.tobytes()[0], expected[0])
00936         # Resizing is forbidden when there are buffer exports.
00937         # For issue 4509, we also check after each error that
00938         # the array was not modified.
00939         self.assertRaises(BufferError, a.append, a[0])
00940         self.assertEqual(m.tobytes(), expected)
00941         self.assertRaises(BufferError, a.extend, a[0:1])
00942         self.assertEqual(m.tobytes(), expected)
00943         self.assertRaises(BufferError, a.remove, a[0])
00944         self.assertEqual(m.tobytes(), expected)
00945         self.assertRaises(BufferError, a.pop, 0)
00946         self.assertEqual(m.tobytes(), expected)
00947         self.assertRaises(BufferError, a.fromlist, a.tolist())
00948         self.assertEqual(m.tobytes(), expected)
00949         self.assertRaises(BufferError, a.frombytes, a.tobytes())
00950         self.assertEqual(m.tobytes(), expected)
00951         if self.typecode == 'u':
00952             self.assertRaises(BufferError, a.fromunicode, a.tounicode())
00953             self.assertEqual(m.tobytes(), expected)
00954         self.assertRaises(BufferError, operator.imul, a, 2)
00955         self.assertEqual(m.tobytes(), expected)
00956         self.assertRaises(BufferError, operator.imul, a, 0)
00957         self.assertEqual(m.tobytes(), expected)
00958         self.assertRaises(BufferError, operator.setitem, a, slice(0, 0), a)
00959         self.assertEqual(m.tobytes(), expected)
00960         self.assertRaises(BufferError, operator.delitem, a, 0)
00961         self.assertEqual(m.tobytes(), expected)
00962         self.assertRaises(BufferError, operator.delitem, a, slice(0, 1))
00963         self.assertEqual(m.tobytes(), expected)

Here is the call graph for this function:

def test.test_array.BaseTest.test_buffer_info (   self) [inherited]

Definition at line 201 of file test_array.py.

00201 
00202     def test_buffer_info(self):
00203         a = array.array(self.typecode, self.example)
00204         self.assertRaises(TypeError, a.buffer_info, 42)
00205         bi = a.buffer_info()
00206         self.assertIsInstance(bi, tuple)
00207         self.assertEqual(len(bi), 2)
00208         self.assertIsInstance(bi[0], int)
00209         self.assertIsInstance(bi[1], int)
00210         self.assertEqual(bi[1], len(a))

Here is the call graph for this function:

def test.test_array.BaseTest.test_bug_782369 (   self) [inherited]

Definition at line 971 of file test_array.py.

00971 
00972     def test_bug_782369(self):
00973         import sys
00974         if hasattr(sys, "getrefcount"):
00975             for i in range(10):
00976                 b = array.array('B', range(64))
00977             rc = sys.getrefcount(10)
00978             for i in range(10):
00979                 b = array.array('B', range(64))
00980             self.assertEqual(rc, sys.getrefcount(10))

Here is the call graph for this function:

def test.test_array.FPTest.test_byteswap (   self) [inherited]

Reimplemented from test.test_array.BaseTest.

Definition at line 1217 of file test_array.py.

01217 
01218     def test_byteswap(self):
01219         a = array.array(self.typecode, self.example)
01220         self.assertRaises(TypeError, a.byteswap, 42)
01221         if a.itemsize in (1, 2, 4, 8):
01222             b = array.array(self.typecode, self.example)
01223             b.byteswap()
01224             if a.itemsize==1:
01225                 self.assertEqual(a, b)
01226             else:
01227                 # On alphas treating the byte swapped bit patters as
01228                 # floats/doubles results in floating point exceptions
01229                 # => compare the 8bit string values instead
01230                 self.assertNotEqual(a.tobytes(), b.tobytes())
01231             b.byteswap()
01232             self.assertEqual(a, b)

Here is the call graph for this function:

def test.test_array.BaseTest.test_cmp (   self) [inherited]

Definition at line 417 of file test_array.py.

00417 
00418     def test_cmp(self):
00419         a = array.array(self.typecode, self.example)
00420         self.assertTrue((a == 42) is False)
00421         self.assertTrue((a != 42) is True)
00422 
00423         self.assertTrue((a == a) is True)
00424         self.assertTrue((a != a) is False)
00425         self.assertTrue((a < a) is False)
00426         self.assertTrue((a <= a) is True)
00427         self.assertTrue((a > a) is False)
00428         self.assertTrue((a >= a) is True)
00429 
00430         al = array.array(self.typecode, self.smallerexample)
00431         ab = array.array(self.typecode, self.biggerexample)
00432 
00433         self.assertTrue((a == 2*a) is False)
00434         self.assertTrue((a != 2*a) is True)
00435         self.assertTrue((a < 2*a) is True)
00436         self.assertTrue((a <= 2*a) is True)
00437         self.assertTrue((a > 2*a) is False)
00438         self.assertTrue((a >= 2*a) is False)
00439 
00440         self.assertTrue((a == al) is False)
00441         self.assertTrue((a != al) is True)
00442         self.assertTrue((a < al) is False)
00443         self.assertTrue((a <= al) is False)
00444         self.assertTrue((a > al) is True)
00445         self.assertTrue((a >= al) is True)
00446 
00447         self.assertTrue((a == ab) is False)
00448         self.assertTrue((a != ab) is True)
00449         self.assertTrue((a < ab) is True)
00450         self.assertTrue((a <= ab) is True)
00451         self.assertTrue((a > ab) is False)
00452         self.assertTrue((a >= ab) is False)

Here is the call graph for this function:

def test.test_array.BaseTest.test_constructor (   self) [inherited]

Definition at line 187 of file test_array.py.

00187 
00188     def test_constructor(self):
00189         a = array.array(self.typecode)
00190         self.assertEqual(a.typecode, self.typecode)
00191         self.assertTrue(a.itemsize>=self.minitemsize)
00192         self.assertRaises(TypeError, array.array, self.typecode, None)

Here is the call graph for this function:

Definition at line 899 of file test_array.py.

00899 
00900     def test_constructor_with_iterable_argument(self):
00901         a = array.array(self.typecode, iter(self.example))
00902         b = array.array(self.typecode, self.example)
00903         self.assertEqual(a, b)
00904 
00905         # non-iterable argument
00906         self.assertRaises(TypeError, array.array, self.typecode, 10)
00907 
00908         # pass through errors raised in __iter__
00909         class A:
00910             def __iter__(self):
00911                 raise UnicodeError
00912         self.assertRaises(UnicodeError, array.array, self.typecode, A())
00913 
00914         # pass through errors raised in next()
00915         def B():
00916             raise UnicodeError
00917             yield None
00918         self.assertRaises(UnicodeError, array.array, self.typecode, B())

Here is the call graph for this function:

def test.test_array.BaseTest.test_copy (   self) [inherited]

Definition at line 224 of file test_array.py.

00224 
00225     def test_copy(self):
00226         import copy
00227         a = array.array(self.typecode, self.example)
00228         b = copy.copy(a)
00229         self.assertNotEqual(id(a), id(b))
00230         self.assertEqual(a, b)

Here is the call graph for this function:

def test.test_array.BaseTest.test_count (   self) [inherited]

Definition at line 814 of file test_array.py.

00814 
00815     def test_count(self):
00816         example = 2*self.example
00817         a = array.array(self.typecode, example)
00818         self.assertRaises(TypeError, a.count)
00819         for x in example:
00820             self.assertEqual(a.count(x), example.count(x))
00821         self.assertEqual(a.count(self.outside), 0)
00822         self.assertEqual(a.count(None), 0)

Here is the call graph for this function:

Definition at line 919 of file test_array.py.

00919 
00920     def test_coveritertraverse(self):
00921         try:
00922             import gc
00923         except ImportError:
00924             return
00925         a = array.array(self.typecode)
00926         l = [iter(a)]
00927         l.append(l)
00928         gc.collect()

Definition at line 985 of file test_array.py.

00985 
00986     def test_create_from_bytes(self):
00987         # XXX This test probably needs to be moved in a subclass or
00988         # generalized to use self.typecode.
00989         a = array.array('H', b"1234")
00990         self.assertEqual(len(a) * a.itemsize, 4)
00991 

Here is the call graph for this function:

def test.test_array.BaseTest.test_deepcopy (   self) [inherited]

Definition at line 231 of file test_array.py.

00231 
00232     def test_deepcopy(self):
00233         import copy
00234         a = array.array(self.typecode, self.example)
00235         b = copy.deepcopy(a)
00236         self.assertNotEqual(id(a), id(b))
00237         self.assertEqual(a, b)

Here is the call graph for this function:

def test.test_array.BaseTest.test_delitem (   self) [inherited]

Definition at line 600 of file test_array.py.

00600 
00601     def test_delitem(self):
00602         a = array.array(self.typecode, self.example)
00603         del a[0]
00604         self.assertEqual(
00605             a,
00606             array.array(self.typecode, self.example[1:])
00607         )
00608 
00609         a = array.array(self.typecode, self.example)
00610         del a[-1]
00611         self.assertEqual(
00612             a,
00613             array.array(self.typecode, self.example[:-1])
00614         )
00615 
00616         a = array.array(self.typecode, self.example)
00617         del a[len(self.example)-1]
00618         self.assertEqual(
00619             a,
00620             array.array(self.typecode, self.example[:-1])
00621         )
00622 
00623         a = array.array(self.typecode, self.example)
00624         del a[-len(self.example)]
00625         self.assertEqual(
00626             a,
00627             array.array(self.typecode, self.example[1:])
00628         )
00629 
00630         self.assertRaises(TypeError, a.__delitem__)
00631         self.assertRaises(TypeError, a.__delitem__, None)
00632         self.assertRaises(IndexError, a.__delitem__, len(self.example))
00633         self.assertRaises(IndexError, a.__delitem__, -len(self.example)-1)

Here is the call graph for this function:

def test.test_array.NumberTest.test_delslice (   self) [inherited]

Definition at line 1044 of file test_array.py.

01044 
01045     def test_delslice(self):
01046         a = array.array(self.typecode, range(5))
01047         del a[::2]
01048         self.assertEqual(a, array.array(self.typecode, [1,3]))
01049         a = array.array(self.typecode, range(5))
01050         del a[1::2]
01051         self.assertEqual(a, array.array(self.typecode, [0,2,4]))
01052         a = array.array(self.typecode, range(5))
01053         del a[1::-2]
01054         self.assertEqual(a, array.array(self.typecode, [0,2,3,4]))
01055         a = array.array(self.typecode, range(10))
01056         del a[::1000]
01057         self.assertEqual(a, array.array(self.typecode, [1,2,3,4,5,6,7,8,9]))
01058         # test issue7788
01059         a = array.array(self.typecode, range(10))
01060         del a[9::1<<333]

Here is the call graph for this function:

def test.test_array.BaseTest.test_extend (   self) [inherited]

Definition at line 873 of file test_array.py.

00873 
00874     def test_extend(self):
00875         a = array.array(self.typecode, self.example)
00876         self.assertRaises(TypeError, a.extend)
00877         a.extend(array.array(self.typecode, self.example[::-1]))
00878         self.assertEqual(
00879             a,
00880             array.array(self.typecode, self.example+self.example[::-1])
00881         )
00882 
00883         a = array.array(self.typecode, self.example)
00884         a.extend(a)
00885         self.assertEqual(
00886             a,
00887             array.array(self.typecode, self.example+self.example)
00888         )
00889 
00890         b = array.array(self.badtypecode())
00891         self.assertRaises(TypeError, a.extend, b)
00892 
00893         a = array.array(self.typecode, self.example)
00894         a.extend(self.example[::-1])
00895         self.assertEqual(
00896             a,
00897             array.array(self.typecode, self.example+self.example[::-1])
00898         )

Here is the call graph for this function:

Definition at line 684 of file test_array.py.

00684 
00685     def test_extended_getslice(self):
00686         # Test extended slicing by comparing with list slicing
00687         # (Assumes list conversion works correctly, too)
00688         a = array.array(self.typecode, self.example)
00689         indices = (0, None, 1, 3, 19, 100, -1, -2, -31, -100)
00690         for start in indices:
00691             for stop in indices:
00692                 # Everything except the initial 0 (invalid step)
00693                 for step in indices[1:]:
00694                     self.assertEqual(list(a[start:stop:step]),
00695                                      list(a)[start:stop:step])

Here is the call graph for this function:

Definition at line 785 of file test_array.py.

00785 
00786     def test_extended_set_del_slice(self):
00787         indices = (0, None, 1, 3, 19, 100, -1, -2, -31, -100)
00788         for start in indices:
00789             for stop in indices:
00790                 # Everything except the initial 0 (invalid step)
00791                 for step in indices[1:]:
00792                     a = array.array(self.typecode, self.example)
00793                     L = list(a)
00794                     # Make sure we have a slice of exactly the right length,
00795                     # but with (hopefully) different data.
00796                     data = L[start:stop:step]
00797                     data.reverse()
00798                     L[start:stop:step] = data
00799                     a[start:stop:step] = array.array(self.typecode, data)
00800                     self.assertEqual(a, array.array(self.typecode, L))
00801 
00802                     del L[start:stop:step]
00803                     del a[start:stop:step]
00804                     self.assertEqual(a, array.array(self.typecode, L))

Here is the call graph for this function:

def test.test_array.NumberTest.test_extslice (   self) [inherited]

Definition at line 1030 of file test_array.py.

01030 
01031     def test_extslice(self):
01032         a = array.array(self.typecode, range(5))
01033         self.assertEqual(a[::], a)
01034         self.assertEqual(a[::2], array.array(self.typecode, [0,2,4]))
01035         self.assertEqual(a[1::2], array.array(self.typecode, [1,3]))
01036         self.assertEqual(a[::-1], array.array(self.typecode, [4,3,2,1,0]))
01037         self.assertEqual(a[::-2], array.array(self.typecode, [4,2,0]))
01038         self.assertEqual(a[3::-2], array.array(self.typecode, [3,1]))
01039         self.assertEqual(a[-100:100:], a)
01040         self.assertEqual(a[100:-100:-1], a[::-1])
01041         self.assertEqual(a[-100:100:2], array.array(self.typecode, [0,2,4]))
01042         self.assertEqual(a[1000:2000:2], array.array(self.typecode, []))
01043         self.assertEqual(a[-1000:-2000:-2], array.array(self.typecode, []))

Here is the call graph for this function:

def test.test_array.BaseTest.test_filewrite (   self) [inherited]

Definition at line 341 of file test_array.py.

00341 
00342     def test_filewrite(self):
00343         a = array.array(self.typecode, 2*self.example)
00344         f = open(support.TESTFN, 'wb')
00345         try:
00346             f.write(a)
00347             f.close()
00348             b = array.array(self.typecode)
00349             f = open(support.TESTFN, 'rb')
00350             b.fromfile(f, len(self.example))
00351             self.assertEqual(b, array.array(self.typecode, self.example))
00352             self.assertNotEqual(a, b)
00353             b.fromfile(f, len(self.example))
00354             self.assertEqual(a, b)
00355             f.close()
00356         finally:
00357             if not f.closed:
00358                 f.close()
00359             support.unlink(support.TESTFN)

Here is the call graph for this function:

def test.test_array.BaseTest.test_fromarray (   self) [inherited]

Definition at line 401 of file test_array.py.

00401 
00402     def test_fromarray(self):
00403         a = array.array(self.typecode, self.example)
00404         b = array.array(self.typecode, a)
00405         self.assertEqual(a, b)

Here is the call graph for this function:

Definition at line 1121 of file test_array.py.

01121 
01122     def test_frombytearray(self):
01123         a = array.array('b', range(10))
01124         b = array.array(self.typecode, a)
01125         self.assertEqual(a, b)

Here is the call graph for this function:

Definition at line 330 of file test_array.py.

00330 
00331     def test_fromfile_ioerror(self):
00332         # Issue #5395: Check if fromfile raises a proper IOError
00333         # instead of EOFError.
00334         a = array.array(self.typecode)
00335         f = open(support.TESTFN, 'wb')
00336         try:
00337             self.assertRaises(IOError, a.fromfile, f, len(self.example))
00338         finally:
00339             f.close()
00340             support.unlink(support.TESTFN)

Here is the call graph for this function:

def test.test_array.BaseTest.test_getitem (   self) [inherited]

Definition at line 549 of file test_array.py.

00549 
00550     def test_getitem(self):
00551         a = array.array(self.typecode, self.example)
00552         self.assertEntryEqual(a[0], self.example[0])
00553         self.assertEntryEqual(a[0], self.example[0])
00554         self.assertEntryEqual(a[-1], self.example[-1])
00555         self.assertEntryEqual(a[-1], self.example[-1])
00556         self.assertEntryEqual(a[len(self.example)-1], self.example[-1])
00557         self.assertEntryEqual(a[-len(self.example)], self.example[0])
00558         self.assertRaises(TypeError, a.__getitem__)
00559         self.assertRaises(IndexError, a.__getitem__, len(self.example))
00560         self.assertRaises(IndexError, a.__getitem__, -len(self.example)-1)

Here is the call graph for this function:

def test.test_array.BaseTest.test_getslice (   self) [inherited]

Definition at line 634 of file test_array.py.

00634 
00635     def test_getslice(self):
00636         a = array.array(self.typecode, self.example)
00637         self.assertEqual(a[:], a)
00638 
00639         self.assertEqual(
00640             a[1:],
00641             array.array(self.typecode, self.example[1:])
00642         )
00643 
00644         self.assertEqual(
00645             a[:1],
00646             array.array(self.typecode, self.example[:1])
00647         )
00648 
00649         self.assertEqual(
00650             a[:-1],
00651             array.array(self.typecode, self.example[:-1])
00652         )
00653 
00654         self.assertEqual(
00655             a[-1:],
00656             array.array(self.typecode, self.example[-1:])
00657         )
00658 
00659         self.assertEqual(
00660             a[-1:-1],
00661             array.array(self.typecode)
00662         )
00663 
00664         self.assertEqual(
00665             a[2:1],
00666             array.array(self.typecode)
00667         )
00668 
00669         self.assertEqual(
00670             a[1000:],
00671             array.array(self.typecode)
00672         )
00673         self.assertEqual(a[-1000:], a)
00674         self.assertEqual(a[:1000], a)
00675         self.assertEqual(
00676             a[:-1000],
00677             array.array(self.typecode)
00678         )
00679         self.assertEqual(a[-1000:1000], a)
00680         self.assertEqual(
00681             a[2000:1000],
00682             array.array(self.typecode)
00683         )

Here is the call graph for this function:

def test.test_array.BaseTest.test_iadd (   self) [inherited]

Definition at line 466 of file test_array.py.

00466 
00467     def test_iadd(self):
00468         a = array.array(self.typecode, self.example[::-1])
00469         b = a
00470         a += array.array(self.typecode, 2*self.example)
00471         self.assertTrue(a is b)
00472         self.assertEqual(
00473             a,
00474             array.array(self.typecode, self.example[::-1]+2*self.example)
00475         )
00476         a = array.array(self.typecode, self.example)
00477         a += a
00478         self.assertEqual(
00479             a,
00480             array.array(self.typecode, self.example + self.example)
00481         )
00482 
00483         b = array.array(self.badtypecode())
00484         self.assertRaises(TypeError, a.__add__, b)
00485 
00486         self.assertRaises(TypeError, a.__iadd__, "bad")

Here is the call graph for this function:

def test.test_array.BaseTest.test_imul (   self) [inherited]

Definition at line 520 of file test_array.py.

00520 
00521     def test_imul(self):
00522         a = array.array(self.typecode, self.example)
00523         b = a
00524 
00525         a *= 5
00526         self.assertTrue(a is b)
00527         self.assertEqual(
00528             a,
00529             array.array(self.typecode, 5*self.example)
00530         )
00531 
00532         a *= 0
00533         self.assertTrue(a is b)
00534         self.assertEqual(a, array.array(self.typecode))
00535 
00536         a *= 1000
00537         self.assertTrue(a is b)
00538         self.assertEqual(a, array.array(self.typecode))
00539 
00540         a *= -1
00541         self.assertTrue(a is b)
00542         self.assertEqual(a, array.array(self.typecode))
00543 
00544         a = array.array(self.typecode, self.example)
00545         a *= -1
00546         self.assertEqual(a, array.array(self.typecode))
00547 
00548         self.assertRaises(TypeError, a.__imul__, "bad")

Here is the call graph for this function:

def test.test_array.BaseTest.test_index (   self) [inherited]

Definition at line 805 of file test_array.py.

00805 
00806     def test_index(self):
00807         example = 2*self.example
00808         a = array.array(self.typecode, example)
00809         self.assertRaises(TypeError, a.index)
00810         for x in example:
00811             self.assertEqual(a.index(x), example.index(x))
00812         self.assertRaises(ValueError, a.index, None)
00813         self.assertRaises(ValueError, a.index, self.outside)

Here is the call graph for this function:

def test.test_array.BaseTest.test_insert (   self) [inherited]

Definition at line 275 of file test_array.py.

00275 
00276     def test_insert(self):
00277         a = array.array(self.typecode, self.example)
00278         a.insert(0, self.example[0])
00279         self.assertEqual(len(a), 1+len(self.example))
00280         self.assertEqual(a[0], a[1])
00281         self.assertRaises(TypeError, a.insert)
00282         self.assertRaises(TypeError, a.insert, None)
00283         self.assertRaises(TypeError, a.insert, 0, None)
00284 
00285         a = array.array(self.typecode, self.example)
00286         a.insert(-1, self.example[0])
00287         self.assertEqual(
00288             a,
00289             array.array(
00290                 self.typecode,
00291                 self.example[:-1] + self.example[:1] + self.example[-1:]
00292             )
00293         )
00294 
00295         a = array.array(self.typecode, self.example)
00296         a.insert(-1000, self.example[0])
00297         self.assertEqual(
00298             a,
00299             array.array(self.typecode, self.example[:1] + self.example)
00300         )
00301 
00302         a = array.array(self.typecode, self.example)
00303         a.insert(1000, self.example[0])
00304         self.assertEqual(
00305             a,
00306             array.array(self.typecode, self.example + self.example[:1])
00307         )

Here is the call graph for this function:

Definition at line 1079 of file test_array.py.

01079 
01080     def test_iterationcontains(self):
01081         a = array.array(self.typecode, range(10))
01082         self.assertEqual(list(a), list(range(10)))
01083         b = array.array(self.typecode, [20])
01084         self.assertEqual(a[-1] in a, True)
01085         self.assertEqual(b[0] not in a, True)

Here is the call graph for this function:

def test.test_array.BaseTest.test_len (   self) [inherited]

Definition at line 193 of file test_array.py.

00193 
00194     def test_len(self):
00195         a = array.array(self.typecode)
00196         a.append(self.example[0])
00197         self.assertEqual(len(a), 1)
00198 
00199         a = array.array(self.typecode, self.example)
00200         self.assertEqual(len(a), len(self.example))

Here is the call graph for this function:

def test.test_array.BaseTest.test_mul (   self) [inherited]

Definition at line 487 of file test_array.py.

00487 
00488     def test_mul(self):
00489         a = 5*array.array(self.typecode, self.example)
00490         self.assertEqual(
00491             a,
00492             array.array(self.typecode, 5*self.example)
00493         )
00494 
00495         a = array.array(self.typecode, self.example)*5
00496         self.assertEqual(
00497             a,
00498             array.array(self.typecode, self.example*5)
00499         )
00500 
00501         a = 0*array.array(self.typecode, self.example)
00502         self.assertEqual(
00503             a,
00504             array.array(self.typecode)
00505         )
00506 
00507         a = (-1)*array.array(self.typecode, self.example)
00508         self.assertEqual(
00509             a,
00510             array.array(self.typecode)
00511         )
00512 
00513         a = 5 * array.array(self.typecode, self.example[:1])
00514         self.assertEqual(
00515             a,
00516             array.array(self.typecode, [a[0]] * 5)
00517         )
00518 
00519         self.assertRaises(TypeError, a.__mul__, "bad")

Here is the call graph for this function:

def test.test_array.BaseTest.test_pickle (   self) [inherited]

Definition at line 245 of file test_array.py.

00245 
00246     def test_pickle(self):
00247         for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
00248             a = array.array(self.typecode, self.example)
00249             b = pickle.loads(pickle.dumps(a, protocol))
00250             self.assertNotEqual(id(a), id(b))
00251             self.assertEqual(a, b)
00252 
00253             a = ArraySubclass(self.typecode, self.example)
00254             a.x = 10
00255             b = pickle.loads(pickle.dumps(a, protocol))
00256             self.assertNotEqual(id(a), id(b))
00257             self.assertEqual(a, b)
00258             self.assertEqual(a.x, b.x)
00259             self.assertEqual(type(a), type(b))

Here is the call graph for this function:

Definition at line 260 of file test_array.py.

00260 
00261     def test_pickle_for_empty_array(self):
00262         for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
00263             a = array.array(self.typecode)
00264             b = pickle.loads(pickle.dumps(a, protocol))
00265             self.assertNotEqual(id(a), id(b))
00266             self.assertEqual(a, b)
00267 
00268             a = ArraySubclass(self.typecode)
00269             a.x = 10
00270             b = pickle.loads(pickle.dumps(a, protocol))
00271             self.assertNotEqual(id(a), id(b))
00272             self.assertEqual(a, b)
00273             self.assertEqual(a.x, b.x)
00274             self.assertEqual(type(a), type(b))

Here is the call graph for this function:

def test.test_array.BaseTest.test_pop (   self) [inherited]

Definition at line 837 of file test_array.py.

00837 
00838     def test_pop(self):
00839         a = array.array(self.typecode)
00840         self.assertRaises(IndexError, a.pop)
00841 
00842         a = array.array(self.typecode, 2*self.example)
00843         self.assertRaises(TypeError, a.pop, 42, 42)
00844         self.assertRaises(TypeError, a.pop, None)
00845         self.assertRaises(IndexError, a.pop, len(a))
00846         self.assertRaises(IndexError, a.pop, -len(a)-1)
00847 
00848         self.assertEntryEqual(a.pop(0), self.example[0])
00849         self.assertEqual(
00850             a,
00851             array.array(self.typecode, self.example[1:]+self.example)
00852         )
00853         self.assertEntryEqual(a.pop(1), self.example[2])
00854         self.assertEqual(
00855             a,
00856             array.array(self.typecode, self.example[1:2]+self.example[3:]+self.example)
00857         )
00858         self.assertEntryEqual(a.pop(0), self.example[1])
00859         self.assertEntryEqual(a.pop(), self.example[-1])
00860         self.assertEqual(
00861             a,
00862             array.array(self.typecode, self.example[3:]+self.example[:-1])
00863         )

Here is the call graph for this function:

def test.test_array.BaseTest.test_reduce_ex (   self) [inherited]

Definition at line 238 of file test_array.py.

00238 
00239     def test_reduce_ex(self):
00240         a = array.array(self.typecode, self.example)
00241         for protocol in range(3):
00242             self.assertIs(a.__reduce_ex__(protocol)[0], array.array)
00243         for protocol in range(3, pickle.HIGHEST_PROTOCOL):
00244             self.assertIs(a.__reduce_ex__(protocol)[0], array_reconstructor)

Here is the call graph for this function:

def test.test_array.BaseTest.test_remove (   self) [inherited]

Definition at line 823 of file test_array.py.

00823 
00824     def test_remove(self):
00825         for x in self.example:
00826             example = 2*self.example
00827             a = array.array(self.typecode, example)
00828             pos = example.index(x)
00829             example2 = example[:pos] + example[pos+1:]
00830             a.remove(x)
00831             self.assertEqual(a, array.array(self.typecode, example2))
00832 
00833         a = array.array(self.typecode, self.example)
00834         self.assertRaises(ValueError, a.remove, self.outside)
00835 
00836         self.assertRaises(ValueError, a.remove, None)

Here is the call graph for this function:

def test.test_array.BaseTest.test_repr (   self) [inherited]

Definition at line 406 of file test_array.py.

00406 
00407     def test_repr(self):
00408         a = array.array(self.typecode, 2*self.example)
00409         self.assertEqual(a, eval(repr(a), {"array": array.array}))
00410 
00411         a = array.array(self.typecode)
00412         self.assertEqual(repr(a), "array('%s')" % self.typecode)

Here is the call graph for this function:

def test.test_array.BaseTest.test_reverse (   self) [inherited]

Definition at line 864 of file test_array.py.

00864 
00865     def test_reverse(self):
00866         a = array.array(self.typecode, self.example)
00867         self.assertRaises(TypeError, a.reverse, 42)
00868         a.reverse()
00869         self.assertEqual(
00870             a,
00871             array.array(self.typecode, self.example[::-1])
00872         )

Here is the call graph for this function:

def test.test_array.BaseTest.test_setitem (   self) [inherited]

Reimplemented in test.test_array.StringTest.

Definition at line 561 of file test_array.py.

00561 
00562     def test_setitem(self):
00563         a = array.array(self.typecode, self.example)
00564         a[0] = a[-1]
00565         self.assertEntryEqual(a[0], a[-1])
00566 
00567         a = array.array(self.typecode, self.example)
00568         a[0] = a[-1]
00569         self.assertEntryEqual(a[0], a[-1])
00570 
00571         a = array.array(self.typecode, self.example)
00572         a[-1] = a[0]
00573         self.assertEntryEqual(a[0], a[-1])
00574 
00575         a = array.array(self.typecode, self.example)
00576         a[-1] = a[0]
00577         self.assertEntryEqual(a[0], a[-1])
00578 
00579         a = array.array(self.typecode, self.example)
00580         a[len(self.example)-1] = a[0]
00581         self.assertEntryEqual(a[0], a[-1])
00582 
00583         a = array.array(self.typecode, self.example)
00584         a[-len(self.example)] = a[-1]
00585         self.assertEntryEqual(a[0], a[-1])
00586 
00587         self.assertRaises(TypeError, a.__setitem__)
00588         self.assertRaises(TypeError, a.__setitem__, None)
00589         self.assertRaises(TypeError, a.__setitem__, 0, None)
00590         self.assertRaises(
00591             IndexError,
00592             a.__setitem__,
00593             len(self.example), self.example[0]
00594         )
00595         self.assertRaises(
00596             IndexError,
00597             a.__setitem__,
00598             -len(self.example)-1, self.example[0]
00599         )

Here is the call graph for this function:

def test.test_array.BaseTest.test_setslice (   self) [inherited]

Definition at line 696 of file test_array.py.

00696 
00697     def test_setslice(self):
00698         a = array.array(self.typecode, self.example)
00699         a[:1] = a
00700         self.assertEqual(
00701             a,
00702             array.array(self.typecode, self.example + self.example[1:])
00703         )
00704 
00705         a = array.array(self.typecode, self.example)
00706         a[:-1] = a
00707         self.assertEqual(
00708             a,
00709             array.array(self.typecode, self.example + self.example[-1:])
00710         )
00711 
00712         a = array.array(self.typecode, self.example)
00713         a[-1:] = a
00714         self.assertEqual(
00715             a,
00716             array.array(self.typecode, self.example[:-1] + self.example)
00717         )
00718 
00719         a = array.array(self.typecode, self.example)
00720         a[1:] = a
00721         self.assertEqual(
00722             a,
00723             array.array(self.typecode, self.example[:1] + self.example)
00724         )
00725 
00726         a = array.array(self.typecode, self.example)
00727         a[1:-1] = a
00728         self.assertEqual(
00729             a,
00730             array.array(
00731                 self.typecode,
00732                 self.example[:1] + self.example + self.example[-1:]
00733             )
00734         )
00735 
00736         a = array.array(self.typecode, self.example)
00737         a[1000:] = a
00738         self.assertEqual(
00739             a,
00740             array.array(self.typecode, 2*self.example)
00741         )
00742 
00743         a = array.array(self.typecode, self.example)
00744         a[-1000:] = a
00745         self.assertEqual(
00746             a,
00747             array.array(self.typecode, self.example)
00748         )
00749 
00750         a = array.array(self.typecode, self.example)
00751         a[:1000] = a
00752         self.assertEqual(
00753             a,
00754             array.array(self.typecode, self.example)
00755         )
00756 
00757         a = array.array(self.typecode, self.example)
00758         a[:-1000] = a
00759         self.assertEqual(
00760             a,
00761             array.array(self.typecode, 2*self.example)
00762         )
00763 
00764         a = array.array(self.typecode, self.example)
00765         a[1:0] = a
00766         self.assertEqual(
00767             a,
00768             array.array(self.typecode, self.example[:1] + self.example + self.example[1:])
00769         )
00770 
00771         a = array.array(self.typecode, self.example)
00772         a[2000:1000] = a
00773         self.assertEqual(
00774             a,
00775             array.array(self.typecode, 2*self.example)
00776         )
00777 
00778         a = array.array(self.typecode, self.example)
00779         self.assertRaises(TypeError, a.__setitem__, slice(0, 0), None)
00780         self.assertRaises(TypeError, a.__setitem__, slice(0, 1), None)
00781 
00782         b = array.array(self.badtypecode())
00783         self.assertRaises(TypeError, a.__setitem__, slice(0, 0), b)
00784         self.assertRaises(TypeError, a.__setitem__, slice(0, 1), b)

Here is the call graph for this function:

def test.test_array.BaseTest.test_str (   self) [inherited]

Definition at line 413 of file test_array.py.

00413 
00414     def test_str(self):
00415         a = array.array(self.typecode, 2*self.example)
00416         str(a)

Definition at line 981 of file test_array.py.

00981 
00982     def test_subclass_with_kwargs(self):
00983         # SF bug #1486663 -- this used to erroneously raise a TypeError
00984         ArraySubclassWithKwargs('b', newarg=1)

def test.test_array.NumberTest.test_subclassing (   self) [inherited]

Definition at line 1102 of file test_array.py.

01102 
01103     def test_subclassing(self):
01104         typecode = self.typecode
01105         class ExaggeratingArray(array.array):
01106             __slots__ = ['offset']
01107 
01108             def __new__(cls, typecode, data, offset):
01109                 return array.array.__new__(cls, typecode, data)
01110 
01111             def __init__(self, typecode, data, offset):
01112                 self.offset = offset
01113 
01114             def __getitem__(self, i):
01115                 return array.array.__getitem__(self, i) + self.offset
01116 
01117         a = ExaggeratingArray(self.typecode, [3, 6, 7, 11], 4)
01118         self.assertEntryEqual(a[0], 7)
01119 
01120         self.assertRaises(AttributeError, setattr, a, "color", "blue")

Here is the call graph for this function:

def test.test_array.BaseTest.test_tofrombytes (   self) [inherited]

Definition at line 388 of file test_array.py.

00388 
00389     def test_tofrombytes(self):
00390         a = array.array(self.typecode, 2*self.example)
00391         b = array.array(self.typecode)
00392         self.assertRaises(TypeError, a.tobytes, 42)
00393         self.assertRaises(TypeError, b.frombytes)
00394         self.assertRaises(TypeError, b.frombytes, 42)
00395         b.frombytes(a.tobytes())
00396         c = array.array(self.typecode, bytearray(a.tobytes()))
00397         self.assertEqual(a, b)
00398         self.assertEqual(a, c)
00399         if a.itemsize>1:
00400             self.assertRaises(ValueError, b.frombytes, b"x")

Here is the call graph for this function:

def test.test_array.BaseTest.test_tofromfile (   self) [inherited]

Definition at line 308 of file test_array.py.

00308 
00309     def test_tofromfile(self):
00310         a = array.array(self.typecode, 2*self.example)
00311         self.assertRaises(TypeError, a.tofile)
00312         support.unlink(support.TESTFN)
00313         f = open(support.TESTFN, 'wb')
00314         try:
00315             a.tofile(f)
00316             f.close()
00317             b = array.array(self.typecode)
00318             f = open(support.TESTFN, 'rb')
00319             self.assertRaises(TypeError, b.fromfile)
00320             b.fromfile(f, len(self.example))
00321             self.assertEqual(b, array.array(self.typecode, self.example))
00322             self.assertNotEqual(a, b)
00323             self.assertRaises(EOFError, b.fromfile, f, len(self.example)+1)
00324             self.assertEqual(a, b)
00325             f.close()
00326         finally:
00327             if not f.closed:
00328                 f.close()
00329             support.unlink(support.TESTFN)

Here is the call graph for this function:

def test.test_array.BaseTest.test_tofromlist (   self) [inherited]

Definition at line 360 of file test_array.py.

00360 
00361     def test_tofromlist(self):
00362         a = array.array(self.typecode, 2*self.example)
00363         b = array.array(self.typecode)
00364         self.assertRaises(TypeError, a.tolist, 42)
00365         self.assertRaises(TypeError, b.fromlist)
00366         self.assertRaises(TypeError, b.fromlist, 42)
00367         self.assertRaises(TypeError, b.fromlist, [None])
00368         b.fromlist(a.tolist())
00369         self.assertEqual(a, b)

Here is the call graph for this function:

def test.test_array.BaseTest.test_tofromstring (   self) [inherited]

Definition at line 370 of file test_array.py.

00370 
00371     def test_tofromstring(self):
00372         nb_warnings = 4
00373         with warnings.catch_warnings(record=True) as r:
00374             warnings.filterwarnings("always",
00375                                     message=r"(to|from)string\(\) is deprecated",
00376                                     category=DeprecationWarning)
00377             a = array.array(self.typecode, 2*self.example)
00378             b = array.array(self.typecode)
00379             self.assertRaises(TypeError, a.tostring, 42)
00380             self.assertRaises(TypeError, b.fromstring)
00381             self.assertRaises(TypeError, b.fromstring, 42)
00382             b.fromstring(a.tostring())
00383             self.assertEqual(a, b)
00384             if a.itemsize>1:
00385                 self.assertRaises(ValueError, b.fromstring, "x")
00386                 nb_warnings += 1
00387         self.assertEqual(len(r), nb_warnings)

Here is the call graph for this function:

def test.test_array.BaseTest.test_weakref (   self) [inherited]

Definition at line 964 of file test_array.py.

00964 
00965     def test_weakref(self):
00966         s = array.array(self.typecode, self.example)
00967         p = weakref.proxy(s)
00968         self.assertEqual(p.tobytes(), s.tobytes())
00969         s = None
00970         self.assertRaises(ReferenceError, len, p)

Here is the call graph for this function:


Member Data Documentation

list test.test_array.FPTest.biggerexample = [-42.0, 0, 42, 1e5, 1e10] [static, inherited]

Definition at line 1211 of file test_array.py.

list test.test_array.FPTest.example = [-42.0, 0, 42, 1e5, -1e10] [static, inherited]

Definition at line 1209 of file test_array.py.

Definition at line 1235 of file test_array.py.

Definition at line 1111 of file test_array.py.

int test.test_array.FPTest.outside = 23 [static, inherited]

Definition at line 1212 of file test_array.py.

list test.test_array.FPTest.smallerexample = [-42.0, 0, 42, 1e5, -2e10] [static, inherited]

Definition at line 1210 of file test_array.py.

Reimplemented from test.test_array.BaseTest.

Definition at line 1234 of file test_array.py.


The documentation for this class was generated from the following file: