σ
ίΘ[c           @` sΤ   d  Z  d d l m Z m Z m Z m Z d d l Z d d l Z d d l Z	 d d l
 m Z d d l m Z e j d  Z e j d  Z e j d	  Z e j d
  Z e j d  Z d e j f d     YZ d S(   uΆ   
Implements a replacement for `doctest.OutputChecker` that handles certain
normalizations of Python expression output.  See the docstring on
`AstropyOutputChecker` for more details.
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsNi   (   t   six(   t   zipu   FIXu	   FLOAT_CMPu   IGNORE_OUTPUTu   IGNORE_OUTPUT_2u   IGNORE_OUTPUT_3t   AstropyOutputCheckerc           B` s   e  Z d  Z e j Z e j d e j  Z	 e j d e j  Z
 e j d e j  Z e j d e j  Z d   Z d   Z d   Z d   Z d	   Z RS(
   u	  
    - Removes u'' prefixes on string literals
    - Ignores the 'L' suffix on long integers
    - In Numpy dtype strings, removes the leading pipe, i.e. '|S9' ->
      'S9'.  Numpy 1.7 no longer includes it in display.
    - Supports the FLOAT_CMP flag, which parses floating point values
      out of the output and compares their numerical values rather than their
      string representation.  This naturally supports complex numbers as well
      (simply by comparing their real and imaginary parts separately).
    u   (\W|^)[uU]([rR]?[\'\"])u(   ([\'\"])[|<>]([biufcSaUV][0-9]+)([\'\"])u   ([\'\"])([iu])[48]([\'\"])u	   ([0-9]+)Lc         C` s½   d } d j  |  } | d } d } | d } d j  | |  } d j  | | |  } t j d j  | |   |  _ d j  | |  } d j  | | |  } t j d j  | |   |  _ d  S(	   Nu   (?:e[+-]?\d+)u>   \s*([+-]?\d+\.\d*{0}?|[+-]?\.\d+{0}?|[+-]?\d+{0}|nan|[+-]?inf)u   (\.{3})?u   \s|[*+-,<=(\[]u   |[>j)\]]u   ^{}(?={}|$)u   (?<={}){}(?={}|$)u   ({}|{})(   t   formatt   ret   compilet   num_got_rgxt   num_want_rgx(   t   selft   expt
   got_floatst   want_floatst	   front_sept   back_sept   fbegt   fmidend(    (    s;   lib/python2.7/site-packages/astropy/tests/output_checker.pyt   __init__4   s    	

c         C` sΚ   t  j |  j d |  } t  j |  j d |  } t  j |  j d |  } t  j |  j d |  } t  j |  j d |  } t  j |  j d |  } t  j |  j d |  } t  j |  j d |  } | | f S(   Nu   \1\2u   \1\2\3u   \1(   R   t   subt   _str_literal_ret   _byteorder_ret   _fix_32bit_ret   _long_int_re(   R   t   wantt   got(    (    s;   lib/python2.7/site-packages/astropy/tests/output_checker.pyt   do_fixesN   s    c   
      ` s  | | k r t  S|  j j |  } g  | D] } | j d  ^ q) } |  j j |  } g  | D] } | j d  ^ q] } t |  t |  k r t St |  d k rAg    xq t | |  D]` \ } }	 d |	 k rη   j |  qΌ n   j |	  t	 j
 t |  t |	  d t  sΌ t SqΌ W|  j j   f d   |  } n  | t j @s t j d j t j t j   d |  } t j d d |  } | | k r t  Sn  | t j @rκd	 j | j    } d	 j | j    } | | k rκt  Sn  | t j @rt j | |  rt  Sn  t S(
   uQ  
        Alternative to the built-in check_output that also handles parsing
        float values and comparing their numeric values rather than their
        string representations.

        This requires rewriting enough of the basic check_output that, when
        FLOAT_CMP is enabled, it totally takes over for check_output.
        i   i    u   ...t	   equal_nanc         ` s     j  d  S(   Ni    (   t   pop(   t   x(   t   nw_(    s;   lib/python2.7/site-packages/astropy/tests/output_checker.pyt   <lambda>   s    u   (?m)^{}\s*?$u    u
   (?m)^\s*?$u    (   t   TrueR
   t   finditert   groupR   t   lent   FalseR   t   appendt   npt   allcloset   floatR   t   doctestt   DONT_ACCEPT_BLANKLINER   R   t   escapet   BLANKLINE_MARKERt   NORMALIZE_WHITESPACEt   joint   splitt   ELLIPSISt   _ellipsis_match(
   R   R   R   t   flagst   matchest   matcht   numbers_gott   numbers_wantt   ngt   nw(    (   R    s;   lib/python2.7/site-packages/astropy/tests/output_checker.pyt   normalize_floats[   sB    ""$!c         C` s   | t  @s1 t j r | t @s1 t j r5 | t @r5 t S| t @rZ |  j | |  \ } } n  | t @rw |  j	 | | |  S|  j
 j |  | | |  S(   N(   t   IGNORE_OUTPUTR   t   PY2t   IGNORE_OUTPUT_2t   IGNORE_OUTPUT_3R"   t   FIXR   t	   FLOAT_CMPR;   t   _original_output_checkert   check_output(   R   R   R   R4   (    (    s;   lib/python2.7/site-packages/astropy/tests/output_checker.pyRC   £   s    

	c         C` s>   | t  @r% |  j | |  \ } } n  |  j j |  | | |  S(   N(   R@   R   RB   t   output_difference(   R   R   R   R4   (    (    s;   lib/python2.7/site-packages/astropy/tests/output_checker.pyRD   ³   s    
	(   t   __name__t
   __module__t   __doc__R+   t   OutputCheckerRB   R   R	   t   UNICODER   R   R   R   R   R   R;   RC   RD   (    (    (    s;   lib/python2.7/site-packages/astropy/tests/output_checker.pyR      s   
				H	(   RG   t
   __future__R    R   R   R   R+   R   t   numpyR(   t   externR   t   extern.six.movesR   t   register_optionflagR@   RA   R<   R>   R?   RH   R   (    (    (    s;   lib/python2.7/site-packages/astropy/tests/output_checker.pyt   <module>   s   "