
    ^                     r    d Z eZdgZddlmZ ddlZddlmZm	Z	m
Z
mZmZ  G d dej                        Zd Zy)	zUnit tests.
test_suite    )defaultdictN)InvalidURIErrorURIfind_uris_in_textmergeremove_dot_segmentsc                   B    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)URITestCasec                    | j                  t        t        d            d       | j                  t        t        d            d       | j                  t        t        d            d       | j                  t        t        d            d       | j                  t        t        d	            d       | j                  t        t        d
            d       y )N"eXAMPLE://a/./b/../b/%63/%7bfoo%7dexample://a/b/c/%7Bfoo%7Dhttp://www.EXAMPLE.com/http://www.example.com/http://www.gnome.org/%7ejamesh/http://www.gnome.org/~jamesh/http://example.comhttp://example.com/http://example.com:/http://example.com:80/)assertEqualstrr   selfs    9/usr/lib/python3/dist-packages/lazr/uri/tests/test_uri.pytest_normalisationzURITestCase.test_normalisation!   s    S!EFG4	6 	S!:;<2	4S!BCD8	:
 	S!5672	4S!7892	4S!9:;2	4    c                 t   ddgddgddgg dg}t        t              }|D ]/  }|D ](  }|t        t        |               j	                  |       * 1 | j                  t        |      t        |             |D ]>  }| j                  t        |      t        |t        t        |d                               @ y )	Nr   r   r   r   r   r   )r   r   r   r   r   )r   listhashr   appendr   lensorted)r   
uri_groups
uri_hashes	uri_groupuris        r   test_hashablezURITestCase.test_hashable4   s    1(*&&(.,.'
 !&
# 	7I  74C>*11#67	7 	Z#j/:# 	=Iy!z$s9Q<'8"9:;=	=r   c                 :    | j                  t        t        d       y )Nu   http://€xample.com/)assertRaisesr   r   r   s    r   test_invalid_urizURITestCase.test_invalid_uriK   s    /30GHr   c                     | j                  t        ddd      d       | j                  t        ddd      d       | j                  t        ddd      d       | j                  t        d	dd      d       y )
N fooT)has_authorityz/fooFz/a/b/cz/a/b/fooz/a/b/)r   r   r   s    r   
test_mergezURITestCase.test_mergeN   sn     	r5=vFr5>FxdC#	%wTB#	%r   c                 p    | j                  t        d      d       | j                  t        d      d       y )Nz/a/b/c/./../../gz/a/gzmid/content=5/../6zmid/6)r   r	   r   s    r   test_remove_dot_segmentsz$URITestCase.test_remove_dot_segmentsX   s0    ,-?@&I,-ABGLr   c                 v   t        d      fd}| j                   |d      d       | j                   |d      d       | j                   |d      d       | j                   |d      d       | j                   |d	      d
       | j                   |d      d       | j                   |d      d       | j                   |d      d       | j                   |d      d       | j                   |d      d       | j                   |d      d       | j                   |d      d       | j                   |d      d       | j                   |d      d       | j                   |d      d       | j                   |d      d       | j                   |d       d       | j                   |d!      d"       | j                   |d#      d"       | j                   |d$      d%       | j                   |d&      d'       | j                   |d(      d'       | j                   |d)      d
       y )*Nhttp://a/b/c/d;p?qc                 8    t        j                  |             S Nr   resolverelativebases    r   r8   z3URITestCase.test_normal_resolution.<locals>.resolve`       t||H-..r   zg:hgzhttp://a/b/c/gz./gzg/http://a/b/c/g/z/g
http://a/gz//gz	http://g/z?yzhttp://a/b/c/d;p?yzg?yzhttp://a/b/c/g?yz#szhttp://a/b/c/d;p?q#szg#szhttp://a/b/c/g#szg?y#szhttp://a/b/c/g?y#sz;xzhttp://a/b/c/;xzg;xzhttp://a/b/c/g;xzg;x?y#szhttp://a/b/c/g;x?y#sr-   .zhttp://a/b/c/z./z..zhttp://a/b/z../z../ghttp://a/b/gz../..z	http://a/z../../z../../gr   r   r   r8   r;   s     @r   test_normal_resolutionz"URITestCase.test_normal_resolution]   s   '(	/U3-=>-=>->?\:[9-AB-?@-CD-?@)-AB->?-?@+-CD-AB_=_=];];^<)[9*[9+\:r   c                    t        d      fd}| j                   |d      d       | j                   |d      d       | j                   |d      d       | j                   |d      d       | j                   |d      d	       | j                   |d
      d       | j                   |d      d       | j                   |d      d       | j                   |d      d       | j                   |d      d       | j                   |d      d       | j                   |d      d       | j                   |d      d       | j                   |d      d       | j                   |d      d       | j                   |d      d       | j                   |d       d!       | j                   |d"      d#       y )$Nr4   c                 8    t        j                  |             S r6   r7   r9   s    r   r8   z5URITestCase.test_abnormal_resolution.<locals>.resolve~   r<   r   z
../../../gr?   z../../../../gz/./gz/../gzg.zhttp://a/b/c/g.z.gzhttp://a/b/c/.gzg..zhttp://a/b/c/g..z..gzhttp://a/b/c/..gz./../grA   z./g/.r>   zg/./hzhttp://a/b/c/g/hzg/../hzhttp://a/b/c/hz	g;x=1/./yzhttp://a/b/c/g;x=1/yz
g;x=1/../yzhttp://a/b/c/yzg?y/./xzhttp://a/b/c/g?y/./xzg?y/../xzhttp://a/b/c/g?y/../xzg#s/./xzhttp://a/b/c/g#s/./xzg#s/../xzhttp://a/b/c/g#s/../xrB   rC   s     @r   test_abnormal_resolutionz$URITestCase.test_abnormal_resolution{   s   '(	/.,?1,?,?),?2CD2CD2DE2DE*.A)2CD)2DE*2BC-2HI.2BC+2HI,2IJ+2HI,2IJr   c                     t        d      }| j                  |j                  d             | j                  |j                  d             | j                  |j                  d             y )Nhttp://code.launchpad.dev/foozcode.launchpad.devzlaunchpad.devr-   )r   
assertTrueunderDomainr   r'   s     r   "test_underDomain_matches_subdomainz.URITestCase.test_underDomain_matches_subdomain   sO     12(<=>89+,r   c                     t        d      }| j                  |j                  d             | j                  |j                  d             | j                  |j                  d             y )NrI   zbeta.code.launchpad.devz
google.comzunchpad.dev)r   assertFalserK   rL   s     r   +test_underDomain_doesnt_match_non_subdomainz7URITestCase.test_underDomain_doesnt_match_non_subdomain   sU     12)BCD6778r   N)__name__
__module____qualname__r   r(   r+   r0   r2   rD   rG   rM   rP    r   r   r   r      s2    4&=.I%M
;<K8-9r   r   c                  P    t        j                         j                  t              S r6   )unittest
TestLoaderloadTestsFromNamerQ   rT   r   r   additional_testsrY      s     228<<r   )__doc__type__metaclass____all__collectionsr   rV   lazr.urir   r   r   r   r	   TestCaser   rY   rT   r   r   <module>ra      sG   "  $ I IF9(## F9R=r   