ó
›ßÈ[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	 Z	 d d l
 Z d d l m Z m Z d d l m Z m Z d d l m 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 m Z d g Z  d Z! d Z" d Z# e e! e j$ e" e j$ ƒ Z% e# e j$ Z& d „  Z' d „  Z( e d e) f d „  ƒ  Yƒ Z* d e) f d „  ƒ  YZ+ d „  Z, d S(   uJ   Tests for `astropy.vo.client.conesearch` and `astropy.vo.client.vo_async`.i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsNi   (   t
   conesearcht   vos_catalog(   t   VOSErrort   ConeSearchErrori   (   t   confi   (   t   units(   t   ICRSt   SkyCoord(   t   remote_data(   t   get_pkg_data_filename(   t   AstropyDeprecationWarning(   t   datau   *gš™™™™™¹?c           C` s   t  j d t ƒ d S(   u%   Ignore all deprecation warnings here.u   ignoreN(   t   warningst   simplefilterR   (    (    (    sF   lib/python2.7/site-packages/astropy/vo/client/tests/test_conesearch.pyt   setup_module&   s    c           C` s   t  j ƒ  d  S(   N(   R   t   resetwarnings(    (    (    sF   lib/python2.7/site-packages/astropy/vo/client/tests/test_conesearch.pyt   teardown_module+   s    t   TestConeSearchc           B` s  e  Z d  Z d „  Z d „  Z d „  Z e j j d e	 e
 f e f e e f g ƒ d „  ƒ Z d „  Z d „  Z d	 „  Z e j j d e	 e
 f e f e e f g ƒ d
 „  ƒ Z d „  Z d „  Z e j j d e	 e
 f d f e d e j f g ƒ d „  ƒ Z d „  Z d „  Z RS(   uU  Test Cone Search on a pre-defined access URL.

    .. note::

        This test will fail if the URL becomes inaccessible,
        which is beyond AstroPy's control. When this happens,
        change the test to use a different URL.

        At the time this was written, ``pedantic=True`` will
        not yield any successful search.

    c         C` s=   d |  _  d |  _ d t _ d t j _ t |  _ t |  _ d  S(   NuI   http://vizier.u-strasbg.fr/viz-bin/votable/-A?-out.all&-source=I/252/out&u   USNO-A2u   conesearch_simplei
   (	   t   urlt   catnameR   t   conesearch_dbnameR   t   remote_timeoutt   Falset   verboset   pedantic(   t   self(    (    sF   lib/python2.7/site-packages/astropy/vo/client/tests/test_conesearch.pyt   setup_class>   s    				c         C` sR   t  j ƒ  d d d d d g k s' t ‚ t  j d d ƒ d d d g k sN t ‚ d  S(   Nu   BROKENu   USNO ACTu
   USNO NOMADu   USNO-A2u   USNO-B1t   patternu   usno*a(   R   t   list_catalogst   AssertionError(   R   (    (    sF   lib/python2.7/site-packages/astropy/vo/client/tests/test_conesearch.pyt   test_cat_listingM   s    	c         C` sE   t  j t ƒ 0 t j t d d |  j d |  j d |  j ƒWd  QXd  S(   Ngü©ñÒMbP?t
   catalog_dbR   R   (   t   pytestt   raisesR   R   t
   SCS_CENTERR   R   R   (   R   (    (    sF   lib/python2.7/site-packages/astropy/vo/client/tests/test_conesearch.pyt   test_no_resultS   s    u   centeru   radiusc         C` s=   t  j  | | d d d |  j ƒ} | j j d k s9 t ‚ d S(   ue   This does not necessarily uses ``self.url`` because of
        unordered dict in JSON tree.

        R   R   i    N(   R   t   NoneR   t   arrayt   sizeR!   (   R   t   centert   radiust   tab_1(    (    sF   lib/python2.7/site-packages/astropy/vo/client/tests/test_conesearch.pyt   test_one_searchY   s    c      	   C` sU   t  t ƒ } t j | t d |  j d |  j d |  j ƒ} | j j d k sQ t	 ‚ d S(   u@   
        Check that searching with a SkyCoord works too
        R#   R   R   i    N(
   R   R&   R   t
   SCS_RADIUSR   R   R   R)   R*   R!   (   R   t   sc_cent   tab(    (    sF   lib/python2.7/site-packages/astropy/vo/client/tests/test_conesearch.pyt   test_sky_coordf   s
    c         C` s„   t  j t ƒ o } t j j d d ƒ 6 t j t t d |  j	 d |  j
 d |  j d t ƒWd QXd | j k sz t d	 ƒ ‚ Wd QXd S(
   u   Test time out error.u   remote_timeoutgü©ñÒMbP?R   R   R#   t   cacheNu	   timed outu   test_timeout failed(   R$   R%   R   R   R   t   set_tempR   R&   R/   R   R   R   R   t   infoR!   (   R   t   e(    (    sF   lib/python2.7/site-packages/astropy/vo/client/tests/test_conesearch.pyt   test_timeoutq   s    c      	   C` s	  t  j  t t d |  j d |  j d |  j ƒ} t  j  t t d |  j |  j g d |  j d |  j ƒ} t  j  t t d t j t	 j
 ƒ d |  j d |  j ƒ} | j | j k s± t ‚ t j j | j | j ƒ | j | j k rø t j j | j | j ƒ n t j d ƒ d  S(   NR#   R   R   u+   conesearch_simple.json used a different URL(   R   R&   R/   R   R   R   R   R   t   get_remote_catalog_dbR   R   R!   t   npt   testingt   assert_array_equalR)   R$   t   xfail(   R   t   tab_2t   tab_3t   tab_4(    (    sF   lib/python2.7/site-packages/astropy/vo/client/tests/test_conesearch.pyt   test_searchesz   s"    		c      	   C` st   t  j | | d d |  j g d |  j d |  j ƒ} t | ƒ d k sK t ‚ | |  j } | j j d k sp t ‚ d  S(   NR#   u   BROKENR   R   i   i    (	   R   t
   search_allR   R   R   t   lenR!   R)   R*   (   R   R+   R,   t   all_resultsR-   (    (    sF   lib/python2.7/site-packages/astropy/vo/client/tests/test_conesearch.pyt   test_search_all“   s    c         C` s›   t  j t t d |  j ƒ} t j d ƒ | j d t j	 j
 ƒ } y | j ƒ  sU t ‚ Wn& t k
 r~ } t j t | ƒ ƒ n X| j j d k s— t ‚ d  S(   NR   i   t   timeouti    (   R   t   AsyncConeSearchR&   R/   R   t   timet   sleept   getR   R   R   t   doneR!   R$   R<   t   strR)   R*   (   R   t   async_searchR1   t   exc(    (    sF   lib/python2.7/site-packages/astropy/vo/client/tests/test_conesearch.pyt
   test_async¡   s    c         C` s¶   t  j t t d |  j ƒ} t j d ƒ | j d t j	 j
 d ƒ } y | j ƒ  sY t ‚ Wn& t k
 r‚ } t j t | ƒ ƒ n0 Xx, | j ƒ  D] } | j j d k s t ‚ q Wd  S(   NR   i   RE   i   i    (   R   t   AsyncSearchAllR&   R/   R   RG   RH   RI   R   R   R   RJ   R!   R$   R<   RK   t   valuesR)   R*   (   R   t   async_search_allRC   RM   R1   (    (    sF   lib/python2.7/site-packages/astropy/vo/client/tests/test_conesearch.pyt   test_async_all±   s    gš™™™™™é?c      	   C` s·   t  j | | d |  j d |  j d |  j ƒ\ } } | j j } t  j |  j | | d |  j d |  j ƒ\ } } | d k r‹ | | d k s‘ t ‚ | d k r­ | | d k s³ t ‚ d S(   u;   Prediction tests are not very accurate but will have to do.R#   R   R   i    g      ø?i
   N(	   R   t   conesearch_timerR   R   R   R)   R*   t   predict_searchR!   (   R   R+   R,   t   t_1R-   t   n_1t   t_2t   n_2(    (    sF   lib/python2.7/site-packages/astropy/vo/client/tests/test_conesearch.pyt   test_predictionÂ   s    "c         C` sJ   t  j t ƒ 5 t j |  j t d d |  j d |  j ƒ\ } } Wd  QXd  S(   NiÿÿÿÿR   R   (	   R$   R%   R   R   RT   R   R&   R   R   (   R   t   tt   n(    (    sF   lib/python2.7/site-packages/astropy/vo/client/tests/test_conesearch.pyt   test_prediction_neg_radiusÕ   s    c         C` s!   t  j d ƒ t j  j d ƒ d  S(   Nu   conesearch_dbnameu   remote_timeout(   R   t   resetR   (   R   (    (    sF   lib/python2.7/site-packages/astropy/vo/client/tests/test_conesearch.pyt   teardown_classÛ   s    (   u   centeru   radius(   u   centeru   radius(   u   centeru   radius(   t   __name__t
   __module__t   __doc__R   R"   R'   R$   t   markt   parametrizet   SCS_RAt   SCS_DECt   SCS_SRR&   R/   R.   R2   R7   R@   RD   RN   RR   t   ut   degreeRY   R\   R^   (    (    (    sF   lib/python2.7/site-packages/astropy/vo/client/tests/test_conesearch.pyR   /   s(   									"	t   TestErrorResponsec           B` sJ   e  Z d  Z d „  Z d „  Z e j j d d d d d g ƒ d „  ƒ Z RS(	   uß   Test Cone Search error response handling.

    This is defined in Section 2.3 of Simple Cone Search Version 1.03,
    IVOA Recommendation, 22 February 2008.

    Also see https://github.com/astropy/astropy/issues/1001

    c         C` s;   d |  _  t |  _ i d d 6d d 6d d 6d d 6|  _ d  S(   Nu   datau   Error in input RA value: as3fu   conesearch_error1.xmlu   conesearch_error2.xmlu   Invalid data type: text/htmlu   conesearch_error3.xmlu   conesearch_error4.xml(   t   datadirR   R   t   conesearch_errmsg(   R   (    (    sF   lib/python2.7/site-packages/astropy/vo/client/tests/test_conesearch.pyR   ê   s    		c         C` s†   | d k r t  j d ƒ n  t t j j |  j | ƒ ƒ } y t j | |  j	 i  ƒ Wn+ t
 k
 r } | t | ƒ k s‚ t ‚ n Xd S(   u~   Bypassing Cone Search query and just imitating the reply,
        then check if appropriate error message is caught.

        u   conesearch_error4.xmlu>   Currently not supported, see astropy.io.votable.exceptions.W22N(   R$   R<   R   t   ost   patht   joinRj   R   t   _vo_service_requestR   R   RK   R!   (   R   t   xmlfilet   msgR   R6   (    (    sF   lib/python2.7/site-packages/astropy/vo/client/tests/test_conesearch.pyt   conesearch_compareó   s    u   idi   i   i   i   c         C` s0   d j  | ƒ } |  j | } |  j | | ƒ d  S(   Nu   conesearch_error{0}.xml(   t   formatRk   Rr   (   R   t   idt   xmlRq   (    (    sF   lib/python2.7/site-packages/astropy/vo/client/tests/test_conesearch.pyt   test_conesearch_response  s    (	   R_   R`   Ra   R   Rr   R$   Rb   Rc   Rv   (    (    (    sF   lib/python2.7/site-packages/astropy/vo/client/tests/test_conesearch.pyRi   à   s   			c          C` sØ   t  j t d t j d t j ƒ ƒ }  t j j |  d d g ƒ t  j t d t j d t j d d ƒƒ }  t j j |  d d g ƒ t  j d
 ƒ }  t j j |  d d g ƒ t  j d ƒ }  t j j |  d d g ƒ d	 S(   u,   Valid coordinates should not raise an error.gôàî¬Ý@g…%P6RÀg áî¬Ý@t   frameu   icrsi    iÿÿÿÿig  N(   i    i    (   iÿÿÿÿiÿÿÿÿ(	   R   t   _validate_coordR
   Rg   Rh   R9   R:   t   assert_allcloseR   (   t   result(    (    sF   lib/python2.7/site-packages/astropy/vo/client/tests/test_conesearch.pyt   test_validate_coord
  s     &(-   Ra   t
   __future__R    R   R   R   Rl   RG   R   R$   t   numpyR9   t    R   R   t
   exceptionsR   R   R   R	   Rg   t   coordinatesR
   R   t   tests.helperR   t
   utils.dataR   t   utils.exceptionsR   t   utilsR   t   __doctest_skip__Rd   Re   Rf   Rh   R&   R/   R   R   t   objectR   Ri   R{   (    (    (    sF   lib/python2.7/site-packages/astropy/vo/client/tests/test_conesearch.pyt   <module>   s6   "			°*