PNG  IHDR;IDATxܻn0K )(pA 7LeG{ §㻢|ذaÆ 6lذaÆ 6lذaÆ 6lom$^yذag5bÆ 6lذaÆ 6lذa{ 6lذaÆ `}HFkm,mӪôô! x|'ܢ˟;E:9&ᶒ}{v]n&6 h_tڠ͵-ҫZ;Z$.Pkž)!o>}leQfJTu іچ\X=8Rن4`Vwl>nG^is"ms$ui?wbs[m6K4O.4%/bC%t Mז -lG6mrz2s%9s@-k9=)kB5\+͂Zsٲ Rn~GRC wIcIn7jJhۛNCS|j08yiHKֶۛkɈ+;SzL/F*\Ԕ#"5m2[S=gnaPeғL lذaÆ 6l^ḵaÆ 6lذaÆ 6lذa; _ذaÆ 6lذaÆ 6lذaÆ RIENDB`  qYy2@sdddddddddd d d d f Zd ZddlZddlZddlZddlZddlmZddlm Z m Z dde eDZ e fZdejkrddlZe ejjfZdZeZddZddZGdddeZeejefZddZddd Zd!d"Z d#d$Z!d%d&Z"d'd(Z#dd)d*Z$d+d,Z%d-d.Z&Gd/d0d0eZ'Gd1d2d2eZ(e(Z)e)j*Z*e)j+Z,e)j-Z.d3d4Z/d5d6d7d8d9d:d;d<hZ0d=d>Z1Gd?d@d@e2Z3dAdBZ4GdCdDdDeZ5GdEdFdFeZ6GdGd d e6Z7dHdIZ8GdJdKdKe6Z9GdLdde9e7Z:dMdNZ;dOdPZ<dQdRZ=GdSdTdTeZ>dUdVZ?e*ddddddWdXZ@ddddddYdZZAe*dddddd[dZBGd\d]d]eZCd^d_ZDd`daZEe@eB_eCeB_FeAeB_GeEeB_HdbeB_IdcZJddZKdejLdfdgeKjMDZNdejLdhdgeKjMDZOdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzhZPd{d|ZQd}ddejLeJeKeNeOgjMDZReRePBZSd~ddddddhZTdddddddddiZUdeVdeVdeVdeVddddddddddddddddi ZWddZXddZYddZZdeXdeYdeZiZ[ddZ\GdddeZ]Gdd d e]e7Z^Gddde]e:Z_GdddeZ`GdddeZaeaZbddZcGdddedZeeeddZfddddddZgddZhddZiGdddeZjeegeebjkfZleebjkjmfZndaoddZpdddd ZqGdd d e:ZrdS)Mock MagicMockpatchsentinelDEFAULTANYcallcreate_autospec FILTER_DIRNonCallableMockNonCallableMagicMock mock_open PropertyMockz1.0N) ModuleType)wrapspartialcCs%h|]}|jds|qS)_) startswith).0namer#/opt/python35/lib/python3.5/mock.py #s rjavaTcCstt|tS)N) issubclasstyper )objrrr_is_instance_mock2srcCs+t|tp*t|to*t|tS)N) isinstanceBaseExceptionsrr)rrrr _is_exception8sr c@seZdZdgZdS)_slottedaN)__name__ __module__ __qualname__ __slots__rrrrr!?s r!cCst|trE| rEy |j}Wntk r;dSYnXd}n5t|tszy |j}Wntk rydSYnX|rt|d}n|}y|tj|fSWnt k rdSYnXdS)z Given an arbitrary, possibly callable object, try to create a suitable signature object. Return a (reduced func, signature) tuple, or None. NT) rr__init__AttributeError FunctionTypes__call__rinspectZ signature ValueError)funcZ as_instanceZeat_selfZsig_funcrrr_get_signature_objectKs$        r.Fcs`t|||dkr"dS\}fdd}t|||t|_dS)Ncsj||dS)N)bind) _mock_selfargskwargs)sigrrchecksigpsz"_check_signature..checksig)r._copy_func_detailsr_mock_check_sig)r-mock skipfirstinstancer4r)r3r_check_signatureks   r:c#Cs|j|_|j|_y|j|_Wntk r<YnXy|j|_Wntk raYnXy|j|_Wntk rYnXy|j|_Wntk rYnXdS)N)r#__doc____text_signature__r(r$ __defaults____kwdefaults__)r-funcopyrrrr5vs$      r5cCs3t|trdSt|dddk r/dSdS)NTr*F)rrgetattr)rrrr _callables rAcCst|ttfkS)N)rlisttuple)rrrr_is_listsrDcCs`t|ts%t|dddk Sx4|f|jD]"}|jjddk r6dSq6WdS)ztGiven an object, return True if the object is callable. For classes, return True if instances would be callable.r*NTF)rrr@__mro____dict__get)rbaserrr_instance_callables rIc st|sdSt|t}t|||}|dkrA|S|\}fdd}t|||j}|jsd}d|d|i}d|} t| |||} t| || S)Ncsj||dS)N)r/)r1r2)r3rrr4sz _set_signature..checksigr?Z _checksig_r7zYdef %s(*args, **kwargs): _checksig_(*args, **kwargs) return mock(*args, **kwargs)) rArrr.r5r# isidentifierexec _setup_func) r7originalr9r8resultr-r4rcontextsrcr?r)r3r_set_signatures$          rQcs_tsdSfdd}fdd}fdd}fdd}fd d }d _d _d_t_t_t_j _ j _ j _ |_ |_ |_|_|__dS) Ncsj||S)N)assert_called_with)r1r2)r7rrrRsz'_setup_func..assert_called_withcsj||S)N)assert_called_once_with)r1r2)r7rrrSsz,_setup_func..assert_called_once_withcsj||S)N)assert_has_calls)r1r2)r7rrrTsz%_setup_func..assert_has_callscsj||S)N)assert_any_call)r1r2)r7rrrUsz$_setup_func..assert_any_callcsQt_t_jj}t|rM|k rM|jdS)N) _CallList method_calls mock_calls reset_mock return_valuer)ret)r?r7rrrYs     z_setup_func..reset_mockFr)r7rcalled call_count call_argsrVcall_args_listrWrXrZ side_effect_mock_childrenrRrSrTrUrY_mock_delegate)r?r7rRrSrTrUrYr)r?r7rrLs.                rLcCsd|dd|kS)Nz__%s__r)rrrr _is_magicsrec@s.eZdZdZddZddZdS)_SentinelObjectz!A unique, named, sentinel object.cCs ||_dS)N)r)selfrrrrr'sz_SentinelObject.__init__cCs d|jS)Nz sentinel.%s)r)rgrrr__repr__sz_SentinelObject.__repr__N)r#r$r%r;r'rhrrrrrfs  rfc@s.eZdZdZddZddZdS) _SentinelzAAccess attributes to return a named object, usable as a sentinel.cCs i|_dS)N) _sentinels)rgrrrr'sz_Sentinel.__init__cCs+|dkrt|jj|t|S)N __bases__)r(rj setdefaultrf)rgrrrr __getattr__s z_Sentinel.__getattr__N)r#r$r%r;r'rmrrrrris  ricCs2t|ttttfkr.t||S|S)N)rdictrBrCset)valuerrr_copysrqrZ_mock_return_valuer`_mock_side_effect _mock_parent_mock_new_parent _mock_name_mock_new_namecCsHtj|d|}||dd}||dd}t||S)NZ_mock_cSs/|j}|dkr"t||St||S)N)rbr@)rgr _the_namer3rrr_get"s   z"_delegating_property.._getcSs9|j}|dkr%||j|._set)_allowed_namesaddproperty)rrxryr{rrr_delegating_propertys   rc@s(eZdZddZddZdS)rVcCst|tstj||St|}t|}||krGdSxCtd||dD]*}||||}||kr_dSq_WdS)NFrT)rrB __contains__lenrange)rgrpZ len_valueZlen_selfiZsub_listrrrr4s    z_CallList.__contains__cCstjt|S)N)pprintZpformatrB)rgrrrrhBsz_CallList.__repr__N)r#r$r%rrhrrrrrV2s  rVcCst|sdS|js@|js@|jdk s@|jdk rDdS|}x)|dk ru||kridS|j}qMW|r||_||_|r||_||_dS)NFT)rrvrwrtru)parentrprnew_name_parentrrr_check_and_set_parentFs$       rc@s4eZdZddZddZddZdS) _MockItercCst||_dS)N)iterr)rgrrrrr'`sz_MockIter.__init__cCs|S)Nr)rgrrr__iter__bsz_MockIter.__iter__cCs t|jS)N)nextr)rgrrr__next__dsz_MockIter.__next__N)r#r$r%r'rrrrrrr_s   rc@s(eZdZeZdZddZdS)BaseNcOsdS)Nr)rgr1r2rrrr'jsz Base.__init__)r#r$r%rrrrsr'rrrrrgs rc @seZdZdZddZddddddddddddd Zd d Zdd d Zddd dZddZ ddZ dZ e e e e Z e ddZedZedZedZedZedZddZddZe eeZddd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Z d1d2Z!d3d4Z"d5d6Z#d7d8Z$dd9d:Z%d;d<Z&d=d>Z'dS)?r z A non-callable version of `Mock`cOs4t|j|fd|ji}tj|}|S)Nr;)rr#r;object__new__)clsr1kwnewr9rrrrrs!zNonCallableMock.__new__NFc Ks2|dkr|}|j} || d<|| d<|| d<|| d<|dk r[|}d}| dkrs|dk } |j||| | i| d<|| d|jdk r||j_n||_t||dddS)Nz())rbrZrrr)rgrprrrZ__set_return_values z"NonCallableMock.__set_return_valuez1The value to be returned when the mock is called.cCs |jdkrt|S|jS)N)rr)rgrrr __class__s zNonCallableMock.__class__r\r]r^r_rXcCst|j}|dkr|jS|j}|dk rpt| rpt|t rpt| rpt|}||_|S)N)rbrsr`callablerrr )rg delegatedZsfrrrZ__get_side_effects     z!NonCallableMock.__get_side_effectcCs:t|}|j}|dkr-||_n ||_dS)N) _try_iterrbrsr`)rgrprrrrZ__set_side_effects     z!NonCallableMock.__set_side_effectcCs|dkrg}t||kr(dS|jt|d|_d|_d|_t|_t|_t|_x6|j j D]%}t |t rq|j |qW|j}t|r||k r|j |dS)z-Restore the mock object to its initial state.NFr)idappendr\r^r]rVrXr_rWravaluesr _SpecStaterYrrr)rgZvisitedZchildr[rrrrYs$        zNonCallableMock.reset_mockcKsx}t|jdddD]]\}}|jd}|j}|}x|D]}t||}qSWt|||qWdS)aZSet 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)keycSs|djdS)Nr.)count)entryrrr6sz0NonCallableMock.configure_mock..rN)sorteditemssplitpopr@rz)rgr2argvalr1finalrrrrrr)s   zNonCallableMock.configure_mockc Csu|d krt|nU|jdk rX||jksE|tkrptd|nt|rpt||js|jd rt||jj|}|tkrt|n|dkr.d}|j dk rt |j |}|j d|d|d|d |d |}||j|rr)rr)r(r _all_magicsrerrrarG_deletedrr@rrrrrrr9rr)rgrrNrrrrrm?s6          zNonCallableMock.__getattr__c Cs|jg}|j}|}d}|dgkr6d}t}xt|dk r|}|j|j|d}|jdkrd}|j}t||krP|jt|qBWtt|}|jpd}t |dkr|dd kr|d7}||d)rr)r7r)rwrurorrr}rBreversedrvrjoinrrr#r) rgZ _name_listrZlastdotseenZ_firstrZ name_stringZ spec_stringrrrrhesL          zNonCallableMock.__repr__cCststj|S|jpg}tt|}t|j}dd|D}dd|D}tt |||t|j S)z8Filter the output of `dir(mock)` to only useful members.cSs%g|]}|jds|qS)r)r)rerrr s z+NonCallableMock.__dir__..cSs2g|](}|jd s(t|r|qS)r)rre)rrrrrrs ) r r__dir__rrrrBrFrrora)rgextrasZ from_typeZ from_dictrrrrs zNonCallableMock.__dir__cs|tkrtj||Sjrhjdk rh|jkrh|jkrhtd|n|tkrd|}t|n|tkrIjdk r|jkrtd|t |st t |t |||fdd}qt |d|t t |||j|.r)r|r __setattr__rrrFr(_unsupported_magicsrrrzr _get_methodrrar)rgrrpmsgr)rMrgrrs2        zNonCallableMock.__setattr__cCs|tkrG|t|jkrGtt||||jkrGdS||jkrftj|||jj|t}|t krt ||tk r|j|=t |j|._error_message)r^rrrr Exception)r0r1r2expectedractualcauser)r1r2rgrrR s z"NonCallableMock.assert_called_withcOsM|}|jdks=d|jp$d|jf}t||j||S)ziassert that the mock was called exactly once and that that call was with the specified arguments.rz1Expected '%s' to be called once. Called %s times.r7)r]rvrrR)r0r1r2rgrrrrrSs  z'NonCallableMock.assert_called_once_withc sfdd|D}t|tr.|nd}tfddjD}|s||krtd|jf|dSt|}g}xA|D]9}y|j|Wqtk r|j|YqXqW|rtdt |f|dS)aassert the mock has been called with the specified calls. The `mock_calls` list is checked for the calls. If `any_order` is False (the default) then the calls must be sequential. There can be extra calls before or after the specified calls. If `any_order` is True then the calls can be in any order, but they must all appear in `mock_calls`.csg|]}j|qSr)r)rc)rgrrr2s z4NonCallableMock.assert_has_calls..Nc3s|]}j|VqdS)N)r)rr)rgrr 4sz3NonCallableMock.assert_has_calls..z(Calls not found. Expected: %r Actual: %rz%r not all found in call list) rrrVrXrrBremover,rrC)rgZcallsZ any_orderrrZ all_callsZ not_foundZkallr)rgrrT(s* "    z NonCallableMock.assert_has_callscsj||f}fddjD}||kr}t|trR|nd}j||}td||dS)zassert 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.csg|]}j|qSr)r)rr)rgrrrRs z3NonCallableMock.assert_any_call..Nz%s call not found)rr_rrrr)rgr1r2rrrrr)rgrrUKs  zNonCallableMock.assert_any_callcKsbt|}t|tsKt|tr3t}qXt|trXt}n |jd}||S)aPCreate 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).r)rr CallableMixinr rr rrE)rgr_typeklassrrrr[s    zNonCallableMock._get_child_mock)(r#r$r%r;rr'rrrZ"_NonCallableMock__get_return_valueZ"_NonCallableMock__set_return_valueZ"_NonCallableMock__return_value_docr~rZrrr\r]r^r_rXZ!_NonCallableMock__get_side_effectZ!_NonCallableMock__set_side_effectr`rYrrmrhrrrrrrrrRrSrTrUrrrrrr osN   )             & 2  "     # c Cs[|dkr|St|r |St|r0|Syt|SWntk rV|SYnXdS)N)r rArr)rrrrros    rc @s^eZdZddeddddddddd ZddZddZd d ZdS) rNrc KsH||jd.) rrrrrrrrrr2attribute_namer)rgrrrrrQs  z _patch.copycCs)t|tr|j|S|j|S)N)rrdecorate_classdecorate_callable)rgr-rrrr*^s z_patch.__call__cCssxlt|D]^}|jtjs(q t||}t|dsIq |j}t||||q W|S)Nr*)rrr TEST_PREFIXr@rrrz)rgrattr attr_valuerrrrrds z_patch.decorate_classcsTtdr#jj|Stfdd|g_S)N patchingscs g}g}t}zyxejD]Z}|j}|j||jdk rc|j|q%|jtkr%|j|q%W|t|7}||SWn<||krt|r|j|t j }YnXWdx!t |D]}|j |qWXdS)N) rCr  __enter__rrupdaterrrsysexc_infor__exit__)r1Zkeywargs extra_argsZentered_patchersrpatchingr)r-patchedrrrws*        z)_patch.decorate_callable..patched)rr rr)rgr-r)r-rrrrs ! z_patch.decorate_callablec Cs|j}|j}t}d}y|j|}Wn*ttfk r^t||t}YnXd}|tkrt|t rd|_ |j r|tkrtd||f||fS)NFTz!%s does not have the attribute %r) rrrrFr(KeyErrorr@ _builtinsrrr)rgrrrMlocalrrr get_originals   z_patch.get_originalcCsP|j|j|j}}}|j|j}}|j}|j|_|dkrZd}|dkrld}|dkr~d}|dk r|dk rtd|dk s|dk r|dkrtd|j \}}|t kr |dkr d} |dkr/|}|dkrh|}d}n9|dk rV|dkrh|}d}n|dkrh|}|dk s|dk r|t krtdt |t rd} t } i} |dk r|} nd|dk s|dk r2|} |dk r|} t| rd| k} n t|  } | r2t} |dk rH|| d<|dk r^|| d N)r;r$r=rr>)r RuntimeErrorrrrrzrrrrrrrr)rgrrrrrr0s      z_patch.__exit__cCs |j}|jj||S)z-Activate a patch, returning any created mock.)r _active_patchesr)rgrNrrrstartHs z _patch.startc Cs3y|jj|Wntk r(YnX|jS)zStop an active patch.)rrr,r)rgrrrstopOs  z _patch.stop)r#r$r%rrr'rr*rrrr rr r!rrrrr1s     (  ~  rc sfyjdd\}Wn+ttfk rItdfYnXfdd}||fS)Nrrz.Need a valid target to patch. You supplied: %rcs tS)N)rr)rrrrasz_get_target..)rsplitrr,)rrrr)rr _get_target[sr#c s4fdd} t| |||||||| S)a patch the named member (`attribute`) on an object (`target`) with a mock object. `patch.object` can be used as a decorator, class decorator or a context manager. Arguments `new`, `spec`, `create`, `spec_set`, `autospec` and `new_callable` have the same meaning as for `patch`. Like `patch`, `patch.object` takes arbitrary keyword arguments for configuring the mock object it creates. When used as a class decorator `patch.object` honours `patch.TEST_PREFIX` for choosing which methods to wrap. csS)Nrr)rrrrwsz_patch_object..)r) rrrrrrrrr2rr)rr _patch_objectesr$c sttkr'fdd}nfdd}|sKtdt|j}|d\} } t|| | |||||i } | | _x[|ddD]I\} } t|| | |||||i } | | _| jj| qW| S)aPerform multiple patches in a single call. It takes the object to be patched (either as an object or a string to fetch the object by importing) and keyword arguments for the patches:: with patch.multiple(settings, FIRST_PATCH='one', SECOND_PATCH='two'): ... Use `DEFAULT` as the value if you want `patch.multiple` to create mocks for you. In this case the created mocks are passed into a decorated function by keyword, and a dictionary is returned when `patch.multiple` is used as a context manager. `patch.multiple` can be used as a decorator, class decorator or a context manager. The arguments `spec`, `spec_set`, `create`, `autospec` and `new_callable` have the same meaning as for `patch`. These arguments will be applied to *all* patches done by `patch.multiple`. When used as a class decorator `patch.multiple` honours `patch.TEST_PREFIX` for choosing which methods to wrap. cs tS)N)rr)rrrrsz!_patch_multiple..csS)Nrr)rrrrsz=Must supply at least one keyword argument with patch.multiplerrN) rstrr,rBrrrrr) rrrrrrr2rrrrrZ this_patcherr)rr_patch_multiple~s&   r&c Ks4t|\}} t|| ||||||| S)a `patch` acts as a function decorator, class decorator or a context manager. Inside the body of the function or with statement, the `target` is patched with a `new` object. When the function/with statement exits the patch is undone. If `new` is omitted, then the target is replaced with a `MagicMock`. If `patch` is used as a decorator and `new` is omitted, the created mock is passed in as an extra argument to the decorated function. If `patch` is used as a context manager the created mock is returned by the context manager. `target` should be a string in the form `'package.module.ClassName'`. The `target` is imported and the specified object replaced with the `new` object, so the `target` must be importable from the environment you are calling `patch` from. The target is imported when the decorated function is executed, not at decoration time. The `spec` and `spec_set` keyword arguments are passed to the `MagicMock` if patch is creating one for you. In addition you can pass `spec=True` or `spec_set=True`, which causes patch to pass in the object being mocked as the spec/spec_set object. `new_callable` allows you to specify a different class, or callable object, that will be called to create the `new` object. By default `MagicMock` is used. A more powerful form of `spec` is `autospec`. If you set `autospec=True` then the mock will be created with a spec from the object being replaced. All attributes of the mock will also have the spec of the corresponding attribute of the object being replaced. Methods and functions being mocked will have their arguments checked and will raise a `TypeError` if they are called with the wrong signature. For mocks replacing a class, their return value (the 'instance') will have the same spec as the class. Instead of `autospec=True` you can pass `autospec=some_object` to use an arbitrary object as the spec instead of the one being replaced. By default `patch` will fail to replace attributes that don't exist. If you pass in `create=True`, and the attribute doesn't exist, patch will create the attribute for you when the patched function is called, and delete it again afterwards. This is useful for writing tests against attributes that your production code creates at runtime. It is off by default because it can be dangerous. With it switched on you can write passing tests against APIs that don't actually exist! Patch can be used as a `TestCase` class decorator. It works by decorating each test method in the class. This reduces the boilerplate code when your test methods share a common patchings set. `patch` finds tests by looking for method names that start with `patch.TEST_PREFIX`. By default this is `test`, which matches the way `unittest` finds tests. You can specify an alternative prefix by setting `patch.TEST_PREFIX`. Patch can be used as a context manager, with the with statement. Here the patching applies to the indented block after the with statement. If you use "as" then the patched object will be bound to the name after the "as"; very useful if `patch` is creating a mock object for you. `patch` takes arbitrary keyword arguments. These will be passed to the `Mock` (or `new_callable`) on construction. `patch.dict(...)`, `patch.multiple(...)` and `patch.object(...)` are available for alternate use-cases. )r#r) rrrrrrrr2rrrrrrsEc@s|eZdZdZfdddZddZddZd d Zd d Zd dZ ddZ eZ e Z dS) _patch_dicta# Patch a dictionary, or dictionary like object, and restore the dictionary to its original state after the test. `in_dict` can be a dictionary or a mapping like container. If it is a mapping then it must at least support getting, setting and deleting items plus iterating over keys. `in_dict` can also be a string specifying the name of the dictionary, which will then be fetched by importing it. `values` can be a dictionary of values to set in the dictionary. `values` can also be an iterable of `(key, value)` pairs. If `clear` is True then the dictionary will be cleared before the new values are set. `patch.dict` can also be called with arbitrary keyword arguments to set values in the dictionary:: with patch.dict('sys.modules', mymodule=Mock(), other_module=Mock()): ... `patch.dict` can be used as a context manager, decorator or class decorator. When used as a class decorator `patch.dict` honours `patch.TEST_PREFIX` for choosing which methods to wrap. FcKsYt|trt|}||_t||_|jj|||_d|_dS)N) rr%rin_dictrnrr clear _original)rgr(rr)r2rrrr's   z_patch_dict.__init__csAttrjStfdd}|S)Nc s-jz||SWdjXdS)N)r' _unpatch_dict)r1r)frgrr_inner&s z$_patch_dict.__call__.._inner)rrrr)rgr,r-r)r,rgrr*#s !z_patch_dict.__call__cCsx{t|D]m}t||}|jtjr t|dr t|j|j|j }||}t |||q W|S)Nr*) rr@rrrrr'r(rr)rz)rgrr r Z decoratorZ decoratedrrrr1s z_patch_dict.decorate_classcCs|jdS)zPatch the dict.N)r')rgrrrr <sz_patch_dict.__enter__cCs|j}|j}|j}y|j}Wn7tk rdi}x|D]}||||.method)r#)rr-rCr)r-rrs rcCsh|]}d|qS)z__%s__r)rrCrrrrs rmrr'rZ__prepare____instancecheck____subclasscheck____del____hash__cCs tj|S)N)rrF)rgrrrrsr__str__cCs tj|S)N)rrG)rgrrrrs __sizeof__cCs tj|S)N)rrH)rgrrrrs__lt____gt____le____ge____int__rr__len__r __complex__y? __float__g?__bool__ __index__csfdd}|S)Ncs0jj}|tk r|S|kr,dStS)NT)__eq__rrrNotImplemented)otherr)rgrrrSs    z_get_eq..__eq__r)rgrSr)rgr_get_eqsrVcsfdd}|S)Ncs*jjtk rtS|kr&dStS)NF)__ne__rrrrT)rU)rgrrrWs  z_get_ne..__ne__r)rgrWr)rgr_get_nesrXcsfdd}|S)Ncs,jj}|tkr"tgSt|S)N)rrrrr)r)rgrrrs   z_get_iter..__iter__r)rgrr)rgr _get_itersrYrSrWrc Cstj|t}|tk r+||_dStj|}|dk ry||}Wntk rvt|}YnX||_dStj|}|dk r|||_dS)N)_return_valuesrGrrZ_calculate_return_valuer(_side_effect_methodsr`)r7rCrZfixedZreturn_calulatorrZZ side_effectorrrr_set_return_values      r]c@s(eZdZddZddZdS) MagicMixincOs1|jtt|j|||jdS)N)_mock_set_magicsrr^r')rgr1rrrrr's zMagicMixin.__init__cCst}t|dddk rvtj|j}t}t|}x0|D](}|t|jkrJt||qJW|tt|j}t|}x'|D]}t||t ||qWdS)Nr) _magicsr@ intersectionrrorrFrrz MagicProxy)rgZ these_magicsZ remove_magicsrrrrrr_s     zMagicMixin._mock_set_magicsN)r#r$r%r'r_rrrrr^s  r^c@s%eZdZdZdddZdS)r z-A version of `MagicMock` that isn't callable.FcCs|j|||jdS)zAdd 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_)rgrrrrrr/sz"NonCallableMagicMock.mock_add_specN)r#r$r%r;rrrrrr -s c@s%eZdZdZdddZdS)ra 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`. FcCs|j|||jdS)zAdd 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_)rgrrrrrrEszMagicMock.mock_add_specN)r#r$r%r;rrrrrr:s c@sCeZdZddZddZddZddd ZdS) rbcCs||_||_dS)N)rr)rgrrrrrr'Qs zMagicProxy.__init__cOs|j}|||S)N) create_mock)rgr1r2mrrrr*Us zMagicProxy.__call__cCsT|j}|j}|jd|d|d|}t|||t||||S)Nrrr)rrrrzr])rgrrrdrrrrcYs   zMagicProxy.create_mockNcCs |jS)N)rc)rgrrrrrr3bszMagicProxy.__get__)r#r$r%r'r*rcr3rrrrrbPs    rbc@s:eZdZdZddZddZddZdS) _ANYz2A helper object that compares equal to everything.cCsdS)NTr)rgrUrrrrSjsz _ANY.__eq__cCsdS)NFr)rgrUrrrrWmsz _ANY.__ne__cCsdS)Nzr)rgrrrrhpsz _ANY.__repr__N)r#r$r%r;rSrWrhrrrrregs   recCsd|}d}djdd|D}djddt|jD}|r`|}|r|rv|d7}||7}||S)Nz%s(%%s)rz, cSsg|]}t|qSr)repr)rrrrrrzs z*_format_call_signature..cSs&g|]\}}d||fqS)z%s=%rr)rrrprrrr|s )rrr)rr1r2rZformatted_args args_stringZ kwargs_stringrrrrws "  rc@seZdZdZfddddddZfdddddd Zd d ZejZd d Z ddZ ddZ ddZ ddZ ddZdS)ra 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. rNFTc Csf}i}t|}|dkr6|\}}}n|dkr|\} } t| tr| }t| tr{| }q| }q| | }}nK|dkr|\}t|tr|}nt|tr|}n|}|rtj|||fStj||||fS)Nrrcr)rrr%rCr) rrprrr from_kallr1r2_lenfirstsecondrrrrs.          z _Call.__new__cCs||_||_||_dS)N)rrrh)rgrprrrrhrrrr's  z_Call.__init__c Cs|tkrdSyt|}Wntk r8dSYnXd}t|dkr`|\}}n|\}}}d}|dkrfi}}n|dkr|\}}}n|dkr|\} t| tr| }i}qt| tr| }fi}}qf}| }np|dkr|\} } t| trr| }t| trb| i}}qf| }}q| | }}ndS|r||krdS||f||fkS)NTFrrcrrr)rrrrrCr%) rgrUZ len_otherZ self_nameZ self_argsZ self_kwargsZ other_nameZ other_argsZ other_kwargsrprjrkrrrrSsJ           z _Call.__eq__cOsW|jdkr(td||fddS|jd}t|j||fd|d|S)Nrrz()r)rr)rgr1r2rrrrr*s z_Call.__call__cCsN|jdkr"td|ddSd|j|f}td|d|ddS)NrrhFz%s.%sr)rr)rgr rrrrrmsz_Call.__getattr__cOs|jd||S)Nr)rm)rgr1r2rrrrsz _Call.countcOs|jd||S)Nindex)rm)rgr1r2rrrrl sz _Call.indexcCs|js5|jpd}|jdr1d|}|St|dkr\d}|\}}nD|\}}}|szd}n&|jdsd|}n d|}t|||S)Nrz()zcall%srczcall.%s)rhrrrr)rgrr1r2rrrrhs     z_Call.__repr__cCsNg}|}x/|dk r=|jr1|j||j}qWtt|S)zFor a call object that represents multiple calls, `call_list` returns a list of all the intermediate calls as well as the final call.N)rhrrrVr)rgvalsrrrr call_list#s   z_Call.call_list)r#r$r%r;rr'rSrrWr*rmrrlrhrnrrrrrs    3      rrhcKst|rt|}t|t}d|i}|rHd|i}n|dkrZi}|rp|rpd|d<|j|t}tj|ri}n4t|st}n|r|rt | rt}|j d|}|} |dkrd} |d|d |d | d||} t|t r>t | |} nt || |||dk rq| rq| |j|<|r| rd |krt||d dd dd| | _x@t|D]2} t| rqyt|| } Wntk rwYnXd| i}|rd| i}t| t sPt| || | |} | | j| t|tt frdStt|ddt r|SdSq>W|S)z[ Return whether we should skip the first argument on spec's `entry` attribute. rFFr3N) rrr@rrErFrGr staticmethod classmethodMethodWrapperTypes)rrrprrNrrrros  roc Cs.y |jSWntk r)t|SYnXdS)N)rr(r)rrrrrs  rc@s+eZdZdddddddZdS)rFNcCs:||_||_||_||_||_||_dS)N)ridsrrr9r)rgrrrrrtr9rrrr's      z_SpecState.__init__)r#r$r%r'rrrrrs rc#st|trdndfdd|jD}|dkr`|dd}n|ddd |d .rrxrxrxrx)rbytesr) read_dataZ data_as_listliner)rwr_iterate_read_datas" r|rcstfdd}fdd}fddtdkrddl}ttt|jjtt|ja|dkrtd d d t }td tj _ t dgdj _ dj_ dj_ dj_ |j_d <d j_|j_fd d}||_|_ |S)a A helper function to create a mock to replace the use of `open`. It works for `open` called directly or used as a context manager. The `mock` argument is the mock object to configure. If `None` (the default) then a `MagicMock` will be created for you, with the API limited to methods or attributes available on standard file handles. `read_data` is a string for the `read` methoddline`, and `readlines` of the file handle to return. This is an empty string by default. cs*jjdk rjjStdS)Nr) readlinesrZrB)r1r2)_statehandlerr_readlines_side_effect s z)mock_open.._readlines_side_effectcs6jjdk rjjStjdS)Nr)readrZrr)r1r2)r~rrzrr_read_side_effect s z$mock_open.._read_side_effectc3sWjjdk r$xjjVqWxdD] }|Vq/WxtVqAWdS)Nr)readlinerZr)r{)r~rrzrr_readline_side_effect s z(mock_open.._readline_side_effectNrropenrrcsGtd<jjdkrCd<dj_tS)Nrr)r|rr`r)r1r2)rr~rrzrr reset_data7 s  zmock_open..reset_data) file_spec_iorBror TextIOWrapperunionBytesIOrrr rZr|writerrr}r`)r7rzrrrrr)rr~rrzrr s.   3           c@s:eZdZdZddZddZddZdS) r aW A mock intended to be used as a property, or other descriptor, on a class. `PropertyMock` provides `__get__` and `__set__` methods so you can specify a return value when it is fetched. Fetching a `PropertyMock` instance from an object calls the mock, with no args. Setting it calls the mock with the value being set. cKs t|S)N)r)rgr2rrrrM szPropertyMock._get_child_mockcCs|S)Nr)rgrZobj_typerrrr3P szPropertyMock.__get__cCs||dS)Nr)rgrrrrrr4R szPropertyMock.__set__N)r#r$r%r;rr3r4rrrrr D s   )s__all__ __version__r+rrbuiltinstypesr functoolsrrrr BaseExceptionrplatformrlangZ Throwabler superrrr rr!rr"r~ZDescriptorTypesr.r:r5rArDrIrQrLrerfrirrZMISSINGrZDELETEDrrqr|rrBrVrrrr rrrrrrrr#r$r&rr'r.r0rnZmultipleZstopallrZ magic_methodsZnumericsrrZinplacerightZ _non_defaultsrr`rrr[rTrZrVrXrYr\r]r^r rrbrerrrCrrrrorrrSr)r3rsrr|r r rrrrs                 +             e5  +   1 Jv      ""      %             w    D