ó
H`¾Tc           @@  só  d  d l  m Z d d l m Z d  d l m Z m Z m Z d  d l m	 Z	 m
 Z
 m Z d  d l m Z d  d l m Z d  d l m Z m Z d  d	 l Z d  d	 l Z d d
 l m Z d d l m Z m Z d d l m Z d d l m Z d d l m Z d  d	 l Z e j d „  ƒ Z d „  Z d „  Z  d „  Z! e j d „  ƒ Z" d „  Z# d  a$ d „  Z% d	 d „ Z' d	 d „ Z( d	 d „ Z) d	 d „ Z* d	 d „ Z+ d „  Z, d „  Z- d e. f d „  ƒ  YZ/ d e. f d  „  ƒ  YZ0 d! e. f d" „  ƒ  YZ1 d	 S(#   i    (   t   absolute_importi   (   t   util(   t   poolt   ormR   (   t   defaultt   create_enginet   url(   t   exc(   t	   decorator(   t   typest   schemaN(   t   resetwarnings(   t   db_spect   _is_excluded(   t	   assertsql(   t   config(   t   failc          g@  s   t  d d d t j ƒ g } |  sC | j t  d d d t j ƒ ƒ n | j d „  |  Dƒ ƒ x | D] } t j |   qa Wz	 d VWd t ƒ  Xd S(   s;   Context manager to expect warnings with the given messages.t   actiont   ignoret   categoryc         s@  s-   |  ]# } t  d  d d | d t j ƒ Vq d S(   R   R   t   messageR   N(   t   dictt   sa_exct	   SAWarning(   t   .0R   (    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pys	   <genexpr>$   s   N(	   R   R   t   SAPendingDeprecationWarningt   appendR   t   extendt   warningst   filterwarningsR   (   t   messagest   filterst   f(    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyt   expect_warnings   s    	c          @  s   t  ‡  f d †  ƒ } | S(   sâ   Mark a test as emitting a warning.

    With no arguments, squelches all SAWarning failures.  Or pass one or more
    strings; these will be matched to the root of the warning description by
    warnings.filterwarnings().
    c         @  s$   t  ˆ  Œ   |  | | Ž  SWd  QXd  S(   N(   R!   (   t   fnt   argst   kw(   R   (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyt   decorate7   s    (   R   (   R   R%   (    (   R   sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyt   emits_warning0   s    c         @  s+   t  ˆ ƒ ‰ t ‡  ‡ ‡ f d †  ƒ } | S(   sø   Mark a test as emitting a warning on a specific dialect.

    With no arguments, squelches all SAWarning failures.  Or pass one or more
    strings; these will be matched to the root of the warning description by
    warnings.filterwarnings().
    c         @  sŒ   t  ˆ t j ƒ rP ˆ t j ƒ s. |  | | Ž  St ˆ  Œ  |  ƒ } | | | Ž  Sn8 t ˆ Œ  si |  | | Ž  St ˆ  Œ  |  ƒ } | | | Ž  Sd  S(   N(   t
   isinstanceR   t   string_typesR   t   _currentR&   R   (   R"   R#   R$   t   wrapped(   R   t   dbt   spec(    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyR%   G   s    (   R   R   (   R+   R   R%   (    (   R   R+   R,   sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyt   emits_warning_on>   s    c          @  s   t  ‡  f d †  ƒ } | S(   sÎ  Mark a test as immune from fatal deprecation warnings.

    With no arguments, squelches all SADeprecationWarning failures.
    Or pass one or more strings; these will be matched to the root
    of the warning description by warnings.filterwarnings().

    As a special case, you may pass a function name prefixed with //
    and it will be re-written as needed to match the standard warning
    verbiage emitted by the sqlalchemy.util.deprecated decorator.
    c         @  s$   t  ˆ  Œ   |  | | Ž  SWd  QXd  S(   N(   t   expect_deprecated(   R"   R#   R$   (   R   (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyR%   d   s    (   R   (   R   R%   (    (   R   sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyt   uses_deprecatedX   s    c       
   g@  sá   t  d d d t j ƒ g } |  sC | j t  d d d t j ƒ ƒ nh | j g  g  |  D]) } | j d ƒ rv d | d py | ^ qS D]$ } t  d d d | d t j ƒ ^ q€ ƒ x | D] } t j |   q² Wz	 d  VWd  t	 ƒ  Xd  S(   NR   R   R   s   //s   Call to deprecated function i   R   (
   R   R   R   R   t   SADeprecationWarningR   t
   startswithR   R   R   (   R   R   t   mR   R    (    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyR.   k   s    \	c           C@  s   t  ƒ  d S(   sÛ   Check things that have to be finalized at the end of a test suite.

    Hardcoded at the moment, a modular system can be built here
    to support things like PG prepared transactions, tables all
    dropped, etc.

    N(   t!   _assert_no_stray_pool_connections(    (    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyt   global_cleanup_assertions…   s    c          C@  s«   t  j ƒ  t j r< t d 7a d t t j ƒ GHt  j ƒ  n  t j r€ t t j ƒ }  t j j ƒ  d a t s§ t	 d |  ƒ ‚ n' t d k r§ t sž t	 d ƒ ‚ d a n  d  S(   Ni   s2   Encountered a stray connection in test cleanup: %si    s8   Stray connection refused to leave after gc.collect(): %si
   s*   Encountered more than 10 stray connections(
   t   testutilt   lazy_gcR   t   _refst   _STRAY_CONNECTION_FAILURESt   strt
   gc_collectt   cleart   Falset   AssertionError(   t   err(    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyR3   ’   s    
	
	c         C@  s,   |  | k s( t  | p" d |  | f ƒ ‚ d S(   s.   Assert a == b, with repr messaging on failure.s   %r != %rN(   R=   (   t   at   bt   msg(    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyt   eq_¹   s    c         C@  s,   |  | k s( t  | p" d |  | f ƒ ‚ d S(   s.   Assert a != b, with repr messaging on failure.s   %r == %rN(   R=   (   R?   R@   RA   (    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyt   ne_¾   s    c         C@  s,   |  | k s( t  | p" d |  | f ƒ ‚ d S(   s.   Assert a is b, with repr messaging on failure.s   %r is not %rN(   R=   (   R?   R@   RA   (    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyt   is_Ã   s    c         C@  s,   |  | k	 s( t  | p" d |  | f ƒ ‚ d S(   s2   Assert a is not b, with repr messaging on failure.s   %r is %rN(   R=   (   R?   R@   RA   (    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyt   is_not_È   s    c         C@  s/   |  j  | ƒ s+ t | p% d |  | f ƒ ‚ d S(   s>   Assert a.startswith(fragment), with repr messaging on failure.s   %r does not start with %rN(   R1   R=   (   R?   t   fragmentRA   (    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyt   startswith_Í   s    c         O@  sG   y | | | Ž  t  } Wn |  k
 r0 t } n X| sC t d ƒ ‚ d  S(   Ns#   Callable did not raise an exception(   R<   t   TrueR=   (   t
   except_clst	   callable_R#   R$   t   success(    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyt   assert_raisesÓ   s    

c         O@  s‹   y# | | | Ž  t  s" t d ƒ ‚ Wna |  k
 r† } t j | t j | ƒ t j ƒ sl t d | | f ƒ ‚ t j | ƒ j d ƒ GHn Xd  S(   Ns#   Callable did not raise an exceptions   %r !~ %ss   utf-8(   R<   R=   t   ret   searchR   t	   text_typet   UNICODEt   encode(   RI   RA   RJ   R#   t   kwargst   e(    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyt   assert_raises_messageÞ   s    1t   AssertsCompiledSQLc           B@  s&   e  Z d d d d e e e d  „ Z RS(   c
         C@  sp  | r t  j ƒ  } n“ | r$ d  } n„ | d  k rE t |  d d  ƒ } n  | d  k r` t j j } nH | d k r{ t  j ƒ  } n- t | t j	 ƒ r¨ t
 j | ƒ j ƒ  ƒ  } n  i  }
 i  } | d  k	 rÓ t | ƒ |
 d <n  |	 ræ t | d <n  t | t j ƒ r| j ƒ  } t | j _ | j } n  | r/| |
 d <n  | j d | |
  } t t | d i  ƒ ƒ } t j r¢| j d ƒ j d	 d
 ƒ } d t j | ƒ | j d ƒ GHn d t j | ƒ j d ƒ | GHt j d d t j | ƒ ƒ } t | | d | | | f ƒ | d  k	 r!t | j | ƒ | ƒ n  | d  k	 rl| j | ƒ } t t g  | j D] } | | ^ qLƒ | ƒ n  d  S(   Nt   __dialect__R   t   column_keyst   literal_bindst   compile_kwargst   dialectt   paramss   utf-8t   asciiR   s   
SQL String:
s   [\n\t]t    s   %r != %r on dialect %r(    R   t   DefaultDialectt   Nonet   getattrR   R+   RZ   R'   R   R(   R   t   URLt   get_dialectt   listRH   R   t   Queryt   _compile_contextt	   statementt
   use_labelst   compilet   reprt   py3kRQ   t   decodeRO   RM   t   subRB   t   construct_paramst   tuplet   positiontup(   t   selft   clauset   resultR[   t   checkparamsRZ   t   checkpositionalt   use_default_dialectt   allow_dialect_selectRX   R$   RY   t   contextt   ct	   param_strt   cct   pt   x(    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyt   assert_compileé   sN    		N(   t   __name__t
   __module__R_   R<   R}   (    (    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyRU   è   s   t   ComparesTablesc           B@  s   e  Z e d  „ Z d „  Z RS(   c         C@  sù  t  | j ƒ t  | j ƒ k s$ t ‚ xwt | j | j ƒ D]`\ } } t | j | j ƒ | | j | j k su t ‚ t | j | j ƒ t | j | j ƒ | rá d } t | j	 t	 | j	 ƒ ƒ sñ t | | j	 | j	 f ƒ ‚ n |  j
 | | ƒ t | j	 t j ƒ r"t | j	 j | j	 j ƒ n  t t g  | j D] } | j j ^ q2ƒ t g  | j D] } | j j ^ qWƒ ƒ | j r: t | j t j ƒ sšt ‚ q: q: Wt  | j ƒ t  | j ƒ k sÂt ‚ x0 | j D]% } | j j | j d  k	 sÌt ‚ qÌWd  S(   Ns)   Type '%s' doesn't correspond to type '%s'(   t   lenRx   R=   t   zipRB   t   namet   primary_keyt   nullableR'   t   typet   assert_types_baset   sqltypest   Stringt   lengtht   sett   foreign_keyst   columnt   server_defaultR
   t   FetchedValuet   columnsR_   (   Rp   t   tablet   reflected_tablet   strict_typesRx   t   reflected_cRA   R    (    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyt   assert_tables_equal,  s,    $"%)		$c         C@  s;   | j  j | j  ƒ s7 t d | j | j  | j  f ƒ ‚ d  S(   Ns7   On column %r, type '%s' doesn't correspond to type '%s'(   R†   t   _compare_type_affinityR=   Rƒ   (   Rp   t   c1t   c2(    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyR‡   J  s    (   R~   R   R<   R•   R‡   (    (    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyR€   *  s   t   AssertsExecutionResultsc           B@  se   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d	 d „ Z d „  Z	 e
 j d „  ƒ Z d „  Z RS(
   c         G@  s.   t  | ƒ } t | ƒ GH|  j | | | ƒ d  S(   N(   Rc   Ri   t   assert_list(   Rp   Rr   t   class_t   objects(    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyt   assert_resultQ  s    c         C@  sl   |  j  t | ƒ t | ƒ k d d | j ƒ x8 t d t | ƒ ƒ D]! } |  j | | | | | ƒ qC Wd  S(   Ns/   result list is not the same size as test list, s
   for class i    (   t   assert_R   R~   t   ranget
   assert_row(   Rp   Rr   R›   Rc   t   i(    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyRš   V  s    c         C@  sé   |  j  | j | k d t | ƒ ƒ x¿ | j ƒ  D]± \ } } t | t ƒ r¬ t | d t ƒ r… |  j t | | ƒ | d | d ƒ qá |  j	 | d t | | ƒ | d ƒ q0 |  j  t | | ƒ | k d | t | | ƒ | f ƒ q0 Wd  S(   Ns   item class is not i   i    s'   attribute %s value %s does not match %s(
   Rž   t	   __class__Ri   t   itemsR'   Rn   Rc   Rš   R`   R    (   Rp   R›   t   rowobjt   desct   keyt   value(    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyR    ]  s    ''c         @  sI  d t  f d „  ƒ  Y} t j | ƒ } t g  | D] } | | ƒ ^ q/ ƒ } xC t j ‡ f d †  | ƒ D]& } t d t | ƒ j ˆ j f ƒ qf Wt | ƒ t | ƒ k rË t d t | ƒ t | ƒ f ƒ n  t	 ƒ  ‰ ‡  ‡ f d †  } x\ | D]T }	 xK | D]& }
 | |
 |	 ƒ rú | j
 |
 ƒ Pqú qú Wt d ˆ j t |	 ƒ f ƒ qí Wt S(   sÉ   As assert_result, but the order of objects is not considered.

        The algorithm is very expensive but not a big deal for the small
        numbers of rows that the test suite manipulates.
        t   immutabledictc           B@  s   e  Z d  „  Z RS(   c         S@  s
   t  |  ƒ S(   N(   t   id(   Rp   (    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyt   __hash__s  s    (   R~   R   Rª   (    (    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyR¨   r  s   c         @  s   t  |  ˆ  ƒ S(   N(   R'   (   t   o(   t   cls(    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyt   <lambda>y  s    s#   Unexpected type "%s", expected "%s"s+   Unexpected object count "%s", expected "%s"c         @  sŒ   x… | j  ƒ  D]w \ } } t | t ƒ rh y( ˆ  j t |  | ƒ | d | d Œ Wq„ t k
 rd t SXq t |  | ˆ ƒ | k r t Sq Wt S(   Ni    i   (   R£   R'   Rn   t   assert_unordered_resultR`   R=   R<   RH   (   t   objR,   R¦   R§   (   Rp   t   NOVALUE(    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyt   _compare_item„  s    "s2   Expected %s instance with attributes %s not found.(   R   R   t   IdentitySetR‹   t   itertools_filterfalseR   R†   R~   R   t   objectt   removeRi   RH   (   Rp   Rr   R¬   t   expectedR¨   t   foundRS   t   wrongR±   t   expected_itemt
   found_item(    (   Rp   R°   R¬   sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyR®   k  s*    %	c         G@  s=   t  j j | ƒ z | ƒ  t  j j ƒ  Wd  t  j j ƒ  Xd  S(   N(   R   t   assertert	   add_rulest   statement_completet   clear_rules(   Rp   R+   RJ   t   rules(    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyt   assert_sql_executionœ  s
    c         C@  sÀ   | d  k	 r$ t j j j r$ | } n | } g  } xv | D]n } t | t ƒ r‰ t j g  | j	 ƒ  D] \ } }	 t j
 | |	 ƒ ^ q_ Œ  }
 n t j
 | Œ  }
 | j |
 ƒ q7 W|  j | | | Œ d  S(   N(   R_   R   R+   RZ   t   supports_sequencesR'   R   R   t   AllOfR£   t   ExactSQLR   RÀ   (   Rp   R+   RJ   t   list_t   with_sequencesR¿   t   newrulest   rulet   kt   vt   newrule(    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyt
   assert_sql¤  s    	7c         C@  s    |  j  | | t j | ƒ ƒ d  S(   N(   RÀ   R   t   CountStatements(   Rp   R+   RJ   t   count(    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyt   assert_sql_count·  s    c         g@  s;   t  j j | ƒ z d  Vt  j j ƒ  Wd  t  j j ƒ  Xd  S(   N(   R   R»   R¼   R½   R¾   (   Rp   R¿   (    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyt   assert_execution»  s
    c         C@  s   |  j  t j | ƒ ƒ S(   N(   RÏ   R   RÌ   (   Rp   RÍ   (    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyt   assert_statement_countÄ  s    N(   R~   R   R   Rš   R    R®   RÀ   R_   RË   RÎ   t
   contextlibt   contextmanagerRÏ   RÐ   (    (    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyR™   P  s   				1			(2   t
   __future__R    R]   R   R5   t
   sqlalchemyR   R   t   sqlalchemy.engineR   R   R   R   R   t   sqlalchemy.utilR   R	   Rˆ   R
   R   RM   R   t
   exclusionsR   R   R   R   R   RÑ   RÒ   R!   R&   R-   R/   R.   R4   R8   R3   R_   RB   RC   RD   RE   RG   RL   RT   R´   RU   R€   R™   (    (    (    sc   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/assertions.pyt   <module>   s@   				
	'		
B&