ó
H`¾Tc           @   sA  d  d l  m Z m Z m Z m Z m Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 Z
 d d l Z e rŒ d „  Z e Z Z n. e r¨ d „  Z e Z Z n e j Z d „  Z d „  Z d „  Z d	 e f d
 „  ƒ  YZ d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d „  ƒ Z d e f d „  ƒ  YZ d S(   i   (   t   jythont   pypyt   defaultdictt	   decoratort   py2kiÿÿÿÿNc          G   s/   t  j ƒ  t j d ƒ t  j ƒ  t  j ƒ  d S(   s    aggressive gc.collect for tests.gš™™™™™¹?i    (   t   gct   collectt   timet   sleep(   t   args(    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/util.pyt   jython_gc_collect   s
    


c          G   s   t  j ƒ  t  j ƒ  d  S(   N(   R   R   (   R	   (    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/util.pyt   pypy_gc_collect   s    
c           C   s   d  S(   N(    (    (    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/util.pyt   lazy_gc$   s    c          #   sœ   t  ƒ  }  t rC y d d  l } |  j | ƒ WqC t k
 r? qC Xn  d d  l } |  j | ƒ x9 |  D]1 ‰ x( d D]  ‰  ˆ j ‡  ‡ f d †  f Vqp Wqc Wd  S(   Niÿÿÿÿi    i   i   c            s   ˆ j  |  ˆ  ƒ S(   N(   t   dumps(   t   d(   t   protocolt   pickle_(    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/util.pyt   <lambda>7   s    (   iÿÿÿÿi    i   i   (   t   setR   t   cPicklet   addt   ImportErrort   picklet   loads(   t   picklersR   R   (    (   R   R   s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/util.pyR   (   s    	c         C   sN   t  |  t ƒ r t |  | ƒ S|  t j d d | ƒ j t j ƒ t d | ƒ S(   Nt   1t   0i
   (   t
   isinstancet   floatt   roundt   decimalt   Decimalt   to_integralt   ROUND_FLOORt   pow(   t   valuet   prec(    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/util.pyt   round_decimal:   s
    	t	   RandomSetc           B   s>   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s,   t  t j |  ƒ ƒ } t j | ƒ t | ƒ S(   N(   t   listR   t   __iter__t   randomt   shufflet   iter(   t   selft   l(    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/util.pyR(   E   s    c         C   sF   t  j d t |  ƒ d ƒ } t t j |  ƒ ƒ | } |  j | ƒ | S(   Ni    i   (   R)   t   randintt   lenR'   R   R(   t   remove(   R,   t   indext   item(    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/util.pyt   popJ   s    c         C   s   t  t j |  | ƒ ƒ S(   N(   R&   R   t   union(   R,   t   other(    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/util.pyR4   P   s    c         C   s   t  t j |  | ƒ ƒ S(   N(   R&   R   t
   difference(   R,   R5   (    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/util.pyR6   S   s    c         C   s   t  t j |  | ƒ ƒ S(   N(   R&   R   t   intersection(   R,   R5   (    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/util.pyR7   V   s    c         C   s
   t  |  ƒ S(   N(   R&   (   R,   (    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/util.pyt   copyY   s    (   t   __name__t
   __module__R(   R3   R4   R6   R7   R8   (    (    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/util.pyR&   D   s   					c         C   s‚   t  t ƒ } x% |  D] \ } } | | j | ƒ q WxG t | ƒ D]5 \ } } x& | | D] } | | | k rX t SqX WqA Wt Sd S(   sA   True if the given sorting conforms to the given partial ordering.N(   R   R   R   t	   enumeratet   Falset   True(   t   tuplest   sorted_elementst   depst   parentt   childt   it   nodet   n(    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/util.pyt   conforms_partial_ordering]   s    c            sV   t  t ƒ ‰ x% |  D] \ } } ˆ | j | ƒ q W‡  ‡ f d †  ‰  t ˆ  | ƒ ƒ S(   Nc         3   s†   t  |  ƒ d k r  t |  ƒ Vnb x_ |  D]W } t |  ƒ j | g ƒ } | j ˆ | ƒ s' x# ˆ  | ƒ D] } | g | Vqe Wq' q' Wd  S(   Ni   (   R/   R'   R   R6   R7   (   t   elementst   elemt   subsett   sub_ordering(   t   _all_orderingst   edges(    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/util.pyRK   p   s    (   R   R   R   R+   (   R>   RG   RA   RB   (    (   RK   RL   s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/util.pyt   all_partial_orderingsk   s
    c         C   sL   y | |  _  Wn8 t k
 rG t j |  j |  j | |  j |  j ƒ }  n X|  S(   sc  Return a function with a given __name__.

    Will assign to __name__ and return the original function if possible on
    the Python implementation, otherwise a new function will be constructed.

    This function should be phased out as much as possible
    in favor of @decorator.   Tests that "generate" many named tests
    should be modernized.

    (   R9   t	   TypeErrort   typest   FunctionTypet   __code__t   __globals__t   __defaults__t   __closure__(   t   fnt   name(    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/util.pyt   function_named~   s    c         O   sx   |  j  ƒ  } y- | | | | Ž } |  j d d d ƒ | SWn8 t j ƒ  } |  j | Œ  } | d k rl ‚  qt | Sn Xd S(   sˆ   Run the given function under the given contextmanager,
    simulating the behavior of 'with' to support older
    Python versions.

    N(   t	   __enter__t   __exit__t   Nonet   syst   exc_info(   t   ctxRU   t   argt   kwt   objt   resultR\   t   raise_(    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/util.pyt   run_as_contextmanager‘   s    c         C   s#   t  g  |  D] } t | ƒ ^ q
 ƒ S(   sŠ   Converts the results of sql execution into a plain set of column tuples.

    Useful for asserting the results of an unordered query.
    (   R   t   tuple(   t   resultst   row(    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/util.pyt   rowset¦   s    c         C   s   t  s t |  ƒ ‚ d  S(   N(   R<   t   AssertionError(   t   msg(    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/util.pyt   fail¯   s    c         O   sƒ   d d l  m } d d l m } | j | j ƒ } | d } t | d d ƒ } | | _ z |  | | Ž  SWd | j	 ƒ  | | _ Xd S(   s>   Provide bound MetaData for a single test, dropping afterwards.i   (   t   configiÿÿÿÿ(   t   schemai    t   metadataN(
   t    Rk   t
   sqlalchemyRl   t   MetaDatat   dbt   getattrRZ   Rm   t   drop_all(   RU   R	   R_   Rk   Rl   Rm   R,   t	   prev_meta(    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/util.pyt   provide_metadata³   s    
	
t   adictc           B   s    e  Z d  Z d „  Z d „  Z RS(   s,   Dict keys available as attributes.  Shadows.c         C   s1   y |  | SWn t  k
 r, t j |  | ƒ SXd  S(   N(   t   KeyErrort   dictt   __getattribute__(   R,   t   key(    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/util.pyRy   È   s    c         G   s!   t  g  | D] } |  | ^ q
 ƒ S(   N(   Rd   (   R,   t   keysRz   (    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/util.pyt   get_allÎ   s    (   R9   R:   t   __doc__Ry   R|   (    (    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/util.pyRv   Å   s   	(   t   utilR    R   R   R   R   R   R   R   R)   R[   RO   R
   t
   gc_collectR   R   R   R   R%   R   R&   RF   RM   RW   Rc   Rg   Rj   Ru   Rx   Rv   (    (    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/testing/util.pyt   <module>   s2   (							
							