<s> import unittest <EOL> import pickle <EOL> from ctypes import * <EOL> import _ctypes_test <EOL> dll = CDLL ( _ctypes_test . __file__ ) <EOL> class X ( Structure ) : <EOL> _fields_ = [ ( "<STR_LIT:a>" , c_int ) , ( "<STR_LIT:b>" , c_double ) ] <EOL> init_called = <NUM_LIT:0> <EOL> def __init__ ( self , * args , ** kw ) : <EOL> X . init_called += <NUM_LIT:1> <EOL> self . x = <NUM_LIT> <EOL> class Y ( X ) : <EOL> _fields_ = [ ( "<STR_LIT:str>" , c_char_p ) ] <EOL> class PickleTest : <EOL> def dumps ( self , item ) : <EOL> return pickle . dumps ( item , self . proto ) <EOL> def loads ( self , item ) : <EOL> return pickle . loads ( item ) <EOL> def test_simple ( self ) : <EOL> for src in [ <EOL> c_int ( <NUM_LIT> ) , <EOL> c_double ( <NUM_LIT> ) , <EOL> ] : <EOL> dst = self . loads ( self . dumps ( src ) ) <EOL> self . assertEqual ( src . __dict__ , dst . __dict__ ) <EOL> self . assertEqual ( memoryview ( src ) . tobytes ( ) , <EOL> memoryview ( dst ) . tobytes ( ) ) <EOL> def test_struct ( self ) : <EOL> X . init_called = <NUM_LIT:0> <EOL> x = X ( ) <EOL> x . a = <NUM_LIT> <EOL> self . assertEqual ( X . init_called , <NUM_LIT:1> ) <EOL> y = self . loads ( self . dumps ( x ) ) <EOL> self . assertEqual ( X . init_called , <NUM_LIT:1> ) <EOL> self . assertEqual ( y . __dict__ , x . __dict__ ) <EOL> self . assertEqual ( memoryview ( y ) . tobytes ( ) , <EOL> memoryview ( x ) . tobytes ( ) ) <EOL> def test_unpickable ( self ) : <EOL> self . assertRaises ( ValueError , lambda : self . dumps ( Y ( ) ) ) <EOL> prototype = CFUNCTYPE ( c_int ) <EOL> for item in [ <EOL> c_char_p ( ) , <EOL> c_wchar_p ( ) , <EOL> c_void_p ( ) , <EOL> pointer ( c_int ( <NUM_LIT> ) ) , <EOL> dll . _testfunc_p_p , <EOL> prototype ( lambda : <NUM_LIT> ) , <EOL> ] : <EOL> self . assertRaises ( ValueError , lambda : self . dumps ( item ) ) <EOL> def test_wchar ( self ) : <EOL> self . dumps ( c_char ( b"<STR_LIT:x>" ) ) <EOL> self . dumps ( c_wchar ( "<STR_LIT:x>" ) ) <EOL> for proto in range ( pickle . HIGHEST_PROTOCOL + <NUM_LIT:1> ) : <EOL> name = '<STR_LIT>' % proto <EOL> globals ( ) [ name ] = type ( name , <EOL> ( PickleTest , unittest . TestCase ) , <EOL> { '<STR_LIT>' : proto } ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
