ó
±éRc           @  si  d  d l  m Z d  d l 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
 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 l Z d  d l m Z m Z m Z d  d l Z d d d	 „ Z d
 e f d „  ƒ  YZ d „  Z d „  Z d e f d „  ƒ  YZ d d d d e  d d „ Z! d „  Z" d S(   iÿÿÿÿ(   t   print_function(   t   KnownFailureTestt   KnownFailureDidNotFailTestt   ImageComparisonFailureN(   t   cbook(   t   ticker(   t   pyplot(   t   ft2font(   t   comparable_formatst   compare_imagest   make_test_filenamec           s.   ˆ d k r d ‰ n  ‡  ‡ ‡ f d †  } | S(   sD  

    Assume a will fail if *fail_condition* is True. *fail_condition*
    may also be False or the string 'indeterminate'.

    *msg* is the error message displayed for the test.

    If *known_exception_class* is not None, the failure is only known
    if the exception is an instance of this class. (Default = None)

    s   Test known to failc           s:   d d  l  } ‡  ‡ ‡ ‡ f d †  } | j j ˆ  ƒ | ƒ S(   Niÿÿÿÿc            sŠ   y ˆ  |  | Ž  } WnO t  k
 rd } ˆ r^ ˆ d  k	 rO t | ˆ ƒ sO ‚  qO n  t ˆ ƒ ‚ qe ‚  n Xˆ r† ˆ d k r† t ˆ ƒ ‚ n  | S(   Nt   indeterminate(   t	   Exceptiont   Nonet
   isinstanceR   R   (   t   argst   kwargst   resultt   err(   t   ft   fail_conditiont   known_exception_classt   msg(    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/testing/decorators.pyt   failer%   s    	(   t   noset   toolst   make_decorator(   R   R   R   (   R   R   R   (   R   sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/testing/decorators.pyt   known_fail_decorator!   s    N(   R   (   R   R   R   R   (    (   R   R   R   sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/testing/decorators.pyt   knownfailureif   s    	t   CleanupTestc           B  s/   e  Z e d  „  ƒ Z e d „  ƒ Z d „  Z RS(   c         C  s   t  j j j ƒ  |  _ d  S(   N(   t
   matplotlibt   unitst   registryt   copyt   original_units_registry(   t   cls(    (    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/testing/decorators.pyt   setup_class:   s    c         C  sN   t  j d ƒ t j j ƒ  t j j j ƒ  t j j j |  j	 ƒ t
 j ƒ  d  S(   Nt   all(   t   pltt   closeR   t   testst   setupR   R    t   cleart   updateR"   t   warningst   resetwarnings(   R#   (    (    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/testing/decorators.pyt   teardown_class>   s
    c         C  s   |  j  ƒ  d  S(   N(   t   _func(   t   self(    (    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/testing/decorators.pyt   testH   s    (   t   __name__t
   __module__t   classmethodR$   R.   R1   (    (    (    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/testing/decorators.pyR   9   s   
c         C  sG   |  j  } t |  ƒ }  d |  j d ƒ _  t | t f i |  d 6ƒ } | S(   Nt   _privatei   R/   (   R2   t   staticmethodt   __get__t   typeR   (   t   funct   namet	   new_class(    (    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/testing/decorators.pyt   cleanupK   s    	c         C  s�   |  d  k r t Sd d l m } t |  t ƒ r> |  |  f }  n  g  |  D] } | j | ƒ ^ qE }  | j t j ƒ } | |  d k o� | |  d k S(   Niÿÿÿÿ(   t   versioni    i   (	   R   t   Truet	   distutilsR=   R   t   strt   StrictVersionR   t   __freetype_version__(   t   verR=   t   xt   found(    (    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/testing/decorators.pyt   check_freetype_versionU   s    "t   ImageComparisonTestc           B  s/   e  Z e d  „  ƒ Z e d „  ƒ Z d „  Z RS(   c         C  s   t  j ƒ  |  j ƒ  d  S(   N(   R   R$   R/   (   R#   (    (    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/testing/decorators.pyR$   b   s    
c         C  s�   |  j  d ƒ xy |  j ƒ  D]k } | j d ƒ | j j t j ƒ  ƒ | j j t j ƒ  ƒ | j j t j ƒ  ƒ | j j t j ƒ  ƒ q Wd  S(   Nt    (	   t   suptitlet   get_axest	   set_titlet   xaxist   set_major_formatterR   t   NullFormattert   set_minor_formattert   yaxis(   t   figuret   ax(    (    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/testing/decorators.pyt   remove_texth   s    c   
      #  s–  t  ˆ j ƒ \ } } xzt t j ƒ  ˆ j ƒ D]`\ } } t j | ƒ ‰ xBˆ j D]7} | t ƒ  k } | r{ d | } n d } t	 j
 j | | ƒ d | } | d k rÙ t	 j
 j | ƒ rÙ t	 j
 j | | ƒ d } n  t t	 j
 j | t	 j
 j | ƒ ƒ d ƒ ‰ t	 j
 j | | ƒ d | ‰  t	 j
 j | ƒ rEt j | ˆ ƒ n t } d ˆ } t | | d t ƒ‡  ‡ ‡ ‡ f d	 †  ƒ }	 |	 f VqS Wq. Wd  S(
   Ns&   Cannot compare %s files on this systems   No failure expectedt   .t   epss   .pdft   expecteds   Do not have baseline image %sR   c            sÒ   ˆ j  r ˆ j ˆ ƒ n  ˆ j ˆ  ˆ j � t ˆ ˆ  ˆ j d t ƒ}  yB t j j	 ˆ ƒ so t
 d ˆ ƒ ‚ n  |  rˆ t
 d |  ƒ ‚ n  WnB t
 k
 rÍ t ˆ j ƒ sÇ t d ˆ j t j f ƒ ‚ n  ‚  n Xd  S(   Nt   in_decorators   image does not exist: %ss=   images not close: %(actual)s vs. %(expected)s (RMS %(rms).3f)sB   Mismatched version of freetype.  Test requires '%s', you have '%s'(   t   _remove_textRS   t   savefigt   _savefig_kwargR	   t   _tolR>   t   ost   patht   existsR   RF   t   _freetype_versionR   R   RB   (   R   (   t   actual_fnamet   expected_fnameRQ   R0   (    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/testing/decorators.pyt   do_test‹   s&    		(   t   _image_directoriesR/   t   zipR&   t   get_fignumst   _baseline_imagesRQ   t   _extensionsR   R\   R]   t   joinR^   R
   t   basenamet   shutilt   copyfileR>   R   R   (
   R0   t   baseline_dirt
   result_dirt   fignumt   baselinet	   extensiont	   will_failt   fail_msgt   orig_expected_fnameRb   (    (   R`   Ra   RQ   R0   sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/testing/decorators.pyR1   r   s,    %
	!(   R2   R3   R4   R$   R6   RS   R1   (    (    (    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/testing/decorators.pyRG   a   s   
i   c           ss   ˆ  d k r t d ƒ ‚ n  ˆ d k r9 d d d g ‰ n  ˆ d k rQ t ƒ  ‰ n  ‡  ‡ ‡ ‡ ‡ ‡ f d †  } | S(   sz  
    call signature::

      image_comparison(baseline_images=['my_figure'], extensions=None)

    Compare images generated by the test with those specified in
    *baseline_images*, which must correspond else an
    ImageComparisonFailure exception will be raised.

    Keyword arguments:

      *baseline_images*: list
        A list of strings specifying the names of the images generated
        by calls to :meth:`matplotlib.figure.savefig`.

      *extensions*: [ None | list ]

        If *None*, default to all supported extensions.

        Otherwise, a list of extensions to test. For example ['png','pdf'].

      *tol*: (default 13)
        The RMS threshold above which the test is considered failed.

      *freetype_version*: str or tuple
        The expected freetype version or range of versions for this
        test to pass.

      *remove_text*: bool
        Remove the title and tick text from the figure before
        comparison.  This does not remove other, more deliberate,
        text, such as legends and annotations.

      *savefig_kwarg*: dict
        Optional arguments that are passed to the savefig method.

    s!   baseline_images must be specifiedt   pngt   pdft   svgc           sq   |  j  } t |  ƒ }  d |  j d ƒ _  t | t f i |  d 6ˆ  d 6ˆ d 6ˆ d 6ˆ d 6ˆ d 6ˆ d	 6ƒ } | S(
   NR5   i   R/   Rf   Rg   R[   R_   RX   RZ   (   R2   R6   R7   R8   RG   (   R9   R:   R;   (   t   baseline_imagest
   extensionst   freetype_versionRS   t   savefig_kwargt   tol(    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/testing/decorators.pyt   compare_images_decoratorÝ   s    	
N(   R   t
   ValueErrort   dict(   Rw   Rx   R{   Ry   RS   Rz   R|   (    (   Rw   Rx   Ry   RS   Rz   R{   sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/testing/decorators.pyt   image_comparison©   s    )c   
        sg  |  j  } | d k rv t j d ƒ t j d } t j j t j j | ƒ ƒ } t j j	 t j j
 | ƒ d ƒ d } nŒ | j
 d ƒ } | j d ƒ | j d ƒ d k s­ t ‚ t j j | Œ  } d d l ‰  d ‡  f d	 † } | |  j  ƒ d } t j j | ƒ } t j j | d
 | ƒ } t j j t j j d | ƒ ƒ }	 t j j |	 ƒ s]t j |	 ƒ n  | |	 f S(   s„   
    Compute the baseline and result image directories for testing *func*.
    Create the result directory if it doesn't exist.
    t   __main__s<   test module run as script. guessing baseline image locationsi    i   RT   R(   iÿÿÿÿNc           se   d } xX |  j d ƒ D]G } ˆ  j | | ƒ } \ } } } | g } | d k	 r | j ƒ  q q W| S(   s9   A version of imp which can handle dots in the module nameRT   N(   R   t   splitt   find_moduleR'   (   t   module_nameR]   t   rest   sub_modt   filet   _(   t   imp(    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/testing/decorators.pyt   find_dotted_module  s    	Rw   t   result_images(   R3   R,   t   warnt   syst   argvR\   R]   t   abspatht   dirnamet   splitextR�   t   popt   AssertionErrorRh   Rˆ   R   R^   R   t   mkdirs(
   R9   Rƒ   t   script_namet   basedirt   subdirt   modsR‰   t   mod_fileRl   Rm   (    (   Rˆ   sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/testing/decorators.pyRc   ú   s&    	)
!(#   t
   __future__R    t   matplotlib.testing.noseclassesR   R   R   R\   RŒ   Rj   R   R   t   matplotlib.testst   matplotlib.unitsR   R   R   R&   R   t   numpyt   npt   matplotlib.testing.compareR   R	   R
   R,   R   R   t   objectR   R<   RF   RG   t   FalseR   Rc   (    (    (    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/testing/decorators.pyt   <module>   s,   $'	
	H	O