Your IP : 216.73.216.196


Current Path : /opt/alt/python27/lib/python2.7/site-packages/_pytest/
Upload File :
Current File : //opt/alt/python27/lib/python2.7/site-packages/_pytest/recwarn.pyc

�
�mYc@`s�dZddlmZmZmZddlZddlZddlZddl	Z	ddl
Z
ddlmZed��Z
dd�Zd�Zde
jfd	��YZd
efd��YZdS(s4 recording warnings during test function execution. i(tabsolute_importtdivisiontprint_functionN(t
yield_fixturecc`s,t�}|�tjd�|VWdQXdS(sReturn a WarningsRecorder instance that provides these methods:

    * ``pop(category=None)``: return last warning matching the category.
    * ``clear()``: clear list of warnings

    See http://docs.python.org/library/warnings.html for information
    on warning categories.
    tdefaultN(tWarningsRecordertwarningstsimplefilter(twrec((s@/opt/alt/python27/lib/python2.7/site-packages/_pytest/recwarn.pytrecwarn
s
	
c	`s�|stdt�Sg��fd�}d�fd�}tj}tj}|t_|t_z|||�}Wd|t_|t_Xttf�t�fd��D��s�t}t	d|f��n|S(sg assert that calling ``func(*args, **kwargs)`` triggers a
    ``DeprecationWarning`` or ``PendingDeprecationWarning``.

    This function can be used as a context manager::

        >>> import warnings
        >>> def api_call_v2():
        ...     warnings.warn('use v3 of this api', DeprecationWarning)
        ...     return 200

        >>> with deprecated_call():
        ...    assert api_call_v2() == 200

    Note: we cannot use WarningsRecorder here because it is still subject
    to the mechanism that prevents warnings of the same type from being
    triggered twice for the same module. See #1190.
    texpected_warningc`s�j|�dS(N(tappend(tmessagetcategorytargstkwargs(t
categories(s@/opt/alt/python27/lib/python2.7/site-packages/_pytest/recwarn.pyt
warn_explicit4sc`s3t|t�r"�j|j�n
�j|�dS(N(t
isinstancetWarningRt	__class__(RR
RR(R(s@/opt/alt/python27/lib/python2.7/site-packages/_pytest/recwarn.pytwarn7sNc3`s|]}t|��VqdS(N(t
issubclass(t.0tc(tdeprecation_categories(s@/opt/alt/python27/lib/python2.7/site-packages/_pytest/recwarn.pys	<genexpr>Gss%%r did not produce DeprecationWarning(
tWarningsCheckertDeprecationWarningtNoneRRRtPendingDeprecationWarningtanytTruetAssertionError(	tfuncRRRRtold_warntold_warn_explicittrett__tracebackhide__((RRs@/opt/alt/python27/lib/python2.7/site-packages/_pytest/recwarn.pytdeprecated_calls$
					
cO`s�t|�}|s|St|dt�r�|\}t|t�sGt�tjd�}|jj�}|j|�|�6t	j
j|�j�}t
jj||j|�WdQXn(|d}|�||d|�SWdQXdS(sGAssert that code raises a particular class of warning.

    Specifically, the input @expected_warning can be a warning class or
    tuple of warning classes, and the code must return that warning
    (if a single class) or one of those warnings (if a tuple).

    This helper produces a list of ``warnings.WarningMessage`` objects,
    one for each warning raised.

    This function can be used as a context manager, or any of the other ways
    ``pytest.raises`` can be used::

        >>> with warns(RuntimeWarning):
        ...    warnings.warn("my warning", RuntimeWarning)
    iiN(RRtstrR tsyst	_getframetf_localstcopytupdatet_pytestt_codetSourcetcompiletpytbuiltintexec_t	f_globals(R
RRtwchecktcodetframetlocR!((s@/opt/alt/python27/lib/python2.7/site-packages/_pytest/recwarn.pytwarnsMs	
"
RcB`sheZdZd�Zed��Zd�Zd�Zd�Ze	d�Z
d�Zd�Zd	�Z
RS(
s^A context manager to record raised warnings.

    Adapted from `warnings.catch_warnings`.
    cC`s/tt|�jdt�t|_g|_dS(Ntrecord(tsuperRt__init__RtFalset_enteredt_list(tself((s@/opt/alt/python27/lib/python2.7/site-packages/_pytest/recwarn.pyR<vs	cC`s|jS(sThe list of recorded warnings.(R?(R@((s@/opt/alt/python27/lib/python2.7/site-packages/_pytest/recwarn.pytlist{scC`s|j|S(s Get a recorded warning by index.(R?(R@ti((s@/opt/alt/python27/lib/python2.7/site-packages/_pytest/recwarn.pyt__getitem__�scC`s
t|j�S(s&Iterate through the recorded warnings.(titerR?(R@((s@/opt/alt/python27/lib/python2.7/site-packages/_pytest/recwarn.pyt__iter__�scC`s
t|j�S(s The number of recorded warnings.(tlenR?(R@((s@/opt/alt/python27/lib/python2.7/site-packages/_pytest/recwarn.pyt__len__�scC`s\x?t|j�D].\}}t|j|�r|jj|�SqWt}td|��dS(s>Pop the first recorded warning, raise exception if not exists.s%r not found in warning listN(t	enumerateR?RR
tpopRR (R@tclsRBtwR%((s@/opt/alt/python27/lib/python2.7/site-packages/_pytest/recwarn.pyRI�s
cC`sg|j(dS(s$Clear the list of recorded warnings.N(R?(R@((s@/opt/alt/python27/lib/python2.7/site-packages/_pytest/recwarn.pytclear�scC`sK|jr"t}td|��ntt|�j�|_tjd�|S(NsCannot enter %r twicetalways(	R>RtRuntimeErrorR;Rt	__enter__R?RR(R@R%((s@/opt/alt/python27/lib/python2.7/site-packages/_pytest/recwarn.pyRO�s	
cG`s<|js"t}td|��ntt|�j|�dS(Ns%Cannot exit %r without entering first(R>RRNR;Rt__exit__(R@texc_infoR%((s@/opt/alt/python27/lib/python2.7/site-packages/_pytest/recwarn.pyRP�s	(t__name__t
__module__t__doc__R<tpropertyRARCRERGRRIRLRORP(((s@/opt/alt/python27/lib/python2.7/site-packages/_pytest/recwarn.pyRps						RcB`seZdd�Zd�ZRS(cC`s�tt|�j�d}t|t�rdxy|D].}tj|�s/t|t|���q/q/Wn@tj|�r|f}n%|dk	r�t|t|���n||_
dS(NsDexceptions must be old-style classes or derived from Warning, not %s(R;RR<Rttupletinspecttisclasst	TypeErrorttypeRR
(R@R
tmsgtexc((s@/opt/alt/python27/lib/python2.7/site-packages/_pytest/recwarn.pyR<�s
 c`s�tt��j|�td�|D��r��jdk	r�t�fd��D��s�t}ddlm	}|dj
�jg�D]}|j^q���q�q�ndS(Ncs`s|]}|dkVqdS(N(R(Rta((s@/opt/alt/python27/lib/python2.7/site-packages/_pytest/recwarn.pys	<genexpr>�sc3`s$|]}t|j�j�VqdS(N(RR
R
(Rtr(R@(s@/opt/alt/python27/lib/python2.7/site-packages/_pytest/recwarn.pys	<genexpr>�si(tfailsXDID NOT WARN. No warnings of type {0} was emitted. The list of emitted warnings is: {1}.(R;RRPtallR
RRRt_pytest.runnerR_tformatR(R@RQR%R_teach((R@s@/opt/alt/python27/lib/python2.7/site-packages/_pytest/recwarn.pyRP�s
	N(RRRSRR<RP(((s@/opt/alt/python27/lib/python2.7/site-packages/_pytest/recwarn.pyR�s(RTt
__future__RRRRWt
_pytest._codeR-R1R(Rt_pytest.fixturesRR	RR&R9tcatch_warningsRR(((s@/opt/alt/python27/lib/python2.7/site-packages/_pytest/recwarn.pyt<module>s0	#7