
    Og                     j    d Z dgZddlZddlmZ ddlmZmZmZm	Z	  G d dej                        Zd Zy)	zUnit tests.
test_suite    N)defaultdict)URIInvalidURIError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    R/var/www/djangounited/venv/lib/python3.12/site-packages/lazr/uri/tests/test_uri.pytest_normalisationzURITestCase.test_normalisation   s    89:'	

 	-./1J	
 	567+	
 	S!5679NO*+,.C	
 	,-.0E	
    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_hashable6   s     5+ '(AB1/

" !&
# 	7I  74C>*11#67	7 	Z#j/:# 	Iy!6*T#il:K5L*M#N	r   c                 :    | j                  t        t        d       y )Nu   http://€xample.com/)assertRaisesr   r   r   s    r   test_invalid_urizURITestCase.test_invalid_uriR   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_mergeU   sm     	r5=vFr5>F(E6
	
 	wTBJOr   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_segments_   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   r7   z3URITestCase.test_normal_resolution.<locals>.resolveh       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   r7   r:   s     @r   test_normal_resolutionz"URITestCase.test_normal_resolutiond   s   '(	/ 	/'78)9:(9:55(<=);<(>?);<)+?@(9:);<+-CD&:;7867.9);7*K8+\: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 )$Nr3   c                 8    t        j                  |             S r5   r6   r8   s    r   r7   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./../gr@   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/../xrA   rB   s     @r   test_abnormal_resolutionz$URITestCase.test_abnormal_resolution   s   '(	/ 	.=1<@,7)<8(9:(9:);<);<*N;)+<=)+=>*,<=-/EF.0@A+-CD,.EF+-CD,.EFr   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 )NrH   zbeta.code.launchpad.devz
google.comzunchpad.dev)r   assertFalserJ   rK   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*   r/   r1   rC   rF   rL   rO    r   r   r
   r
      s4    
28IPM
;@G<-9r   r
   c                  P    t        j                         j                  t              S r5   )unittest
TestLoaderloadTestsFromNamerP   rS   r   r   additional_testsrX      s     228<<r   )__doc____all__rU   collectionsr   lazr.urir   r   r   r   TestCaser
   rX   rS   r   r   <module>r^      s>        # E ET9(## T9n=r   