kWc@sgdddddddddd d d d f Zd ZddlZddlZddlZddlmZddlmZm Z de DZ e fZ dejkrddlZe ejjfZ neZeZdZdZdefdYZeejefZdZedZ dZ!dZ"dZ#dZ$edZ%dZ&d Z'd!efd"YZ(d#efd$YZ)e)Z*e*j+Z+e*j,Z-e*j.Z/d%Z0e1d&d'd(d)d*d+d,d-gZ2d.Z3d/e4fd0YZ5d1Z6d2efd3YZ7d4efd5YZ8d e8fd6YZ9d7Z:d8e8fd9YZ;de;e9fd:YZ<d;Z=d<Z>d=Z?d>efd?YZ@d@ZAe+eBeeBeBeBdAZCeBeeBeBeBdBZDe+eBeeBeBeBdCZEdDefdEYZFdFZGdGZHeCeE_eFeE_IeDeE_JeHeE_KdHeE_LdIZMdJZNdKjOdLeNjPDZQdKjOdMeNjPDZRe1dNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_gDZSd`ZTe1dadKjOeMeNeQeRgjPDZUeUeSBZVe1dbdcdddedfdgdhgZWididj6dkdl6dmdn6ZXi eYdo6eYdp6eYdq6eYdr6dsdt6edu6dvdw6edx6dydz6d{d|6ed}6dsd~6ZZdZ[dZ\dZ]ie[d6e\d6e]d6Z^dZ_defdYZ`d e`e9fdYZade`e<fdYZbdefdYZcdefdYZdedZedZfdegfdYZhehdeZieeeBeBdZjdZkdZldefdYZmeejeeejnfZoeeejnjpfZqeBardZseBddZtd e<fdYZudS(tMockt MagicMocktpatchtsentineltDEFAULTtANYtcalltcreate_autospect FILTER_DIRtNonCallableMocktNonCallableMagicMockt mock_opent PropertyMocks1.0iN(t ModuleType(twrapstpartialcCs%h|]}|jds|qS(t_(t startswith(t.0tname((s)/usr/lib/python2.7/test/_mock_backport.pys #s tjavacCstt|tS(N(t issubclassttypeR (tobj((s)/usr/lib/python2.7/test/_mock_backport.pyt_is_instance_mock2scCs+t|tp*t|to*t|tS(N(t isinstancetBaseExceptionsRR(R((s)/usr/lib/python2.7/test/_mock_backport.pyt _is_exception8st_slottedcBseZdgZRS(ta(t__name__t __module__t __slots__(((s)/usr/lib/python2.7/test/_mock_backport.pyR?scCst|trA| rAy |j}Wntk r7dSXt}n4t|tsuy |j}Wqutk rqdSXn|rt|d}n|}y|t j |fSWnt k rdSXdS(s Given an arbitrary, possibly callable object, try to create a suitable signature object. Return a (reduced func, signature) tuple, or None. N( RRt__init__tAttributeErrortNonetTruet FunctionTypest__call__Rtinspectt signaturet ValueError(tfunct as_instanceteat_selftsig_func((s)/usr/lib/python2.7/test/_mock_backport.pyt_get_signature_objectIs$      cs]t|||dkr"dS\}fd}t|||t|_dS(Ncsj||dS(N(tbind(t _mock_selftargstkwargs(tsig(s)/usr/lib/python2.7/test/_mock_backport.pytchecksigns(R.R#t_copy_func_detailsRt_mock_check_sig(R*tmockt skipfirsttinstanceR4((R3s)/usr/lib/python2.7/test/_mock_backport.pyt_check_signatureis   cCs|j|_|j|_y|j|_Wntk r;nXy|j|_Wntk r_nXy|j|_Wntk rnXy|j|_Wntk rnXdS(N(Rt__doc__t__text_signature__R"Rt __defaults__t__kwdefaults__(R*tfuncopy((s)/usr/lib/python2.7/test/_mock_backport.pyR5ts$      cCs3t|trtSt|dddk r/tStS(NR&(RRR$tgetattrR#tFalse(R((s)/usr/lib/python2.7/test/_mock_backport.pyt _callables cCst|ttfkS(N(Rtlistttuple(R((s)/usr/lib/python2.7/test/_mock_backport.pyt_is_listscCs`t|ts%t|dddk Sx4|f|jD]"}|jjddk r6tSq6WtS(stGiven an object, return True if the object is callable. For classes, return True if instances would be callable.R&N( RRR@R#t__mro__t__dict__tgetR$RA(Rtbase((s)/usr/lib/python2.7/test/_mock_backport.pyt_instance_callables c se|sdSe|e}e|||}|dkrAdS|\}fd}e|||j}|jsd}ni|d6|d6}d|} | |U||} e| || S(Ncsj||dS(N(R/(R1R2(R3(s)/usr/lib/python2.7/test/_mock_backport.pyR4sR?t _checksig_R7sYdef %s(*args, **kwargs): _checksig_(*args, **kwargs) return mock(*args, **kwargs)( RBRRR.R#R5Rt isidentifiert _setup_func( R7toriginalR9R8tresultR*R4RtcontexttsrcR?((R3s)/usr/lib/python2.7/test/_mock_backport.pyt_set_signatures$          cs_tsdSfd}fd}fd}fd}fd}t_d_d_t_t_ t_ j _ j _ j _ |_|_|_|_|__dS(Ncsj||S(N(tassert_called_with(R1R2(R7(s)/usr/lib/python2.7/test/_mock_backport.pyRSscsj||S(N(tassert_called_once_with(R1R2(R7(s)/usr/lib/python2.7/test/_mock_backport.pyRTscsj||S(N(tassert_has_calls(R1R2(R7(s)/usr/lib/python2.7/test/_mock_backport.pyRUscsj||S(N(tassert_any_call(R1R2(R7(s)/usr/lib/python2.7/test/_mock_backport.pyRVscsTt_t_jj}t|rP|k rP|jndS(N(t _CallListt method_callst mock_callst reset_mockt return_valueR(tret(R?R7(s)/usr/lib/python2.7/test/_mock_backport.pyRZs     i(R7RRAtcalledt call_countR#t call_argsRWtcall_args_listRXRYR[t side_effectt_mock_childrenRSRTRURVRZt_mock_delegate(R?R7RSRTRURVRZ((R?R7s)/usr/lib/python2.7/test/_mock_backport.pyRMs.                cCsd|dd!|kS(Ns__%s__ii((R((s)/usr/lib/python2.7/test/_mock_backport.pyt _is_magicst_SentinelObjectcBs eZdZdZdZRS(s!A unique, named, sentinel object.cCs ||_dS(N(R(tselfR((s)/usr/lib/python2.7/test/_mock_backport.pyR!scCs d|jS(Ns sentinel.%s(R(Rf((s)/usr/lib/python2.7/test/_mock_backport.pyt__repr__s(RRR;R!Rg(((s)/usr/lib/python2.7/test/_mock_backport.pyRes t _SentinelcBs eZdZdZdZRS(sAAccess attributes to return a named object, usable as a sentinel.cCs i|_dS(N(t _sentinels(Rf((s)/usr/lib/python2.7/test/_mock_backport.pyR!scCs.|dkrtn|jj|t|S(Nt __bases__(R"Rit setdefaultRe(RfR((s)/usr/lib/python2.7/test/_mock_backport.pyt __getattr__s  (RRR;R!Rl(((s)/usr/lib/python2.7/test/_mock_backport.pyRhs cCs2t|ttttfkr.t||S|S(N(RtdictRCRDtset(tvalue((s)/usr/lib/python2.7/test/_mock_backport.pyt_copysR[t_mock_return_valueRat_mock_side_effectt _mock_parentt_mock_new_parentt _mock_namet_mock_new_namecCsBtj|d|}||d}||d}t||S(Nt_mock_cSs/|j}|dkr"t||St||S(N(RcR#R@(RfRt _the_nameR3((s)/usr/lib/python2.7/test/_mock_backport.pyt_get"s   cSs9|j}|dkr%||j||dkr|}n|j} || d<|| d<|| d<|| d<|dk ra|}t}n| dkr||dk } n|j||| | i| d<|| d|jdk r||j_n||_t||dddS(Ns()(RcR#R[RqR(RfRo((s)/usr/lib/python2.7/test/_mock_backport.pyt__set_return_values s1The value to be returned when the mock is called.cCs |jdkrt|S|jS(N(RR#R(Rf((s)/usr/lib/python2.7/test/_mock_backport.pyt __class__s R]R^R_R`RYcCsj|j}|dkr|jS|j}|dk rft| rft|t rft|}||_n|S(N(RcR#RrRatcallableRR(Rft delegatedtsf((s)/usr/lib/python2.7/test/_mock_backport.pyt__get_side_effects   )  cCs:t|}|j}|dkr-||_n ||_dS(N(t _try_iterRcR#RrRa(RfRoR((s)/usr/lib/python2.7/test/_mock_backport.pyt__set_side_effects     cCst|_d|_d|_t|_t|_t|_x6|j j D]%}t |t rjqOn|j qOW|j}t|r||k r|j ndS(s-Restore the mock object to its initial state.iN(RAR]R#R_R^RWRYR`RXRbtvaluesRt _SpecStateRZRqR(RftchildR\((s)/usr/lib/python2.7/test/_mock_backport.pyRZs       cKsxzt|jddD]]\}}|jd}|j}|}x|D]}t||}qPWt|||qWdS(sZSet attributes on the mock through keyword arguments. Attributes plus return values and side effects can be set on child mocks using standard dot notation and unpacking a dictionary in the method call: >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError} >>> mock.configure_mock(**attrs)tkeycSs|djdS(Nit.(tcount(tentry((s)/usr/lib/python2.7/test/_mock_backport.pyt/sRN(tsortedtitemstsplittpopR@Rz(RfR2targtvalR1tfinalRR((s)/usr/lib/python2.7/test/_mock_backport.pyR"s   c Cs|ddhkr!t|n[|jdk ra||jksK|tkr|td|q|nt|r|t|n|js|jd rt|qn|jj|}|t krt|n|dkrCd}|j dk r t |j |}n|j d|d|d|d |d |}||j|(s()s().(smocksmock.(RvRtRnR#tappendtidR}RCtreversedRuRtjoinRRRR( Rft _name_listRtlasttdottseent_firstRt name_stringt spec_string((s)/usr/lib/python2.7/test/_mock_backport.pyRg^sL            cCststj|S|jpg}tt|}t|j}g|D]}|jdsJ|^qJ}g|D](}|jd st |rr|^qr}t t |||t|j S(s8Filter the output of `dir(mock)` to only useful members.R( RRt__dir__RRRRCRGRRdRRnRb(Rftextrast from_typet from_dictte((s)/usr/lib/python2.7/test/_mock_backport.pyRs (cs|tkrtj||Sjrhjdk rh|jkrh|jkrhtd|n|tkrd|}t|n|t krIjdk r|jkrtd|nt |st t |t |||fd}qt|d|t t |||j||dkrb|_dSt|||r|j|+ss(Calls not found. Expected: %r Actual: %rNs%r not all found in call list( RRWRYRRCtremoveR)RRD(Rftcallst any_orderRRt all_callst not_foundtkall((Rfs)/usr/lib/python2.7/test/_mock_backport.pyRU s$ "    cOso|j||f}g|jD]}|j|^q}||krk|j||}td|ndS(sassert the mock has been called with the specified arguments. The assert passes if the mock has *ever* been called, unlike `assert_called_with` and `assert_called_once_with` that only pass if the call is the most recent one.s%s call not foundN(RR`RR(RfR1R2RRRR((s)/usr/lib/python2.7/test/_mock_backport.pyRVBs % cKset|}t|tsNt|tr3t}q[t|tr[t}q[n |jd}||S(sPCreate the child mocks for attributes and return value. By default child mocks will be the same type as the parent. Subclasses of Mock may want to override this to customize the way child mocks are made. For non-callable mocks the callable variant will be used (rather than any custom subclass).i(RRt CallableMixinR RR RRF(RfRt_typetklass((s)/usr/lib/python2.7/test/_mock_backport.pyRQs    N()RRR;RR#RAR!RRRt"_NonCallableMock__get_return_valuet"_NonCallableMock__set_return_valuet"_NonCallableMock__return_value_docR~R[RRR]R^R_R`RYt!_NonCallableMock__get_side_effectt!_NonCallableMock__set_side_effectRaRZRRlRgRRRRRRRRSRTRURVR(((s)/usr/lib/python2.7/test/_mock_backport.pyR osN  )              & 2  "     " cCsW|dkr|St|r |St|r0|Syt|SWntk rR|SXdS(N(R#RRBRR(R((s)/usr/lib/python2.7/test/_mock_backport.pyRes    Rc BsJeZddedddddddd ZdZdZdZRS(Rc KsH||jd||krt |r|j|nt j }nXWdx!t |D]}|j |qWXdS(N(RDR,t __enter__RR$R#tupdateRRRtsystexc_infoRt__exit__(R1tkeywargst extra_argstentered_patchersR0tpatchingR(R*tpatched(s)/usr/lib/python2.7/test/_mock_backport.pyR6ms,       (RR,RR(RfR*((R*R6s)/usr/lib/python2.7/test/_mock_backport.pyR(hs  cCs|j}|j}t}t}y|j|}Wn)ttfk r]t||t}nXt}|t krt |t rt|_ n|j r|tkrtd||fn||fS(Ns!%s does not have the attribute %r( RRRRARGR"tKeyErrorR@R$t _builtinsRR R (RfRRRNtlocal((s)/usr/lib/python2.7/test/_mock_backport.pyt get_originals   cCs|j|j|j}}}|j|j}}|j}|j|_|tkr]d}n|tkrrd}n|tkrd}n|dk r|dk rt dn|dk s|dk r|t dfkrt dn|j \}}|t krb|dkrbt} |t krG|}|t kr|}d}qn?|dk rq|t kr|}d}qn|t kr|}n|dk s|dk r|t krt dnt|trt } qnt} i} |dk r|} nm|dk s |dk rb|} |dk r(|} nt| rCd| k} n t|  } | rbt} qbn|dk r{|| dttrjStfd}|S(Ncs-jz||SWdjXdS(N(RNt _unpatch_dict(R1R(tfRf(s)/usr/lib/python2.7/test/_mock_backport.pyt_inners (RRR'R(RfRSRT((RSRfs)/usr/lib/python2.7/test/_mock_backport.pyR&s cCsx~t|D]p}t||}|jtjr t|dr t|j|j|j }||}t |||q q W|S(NR&( RR@RRR)RRNRORRPRz(RfRR*R+t decoratort decorated((s)/usr/lib/python2.7/test/_mock_backport.pyR'$s cCs|jdS(sPatch the dict.N(RN(Rf((s)/usr/lib/python2.7/test/_mock_backport.pyR-/scCs|j}|j}|j}y|j}Wn6tk rci}x |D]}||||sccs|]}d|VqdS(sr%sN((RR\((s)/usr/lib/python2.7/test/_mock_backport.pys sccs|]}d|VqdS(s__%s__N((Rtmethod((s)/usr/lib/python2.7/test/_mock_backport.pys sRHRntdeleteRtmissingtreducet reduce_ext getinitargst getnewargstgetstatetsetstatet getformatt setformattreprRt subclassestformatcsfd}||_|S(s:Turns a callable object (like a mock) into a real functioncs|||S(N((RfR1R(R*(s)/usr/lib/python2.7/test/_mock_backport.pyR]s(R(RR*R]((R*s)/usr/lib/python2.7/test/_mock_backport.pyRs ccs|]}d|VqdS(s__%s__N((RR]((s)/usr/lib/python2.7/test/_mock_backport.pys sRlRR!Rt__prepare____instancecheck__t__subclasscheck__t__del__cCs tj|S(N(Rt__hash__(Rf((s)/usr/lib/python2.7/test/_mock_backport.pyRsRncCs tj|S(N(Rt__str__(Rf((s)/usr/lib/python2.7/test/_mock_backport.pyRsRocCs tj|S(N(Rt __sizeof__(Rf((s)/usr/lib/python2.7/test/_mock_backport.pyRsRpt__lt__t__gt__t__le__t__ge__it__int__Rit__len__R1y?t __complex__g?t __float__t__bool__t __index__csfd}|S(Ncs&jj}|tk r|S|kS(N(t__eq__RqR(totherR(Rf(s)/usr/lib/python2.7/test/_mock_backport.pyR{s  ((RfR{((Rfs)/usr/lib/python2.7/test/_mock_backport.pyt_get_eqscsfd}|S(Ncs jjtk rtS|k S(N(t__ne__RqR(R|(Rf(s)/usr/lib/python2.7/test/_mock_backport.pyR~s((RfR~((Rfs)/usr/lib/python2.7/test/_mock_backport.pyt_get_nescsfd}|S(Ncs,jj}|tkr"tgSt|S(N(RRqRR(R(Rf(s)/usr/lib/python2.7/test/_mock_backport.pyRs   ((RfR((Rfs)/usr/lib/python2.7/test/_mock_backport.pyt _get_itersR{R~RcCstj|t}|tk r+||_dStj|}|dk ry||}Wntk rut|}nX||_dStj|}|dk r|||_ndS(N( t_return_valuesRHRR[t_calculate_return_valueR#R"t_side_effect_methodsRa(R7R]Rtfixedtreturn_calulatorR[t side_effector((s)/usr/lib/python2.7/test/_mock_backport.pyt_set_return_values      t MagicMixincBseZdZdZRS(cOs'tt|j|||jdS(N(RRR!t_mock_set_magics(RfR1R((s)/usr/lib/python2.7/test/_mock_backport.pyR!scCst}|jdk rstj|j}t}t|}x6|D]+}|t|jkrAt||qAqAWn|tt|j}t|}x'|D]}t||t ||qWdS(N( t_magicsRR#t intersectionRnRRGRRzt MagicProxy(Rft these_magicst remove_magicsRR((s)/usr/lib/python2.7/test/_mock_backport.pyRs     (RRR!R(((s)/usr/lib/python2.7/test/_mock_backport.pyRs cBseZdZedZRS(s-A version of `MagicMock` that isn't callable.cCs|j|||jdS(sAdd a spec to a mock. `spec` can either be an object or a list of strings. Only attributes on the `spec` can be fetched as attributes from the mock. If `spec_set` is True then only attributes on the spec can be set.N(RR(RfRR((s)/usr/lib/python2.7/test/_mock_backport.pyRs(RRR;RAR(((s)/usr/lib/python2.7/test/_mock_backport.pyR scBseZdZedZRS(s MagicMock is a subclass of Mock with default implementations of most of the magic methods. You can use MagicMock without having to configure the magic methods yourself. If you use the `spec` or `spec_set` arguments then *only* magic methods that exist in the spec will be created. Attributes and the return value of a `MagicMock` will also be `MagicMocks`. cCs|j|||jdS(sAdd a spec to a mock. `spec` can either be an object or a list of strings. Only attributes on the `spec` can be fetched as attributes from the mock. If `spec_set` is True then only attributes on the spec can be set.N(RR(RfRR((s)/usr/lib/python2.7/test/_mock_backport.pyR/s(RRR;RAR(((s)/usr/lib/python2.7/test/_mock_backport.pyR$s RcBs/eZdZdZdZddZRS(cCs||_||_dS(N(RR(RfRR((s)/usr/lib/python2.7/test/_mock_backport.pyR!;s cOs|j}|||S(N(t create_mock(RfR1R2tm((s)/usr/lib/python2.7/test/_mock_backport.pyR&?s cCsT|j}|j}|jd|d|d|}t|||t||||S(NRRR(RRRRzR(RfRRR((s)/usr/lib/python2.7/test/_mock_backport.pyRCs   cCs |jS(N(R(RfRR((s)/usr/lib/python2.7/test/_mock_backport.pyt__get__LsN(RRR!R&RR#R(((s)/usr/lib/python2.7/test/_mock_backport.pyR:s   t_ANYcBs2eZdZejZdZdZdZRS(s2A helper object that compares equal to everything.cCstS(N(R$(RfR|((s)/usr/lib/python2.7/test/_mock_backport.pyR{VscCstS(N(RA(RfR|((s)/usr/lib/python2.7/test/_mock_backport.pyR~YscCsdS(Ns((Rf((s)/usr/lib/python2.7/test/_mock_backport.pyRg\s(RRR;RRnR{R~Rg(((s)/usr/lib/python2.7/test/_mock_backport.pyRQs    c Csd|}d}djg|D]}t|^q}djgt|jD]\}}d||f^qQ} |r|}n| r|r|d7}n|| 7}n||S(Ns%s(%%s)Rs, s%s=%r(RRhRR( RR1R2Rtformatted_argsRt args_stringRRot kwargs_string((s)/usr/lib/python2.7/test/_mock_backport.pyRcs (8   R cBseZdZejZd d d eedZd d d eedZ dZ dZ dZ dZ dZdZd Zd ZRS(s A tuple for holding the results of a call to a mock, either in the form `(args, kwargs)` or `(name, args, kwargs)`. If args or kwargs are empty then a call tuple will compare equal to a tuple without those values. This makes comparisons less verbose:: _Call(('name', (), {})) == ('name',) _Call(('name', (1,), {})) == ('name', (1,)) _Call(((), {'a': 'b'})) == ({'a': 'b'},) The `_Call` object provides a useful shortcut for comparing with call:: _Call(((1, 2), {'a': 3})) == call(1, 2, a=3) _Call(('foo', (1, 2), {'a': 3})) == call.foo(1, 2, a=3) If the _Call has no name then it will match any name. c Csd}d}i}t|}|dkr<|\}}}n|dkr|\} } t| tr| }t| tr| }q| }q| | }}nN|dkr|\}t|tr|}qt|tr|}q|}n|rtj|||fStj||||fS(NRiii((RRRKRDR( RRoRRRt from_kallR1R2t_lentfirsttsecond((s)/usr/lib/python2.7/test/_mock_backport.pyRs0           cCs||_||_||_dS(N(RRR(RfRoRRRR((s)/usr/lib/python2.7/test/_mock_backport.pyR!s  c Cs|tkrtSyt|}Wntk r4tSXd}t|dkr\|\}}n|\}}}d}|dkrdi}}n|dkr|\}}}n|dkr|\} t| tr| }i}qot| tr| }di}}qod}| }n]|\} } t| trb| }t| trR| i}}qod | }}n | | }}|r||krtS||f||fkS( NRiiii(((((RR$RRRARRDRK( RfR|t len_othert self_namet self_argst self_kwargst other_namet other_argst other_kwargsRoRR((s)/usr/lib/python2.7/test/_mock_backport.pyR{sF          cCs|j| S(N(R{(RfR|((s)/usr/lib/python2.7/test/_mock_backport.pyR~scOsW|jdkr(td||fddS|jd}t|j||fd|d|S(NRRs()R(RR#R (RfR1R2R((s)/usr/lib/python2.7/test/_mock_backport.pyR&s cCsN|jdkr"td|dtSd|j|f}td|d|dtS(NRRs%s.%sR(RR#R RA(RfR*R((s)/usr/lib/python2.7/test/_mock_backport.pyRlscOs|jd||S(NR(Rl(RfR1R2((s)/usr/lib/python2.7/test/_mock_backport.pyRscOs|jd||S(Ntindex(Rl(RfR1R2((s)/usr/lib/python2.7/test/_mock_backport.pyRscCs|js8|jpd}|jdr4d|}n|St|dkr_d}|\}}nD|\}}}|s}d}n&|jdsd|}n d|}t|||S(NRs()scall%siscall.%s(RRRRR(RfRR1R2((s)/usr/lib/python2.7/test/_mock_backport.pyRgs     cCsQg}|}x2|dk r@|jr4|j|n|j}qWtt|S(sFor a call object that represents multiple calls, `call_list` returns a list of all the intermediate calls as well as the final call.N(R#RRRRWR(RftvalsR((s)/usr/lib/python2.7/test/_mock_backport.pyt call_lists  (N((RRR;RRnR#RAR$RR!R{R~R&RlRRRgR(((s)/usr/lib/python2.7/test/_mock_backport.pyR us     2      Rc Kst|rt|}nt|t}i|d6}|rMi|d6}n|dkrbi}n|r{|r{t|ds"                +            e5  (    1 Jv         (                 w    8