<s> import unittest <EOL> from ctypes import * <EOL> formats = "<STR_LIT>" <EOL> formats = c_byte , c_ubyte , c_short , c_ushort , c_int , c_uint , c_long , c_ulonglong , c_float , c_double <EOL> class ArrayTestCase ( unittest . TestCase ) : <EOL> def test_simple ( self ) : <EOL> init = range ( <NUM_LIT:15> , <NUM_LIT> ) <EOL> for fmt in formats : <EOL> alen = len ( init ) <EOL> int_array = ARRAY ( fmt , alen ) <EOL> ia = int_array ( * init ) <EOL> self . failUnlessEqual ( len ( ia ) , alen ) <EOL> values = [ ia [ i ] for i in range ( len ( init ) ) ] <EOL> self . failUnlessEqual ( values , init ) <EOL> from operator import setitem <EOL> new_values = range ( <NUM_LIT> , <NUM_LIT> + alen ) <EOL> [ setitem ( ia , n , new_values [ n ] ) for n in range ( alen ) ] <EOL> values = [ ia [ i ] for i in range ( len ( init ) ) ] <EOL> self . failUnlessEqual ( values , new_values ) <EOL> ia = int_array ( ) <EOL> values = [ ia [ i ] for i in range ( len ( init ) ) ] <EOL> self . failUnlessEqual ( values , [ <NUM_LIT:0> ] * len ( init ) ) <EOL> self . assertRaises ( IndexError , int_array , * range ( alen * <NUM_LIT:2> ) ) <EOL> CharArray = ARRAY ( c_char , <NUM_LIT:3> ) <EOL> ca = CharArray ( "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:c>" ) <EOL> self . assertRaises ( TypeError , CharArray , "<STR_LIT:abc>" ) <EOL> self . failUnlessEqual ( ca [ <NUM_LIT:0> ] , "<STR_LIT:a>" ) <EOL> self . failUnlessEqual ( ca [ <NUM_LIT:1> ] , "<STR_LIT:b>" ) <EOL> self . failUnlessEqual ( ca [ <NUM_LIT:2> ] , "<STR_LIT:c>" ) <EOL> self . failUnlessEqual ( ca [ - <NUM_LIT:3> ] , "<STR_LIT:a>" ) <EOL> self . failUnlessEqual ( ca [ - <NUM_LIT:2> ] , "<STR_LIT:b>" ) <EOL> self . failUnlessEqual ( ca [ - <NUM_LIT:1> ] , "<STR_LIT:c>" ) <EOL> self . failUnlessEqual ( len ( ca ) , <NUM_LIT:3> ) <EOL> from operator import getslice , delitem <EOL> self . assertRaises ( TypeError , getslice , ca , <NUM_LIT:0> , <NUM_LIT:1> , - <NUM_LIT:1> ) <EOL> self . assertRaises ( TypeError , delitem , ca , <NUM_LIT:0> ) <EOL> def test_numeric_arrays ( self ) : <EOL> alen = <NUM_LIT:5> <EOL> numarray = ARRAY ( c_int , alen ) <EOL> na = numarray ( ) <EOL> values = [ na [ i ] for i in range ( alen ) ] <EOL> self . failUnlessEqual ( values , [ <NUM_LIT:0> ] * alen ) <EOL> na = numarray ( * [ c_int ( ) ] * alen ) <EOL> values = [ na [ i ] for i in range ( alen ) ] <EOL> self . failUnlessEqual ( values , [ <NUM_LIT:0> ] * alen ) <EOL> na = numarray ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ) <EOL> values = [ i for i in na ] <EOL> self . failUnlessEqual ( values , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ) <EOL> na = numarray ( * map ( c_int , ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ) ) ) <EOL> values = [ i for i in na ] <EOL> self . failUnlessEqual ( values , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ) <EOL> def test_classcache ( self ) : <EOL> self . failUnless ( not ARRAY ( c_int , <NUM_LIT:3> ) is ARRAY ( c_int , <NUM_LIT:4> ) ) <EOL> self . failUnless ( ARRAY ( c_int , <NUM_LIT:3> ) is ARRAY ( c_int , <NUM_LIT:3> ) ) <EOL> def test_from_address ( self ) : <EOL> p = create_string_buffer ( "<STR_LIT:foo>" ) <EOL> sz = ( c_char * <NUM_LIT:3> ) . from_address ( addressof ( p ) ) <EOL> self . failUnlessEqual ( sz [ : ] , "<STR_LIT:foo>" ) <EOL> self . failUnlessEqual ( sz . value , "<STR_LIT:foo>" ) <EOL> try : <EOL> create_unicode_buffer <EOL> except NameError : <EOL> pass <EOL> else : <EOL> def test_from_addressW ( self ) : <EOL> p = create_unicode_buffer ( "<STR_LIT:foo>" ) <EOL> sz = ( c_wchar * <NUM_LIT:3> ) . from_address ( addressof ( p ) ) <EOL> self . failUnlessEqual ( sz [ : ] , "<STR_LIT:foo>" ) <EOL> self . failUnlessEqual ( sz . value , "<STR_LIT:foo>" ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
