o
    Åü(_ç  ã                   @   s  d Z zddlZ[W n
 ey   Y dS w ddlmZ ddlmZmZ zddlm	Z	 W n ey9   ddl
m	Z	 Y nw ddlmZmZ ddlmZmZ ddlmZmZmZ d	d
lmZ ddlmZmZ ddlmZmZmZmZmZmZm Z m!Z!m"Z" G dd„ deƒZ#dS )z!
Tests for hyperlink.hypothesis.
é    N)Údigits)ÚSequenceÚText)Úpatch)ÚgivenÚsettings)ÚSearchStrategyÚdata)Ú	IDNAErrorÚcheck_labelÚencodeé   )ÚHyperlinkTestCaseé   )Ú
DecodedURLÚ
EncodedURL)	ÚDrawCallableÚ	compositeÚdecoded_urlsÚencoded_urlsÚhostname_labelsÚ	hostnamesÚ	idna_textÚpathsÚport_numbersc                   @   s,  e Zd ZdZeeƒ ƒdd„ ƒZeeƒ ƒdd„ ƒZee	ƒ ƒdd„ ƒZ
ee	dd	�ƒd
d„ ƒZeeƒ ƒdd„ ƒZeeƒ ƒedd�dd„ ƒƒZeedd�ƒdd„ ƒZeeƒ ƒdd„ ƒZeedd�ƒdd„ ƒZeedd�ƒdd„ ƒZeeddd�ƒdd„ ƒZeeƒ ƒd d!„ ƒZeeƒ ƒd"d#„ ƒZeeƒ ƒd$d%„ ƒZd&S )'ÚTestHypothesisStrategiesz1
        Tests for hyperlink.hypothesis.
        c                 C   s,   zt |ƒ W dS  ty   td |¡ƒ‚w )zD
            idna_text() generates IDNA-encodable text.
            zInvalid IDNA text: {!r}N)Úidna_encoder
   ÚAssertionErrorÚformat)ÚselfÚtext© r!   ú@/usr/lib/python3/dist-packages/hyperlink/test/test_hypothesis.pyÚtest_idna_text_valid-   s
   ÿz-TestHypothesisStrategies.test_idna_text_validc                 C   s0   |   t|jtdd�¡ |   t|jtdd�¡ dS )zO
            idna_text() raises AssertionError if min_size is < 1.
            r   )Úmin_size)Úmax_sizeN)ÚassertRaisesr   Údrawr   )r   r	   r!   r!   r"   Útest_idna_text_min_max8   s   z/TestHypothesisStrategies.test_idna_text_min_maxc                 C   ó   |   |d¡ |  |d¡ dS )z[
            port_numbers() generates integers between 1 and 65535, inclusive.
            r   éÿÿ  N©ÚassertGreaterEqualÚassertLessEqual©r   Úportr!   r!   r"   Útest_port_numbers_boundsA   s   z1TestHypothesisStrategies.test_port_numbers_boundsT)Ú
allow_zeroc                 C   r)   )zv
            port_numbers(allow_zero=True) generates integers between 0 and
            65535, inclusive.
            r   r*   Nr+   r.   r!   r!   r"   Ú#test_port_numbers_bounds_allow_zeroJ   s   z<TestHypothesisStrategies.test_port_numbers_bounds_allow_zeroc                 C   s4   zt |ƒ t|ƒ W dS  ty   td |¡ƒ‚w )zK
            hostname_labels() generates IDN host name labels.
            úInvalid IDN label: {!r}N)r   r   ÚUnicodeErrorr   r   ©r   Úlabelr!   r!   r"   Útest_hostname_labels_valid_idnT   s   ÿz7TestHypothesisStrategies.test_hostname_labels_valid_idné
   )Úmax_examplesc              	   C   sz   t dd„ ƒ}td|ƒ�( | tƒ ¡}z
t|ƒ t|ƒ W n ty*   td |¡ƒ‚w W d  ƒ dS 1 s6w   Y  dS )zž
            hostname_labels() handles case where idna_text() generates text
            that encoded to punycode ends up as longer than allowed.
            c                 S   s   d| S )Nõ   Ã¡r!   )r'   r$   r%   r!   r!   r"   Úmock_idna_texti   s   zWTestHypothesisStrategies.test_hostname_labels_long_idn_punycode.<locals>.mock_idna_textzhyperlink.hypothesis.idna_textr3   N)	r   r   r'   r   r   r   r4   r   r   )r   r	   r;   r6   r!   r!   r"   Ú&test_hostname_labels_long_idn_punycode`   s   	
	ÿÿÿ"üz?TestHypothesisStrategies.test_hostname_labels_long_idn_punycodeF)Ú	allow_idnc                 C   s6   zt |ƒ | d¡ W dS  ty   td |¡ƒ‚w )zO
            hostname_labels() generates a ASCII host name labels.
            ÚasciizInvalid ASCII label: {!r}N)r   r   r4   r   r   r5   r!   r!   r"   Ú test_hostname_labels_valid_ascii}   s   ÿz9TestHypothesisStrategies.test_hostname_labels_valid_asciic                 C   sD   z|  d¡D ]}t|ƒ qt|ƒ W dS  ty!   td |¡ƒ‚w )zA
            hostnames() generates a IDN host names.
            Ú.zInvalid IDN host name: {!r}N)Úsplitr   r   r4   r   r   ©r   Úhostnamer6   r!   r!   r"   Útest_hostnames_idn‰   s   
ÿÿz+TestHypothesisStrategies.test_hostnames_idn)Úallow_leading_digitc                 C   ó   |   || t¡k¡ dS )z}
            hostnames(allow_leading_digit=False) generates a IDN host names
            without leading digits.
            N©Ú
assertTrueÚlstripr   ©r   rC   r!   r!   r"   Útest_hostnames_idn_nolead˜   ó   z2TestHypothesisStrategies.test_hostnames_idn_noleadc                 C   sF   z|  d¡D ]}t|ƒ q| d¡ W dS  ty"   td |¡ƒ‚w )zC
            hostnames() generates a ASCII host names.
            r@   r>   zInvalid ASCII host name: {!r}N)rA   r   r   r4   r   r   rB   r!   r!   r"   Útest_hostnames_ascii¡   s   
ÿÿz-TestHypothesisStrategies.test_hostnames_ascii)rE   r=   c                 C   rF   )zŽ
            hostnames(allow_leading_digit=False, allow_idn=False) generates
            ASCII host names without leading digits.
            NrG   rJ   r!   r!   r"   Útest_hostnames_ascii_nolead°   rL   z4TestHypothesisStrategies.test_hostnames_ascii_noleadc                 C   sP   d  |¡}z| d¡ W n ty   td |¡ƒ‚w |D ]}|  d|¡ qdS )zM
            paths() generates sequences of URL path components.
            ú/zutf-8zInvalid URL path: {!r}z#/?N)Újoinr   r4   r   r   ÚassertNotIn)r   Úpathr    Úsegmentr!   r!   r"   Ú
test_paths¹   s   
ÿÿz#TestHypothesisStrategies.test_pathsc                 C   ó   |   |t¡ dS )z?
            encoded_urls() generates EncodedURLs.
            N)ÚassertIsInstancer   ©r   Úurlr!   r!   r"   Útest_encoded_urlsÈ   ó   z*TestHypothesisStrategies.test_encoded_urlsc                 C   rU   )z?
            decoded_urls() generates DecodedURLs.
            N)rV   r   rW   r!   r!   r"   Útest_decoded_urlsÐ   rZ   z*TestHypothesisStrategies.test_decoded_urlsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r#   r	   r(   r   r0   r2   r   r7   r   r<   r?   r   rD   rK   rM   rN   r   rT   r   rY   r   r[   r!   r!   r!   r"   r   (   s>    




	







r   )$r_   Ú
hypothesisÚImportErrorÚstringr   Útypingr   r   Úunittest.mockr   Úmockr   r   Úhypothesis.strategiesr   r	   Úidnar
   r   r   r   Úcommonr   Ú r   r   r   r   r   r   r   r   r   r   r   r   r!   r!   r!   r"   Ú<module>   s*   ÿÿ,