[c@sdZddlZddlZddlZddlmZddlmZddlZddl m Z m Z ej d krdZ eZnd Z eZd efd YZdS( s` Helpers for the OpenSSL test suite, largely copied from U{Twisted}. iN(tmktemp(tTestCase(tErrort_exception_from_error_queueiicCs|S(N((ts((s7/usr/lib64/python2.7/site-packages/OpenSSL/test/util.pytbscCs |jdS(Ntcharmap(tencode(R((s7/usr/lib64/python2.7/site-packages/OpenSSL/test/util.pyRsRcBseZdZdZd dZeZd dZeZd dZ e Z dZ e Z d Z dZdZdZd ZRS( s L{TestCase} adds useful testing functionality beyond what is available from the standard library L{unittest.TestCase}. cCstrp|jdk rpxX|jD]J}tjj|rGtj|qtjj|rtj |qqWny t WnMt k rt j d}|jgfkr|jdt|qnXdS(s Clean up any files or directories created using L{TestCase.mktemp}. Subclasses must invoke this method if they override it or the cleanup will not occur. is)Left over errors in OpenSSL error queue: N(tFalset_temporaryFilestNonetostpathtisdirtshutiltrmtreetexiststunlinkRRtsystexc_infotargstfailtrepr(tselfttempte((s7/usr/lib64/python2.7/site-packages/OpenSSL/test/util.pyttearDown!s  cCs2||kr.|j|p%d||fn|S(s Fail the test if C{containee} is not found in C{container}. @param containee: the value that should be in C{container} @param container: a sequence type, or in the case of a mapping type, will follow semantics of 'if key in dict.keys()' @param msg: if msg is None, then the failure message will be '%r not in %r' % (first, second) s %r not in %r(tfailureException(Rt containeet containertmsg((s7/usr/lib64/python2.7/site-packages/OpenSSL/test/util.pyt failUnlessIn5s cCs2||k r.|j|p%d||fn|S(s Fail the test if C{first} is not C{second}. This is an obect-identity-equality test, not an object equality (i.e. C{__eq__}) test. @param msg: if msg is None, then the failure message will be '%r is not %r' % (first, second) s %r is not %r(R(RtfirsttsecondR((s7/usr/lib64/python2.7/site-packages/OpenSSL/test/util.pytfailUnlessIdenticalEs "cCs2||kr.|j|p%d||fn|S(s  Fail the test if C{first} is C{second}. This is an obect-identity-equality test, not an object equality (i.e. C{__eq__}) test. @param msg: if msg is None, then the failure message will be '%r is %r' % (first, second) s%r is %r(R(RR R!R((s7/usr/lib64/python2.7/site-packages/OpenSSL/test/util.pytfailIfIdenticalTs "cOsy|||}WnN|k r7tjd}|S|jdtjd|jfnX|jd|j|fdS(s9 Fail the test unless calling the function C{f} with the given C{args} and C{kwargs} raises C{exception}. The failure will report the traceback and call stack of the unexpected exception. @param exception: exception type that is to be expected @param f: the function to call @return: The raised exception instance, if it is of the given type. @raise self.failureException: Raised if the function call does not raise an exception or if it raises an exception of a different type. is%s raised instead of %sis%s not raised (%r returned)N(RRRt__name__(Rt exceptiontfRtkwargstresulttinst((s7/usr/lib64/python2.7/site-packages/OpenSSL/test/util.pytfailUnlessRaisescs    cCs>|jdkrg|_ntdd}|jj||S(sQ Pathetic substitute for twisted.trial.unittest.TestCase.mktemp. tdirt.N(R R Rtappend(RR((s7/usr/lib64/python2.7/site-packages/OpenSSL/test/util.pyRs  cOs|j||S(N(t failUnless(Rtatkw((s7/usr/lib64/python2.7/site-packages/OpenSSL/test/util.pyt assertTruescOs|j||S(N(tfailIf(RR/R0((s7/usr/lib64/python2.7/site-packages/OpenSSL/test/util.pyt assertFalsescGsO|j|j||jt|t||}|jt||dS(s Perform various assertions about C{theType} to ensure that it is a well-defined type. This is useful for extension types, where it's pretty easy to do something wacky. If something about the type is unusual, an exception will be raised. @param theType: The type object about which to make assertions. @param name: A string giving the name of the type. @param constructionArgs: Positional arguments to use with C{theType} to create an instance of it. N(t assertEqualR$R1t isinstancettypetassertIdentical(RttheTypetnametconstructionArgstinstance((s7/usr/lib64/python2.7/site-packages/OpenSSL/test/util.pytassertConsistentTypes  N(R$t __module__t__doc__RR RtassertInR"R7R#tassertNotIdenticalR*t assertRaisesR RR1R3R<(((s7/usr/lib64/python2.7/site-packages/OpenSSL/test/util.pyRs       (ii(R>RR tos.pathttempfileRtunittestRRtOpenSSL.cryptoRRt version_infoRtstrtbytes(((s7/usr/lib64/python2.7/site-packages/OpenSSL/test/util.pyts