File "mock.cpython-34.pyc"

Full Path: /home/attunedd/public_html/byp/izo/con7ext_sym404/rintoar.txt/opt/alt/python34/lib64/python3.4/unittest/__pycache__/mock.cpython-34.pyc
File size: 63.51 KB
MIME-type: text/x-bytecode.python
Charset: 8 bit


j f,@sdddddddddd	d
ddf
Zd
ZddlZddlZddlZddlmZmZefZ	dej
krddlZeejj
fZ	ndZeZddZddZGdddeZeejefZddZdddZddZd d!Zd"d#Zd$d%Zdd&d'Zd(d)Z d*d+Z!Gd,d-d-eZ"Gd.d/d/eZ#e#Z$e$j%Z%e$j&Z'e$j(Z)d0d1Z*e+d2d3d4d5d6d7d8d9gZ,d:d;Z-Gd<d=d=e.Z/d>d?Z0Gd@dAdAeZ1GdBdCdCeZ2GdDd	d	e2Z3dEdFZ4GdGdHdHe2Z5GdIdde5e3Z6dJdKZ7dLdMZ8dNdOZ9GdPdQdQeZ:dRdSZ;e%ddddddTdUZ<ddddddVdWZ=e%ddddddXdZ>GdYdZdZeZ?d[d\Z@d]d^ZAe<e>_e?e>_Be=e>_CeAe>_Dd_e>_Ed`ZFdaZGdbjHdcddeGjIDZJdbjHdeddeGjIDZKe+dfdddgdhdidjdkdldmdndodpdqdrdsdtdudvdwgDZLdxdyZMe+dzdddbjHeFeGeJeKgjIDZNeNeLBZOe+d{d|d}d~dddgZPiddd6ddd6ddd6ZQieRd6eRd6eRd6eRd6dd6dd6dd6dd6dd6dd6dd6dd6ZSddZTddZUddZVieTd6eUd6eVd6ZWddZXGdddeZYGdd
d
eYe3ZZGdddeYe6Z[GdddeZ\GdddeZ]e]Z^ddZ_Gddde`ZaeaddZbddddddZcddZdddZeGdddeZfeecee^jgfZhee^jgjifZjdakddZlddddZmGddde6ZndS)Mock	MagicMockpatchsentinelDEFAULTANYcallcreate_autospec
FILTER_DIRNonCallableMockNonCallableMagicMock	mock_openPropertyMockz1.0N)wrapspartialjavaTcCstt|tS)N)
issubclasstyper
)objr2/opt/alt/python34/lib64/python3.4/unittest/mock.py_is_instance_mock.srcCs+t|tp*t|to*t|tS)N)
isinstanceBaseExceptionsrr)rrrr
_is_exception4src@seZdZdgZdS)_slottedaN)__name__
__module____qualname__	__slots__rrrrr;srcCst|trE|rEy
|j}Wntk
r;dSYnXd}n8t|ts}y
|j}Wq}tk
rydSYq}Xn|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)funcZas_instanceZeat_selfZsig_funcrrr_get_signature_objectEs$

		


r(Fcs`t|||dkr"dS\}fdd}t|||t|_dS)Ncsj||dS)N)bind)
_mock_selfargskwargs)sigrrchecksigjsz"_check_signature.<locals>.checksig)r(_copy_func_detailsr_mock_check_sig)r'mock	skipfirstinstancer.r)r-r_check_signaturees
r4c#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'funcopyrrrr/ps$



r/cCs3t|trdSt|dddk	r/dSdS)NTr$F)rrgetattr)rrrr	_callables
r;cCst|ttfkS)N)rlisttuple)rrrr_is_listsr>cCs`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rCcst|sdSt|t}t|||}|dkrAdS|\}fdd}t|||j}|jsd}ni|d6|d6}d|}	t|	|||}
t|
||
S)Ncsj||dS)N)r))r+r,)r-rrr.sz _set_signature.<locals>.checksigr9Z
_checksig_r1zYdef %s(*args, **kwargs):
    _checksig_(*args, **kwargs)
    return mock(*args, **kwargs))	r;rrr(r/risidentifierexec_setup_func)r1originalr3r2resultr'r.namecontextsrcr9r)r-r_set_signatures$
		



rLcs_tsdSfdd}fdd}fdd}fdd}fd	d
}d_d_d_t_t_t_j	_	j
_
j_|_|_
|_|_|__dS)
Ncsj||S)N)assert_called_with)r+r,)r1rrrMsz'_setup_func.<locals>.assert_called_withcsj||S)N)assert_called_once_with)r+r,)r1rrrNsz,_setup_func.<locals>.assert_called_once_withcsj||S)N)assert_has_calls)r+r,)r1rrrOsz%_setup_func.<locals>.assert_has_callscsj||S)N)assert_any_call)r+r,)r1rrrPsz$_setup_func.<locals>.assert_any_callcsTt_t_jj}t|rP|k	rP|jndS)N)	_CallListmethod_calls
mock_calls
reset_mockreturn_valuer)ret)r9r1rrrTs
	z_setup_func.<locals>.reset_mockFr)r1rcalled
call_count	call_argsrQcall_args_listrRrSrUside_effect_mock_childrenrMrNrOrPrT_mock_delegate)r9r1rMrNrOrPrTr)r9r1rrFs.									rFcCsd|dd|kS)Nz__%s__r)rIrrr	_is_magicsr`c@s.eZdZdZddZddZdS)_SentinelObjectz!A unique, named, sentinel object.cCs
||_dS)N)rI)selfrIrrrr!sz_SentinelObject.__init__cCsd|jS)Nzsentinel.%s)rI)rbrrr__repr__sz_SentinelObject.__repr__N)rrrr5r!rcrrrrrasrac@s.eZdZdZddZddZdS)	_SentinelzAAccess attributes to return a named object, usable as a sentinel.cCs
i|_dS)N)
_sentinels)rbrrrr!sz_Sentinel.__init__cCs.|dkrtn|jj|t|S)N	__bases__)r"re
setdefaultra)rbrIrrr__getattr__s	z_Sentinel.__getattr__N)rrrr5r!rhrrrrrdsrdcCs2t|ttttfkr.t||S|S)N)rdictr<r=set)valuerrr_copysrlrU_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)r]r:)rbrI	_the_namer-rrr_gets	
z"_delegating_property.<locals>._getcSs9|j}|dkr%||j|<nt|||dS)N)r]r@setattr)rbrkrIrsr-rrr_set#s	z"_delegating_property.<locals>._set)_allowed_namesaddproperty)rIrsrtrvrrr_delegating_propertys


rzc@s(eZdZddZddZdS)rQcCst|tstj||St|}t|}||krGdSxCtd||dD]*}||||}||kr_dSq_WdS)NFrT)rr<__contains__lenrange)rbrkZ	len_valueZlen_selfiZsub_listrrrr|0sz_CallList.__contains__cCstjt|S)N)pprintZpformatr<)rbrrrrc>sz_CallList.__repr__N)rrrr|rcrrrrrQ.srQcCst|sdS|js@|js@|jdk	s@|jdk	rDdS|}x)|dk	ru||kridS|j}qMW|r||_||_n|r||_||_ndS)NFT)rrqrrrorp)parentrkrInew_name_parentrrr_check_and_set_parentBs$
		rc@s4eZdZddZddZddZdS)	_MockItercCst||_dS)N)iterr)rbrrrrr!\sz_MockIter.__init__cCs|S)Nr)rbrrr__iter__^sz_MockIter.__iter__cCs
t|jS)N)nextr)rbrrr__next__`sz_MockIter.__next__N)rrrr!rrrrrrr[src@s(eZdZeZdZddZdS)BaseNcOsdS)Nr)rbr+r,rrrr!fsz
Base.__init__)rrrrrmrnr!rrrrrcsrc@seZdZdZddZdddddddddddd
Zd	d
ZdddZddd
dZddZ	ddZ
dZee	e
eZ
eddZedZedZedZedZedZddZddZeeeZddd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Z d1d2Z!d3d4Z"d5d6Z#dd7d8Z$d9d:Z%d;d<Z&dS)=r
z A non-callable version of `Mock`cOs5t|j|fi|jd6}tj|}|S)Nr5)rrr5object__new__)clsr+kwnewr3rrrrns"zNonCallableMock.__new__NFc
Ks4|dkr|}n|j}||d<||d<||d<||d<|dk	ra|}d}n|
dkr||dk	}
n|j|||	|
i|d<||d<d|d<d	|d
<d|d<d|d
<t|d<t|d<t|d<|r|j|ntt|j||||||dS)NrorqrrrpTr\_mock_wrapsr]FZ_mock_calledZ_mock_call_argsrZ_mock_call_countZ_mock_call_args_listZ_mock_mock_callsrR)r@_mock_add_specrQconfigure_mock_safe_superr
r!)
rbspecrrIspec_setr_spec_state	_new_name_new_parent_spec_as_instance	_eat_selfr,r@rrrr!ws6		



	








zNonCallableMock.__init__cCs8d|_d|_d|_d|_t|||dS)z
        Attach a mock as an attribute of this one, replacing its name and
        parent. Calls to the attached mock will be recorded in the
        `method_calls` and `mock_calls` attributes of this one.Nr)rorprqrrru)rbr1	attributerrrattach_mocks
				zNonCallableMock.attach_mockcCs|j||dS)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)r)rbrrrrr
mock_add_specszNonCallableMock.mock_add_specc	Csd}d}|dk	rzt|rzt|tr=|}nt|}t|||}|oh|d}t|}n|j}||d<||d<||d<||d<dS)Nr{_spec_class	_spec_set_spec_signature
_mock_methods)r>rr
_get_classr(dirr@)	rbrrrrrrresr@rrrrs		


zNonCallableMock._mock_add_speccCs[|j}|jdk	r'|jj}n|tkrW|jd|dd}||_n|S)Nrrz())rmr]rUr_get_child_mock)rbrVrrrZ__get_return_values		z"NonCallableMock.__get_return_valuecCs>|jdk	r||j_n||_t||dddS)Nz())r]rUrmr)rbrkrrrZ__set_return_values	z"NonCallableMock.__set_return_valuez1The value to be returned when the mock is called.cCs |jdkrt|S|jS)N)rr)rbrrr	__class__s
zNonCallableMock.__class__rWrXrYrZrScCsj|j}|dkr|jS|j}|dk	rft|rft|trft|}||_n|S)N)r]rnr[callablerr)rb	delegatedZsfrrrZ__get_side_effects		)z!NonCallableMock.__get_side_effectcCs:t|}|j}|dkr-||_n	||_dS)N)	_try_iterr]rnr[)rbrkrrrrZ__set_side_effects
	z!NonCallableMock.__set_side_effectcCs|dkrg}nt||kr+dS|jt|d|_d|_d|_t|_t|_t|_x9|j	j
D](}t|trqn|j
|qW|j}t|r||k	r|j
|ndS)z-Restore the mock object to its initial state.NFr)idappendrWrYrXrQrSrZrRr\valuesr
_SpecStaterTrmr)rbZvisitedZchildrVrrrrT
s$					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)entryrrr<lambda>0sz0NonCallableMock.configure_mock.<locals>.<lambda>rN)sorteditemssplitpopr:ru)rbr,argvalr+finalrrrrrr#s	
zNonCallableMock.configure_mockcCs]|dkrt|n[|jdk	r[||jksE|tkrvtd|qvnt|rvt|n|jj|}|tkrt|n|dkrd}|jdk	rt|j|}n|j	d|d|d|d|d|}||j|<nFt
|trYt|j
|j|j|j|j}||j|<n|S)NrzMock object has no attribute %rrrIrrr)r"r_all_magicsr`r\rA_deletedrr:rrrrrrr3rrI)rbrIrHrrrrrh9s0		zNonCallableMock.__getattr__c
Cs|jg}|j}|}d}|dgkr9d}nt}xz|dk	r|}|j|j|d}|jdkrd}n|j}t||krPn|jt|qEWtt|}|jpd}t	|dkr|dd
kr|d7}qn||d<dj
|}d}|dkrJd	|}nd}	|jdk	rd
}	|jrwd}	n|	|jj
}	ndt|j
||	t|fS)Nr()rr1r{().rmock.z name=%rz spec=%rz spec_set=%rz<%s%s%s id='%s'>)rr)zmockr)rrrprjrrrxr<reversedrqr}joinrrrr)
rbZ
_name_listrlastdotseenZ_firstrIZname_stringZspec_stringrrrrc\sL					

		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)_)
startswith).0errr
<listcomp>s	z+NonCallableMock.__dir__.<locals>.<listcomp>cSs2g|](}|jds(t|r|qS)r)rr`)rrrrrrs	)r	r__dir__rrrr<r@rrjr\)rbZextrasZ	from_typeZ	from_dictrrrrs
zNonCallableMock.__dir__cs|tkrtj||Sjrhjdk	rh|jkrh|jkrhtd|n"|tkrd|}t|n|tkrLjdk	r|jkrtd|nt	|st
t|t|||fdd}qt
|d|t
t|||j|<n>|dkre|_dSt
|||r|j|<ntj||S)Nz!Mock object has no attribute '%s'z.Attempting to set unsupported magic method %r.cs||S)Nr)r+r)rGrbrrrsz-NonCallableMock.__setattr__.<locals>.<lambda>r)rwr__setattr__rrr@r"_unsupported_magicsrrrur_get_methodrr\r)rbrIrkmsgr)rGrbrrs2
	zNonCallableMock.__setattr__cCs|tkrJ|t|jkrJtt||||jkrJdSn||jkrltj||n|jj|t}|t	krt
|n|tk	r|j|=nt	|j|<dS)N)rrr@delattrr__delattr__r\rA_missingrr")rbrIrrrrrs!
zNonCallableMock.__delattr__cCs|jpd}t|||S)Nr1)rq_format_call_signature)rbr+r,rIrrr_format_mock_call_signaturesz+NonCallableMock._format_mock_call_signaturecCscd}|j||}|j}t|dkrF|dd}n|j|}|||fS)Nz!Expected call: %s
Actual call: %sr{)rrYr})rbr+r,messageexpected_stringrYZ
actual_stringrrr_format_mock_failure_messages	z,NonCallableMock._format_mock_failure_messagecCs|j}|dk	rt|dkr<d}|\}}n|\}}}y||j||fSWqtk
r}z|jdSWYdd}~XqXn|SdS)a
        Given a call (or simply a (args, kwargs) tuple), return a
        comparison key suitable for matching with other calls.
        This is a best effort method which relies on the spec's signature,
        if available, or falls back on the arguments themselves.
        Nr^r)rr}r)	TypeErrorwith_traceback)rb_callr-rIr+r,rrrr
_call_matchers	#zNonCallableMock._call_matchercs|jdkr=j}td|fnfdd}jf}jj}||krt|tr|nd}t||ndS)zassert that the mock was called with the specified arguments.

        Raises an AssertionError if the args and keyword args passed in are
        different to the last call to the mock.NzExpected call: %s
Not calledcsj}|S)N)r)r)r+r,rbrr_error_messagesz:NonCallableMock.assert_called_with.<locals>._error_message)rYrAssertionErrorrr	Exception)r*r+r,expectedractualcauser)r+r,rbrrMsz"NonCallableMock.assert_called_withcOsP|}|jdks@d|jp$d|jf}t|n|j||S)zVassert that the mock was called exactly once and with the specified
        arguments.r{z1Expected '%s' to be called once. Called %s times.r1)rXrqrrM)r*r+r,rbrrrrrNsz'NonCallableMock.assert_called_once_withcs
fdd|D}t|tr.|nd}tfddjD}|s||krtd|jf|ndSt|}g}xA|D]9}y|j|Wqtk
r|j|YqXqW|rtdt	|f|ndS)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)rbrrr!s	z4NonCallableMock.assert_has_calls.<locals>.<listcomp>Nc3s|]}j|VqdS)N)r)rr)rbrr	<genexpr>#sz3NonCallableMock.assert_has_calls.<locals>.<genexpr>z(Calls not found.
Expected: %r
Actual: %rz%r not all found in call list)
rrrQrSrr<remover&rr=)rbZcallsZ	any_orderrrZ	all_callsZ	not_foundZkallr)rbrrOs*
"	

z NonCallableMock.assert_has_callscsj||f}fddjD}||krt|trR|nd}j||}td||ndS)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)rbrrrAs	z3NonCallableMock.assert_any_call.<locals>.<listcomp>Nz%s call not found)rrZrrrr)rbr+r,rrrrr)rbrrP:s
zNonCallableMock.assert_any_callcKset|}t|tsNt|tr3t}q[t|tr[t}q[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
CallableMixinrrr
rr?)rbr_typeklassrrrrJs	
zNonCallableMock._get_child_mock)'rrrr5rr!rrrZ"_NonCallableMock__get_return_valueZ"_NonCallableMock__set_return_valueZ"_NonCallableMock__return_value_docryrUrrzrWrXrYrZrSZ!_NonCallableMock__get_side_effectZ!_NonCallableMock__set_side_effectr[rTrrhrcrrrrrrrMrNrOrPrrrrrr
ksL
(
	
		
#2"
#cCs[|dkr|St|r |St|r0|Syt|SWntk
rV|SYnXdS)N)rr;rr)rrrrr^s
rc@s^eZdZddeddddddddd
ZddZddZd	d
ZdS)rNrc
KsH||jd<tt|j|||||||	|
|||_dS)Nrm)r@rrr!r[)rbrr[rUrrIrrrrrr,rrrr!ps

zCallableMixin.__init__cOsdS)Nr)rbr+r,rrrr0}szCallableMixin._mock_check_sigcOs |j|||j||S)N)r0
_mock_call)r*r+r,rrrr$szCallableMixin.__call__cOs|}d|_|jd7_|j}|j}t||fdd}||_|jj||jjtd||ft	}|dk}|j
dk	}	|j}
x#|dk	rt|||f}|jr!d}|rd}nd}|jdkr
d}n|j||}n|	r||
kr<|}
nt|
||f}
|jj|
|j
dk	}	|	r|jd|
}
qn|jj||j}t
|}||krPn|j|qWt}|j}|dk	r^t|r|nt|sLt|}t|r0|n|tkrH|j}n|S|||}n|jdk	r|jtkr|j||S|tkr|j}n|S)NTr{tworz()rF)rWrXrrrp_CallrYrZrrSrjrorqrRrrxrr[rr;rrUrrm)r*r+r,rbrrrrZ
skip_next_dotZdo_method_callsrIZthis_mock_callrZthis_method_callZ_new_parent_idret_valZeffectrHrrrrsp														zCallableMixin._mock_call)rrrrr!r0r$rrrrrrns	rc@seZdZdZdS)ra	
    Create a new `Mock` object. `Mock` takes several optional arguments
    that specify the behaviour of the Mock object:

    * `spec`: This can be either a list of strings or an existing object (a
      class or instance) that acts as the specification for the mock object. If
      you pass in an object then a list of strings is formed by calling dir on
      the object (excluding unsupported magic attributes and methods). Accessing
      any attribute not in this list will raise an `AttributeError`.

      If `spec` is an object (rather than a list of strings) then
      `mock.__class__` returns the class of the spec object. This allows mocks
      to pass `isinstance` tests.

    * `spec_set`: A stricter variant of `spec`. If used, attempting to *set*
      or get an attribute on the mock that isn't on the object passed as
      `spec_set` will raise an `AttributeError`.

    * `side_effect`: A function to be called whenever the Mock is called. See
      the `side_effect` attribute. Useful for raising exceptions or
      dynamically changing return values. The function is called with the same
      arguments as the mock, and unless it returns `DEFAULT`, the return
      value of this function is used as the return value.

      If `side_effect` is an iterable then each call to the mock will return
      the next value from the iterable. If any of the members of the iterable
      are exceptions they will be raised instead of returned.

    * `return_value`: The value returned when the mock is called. By default
      this is a new Mock (created on first access). See the
      `return_value` attribute.

    * `wraps`: Item for the mock object to wrap. If `wraps` is not None then
      calling the Mock will pass the call through to the wrapped object
      (returning the real result). Attribute access on the mock will return a
      Mock object that wraps the corresponding attribute of the wrapped object
      (so attempting to access an attribute that doesn't exist will raise an
      `AttributeError`).

      If the mock has an explicit `return_value` set then calls are not passed
      to the wrapped object and the `return_value` is returned instead.

    * `name`: If the mock has a name then it will be used in the repr of the
      mock. This can be useful for debugging. The name is propagated to child
      mocks.

    Mocks can also be called with arbitrary keyword arguments. These will be
    used to set attributes on the mock after it is created.
    N)rrrr5rrrrrs1cCsAyt||SWn)tk
r<t|t||SYnXdS)N)r:r"
__import__)thingcompimport_pathrrr_dot_lookups


rcCs_|jd}|jd}t|}x.|D]&}|d|7}t|||}q1W|S)Nrrz.%s)rrrr)targetZ
componentsrrrrrr	_importers
rcCs
t|dS)Nis_local)hasattr)patcherrrr_is_startedsrc@seZdZdZgZddZddZddZdd	Zd
dZ	dd
Z
ddZddZddZ
ddZdS)_patchNc

Cs|dk	rE|tk	r'tdn|dk	rEtdqEn||_||_||_||_||_||_d|_||_	||_
|	|_g|_dS)Nz,Cannot use 'new' and 'new_callable' togetherz1Cannot use 'autospec' and 'new_callable' togetherF)
rr&getterrrnew_callablercreateZ	has_localrautospecr,additional_patchers)
rbrrrrrrrrr,rrrr!%s$										z_patch.__init__c
Csht|j|j|j|j|j|j|j|j|j		}|j
|_
dd|jD|_|S)NcSsg|]}|jqSr)copy)rprrrrHs	z_patch.copy.<locals>.<listcomp>)rrrrrrrrrr,attribute_namer)rbrrrrr@sz_patch.copycCs)t|tr|j|S|j|S)N)rrdecorate_classdecorate_callable)rbr'rrrr$Ms
z_patch.__call__cCsyxrt|D]d}|jtjs+q
nt||}t|dsOq
n|j}t||||q
W|S)Nr$)rrrTEST_PREFIXr:rrru)rbrattr
attr_valuerrrrrSsz_patch.decorate_classcsTtdr#jj|Stfdd|g_S)N	patchingscsg}g}t}zyxhjD]]}|j}|j||jdk	rc|j|q%|jtkr%|j|q%q%W|t|7}||SWn?||krt|r|j|nt	j
}YnXWdx!t|D]}|j|qWXdS)N)
r=r	__enter__rrupdaterrrsysexc_infor__exit__)r+Zkeywargs
extra_argsZentered_patchersr	patchingr)r'patchedrrr
fs*	
z)_patch.decorate_callable.<locals>.patched)rrrr)rbr'r)r'r
rras!z_patch.decorate_callablecCs|j}|j}t}d}y|j|}Wn*ttfk
r^t||t}YnXd}|jr|tkrtd||fn||fS)NFTz!%s does not have the attribute %r)rrrr@r"KeyErrorr:r)rbrrIrGlocalrrrget_originals	z_patch.get_originalcCs|j|j|j}}}|j|j}}|j}|j|_|dkr]d}n|dkrrd}n|dkrd}n|dk	r|dk	rtdn|dk	s|dk	r|dkrtdn|j	\}}|t
kr\|dkr\d}	|dkrA|}|dkr|}d}qn?|dk	rk|dkr|}d}qn|dkr|}n|dk	s|dk	r|t
krtdnt|trd}	qnt
}
i}|dk	r|}
nm|dk	s|dk	r\|}|dk	r"|}nt|r=d|k}
n
t|}
|
r\t}
q\n|dk	ru||d<n|dk	r||d	<nt|
trt|
tr|jr|j|d
<n|j||
|}|	rt|r|}|dk	r|}nt|r.t|r.t}
n|jd
|
d|dd
||_qn|dk	r|t
k	rtdn|t
krtdnt|}|dkr|}nt|d	|d|j|}n|rtdn|}||_||_t|j|j||jdk	ri}|jt
krW|||j<nx<|jD]1}|j }|jt
kra|j|qaqaW|S|S)zPerform the patch.FNzCan't specify spec and autospecTz6Can't provide explicit spec_set *and* spec or autospecz!Can't use 'spec' with create=Truer$rrrIrrz()zBautospec creates the mock for you. Can't specify autospec and new.z%Can't use 'autospec' with create=True_namez.Can't pass kwargs to a mock we aren't creating)TN)!rrrrr,rrrrrrrrrr>rrrr
rrrrCrrUboolr
temp_originalrrurrr)rbrrrrr,rrGrZinheritKlass_kwargsZ	this_specZnot_callableZnew_attrrrrrrrrs							



	

	
			z_patch.__enter__cGst|stdn|jrO|jtk	rOt|j|j|jnOt|j|j|j	rt
|j|jrt|j|j|jn|`|`|`x3t|jD]"}t|r|j
|qqWdS)zUndo the patch.z stop called on unstarted patcherN)rRuntimeErrorrrrrurrrrrrrr
)rbr	rrrrr
s z_patch.__exit__cCs |j}|jj||S)z-Activate a patch, returning any created mock.)r_active_patchesr)rbrHrrrstart1sz_patch.startcCs3y|jj|Wntk
r(YnX|jS)zStop an active patch.)rrr&r
)rbrrrstop8s

z_patch.stop)rrrrrr!rr$rrrrr
rrrrrrr s
(~rcsfyjdd\}Wn+ttfk
rItdfYnXfdd}||fS)Nrr{z.Need a valid target to patch. You supplied: %rcs
tS)N)rr)rrrrJsz_get_target.<locals>.<lambda>)rsplitrr&)rrrr)rr_get_targetDsrc

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)rrrr`sz_patch_object.<locals>.<lambda>)r)
rrrrrrrrr,rr)rr
_patch_objectNsrc
sttkr'fdd}nfdd}|sNtdnt|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)rrrr~sz!_patch_multiple.<locals>.<lambda>csS)Nrr)rrrrsz=Must supply at least one keyword argument with patch.multiplerr{N)	rstrr&r<rrrrr)
rrrrrrr,rrrrrZthis_patcherr)rr_patch_multiplegs&		rc

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.
    )rr)
rrrrrrrr,rrrrrrsEc@s|eZdZdZfdddZddZddZd	d
ZddZd
dZ	ddZ
eZe
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.
    FcKs\t|trt|}n||_t||_|jj|||_d|_dS)N)	rrrin_dictrirrclear	_original)rbr rr!r,rrrr!s		z_patch_dict.__init__csAttrjStfdd}|S)Nc
s-jz||SWdjXdS)N)r
_unpatch_dict)r+r)frbrr_inners
z$_patch_dict.__call__.<locals>._inner)rrrr)rbr$r%r)r$rbrr$s
!z_patch_dict.__call__cCsx~t|D]p}t||}|jtjr
t|dr
t|j|j|j	}||}t
|||q
q
W|S)Nr$)rr:rrrrrr rr!ru)rbrrrZ	decoratorZ	decoratedrrrrsz_patch_dict.decorate_classcCs|jdS)zPatch the dict.N)r)rbrrrr%sz_patch_dict.__enter__cCs|j}|j}|j}y|j}Wn7tk
rdi}x|D]}||||<qHWYnX||_|rt|ny|j|Wn1tk
rx|D]}||||<qWYnXdS)N)rr r!rr"r"_clear_dictr)rbrr r!rGrrrrr*s"			

	


z_patch_dict._patch_dictcCse|j}|j}t|y|j|Wn1tk
r`x|D]}||||<qDWYnXdS)N)r r"r&rr")rbr rGrrrrr#Ds		


z_patch_dict._unpatch_dictcGs|jdS)zUnpatch the dict.F)r#)rbr+rrrr
Qs
z_patch_dict.__exit__N)
rrrr5r!r$rrrr#r
rrrrrrrs
rcCsKy|jWn6tk
rFt|}x|D]
}||=q1WYnXdS)N)r!r"r<)r keysrrrrr&Zs

r&cCs(x!ttjD]}|jqWdS)z7Stop all active patches. LIFO to unroll nested patches.N)rrrr)rrrr_patch_stopallcsr(Ztestzlt le gt ge eq ne getitem setitem delitem len contains iter hash str sizeof enter exit divmod rdivmod neg pos abs invert complex int float index trunc floor ceil bool next zAadd sub mul div floordiv mod lshift rshift and xor or pow truediv ccs|]}d|VqdS)zi%sNr)rnrrrrsrccs|]}d|VqdS)zr%sNr)rr*rrrrsccs|]}d|VqdS)z__%s__Nr)rmethodrrrrsrArjZdeleterZmissingreduceZ	reduce_exZgetinitargsZ
getnewargsgetstatesetstateZ	getformatZ	setformatreprrZ
subclassesformatcsfdd}||_|S)z:Turns a callable object (like a mock) into a real functioncs|||S)Nr)rbr+r)r'rrr+sz_get_method.<locals>.method)r)rIr'r+r)r'rrs	rccs|]}d|VqdS)z__%s__Nr)rr+rrrrsrhrr!rZ__prepare____instancecheck____subclasscheck____del__cCs
tj|S)N)r__hash__)rbrrrrsrr3cCs
tj|S)N)r__str__)rbrrrrsr4cCs
tj|S)N)r
__sizeof__)rbrrrrsr5__lt____gt____le____ge__r{__int__r|__len__r
y?__complex__g?	__float____bool__	__index__csfdd}|S)Ncs&jj}|tk	r|S|kS)N)__eq__rmr)otherr)rbrrr@sz_get_eq.<locals>.__eq__r)rbr@r)rbr_get_eqsrBcsfdd}|S)Ncs jjtk	rtS|k	S)N)__ne__rmr)rA)rbrrrCsz_get_ne.<locals>.__ne__r)rbrCr)rbr_get_nesrDcsfdd}|S)Ncs,jj}|tkr"tgSt|S)N)rrmrr)r)rbrrrs
z_get_iter.<locals>.__iter__r)rbrr)rbr	_get_itersrEr@rCrcCstj|t}|tk	r+||_dStj|}|dk	ry||}Wntk
rvt|}YnX||_dStj|}|dk	r|||_ndS)N)_return_valuesrArrU_calculate_return_valuer"_side_effect_methodsr[)r1r+rIZfixedZreturn_calulatorrUZ
side_effectorrrr_set_return_values	
	rIc@s(eZdZddZddZdS)
MagicMixincOs1|jtt|j|||jdS)N)_mock_set_magicsrrJr!)rbr+rrrrr!s
zMagicMixin.__init__cCst}t|dddk	r|tj|j}t}t|}x6|D]+}|t|jkrJt||qJqJWn|tt|j}t|}x'|D]}t||t	||qWdS)Nr)
_magicsr:intersectionrrjrr@rru
MagicProxy)rbZthese_magicsZ
remove_magicsrrrrrrKs	


zMagicMixin._mock_set_magicsN)rrrr!rKrrrrrJsrJc@s%eZdZdZdddZdS)rz-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)rrK)rbrrrrrrsz"NonCallableMagicMock.mock_add_specN)rrrr5rrrrrrs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)rrK)rbrrrrrr(szMagicMock.mock_add_specN)rrrr5rrrrrrs
c@sCeZdZddZddZddZddd	ZdS)
rNcCs||_||_dS)N)rIr)rbrIrrrrr!4s	zMagicProxy.__init__cOs|j}|||S)N)create_mock)rbr+r,mrrrr$8szMagicProxy.__call__cCsT|j}|j}|jd|d|d|}t|||t||||S)NrIrr)rIrrrurI)rbrrrPrrrrO<s			zMagicProxy.create_mockNcCs
|jS)N)rO)rbrrrrr__get__EszMagicProxy.__get__)rrrr!r$rOrQrrrrrN3s	rNc@s:eZdZdZddZddZddZdS)	_ANYz2A helper object that compares equal to everything.cCsdS)NTr)rbrArrrr@Msz_ANY.__eq__cCsdS)NFr)rbrArrrrCPsz_ANY.__ne__cCsdS)Nz<ANY>r)rbrrrrcSsz
_ANY.__repr__N)rrrr5r@rCrcrrrrrRJsrRcCsd|}d}djdd|D}djdd|jD}|r]|}n|r|rv|d7}n||7}n||S)Nz%s(%%s)rz, cSsg|]}t|qSr)r/)rrrrrr]s	z*_format_call_signature.<locals>.<listcomp>cSs&g|]\}}d||fqS)z%s=%rr)rrrkrrrr_s	)rr)rIr+r,rZformatted_argsZargs_stringZ
kwargs_stringrrrrZs
	

rc@seZdZdZfddddddZfddddddZd	d
ZddZd
dZddZ	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.
    NFTcCsd}f}i}t|}|dkr<|\}}}n|dkr|\}	}
t|	tr|	}t|
tr|
}q|
}q|	|
}}nN|dkr|\}t|tr|}qt|tr|}q|}n|rtj|||fStj||||fS)Nrrr^r{)r}rrr=r)rrkrIrr	from_kallr+r,_lenfirstsecondrrrrs0						z
_Call.__new__cCs||_||_||_dS)N)rIrrS)rbrkrIrrrSrrrr!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)NTFrr^rrr{)rr}rrr=r)rbrAZ	len_otherZ	self_nameZ	self_argsZself_kwargsZ
other_nameZ
other_argsZother_kwargsrkrUrVrrrr@sJ
				z_Call.__eq__cCs|j|S)N)r@)rbrArrrrCsz_Call.__ne__cOsW|jdkr(td||fddS|jd}t|j||fd|d|S)NrrIz()r)rIr)rbr+r,rIrrrr$s
z_Call.__call__cCsN|jdkr"td|ddSd|j|f}td|d|ddS)NrIrSFz%s.%sr)rIr)rbrrIrrrrhsz_Call.__getattr__cCs|js8|jpd}|jdr4d|}n|St|dkr_d}|\}}nD|\}}}|s}d}n&|jdsd|}n
d|}t|||S)Nrz()zcall%sr^zcall.%s)rSrIrr}r)rbrIr+r,rrrrcs	
	

z_Call.__repr__cCsQg}|}x2|dk	r@|jr4|j|n|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)rSrrrQr)rbvalsrrrr	call_lists	
z_Call.call_list)rrrr5rr!r@rCr$rhrcrXrrrrrls 3rrScKst|rt|}nt|t}i|d6}|rMi|d6}n|dkrbi}n|r{|r{d|d<n|j|t}t|tkri}n7t|st}n"|r|rt|rt}n|j	d|}|}	|dkr
d}	n|d|d	|d
|	d||}
t|t
rRt|
|}
nt||
|||dk	r|r|
|j
|<n|r|rd|krt||ddd
dd|
|
_nxNt|D]@}t|rqnyt||}Wntk
rwYnXi|d6}|r;i|d6}nt|t
srt|||
||}
|
|
j
|<n|
}t|t
r|
j}nt|||}||d<td|d|d
|d	||}
|
|
j
|<t||
d|t|
t
rt|
||
qqW|
S)aICreate a mock object using another object as a spec. Attributes on the
    mock will use the corresponding attribute on the `spec` object as their
    spec.

    Functions or methods being mocked will have their arguments checked
    to check that they are called with the correct signature.

    If `spec_set` is True then attempting to set attributes that don't exist
    on the spec object will raise an `AttributeError`.

    If a class is used as a spec then the return value of the mock (the
    instance of the class) will have the same spec. You can use a class as the
    spec for an instance object by passing `instance=True`. The returned mock
    will only be callable if instances of the mock are callable.

    `create_autospec` also takes arbitrary keyword arguments that are passed to
    the constructor of the created mock.rrNTrrIrrrrrUr3rz()rrr2)r>rrrrDescriptorTypesr;rrCrr#rLr4r\rrUrr`r:r"rr1
_must_skipru)rrr3rrr,is_typerrrr1rrGrrr2rrrrst
	

				


	
cCst|ts7|t|dikr+dS|j}nxt|jD]i}|jj|t}|tkrnqAnt|tt	frdStt|ddt
r|SdSqAW|S)z[
    Return whether we should skip the first argument on spec's `entry`
    attribute.
    r@FrQN)rrr:rr?r@rArstaticmethodclassmethodMethodWrapperTypes)rrr[rrHrrrrZsrZcCs.y|jSWntk
r)t|SYnXdS)N)rr"r)rrrrrs
rc@s+eZdZdddddddZdS)rFNcCs:||_||_||_||_||_||_dS)N)ridsrrr3rI)rbrrrrIr_r3rrrr!s					z_SpecState.__init__)rrrr!rrrrrsrc#st|trdndfdd|jD}|dkr`|dd}n|ddd	|d
<x|D]}|VqWdS)Ns

csg|]}|qSrr)rl)seprrrs	z&_iterate_read_data.<locals>.<listcomp>r{rcrcrcrc)rbytesr)	read_dataZdata_as_listliner)rbr_iterate_read_datas"
rgrcswfdd}fdd}fddtdkrddl}ttt|jjtt|jan|dkrtd	d
dt	}ntdtj
_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)	readlinesrUr<)r+r,)_statehandlerr_readlines_side_effects
z)mock_open.<locals>._readlines_side_effectcs6jjdk	rjjStjdS)Nr)readrUrr)r+r,)rirjrerr_read_side_effects
z$mock_open.<locals>._read_side_effectc3sEjjdk	r'xjjVqWnxdD]}|Vq2WdS)Nr)readlinerU)rf)rirjrr_readline_side_effects
z(mock_open.<locals>._readline_side_effectNrrIopenrr{csJtd<jjdkrFd<dj_ntS)Nrr{)rgrnr[r)r+r,)rorirjrerr
reset_data	s

zmock_open.<locals>.reset_data)	file_spec_ior<rjr
TextIOWrapperunionBytesIOrrprrUrgwriterlrnrhr[)r1rerkrmrsrqr)rorirjrerrs.	6
		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)rbr,rrrr*	szPropertyMock._get_child_mockcCs|S)Nr)rbrZobj_typerrrrQ-	szPropertyMock.__get__cCs||dS)Nr)rbrrrrr__set__/	szPropertyMock.__set__N)rrrr5rrQrxrrrrr
!	s)o__all____version__r%rr	functoolsrr
BaseExceptionrplatformrZlangZ	Throwabler	superrrrrrrrryrYr(r4r/r;r>rCrLrFr`rardrrZMISSINGrZDELETEDrrlrjrwrzr<rQrrrr
rrrrrrrrrrrrr&r(riZmultipleZstopallrZ
magic_methodsZnumericsrrZinplacerightZ
_non_defaultsrrLrrrGNotImplementedrFrBrDrErHrIrJrrrNrRrrr=rrrrZrrr@r#rQr^rrrgrr
rrrr<module>s			 +							e5%		1	Jv						""	(
	





		w	B