ó
ç'ÊUc           @   sz   d  d l  Z  d  d l m Z d  d l m Z m Z m Z m Z m Z d e  j	 f d „  ƒ  YZ
 e d k rv e  j ƒ  n  d S(   iÿÿÿÿN(   t   responsetypes(   t   Responset   TextResponset   XmlResponset   HtmlResponset   Headerst   ResponseTypesTestc           B   sG   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s‹   d t  f d t f d t  f d t f d t f d t  f g } xH | D]@ \ } } t j | ƒ } | | k sC t d | | | f ƒ ‚ qC Wd  S(   Ns   data.bins   file.txts   file.xml.gzs   file.xmls	   file.htmls   file.unknownexts   %s ==> %s != %s(   R   R   R   R   R    t   from_filenamet   AssertionError(   t   selft   mappingst   sourcet   clst   retcls(    (    s<   /home/travis/build/scrapy/scrapy/tests/test_responsetypes.pyt   test_from_filename   s    					c         C   sg   d t  f d t  f g } xH | D]@ \ } } t j | ƒ } | | k s t d | | | f ƒ ‚ q Wd  S(   Ns   attachment; filename="data.xml"s   attachment; filename=data.xmls   %s ==> %s != %s(   R   R    t   from_content_dispositionR   (   R	   R
   R   R   R   (    (    s<   /home/travis/build/scrapy/scrapy/tests/test_responsetypes.pyt   test_from_content_disposition   s
    	c         C   s‹   d t  f d t f d t  f d t  f d t f d t f g } xH | D]@ \ } } t j | ƒ } | | k sC t d | | | f ƒ ‚ qC Wd  S(   Ns   text/html; charset=UTF-8s   text/xml; charset=UTF-8s$   application/xhtml+xml; charset=UTF-8s,   application/vnd.wap.xhtml+xml; charset=utf-8s   application/xml; charset=UTF-8s   application/octet-streams   %s ==> %s != %s(   R   R   R   R    t   from_content_typeR   (   R	   R
   R   R   R   (    (    s<   /home/travis/build/scrapy/scrapy/tests/test_responsetypes.pyt   test_from_content_type   s    					c         C   sy   d t  f d t f d t f d t f g } xH | D]@ \ } } t j | ƒ } | | k s1 t d | | | f ƒ ‚ q1 Wd  S(   Ns   ßÝ#s/   Some plain text
data with tabs	 and null bytes s'   <html><head><title>Hello</title></head>s$   <?xml version="1.0" encoding="utf-8"s   %s ==> %s != %s(   R   R   R   R   R    t	   from_bodyR   (   R	   R
   R   R   R   (    (    s<   /home/travis/build/scrapy/scrapy/tests/test_responsetypes.pyt   test_from_body+   s    			c         C   s®   i d g d 6t  f i d g d 6d g d 6t f i d g d 6d g d 6t f g } xT | D]L \ } } t | ƒ } t j | ƒ } | | k sZ t d | | | f ƒ ‚ qZ Wd  S(	   Ns   text/html; charset=utf-8s   Content-Types   application/octet-streams   attachment; filename=data.txts   Content-Dispositiont   gzips   Content-Encodings   %s ==> %s != %s(   R   R   R   R   R    t   from_headersR   (   R	   R
   R   R   R   (    (    s<   /home/travis/build/scrapy/scrapy/tests/test_responsetypes.pyt   test_from_headers6   s    #c         C   s³   i d d 6t  f i t i d g d 6ƒ d 6d d 6t f i t i d g d 6ƒ d 6d	 d 6t f g } xH | D]@ \ } } t j |   } | | k sk t d
 | | | f ƒ ‚ qk Wd  S(   Ns   http://www.example.com/data.csvt   urls   text/html; charset=utf-8s   Content-Typet   headerss   http://www.example.com/item/s"   attachment; filename="data.xml.gz"s   Content-Dispositions   http://www.example.com/page/s   %s ==> %s != %s(   R   R   R   R   R    t	   from_argsR   (   R	   R
   R   R   R   (    (    s<   /home/travis/build/scrapy/scrapy/tests/test_responsetypes.pyt   test_from_argsA   s    '-c         C   s$   |  j  t j j d ƒ d d ƒ d  S(   Ns   x.scrapytesti    s   x-scrapy/test(   t   assertEqualR    t	   mimetypest
   guess_type(   R	   (    (    s<   /home/travis/build/scrapy/scrapy/tests/test_responsetypes.pyt   test_custom_mime_types_loadedO   s    (	   t   __name__t
   __module__R   R   R   R   R   R   R   (    (    (    s<   /home/travis/build/scrapy/scrapy/tests/test_responsetypes.pyR      s   							t   __main__(   t   unittestt   scrapy.responsetypesR    t   scrapy.httpR   R   R   R   R   t   TestCaseR   R    t   main(    (    (    s<   /home/travis/build/scrapy/scrapy/tests/test_responsetypes.pyt   <module>   s
   (M