<s> """<STR_LIT>""" <EOL> import pickle <EOL> from twisted . trial import unittest <EOL> from twisted . persisted . styles import unpickleMethod <EOL> class Foo : <EOL> """<STR_LIT>""" <EOL> def method ( self ) : <EOL> """<STR_LIT>""" <EOL> class Bar : <EOL> """<STR_LIT>""" <EOL> def sampleFunction ( ) : <EOL> """<STR_LIT>""" <EOL> lambdaExample = lambda x : x <EOL> class UnpickleMethodTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_instanceBuildingNamePresent ( self ) : <EOL> """<STR_LIT>""" <EOL> foo = Foo ( ) <EOL> m = unpickleMethod ( '<STR_LIT>' , foo , Foo ) <EOL> self . assertEqual ( m , foo . method ) <EOL> self . assertNotIdentical ( m , foo . method ) <EOL> def test_instanceBuildingNameNotPresent ( self ) : <EOL> """<STR_LIT>""" <EOL> foo = Foo ( ) <EOL> m = unpickleMethod ( '<STR_LIT>' , foo , Bar ) <EOL> self . assertEqual ( m , foo . method ) <EOL> self . assertNotIdentical ( m , foo . method ) <EOL> def test_primeDirective ( self ) : <EOL> """<STR_LIT>""" <EOL> def expected ( n ) : <EOL> return "<STR_LIT:\n>" . join ( [ <EOL> "<STR_LIT:c>" + __name__ , <EOL> sampleFunction . __name__ , "<STR_LIT:p>" + n , "<STR_LIT:.>" <EOL> ] ) . encode ( "<STR_LIT:ascii>" ) <EOL> self . assertEqual ( pickle . dumps ( sampleFunction , protocol = <NUM_LIT:0> ) , <EOL> expected ( "<STR_LIT:0>" ) ) <EOL> try : <EOL> import cPickle <EOL> except : <EOL> pass <EOL> else : <EOL> self . assertEqual ( <EOL> cPickle . dumps ( sampleFunction , protocol = <NUM_LIT:0> ) , <EOL> expected ( "<STR_LIT:1>" ) <EOL> ) <EOL> def test_lambdaRaisesPicklingError ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( pickle . PicklingError , pickle . dumps , lambdaExample ) <EOL> try : <EOL> import cPickle <EOL> except : <EOL> pass <EOL> else : <EOL> self . assertRaises ( cPickle . PicklingError , cPickle . dumps , <EOL> lambdaExample ) </s>
