o
    >�Ò]¦  ã                   @   s\   d Z ddlmZ ddlmZmZmZ ddlmZ e	dƒZ
edƒZdd„ ZG d	d
„ d
eƒZdS )zP
Tests for the parts of jsonschema related to the :validator:`format` property.
é    )ÚTestCase)ÚFormatErrorÚValidationErrorÚFormatChecker)ÚDraft4ValidatorzBoom!zBang!c                 C   s   | dkrt ‚t‚)NÚbang)ÚBANGÚBOOM©Úthing© r   ú>/usr/lib/python3/dist-packages/jsonschema/tests/test_format.pyÚboom   s   r   c                   @   sL   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S )ÚTestFormatCheckerc                 C   s   t dd�}|  |j¡ d S )Nr   ©Úformats)r   ÚassertFalseÚcheckers©ÚselfÚcheckerr   r   r   Útest_it_can_validate_no_formats   s   
z1TestFormatChecker.test_it_can_validate_no_formatsc                 C   s<   |   t¡� tdgd� W d   ƒ d S 1 sw   Y  d S )Nzo noesr   )ÚassertRaisesÚKeyErrorr   )r   r   r   r   Ú.test_it_raises_a_key_error_for_unknown_formats   s   "ÿz@TestFormatChecker.test_it_raises_a_key_error_for_unknown_formatsc                 C   sF   t tjƒ}|  tjjd¡ t d¡tƒ |  tjt |tdfd�¡ d S ©Nr   r   )r   )Údictr   r   Ú
addCleanupÚpopÚ
cls_checksr   ÚassertEqual)r   Úoriginalr   r   r   Ú!test_it_can_register_cls_checkers   s   
þz3TestFormatChecker.test_it_can_register_cls_checkersc                 C   s4   t ƒ }| d¡tƒ |  |jtt jtdfd�¡ d S r   )r   Úchecksr   r    r   r   r   r   r   r   Útest_it_can_register_checkers'   s   þz/TestFormatChecker.test_it_can_register_checkersc                 C   s¶   t ƒ }|jdttƒd�tƒ |  t¡�}|jddd� W d   ƒ n1 s%w   Y  |  |j	j
t¡ |  |j	jt¡ |  ttƒ¡� |jddd� W d   ƒ d S 1 sTw   Y  d S )Nr   ©Úraisesé   ©ÚinstanceÚformatr   )r   r#   Útyper	   r   r   r   ÚcheckÚassertIsÚ	exceptionÚcauseÚ	__cause__r   )r   r   Úcmr   r   r   Ú!test_it_catches_registered_errors/   s   ÿ"ÿz3TestFormatChecker.test_it_catches_registered_errorsc                 C   s€   t ƒ }|jdtd�tƒ tddi|d�}|  t¡�}| d¡ W d   ƒ n1 s)w   Y  |  |j	j
t¡ |  |j	jt¡ d S )Nr   r%   r*   )Úformat_checkerr	   )r   r#   Ú
ValueErrorr   r   r   r   Úvalidater-   r.   r/   r	   r0   )r   r   Ú	validatorr1   r   r   r   Ú7test_format_error_causes_become_validation_error_causes=   s   ÿzITestFormatChecker.test_format_error_causes_become_validation_error_causesc                 C   sD   t ƒ }|  t¡� |jddd� W d   ƒ d S 1 sw   Y  d S )Nznot-an-ipv4Úipv4r(   )r   r   r   r,   r   r   r   r   Ú'test_format_checkers_come_with_defaultsH   s   "ÿz9TestFormatChecker.test_format_checkers_come_with_defaultsc                 C   sT   t dd�}| d¡dd„ ƒ | d¡dd„ ƒ | d¡d	d„ ƒ |  t|ƒd
¡ d S )Nr   r   Úfooc                 S   ó   dS ©NTr   r
   r   r   r   Ú<lambda>S   ó    z-TestFormatChecker.test_repr.<locals>.<lambda>Úbarc                 S   r;   r<   r   r
   r   r   r   r=   T   r>   Úbazc                 S   r;   r<   r   r
   r   r   r   r=   U   r>   z.<FormatChecker checkers=['bar', 'baz', 'foo']>)r   r#   r    Úreprr   r   r   r   Ú	test_reprQ   s   
þzTestFormatChecker.test_reprN)Ú__name__Ú
__module__Ú__qualname__r   r   r"   r$   r2   r7   r9   rB   r   r   r   r   r      s    		r   N)Ú__doc__Úunittestr   Ú
jsonschemar   r   r   Újsonschema.validatorsr   r4   r	   ÚZeroDivisionErrorr   r   r   r   r   r   r   Ú<module>   s    