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*   ,