ó
ÓnùWc           @   s¼   d  Z  d d l Z d d l Z d d l Z d d l Z d d l m Z m Z m Z m	 Z	 m
 Z
 d d l Z d d l Z d d l m Z d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d S(	   s   Package Index Tests
iÿÿÿÿN(   t   urllib2t   httplibt	   HTTPErrort   unicodet   pathname2url(   t   IndexServert   TestPackageIndexc           B   sb   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z RS(
   c         C   s   t  j j ƒ  } d } y | j | ƒ } Wn: t k
 rd t j ƒ  d } |  j | t | ƒ k ƒ n X|  j t	 | t
 ƒ ƒ d  S(   Ns.   http://127.0.0.1:0/nonesuch/test_package_indexi   (   t
   setuptoolst   package_indext   PackageIndext   open_urlt	   Exceptiont   syst   exc_infot
   assertTruet   strt
   isinstanceR   (   t   selft   indext   urlt   v(    (    sI   /var/www/html/venv/build/setuptools/setuptools/tests/test_packageindex.pyt   test_bad_url_bad_port   s    c         C   s…   t  j j d d ƒ } d } y | j | ƒ } Wn: t k
 rj t j ƒ  d } |  j | t | ƒ k ƒ n X|  j t	 | t
 ƒ ƒ d  S(   Nt   hostss   www.example.comsM   url:%20https://svn.plone.org/svn/collective/inquant.contentmirror.plone/trunki   (   s   www.example.com(   R   R   R	   R
   R   R   R   R   R   R   R   (   R   R   R   R   (    (    sI   /var/www/html/venv/build/setuptools/setuptools/tests/test_packageindex.pyt   test_bad_url_typo   s    	c         C   s   t  j j d d ƒ } d „  } | | _ d } y | j | ƒ } Wn: t k
 r| t j ƒ  d } |  j d t	 | ƒ k ƒ n Xt
 d ƒ ‚ d  S(	   NR   s   www.example.comc          W   s   t  j d ƒ ‚ d  S(   Nt   line(   R   t   BadStatusLine(   t   args(    (    sI   /var/www/html/venv/build/setuptools/setuptools/tests/test_packageindex.pyt   _urlopen/   s    s   http://example.comi   R   s   Should have raise here!(   s   www.example.com(   R   R   R	   t   openerR
   R   R   R   R   R   t   AssertionError(   R   R   R   R   R   (    (    sI   /var/www/html/venv/build/setuptools/setuptools/tests/test_packageindex.pyt   test_bad_url_bad_status_line*   s    			c         C   s   t  j j d d
 ƒ } d } y | j | ƒ Wn^ t j j k
 rŒ t j ƒ  d } t	 | ƒ } d | k sˆ d | k sˆ d | k sˆ t
 ‚ d SXt d	 ƒ ‚ d S(   sO   
        A bad URL with a double scheme should raise a DistutilsError.
        R   s   www.example.coms2   http://http://svn.pythonpaste.org/Paste/wphp/trunki   s   nonnumeric ports   getaddrinfo faileds   Name or service not knownNs   Did not raise(   s   www.example.com(   R   R   R	   R
   t	   distutilst   errorst   DistutilsErrorR   R   R   R   t   RuntimeError(   R   R   R   t   errort   msg(    (    sI   /var/www/html/venv/build/setuptools/setuptools/tests/test_packageindex.pyt   test_bad_url_double_scheme<   s    	*c         C   s^   t  j j d d	 ƒ } t j d d k rZ t j d d k rZ d } d } | j | | ƒ n  d  S(
   NR   s   www.example.comi    i   i   i   s   http://example.coms>   <a href="http://www.famfamfam.com](http://www.famfamfam.com/">(   s   www.example.com(   R   R   R	   R   t   version_infot   process_index(   R   R   R   t   page(    (    sI   /var/www/html/venv/build/setuptools/setuptools/tests/test_packageindex.pyt   test_bad_url_screwy_hrefO   s    	&c         C   s8   t  j j d d ƒ } d } |  j | j | t ƒ ƒ d  S(   NR   s   www.example.coms   file:///tmp/test_package_index(   s   www.example.com(   R   R   R	   R   t   url_okt   True(   R   R   R   (    (    sI   /var/www/html/venv/build/setuptools/setuptools/tests/test_packageindex.pyt   test_url_ok\   s    	c         C   sÆ   t  j j d ƒ r d St ƒ  } | j ƒ  | j ƒ  d } t j j | ƒ } t	 j
 j d ƒ } | j | ƒ | j ƒ  |  j d | k ƒ |  j t | d ƒ d k ƒ |  j d | d d j k ƒ d S(   sq  
        Download links from the pypi simple index should be used before
        external download links.
        https://bitbucket.org/tarek/distribute/issue/163

        Usecase :
        - someone uploads a package on pypi, a md5 is generated
        - someone manually copies this link (with the md5 in the url) onto an
          external page accessible from the package page.
        - someone reuploads the package (with a different md5)
        - while easy_installing, an MD5 error occurs because the external link
          is used
        -> Setuptools should use the link from pypi, not the external one.
        t   javaNs   test_links_priority/simple/t   foobari   t   correct_md5i    (   R   t   platformt
   startswithR   t   startt   base_urlR   R   R	   t   pkg_resourcest   Requirementt   parset   find_packagest   stopR   t   lent   location(   R   t   servert	   index_urlt   pit   requirement(    (    sI   /var/www/html/venv/build/setuptools/setuptools/tests/test_packageindex.pyt   test_links_priorityc   s    	

c         C   st   |  j  t j j d ƒ d
 ƒ |  j  t j j d ƒ d ƒ |  j  t j j d ƒ d ƒ |  j  t j j d	 ƒ d ƒ d  S(   Ns   reportlab-2.5.win32-py2.4.exes   reportlab-2.5s   2.4t   win32s   reportlab-2.5.win32.exes!   reportlab-2.5.win-amd64-py2.7.exes   2.7s	   win-amd64s   reportlab-2.5.win-amd64.exe(   s   reportlab-2.5s   2.4s   win32(   s   reportlab-2.5Ns   win32(   s   reportlab-2.5s   2.7s	   win-amd64(   s   reportlab-2.5Ns	   win-amd64(   t   assertEqualR   R   t   parse_bdist_wininstt   None(   R   (    (    sI   /var/www/html/venv/build/setuptools/setuptools/tests/test_packageindex.pyt   test_parse_bdist_wininstˆ   s    c         C   sE   t  j j j } | d ƒ \ } } |  j | d ƒ |  j | d ƒ d S(   sA   
        Test the basic usage of _vcs_split_rev_from_url
        s   https://example.com/bar@2995s   https://example.com/bart   2995N(   R   R   R	   t   _vcs_split_rev_from_urlRA   (   R   t   vsrfuR   t   rev(    (    sI   /var/www/html/venv/build/setuptools/setuptools/tests/test_packageindex.pyt   test__vcs_split_rev_from_url’   s    c         C   sƒ   t  d d ƒ } | j d ƒ | j ƒ  z0 d t t j ƒ  ƒ d } t j j | ƒ } Wd t j	 d ƒ Xd | j
 ƒ  k s t ‚ d S(   sR   
        local_open should be able to read an index from the file system.
        s
   index.htmlt   ws   <div>content</div>s   file:t   /Nt   content(   t   opent   writet   closeR   t   ost   getcwdR   R   t
   local_opent   removet   readR   (   R   t   fR   t   res(    (    sI   /var/www/html/venv/build/setuptools/setuptools/tests/test_packageindex.pyt   test_local_index›   s    
(   t   __name__t
   __module__R   R   R   R%   R)   R,   R?   RD   RI   RW   (    (    (    sI   /var/www/html/venv/build/setuptools/setuptools/tests/test_packageindex.pyR      s   							%	
		t   TestContentCheckersc           B   s5   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s[   t  j j j d ƒ } | j d j d ƒ ƒ |  j | j j ƒ  d ƒ |  j	 | j
 ƒ  ƒ d  S(   Ns3   http://foo/bar#md5=f12895fdffbd45007040d2e44df98478s$   You should probably not be using MD5t   asciit    f12895fdffbd45007040d2e44df98478(   R   R   t   HashCheckert   from_urlt   feedt   encodeRA   t   hasht	   hexdigestR   t   is_valid(   R   t   checker(    (    sI   /var/www/html/venv/build/setuptools/setuptools/tests/test_packageindex.pyt   test_md5¬   s    	c         C   sB   t  j j j d ƒ } | j d j d ƒ ƒ |  j | j ƒ  ƒ d S(   s<   Content checks should succeed silently if no hash is presents1   http://foo/bar#something%20completely%20differentt   anythingR[   N(   R   R   R]   R^   R_   R`   R   Rc   (   R   Rd   (    (    sI   /var/www/html/venv/build/setuptools/setuptools/tests/test_packageindex.pyt   test_other_fragment´   s    	c         C   sB   t  j j j d ƒ } | j d j d ƒ ƒ |  j | j ƒ  ƒ d S(   s0   Content checks should succeed if a hash is emptys   http://foo/bar#md5=Rf   R[   N(   R   R   R]   R^   R_   R`   R   Rc   (   R   Rd   (    (    sI   /var/www/html/venv/build/setuptools/setuptools/tests/test_packageindex.pyt   test_blank_md5»   s    	c         C   s,   t  j j j d ƒ } |  j | j d ƒ d  S(   Ns3   http://foo/bar#md5=f12895fdffbd45007040d2e44df98478t   md5(   R   R   R]   R^   RA   t	   hash_name(   R   Rd   (    (    sI   /var/www/html/venv/build/setuptools/setuptools/tests/test_packageindex.pyt   test_get_hash_name_md5Â   s    	c         C   s>   t  j j j d ƒ } | j d „  d ƒ } |  j | d ƒ d  S(   Ns3   http://foo/bar#md5=f12895fdffbd45007040d2e44df98478c         S   s   |  S(   N(    (   t   x(    (    sI   /var/www/html/venv/build/setuptools/setuptools/tests/test_packageindex.pyt   <lambda>Ê   s    s   My message about %ss   My message about md5(   R   R   R]   R^   t   reportRA   (   R   Rd   t   rep(    (    sI   /var/www/html/venv/build/setuptools/setuptools/tests/test_packageindex.pyt   test_reportÇ   s    	(   RX   RY   Re   Rg   Rh   Rk   Rp   (    (    (    sI   /var/www/html/venv/build/setuptools/setuptools/tests/test_packageindex.pyRZ   ª   s
   				(   t   __doc__R   RP   t   unittestR4   t   setuptools.compatR    R   R   R   R   t   distutils.errorsR   t   setuptools.package_indexR   t   setuptools.tests.serverR   t   TestCaseR   RZ   (    (    (    sI   /var/www/html/venv/build/setuptools/setuptools/tests/test_packageindex.pyt   <module>   s   (ž