<s> from ctypes import * <EOL> import unittest <EOL> class VarSizeTest ( unittest . TestCase ) : <EOL> def test_resize ( self ) : <EOL> class X ( Structure ) : <EOL> _fields_ = [ ( "<STR_LIT>" , c_int ) , <EOL> ( "<STR_LIT>" , c_int * <NUM_LIT:1> ) ] <EOL> self . assertEqual ( sizeof ( X ) , sizeof ( c_int ) * <NUM_LIT:2> ) <EOL> x = X ( ) <EOL> x . item = <NUM_LIT> <EOL> x . array [ <NUM_LIT:0> ] = <NUM_LIT:100> <EOL> self . assertEqual ( sizeof ( x ) , sizeof ( c_int ) * <NUM_LIT:2> ) <EOL> new_size = sizeof ( X ) + sizeof ( c_int ) * <NUM_LIT:1> <EOL> resize ( x , new_size ) <EOL> self . assertEqual ( sizeof ( x ) , new_size ) <EOL> self . assertEqual ( ( x . item , x . array [ <NUM_LIT:0> ] ) , ( <NUM_LIT> , <NUM_LIT:100> ) ) <EOL> new_size = sizeof ( X ) + sizeof ( c_int ) * <NUM_LIT:9> <EOL> resize ( x , new_size ) <EOL> self . assertEqual ( sizeof ( x ) , new_size ) <EOL> self . assertEqual ( ( x . item , x . array [ <NUM_LIT:0> ] ) , ( <NUM_LIT> , <NUM_LIT:100> ) ) <EOL> new_size = sizeof ( X ) + sizeof ( c_int ) * <NUM_LIT:1> <EOL> resize ( x , new_size ) <EOL> self . assertEqual ( sizeof ( x ) , new_size ) <EOL> self . assertEqual ( ( x . item , x . array [ <NUM_LIT:0> ] ) , ( <NUM_LIT> , <NUM_LIT:100> ) ) <EOL> def test_array_invalid_length ( self ) : <EOL> self . assertRaises ( ValueError , lambda : c_int * - <NUM_LIT:1> ) <EOL> self . assertRaises ( ValueError , lambda : c_int * - <NUM_LIT:3> ) <EOL> def test_zerosized_array ( self ) : <EOL> array = ( c_int * <NUM_LIT:0> ) ( ) <EOL> self . assertRaises ( IndexError , array . __setitem__ , <NUM_LIT:0> , None ) <EOL> self . assertRaises ( IndexError , array . __getitem__ , <NUM_LIT:0> ) <EOL> self . assertRaises ( IndexError , array . __setitem__ , <NUM_LIT:1> , None ) <EOL> self . assertRaises ( IndexError , array . __getitem__ , <NUM_LIT:1> ) <EOL> self . assertRaises ( IndexError , array . __setitem__ , - <NUM_LIT:1> , None ) <EOL> self . assertRaises ( IndexError , array . __getitem__ , - <NUM_LIT:1> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
