B
    KLc4                 @   sx  d dl Z d dlZd dlZd dlZddlmZ ddlmZ ddlmZ ddlm	Z	 d<dd	Z
d=d
dZG dd deZdd Zdd Zd>ddZd?ddZG dd deZG dd deZG dd deZG dd deZG dd deZG d d! d!eZejZd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd@d,d-Zed.d/ Z dAd0d1Z!d2d3 Z"dBd4d5Z#dCd6d7Z$dDd8d9Z%d:d; Z&dS )E    N   )config   )util)	decorator)inspect_getfullargspecc             C   s    t  }t| |}|j| |S )N)compound_as_predicateskipsadd)	predicatereasonrulepred r   <lib/python3.7/site-packages/sqlalchemy/testing/exclusions.pyskip_if   s    
r   c             C   s    t  }t| |}|j| |S )N)r   r	   failsr   )r   r   r   r   r   r   r   fails_if   s    
r   c               @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zedd Z	dd Z
dd Zdd Zdd Zdd Zejdd Zdd Zd!ddZd"ddZd S )#r   c             C   s   t  | _t  | _t  | _d S )N)setr   r
   tags)selfr   r   r   __init__#   s    zcompound.__init__c             C   s
   |  |S )N)r   )r   otherr   r   r   __add__(   s    zcompound.__add__c             C   s4   t  }|j| j |j| j |j| j |S )N)r   r
   updater   r   )r   r   r   r   r   as_skips+   s
    zcompound.as_skipsc             G   sl   t  }|j| j |j| j |j| j x6|D ].}|j|j |j|j |j|j q6W |S )N)r   r   r   r
   r   )r   Zotherscopyr   r   r   r   r   2   s    
zcompound.addc             C   sH   t  }|jdd | jD  |jdd | jD  |j| j |S )Nc             s   s   | ]}t |V  qd S )N)NotPredicate).0failr   r   r   	<genexpr>?   s    z compound.not_.<locals>.<genexpr>c             s   s   | ]}t |V  qd S )N)r   )r   skipr   r   r   r!   @   s    )r   r   r   r
   r   )r   r   r   r   r   not_=   s
    zcompound.not_c             C   s   |  tjS )N)enabled_for_configr   _current)r   r   r   r   enabledD   s    zcompound.enabledc             C   s,   x&| j | jD ]}||rdS qW dS d S )NFT)r
   unionr   )r   r   r   r   r   r   r$   H   s    zcompound.enabled_for_configc                s    fdd| j | jD S )Nc                s   g | ]}| r|  qS r   )
_as_string)r   r   )r   r   r   
<listcomp>Q   s   z4compound.matching_config_reasons.<locals>.<listcomp>)r
   r'   r   )r   r   r   )r   r   matching_config_reasonsO   s    
z compound.matching_config_reasonsc             C   s$   t | j| o | p | j|S )N)boolr   intersection)r   Zinclude_tagsZexclude_tagsr   r   r   include_testV   s    zcompound.include_testc             C   s.   | j |j  | j|j | j|j d S )N)r
   r   r   r   )r   r   r   r   r   _extend\   s    zcompound._extendc                s<   t |dr|j  |S t fdd}||} |_|S )N_sa_exclusion_extendc                s    j tj| f||S )N)_dor   r%   )fnargskw)r   r   r   decoratef   s    z#compound.__call__.<locals>.decorate)hasattrr/   r.   r   )r   r1   r4   Z	decoratedr   )r   r   __call__a   s    
zcompound.__call__c          
   c   sh   t  }|j| j| j y
d V  W n0 tk
rV } z|tj| W d d }~X Y nX |	tj d S )N)
r   r   r   r
   r'   	Exception_expect_failurer   r%   _expect_success)r   Z	all_failsexr   r   r   fail_ifn   s    
 zcompound.fail_ifc       	   
   O   s   x6| j D ],}||rdt ||f }t| qW y|||}W n4 tk
rz } z| j|||jd W d d }~X Y nX | j||jd |S d S )Nz	'%s' : %s)name)	r
   r   Zget_current_test_namer(   Z	skip_testr7   r8   __name__r9   )	r   Zcfgr1   r2   r3   r"   msgZreturn_valuer:   r   r   r   r0   z   s    $zcompound._doblockc             C   sn   xh| j D ]H}||rtjr.t|jddd}nt|}td||||f  P qW tj|t	
 d d d S )Nzutf-8ignore)errorsz%s failed as expected (%s): %s r   )with_traceback)r   r   Zpy2kZunicodeencodestrprintr(   Zraise_sysexc_info)r   r   r:   r<   r    Zstr_exr   r   r   r8      s    zcompound._expect_failurec          	      sL   | j s
d S x<| j D ]2}| rtd|d fdd| j D f qW d S )Nz Unexpected success for '%s' (%s)z and c             3   s   | ]}|  V  qd S )N)r(   )r   r    )r   r   r   r!      s    z+compound._expect_success.<locals>.<genexpr>)r   AssertionErrorjoin)r   r   r<   r    r   )r   r   r9      s    zcompound._expect_successN)r?   )r?   )r=   
__module____qualname__r   r   r   r   r#   propertyr&   r$   r*   r-   r.   r6   
contextlibcontextmanagerr;   r0   r8   r9   r   r   r   r   r   "   s   
r   c             C   s
   t | gS )N)r   )Ztagnamer   r   r   requires_tag   s    rO   c             C   s   t  }|j|  |S )N)r   r   r   )Ztagnamescompr   r   r   r      s    r   c             C   s   t | } tt| |S )N)r	   r   r   )r   r   r   r   r   only_if   s    rQ   c             C   s   t | } tt| |S )N)r	   r   r   )r   r   r   r   r   succeeds_if   s    rR   c               @   s.   e Zd Zed	ddZd
ddZdddZdS )	PredicateNc                s  t |tr |j|S t |tr:|r6|jd kr6||_|S t |ttfr`t fdd|D |S t |t	rrt
| S t |tjrtd|}|std| |d}|d}|drt	dd	 |dd
D nd }t
||||dS t| rt||S dstd| d S )Nc                s   g | ]}  |qS r   )as_predicate)r   r   )clsr   r   r)      s    z*Predicate.as_predicate.<locals>.<listcomp>z.([\+\w]+)\s*(?:(>=|==|!=|<=|<|>)\s*([\d\.]+))?z(Couldn't locate DB name in predicate: %rr   r      c             s   s   | ]}t |V  qd S )N)int)r   dr   r   r   r!      s    z)Predicate.as_predicate.<locals>.<genexpr>.)descriptionFzunknown predicate type: %s)
isinstancer   rT   r$   rS   rZ   listr   OrPredicatetupleSpecPredicater   Zstring_typesrematch
ValueErrorgroupsplitcallableLambdaPredicaterH   )rU   r   rZ   tokensdbopspecr   )rU   r   rT      s2    





(

zPredicate.as_predicateFc             C   sV   | |}|r| }| j |r&|jj nd|r8|jj nd|rBdnd|rLdndd S )Nz<no driver>z<no database>zdoesn't supportzdoes support)driverZdatabaseZdoesnt_supportZdoes_support)rZ   rh   ZurlZget_driver_nameZget_backend_name)r   r   negateZbool_r   r   r   _format_description   s    
zPredicate._format_descriptionc             C   s
   t  d S )N)NotImplementedError)r   r   rl   r   r   r   r(      s    zPredicate._as_string)N)F)NF)r=   rJ   rK   classmethodrT   rm   r(   r   r   r   r   rS      s   #
rS   c               @   s(   e Zd Zd	ddZdd Zd
ddZdS )BooleanPredicateNc             C   s   || _ |pd| | _d S )Nz
boolean %s)valuerZ   )r   rq   rZ   r   r   r   r      s    zBooleanPredicate.__init__c             C   s   | j S )N)rq   )r   r   r   r   r   r6      s    zBooleanPredicate.__call__Fc             C   s   | j ||dS )N)rl   )rm   )r   r   rl   r   r   r   r(     s    zBooleanPredicate._as_string)N)F)r=   rJ   rK   r   r6   r(   r   r   r   r   rp      s   
rp   c            	   @   sP   e Zd ZdddZejejejejej	ej
ejdd dZdd Zdd
dZdS )r_   Nc             C   s   || _ || _|| _|| _d S )N)rh   ri   rj   rZ   )r   rh   ri   rj   rZ   r   r   r   r     s    zSpecPredicate.__init__c             C   s   | |d ko| |d kS )Nr   r   r   )valZpairr   r   r   <lambda>      zSpecPredicate.<lambda>)<>z==z!=z<=z>=inZbetweenc             C   s   |d krdS |j }d| j kr.| j d\}}n| j d  }}|rL|j|krLdS |d k	rb|j|krbdS | jd k	r|d ks|tdt|}t| jdr| jp| j| j }||| j	S dS d S )NF+z%DBAPI version specs not supported yetr6   T)
rh   rd   r<   rk   ri   rH   _server_versionr5   _opsrj   )r   r   enginedialectrk   versionZoperr   r   r   r6     s     

zSpecPredicate.__call__Fc             C   sh   | j d k	r| |S | jd kr8|r,d| j S d| j S n,|rPd| j| j| jf S d| j| j| jf S d S )Nznot %sz%sznot %s %s %sz%s %s %s)rZ   rm   ri   rh   rj   )r   r   rl   r   r   r   r(   4  s    



zSpecPredicate._as_string)NNN)F)r=   rJ   rK   r   operatorltgteqnelegecontainsrz   r6   r(   r   r   r   r   r_     s   
r_   c               @   s(   e Zd Zd	ddZdd Zd
ddZdS )rf   Nc                s`   t  }|d s  fdd| _n | _|p,d| _|p6i | _|rF|| _n jrV j| _nd| _d S )Nr   c                s     S )Nr   )rh   )lambda_r   r   rs   G  rt   z*LambdaPredicate.__init__.<locals>.<lambda>r   zcustom function)r   r   r2   r3   rZ   __doc__)r   r   rZ   r2   r3   rj   r   )r   r   r   D  s    


zLambdaPredicate.__init__c             C   s
   |  |S )N)r   )r   r   r   r   r   r6   S  s    zLambdaPredicate.__call__Fc             C   s
   |  |S )N)rm   )r   r   rl   r   r   r   r(   V  s    zLambdaPredicate._as_string)NNN)F)r=   rJ   rK   r   r6   r(   r   r   r   r   rf   C  s   
rf   c               @   s(   e Zd Zd	ddZdd Zd
ddZdS )r   Nc             C   s   || _ || _d S )N)r   rZ   )r   r   rZ   r   r   r   r   [  s    zNotPredicate.__init__c             C   s   |  | S )N)r   )r   r   r   r   r   r6   _  s    zNotPredicate.__call__Fc             C   s(   | j r| || S | j|| S d S )N)rZ   rm   r   r(   )r   r   rl   r   r   r   r(   b  s    zNotPredicate._as_string)N)F)r=   rJ   rK   r   r6   r(   r   r   r   r   r   Z  s   
r   c               @   s:   e Zd ZdddZdd ZdddZd	d
 ZdddZdS )r]   Nc             C   s   || _ || _d S )N)
predicatesrZ   )r   r   rZ   r   r   r   r   j  s    zOrPredicate.__init__c             C   s    x| j D ]}||rdS qW dS )NTF)r   )r   r   r   r   r   r   r6   n  s    zOrPredicate.__call__Fc                s*   r
d}nd}|  fdd| jD S )Nz and z or c             3   s   | ]}|j  d V  qdS ))rl   N)r(   )r   p)r   rl   r   r   r!   z  s    z(OrPredicate._eval_str.<locals>.<genexpr>)rI   r   )r   r   rl   Zconjunctionr   )r   rl   r   	_eval_strt  s
    zOrPredicate._eval_strc             C   s*   | j d k	rd| | S | j|ddS d S )NzNot T)rl   )rZ   rm   r   )r   r   r   r   r   _negation_str}  s    
zOrPredicate._negation_strc             C   s0   |r|  |S | jd k	r"| |S | |S d S )N)r   rZ   rm   r   )r   r   rl   r   r   r   r(     s
    


zOrPredicate._as_string)N)F)F)r=   rJ   rK   r   r6   r   r   r(   r   r   r   r   r]   i  s
   

	r]   c             C   s   t | ||tjS )N)r_   r   r%   )rh   ri   rj   r   r   r   _is_excluded  s    r   c             C   s.   |   }t| jdd}|dkr"d}|  |S )z#Return a server_version_info tuple.Zserver_version_infoNr   )Zconnectgetattrr|   close)r{   Zconnr}   r   r   r   ry     s    ry   c              G   s   t dd | D S )Nc             S   s   g | ]}t |qS r   )rS   rT   )r   rh   r   r   r   r)     s    zdb_spec.<locals>.<listcomp>)r]   )dbsr   r   r   db_spec  s    r   c               C   s   t tddS )NFzmark as execute)r   rp   r   r   r   r   open  s    r   c               C   s   t tddS )NTzmarked as skip)r   rp   r   r   r   r   closed  s    r   c             C   s   t td| pdS )NTzexpected to fail)r   rp   )r   r   r   r   r     s    r   c             G   s   t t| dS )NzFuture feature)r   rf   )r1   argr   r   r   future  s    r   c             C   s
   t | |S )N)r   )rh   r   r   r   r   fails_on  s    r   c              G   s   t tdd | D S )Nc             S   s   g | ]}t |qS r   )rS   rT   )r   rh   r   r   r   r)     s    z.fails_on_everything_except.<locals>.<listcomp>)rR   r]   )r   r   r   r   fails_on_everything_except  s    r   c             C   s
   t | |S )N)r   )rh   r   r   r   r   r"     s    r"   c                s    t t fddt| D S )Nc                s   g | ]}t | qS r   )rS   rT   )r   rh   )r   r   r   r)     s    zonly_on.<locals>.<listcomp>)rQ   r]   r   Zto_list)r   r   r   )r   r   only_on  s    r   c             C   s   t t| |||S )N)r   r_   )rh   ri   rj   r   r   r   r   exclude  s    r   c             G   s"   |st dtdd |D | S )Nzno queries sent!c             S   s   g | ]}t |qS r   )rS   rT   )r   Zqueryr   r   r   r)     s    zagainst.<locals>.<listcomp>)rH   r]   )r   Zqueriesr   r   r   against  s    r   )N)N)N)N)N)N)N)N)N)'rM   r~   r`   rF    r   r   r   Zutil.compatr   r   r   objectr   rO   r   rQ   rR   rS   rp   r_   rf   r   r]   rT   r	   r   ry   r   r   r   r   r   r   r   r"   r   r   r   r   r   r   r   <module>	   sF   

 

8<$




