Ϫf dZddlZddlZddlmZmZddlmZGddZGddZ dd Z d Z Gd d ejZ Gd dejZy)z( Tests for L{twisted.persisted.styles}. N)_UniversalPicklingErrorunpickleMethod)unittestceZdZdZddZdZy)Foo Helper class. Ncd|_y)N test-valueinstance_memberselfs D/usr/lib/python3/dist-packages/twisted/persisted/test/test_styles.py__init__z Foo.__init__s +c|jS)z Helper method. r r s rmethodz Foo.methods###rreturnN)__name__ __module__ __qualname____doc__rrrrrrs,$rrceZdZdZy)BarrN)rrrrrrrrrsrrcy)z) A sample function for pickling. NrrrrsampleFunctionr$src|S)Nr)xs rr!*s!rceZdZdZdZddZy)UniversalPicklingErrorTestsz9 Tests the L{_UniversalPicklingError} exception. ct)z2 Raise L{UniversalPicklingError}. )rr s rraise_UniversalPicklingErrorz8UniversalPicklingErrorTests.raise_UniversalPicklingError2s &%rNcX|jtj|jy)z^ Handling L{pickle.PicklingError} handles L{_UniversalPicklingError}. N) assertRaisespickle PicklingErrorr%r s rtest_handledByPickleModulez6UniversalPicklingErrorTests.test_handledByPickleModule8s &..0Q0QRrr)rrrrr%r*rrrr#r#-s& Srr#c@eZdZdZd dZd dZd dZd dZd dZd dZ y) UnpickleMethodTestsz0 Tests for the unpickleMethod function. Nct}td|t}|j||j|j ||jy)zj L{unpickleMethod} returns an instance method bound to the instance passed to it. rN)rr assertEqualr assertIsNotrfooms r test_instanceBuildingNamePresentz4UnpickleMethodTests.test_instanceBuildingNamePresentEsA e 8S# . CJJ' CJJ'rc0t}tj|j}|j||j|j ||j|jd|d|_|jd|y)za Copying an instance method returns a new method with the same behavior. r z new-valueN)rcopyrr.r/r r0s rtest_instanceCopyMethodz+UnpickleMethodTests.test_instanceCopyMethodOsq e IIcjj ! CJJ' CJJ' qs+) ac*rct}td|t}|j||j|j ||jy)z If the named method is not present in the class, L{unpickleMethod} finds a method on the class of the instance and returns a bound method from there. rN)rrrr.rr/r0s r#test_instanceBuildingNameNotPresentz7UnpickleMethodTests.test_instanceBuildingNameNotPresent\sA e 8S# . CJJ' CJJ'rcbtjt}|j|ty)zi Copying a function returns the same reference, without creating an actual copy. N)r5rr.)rfs rtest_copyFunctionz%UnpickleMethodTests.test_copyFunctiongs" IIn % N+rcld}|jtjtd|dy)zd We do not contaminate normal function pickling with concerns from Twisted. czdjdtztjd|zdgjdS)N cp.ascii)joinrrencode)ns rexpectedz9UnpickleMethodTests.test_primeDirective..expectedus699x!8!8#'3GfWo rr)protocol0N)r.r(dumpsr)rrFs rtest_primeDirectivez'UnpickleMethodTests.test_primeDirectiveos(   nqA8C=Qrcj|jtjtjty)zY Pickling a C{lambda} function ought to raise a L{pickle.PicklingError}. N)r'r(r)rI lambdaExampler s rtest_lambdaRaisesPicklingErrorz2UnpickleMethodTests.test_lambdaRaisesPicklingError|s  &.. mLrr) rrrrr3r6r8r;rJrMrrrr,r,@s'( + (, RMrr,r)rr5r(twisted.persisted.stylesrr twisted.trialrrrrrLTestCaser#r,rrrrQsb L" $ $   S("3"3S&@M(++@Mr