o
    ^                     @   s\   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 dejZdd	 ZdS )
zUnit tests.
test_suite    )defaultdictN)InvalidURIErrorURIfind_uris_in_textmergeremove_dot_segmentsc                   @   sT   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd ZdS )URITestCasec                 C   s|   |  ttdd |  ttdd |  ttdd |  ttdd |  ttd	d |  ttd
d d S )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   self r   9/usr/lib/python3/dist-packages/lazr/uri/tests/test_uri.pytest_normalisation!   s$   zURITestCase.test_normalisationc              
   C   s   ddgddgddgg dg}t t}|D ]}|D ]}|tt| | qq| t|t| |D ]}| t|t|tt|d   q3d S )	Nr
   r   r   r   r   r   )r   r   r   r   r   )r   listhashr   appendr   lensorted)r   
uri_groups
uri_hashes	uri_groupurir   r   r   test_hashable4   s.   zURITestCase.test_hashablec                 C   s   |  ttd d S )Nu   http://€xample.com/)assertRaisesr   r   r   r   r   r   test_invalid_uriK   s   zURITestCase.test_invalid_uric                 C   s\   |  tddddd |  tddddd |  tddddd |  td	dddd d S )
N fooT)has_authorityz/fooFz/a/b/cz/a/b/fooz/a/b/)r   r   r   r   r   r   
test_mergeN   s   zURITestCase.test_mergec                 C   s$   |  tdd |  tdd d S )Nz/a/b/c/./../../gz/a/gzmid/content=5/../6zmid/6)r   r   r   r   r   r   test_remove_dot_segmentsX   s   z$URITestCase.test_remove_dot_segmentsc                    s  t d  fdd}| |dd | |dd | |dd | |dd	 | |d
d | |dd | |dd | |dd | |dd | |dd | |dd | |dd | |dd | |dd | |dd | |dd  | |d!d  | |d"d# | |d$d# | |d%d& | |d'd( | |d)d( | |d*d d S )+Nhttp://a/b/c/d;p?qc                       t  | S Nr   resolverelativebaser   r   r0   `      z3URITestCase.test_normal_resolution.<locals>.resolvez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   r0   r   r3   r   test_normal_resolution]   s2   z"URITestCase.test_normal_resolutionc                    s8  t d  fdd}| |dd | |dd | |dd | |dd | |d	d
 | |dd | |dd | |dd | |dd | |dd | |dd | |dd | |dd | |dd | |dd | |dd  | |d!d" | |d#d$ d S )%Nr,   c                    r-   r.   r/   r1   r3   r   r   r0   ~   r5   z5URITestCase.test_abnormal_resolution.<locals>.resolvez
../../../gr8   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/.r7   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/../xr;   r<   r   r3   r   test_abnormal_resolution{   s(   z$URITestCase.test_abnormal_resolutionc                 C   <   t d}| |d | |d | |d d S )Nhttp://code.launchpad.dev/foozcode.launchpad.devzlaunchpad.devr'   )r   
assertTrueunderDomainr   r#   r   r   r   "test_underDomain_matches_subdomain      z.URITestCase.test_underDomain_matches_subdomainc                 C   r?   )Nr@   zbeta.code.launchpad.devz
google.comzunchpad.dev)r   assertFalserB   rC   r   r   r   +test_underDomain_doesnt_match_non_subdomain   rE   z7URITestCase.test_underDomain_doesnt_match_non_subdomainN)__name__
__module____qualname__r   r$   r&   r*   r+   r=   r>   rD   rG   r   r   r   r   r	      s    
r	   c                   C   s   t  tS r.   )unittest
TestLoaderloadTestsFromNamerH   r   r   r   r   additional_tests   r5   rN   )__doc__type__metaclass____all__collectionsr   rK   lazr.urir   r   r   r   r   TestCaser	   rN   r   r   r   r   <module>   s    
