U
    [e                     @   s  d Z zddlZ[W n ek
r&   Y nX 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!   `/var/www/html/services/stratfitenv/lib/python3.8/site-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   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$   ,