U
    ˆjç  ã                   @   s  d Z zddlZ[W n ek
r&   Y nÜX ddlmZ ddlmZmZ zddlm	Z	 W n  ek
rt   ddl
m	Z	 Y nX 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   s4   zt |ƒ W n" tk
r.   td |¡ƒ‚Y nX dS )zD
            idna_text() generates IDNA-encodable text.
            zInvalid IDNA text: {!r}N)Úidna_encoder
   ÚAssertionErrorÚformat)ÚselfÚtext© r!   úB/tmp/pip-unpacked-wheel-cuxcz9x0/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   s   |   |d¡ |  |d¡ dS )z[
            port_numbers() generates integers between 1 and 65535, inclusive.
            r   éÿÿ  N©ZassertGreaterEqualZassertLessEqual©r   Úportr!   r!   r"   Útest_port_numbers_boundsA   s    z1TestHypothesisStrategies.test_port_numbers_boundsT)Z
allow_zeroc                 C   s   |   |d¡ |  |d¡ dS )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   s<   zt |ƒ t|ƒ W n" tk
r6   td |¡ƒ‚Y nX dS )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é
   )Zmax_examplesc              	   C   sj   t dd„ ƒ}td|ƒ�J | tƒ ¡}zt|ƒ t|ƒ W n" tk
rZ   td |¡ƒ‚Y nX W 5 Q R X 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_textr/   N)	r   r   r'   r   r   r   r0   r   r   )r   r	   r6   r2   r!   r!   r"   Ú&test_hostname_labels_long_idn_punycode`   s    	
	ÿz?TestHypothesisStrategies.test_hostname_labels_long_idn_punycodeF)Ú	allow_idnc                 C   s>   zt |ƒ | d¡ W n" tk
r8   td |¡ƒ‚Y nX dS )zO
            hostname_labels() generates a ASCII host name labels.
            ÚasciizInvalid ASCII label: {!r}N)r   r   r0   r   r   r1   r!   r!   r"   Ú test_hostname_labels_valid_ascii}   s
    z9TestHypothesisStrategies.test_hostname_labels_valid_asciic                 C   sL   z$|  d¡D ]}t|ƒ qt|ƒ W n" tk
rF   td |¡ƒ‚Y nX dS )zA
            hostnames() generates a IDN host names.
            Ú.zInvalid IDN host name: {!r}N)Úsplitr   r   r0   r   r   ©r   Úhostnamer2   r!   r!   r"   Útest_hostnames_idn‰   s    
ÿz+TestHypothesisStrategies.test_hostnames_idn)Úallow_leading_digitc                 C   s   |   || t¡k¡ dS )z}
            hostnames(allow_leading_digit=False) generates a IDN host names
            without leading digits.
            N©Ú
assertTrueÚlstripr   ©r   r>   r!   r!   r"   Útest_hostnames_idn_nolead˜   s    z2TestHypothesisStrategies.test_hostnames_idn_noleadc                 C   sN   z&|  d¡D ]}t|ƒ q| d¡ W n" tk
rH   td |¡ƒ‚Y nX dS )zC
            hostnames() generates a ASCII host names.
            r;   r9   zInvalid ASCII host name: {!r}N)r<   r   r   r0   r   r   r=   r!   r!   r"   Útest_hostnames_ascii¡   s    
ÿz-TestHypothesisStrategies.test_hostnames_ascii)r@   r8   c                 C   s   |   || t¡k¡ dS )zŽ
            hostnames(allow_leading_digit=False, allow_idn=False) generates
            ASCII host names without leading digits.
            NrA   rD   r!   r!   r"   Útest_hostnames_ascii_nolead°   s    z4TestHypothesisStrategies.test_hostnames_ascii_noleadc                 C   sV   d  |¡}z| d¡ W n" tk
r:   td |¡ƒ‚Y nX |D ]}|  d|¡ q@dS )zM
            paths() generates sequences of URL path components.
            ú/zutf-8zInvalid URL path: {!r}z#/?N)Újoinr   r0   r   r   ZassertNotIn)r   Úpathr    Úsegmentr!   r!   r"   Ú
test_paths¹   s    
z#TestHypothesisStrategies.test_pathsc                 C   s   |   |t¡ dS )z?
            encoded_urls() generates EncodedURLs.
            N)ÚassertIsInstancer   ©r   Úurlr!   r!   r"   Útest_encoded_urlsÈ   s    z*TestHypothesisStrategies.test_encoded_urlsc                 C   s   |   |t¡ dS )z?
            decoded_urls() generates DecodedURLs.
            N)rM   r   rN   r!   r!   r"   Útest_decoded_urlsÐ   s    z*TestHypothesisStrategies.test_decoded_urlsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r#   r	   r(   r   r-   r.   r   r3   r   r7   r:   r   r?   rE   rF   rG   r   rL   r   rP   r   rQ   r!   r!   r!   r"   r   (   s<   




	







r   )$rU   Z
hypothesisÚImportErrorÚstringr   Útypingr   r   Zunittest.mockr   Zmockr   r   Z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$   ,