B
    ÔùÓ`¦  ã               @   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‚d S )NÚbang)ÚBANGÚBOOM)Úthing© r   ú@/tmp/pip-unpacked-wheel-qkyy6ibz/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   Z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 Q R X d S )Nzo noes)r   )Ú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   Z
addCleanupÚpopZ
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 )Nr   r   )r   )r   Úchecksr   r   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 Q R X |  |j	j
t¡ |  |j	jt¡ |  ttƒ¡� |jddd� W d Q R X 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   sl   t ƒ }|jdtd�tƒ tddi|d�}|  t¡�}| d¡ W d Q R X |  |j	j
t¡ |  |j	jt¡ d S )Nr   )r   r!   )Zformat_checkerr	   )r   r   Ú
ValueErrorr   r   r   r   Úvalidater$   r%   r&   r	   r'   )r   r   Z	validatorr(   r   r   r   Ú7test_format_error_causes_become_validation_error_causes=   s    zITestFormatChecker.test_format_error_causes_become_validation_error_causesc          	   C   s.   t ƒ }|  t¡� |jddd� W d Q R X d S )Nznot-an-ipv4Zipv4)r    r!   )r   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   Zfooc             S   s   dS )NTr   )r
   r   r   r   Ú<lambda>S   s    z-TestFormatChecker.test_repr.<locals>.<lambda>Úbarc             S   s   dS )NTr   )r
   r   r   r   r.   T   s    Zbazc             S   s   dS )NTr   )r
   r   r   r   r.   U   s    z.<FormatChecker checkers=['bar', 'baz', 'foo']>)r   r   r   Úrepr)r   r   r   r   r   Ú	test_reprQ   s    
zTestFormatChecker.test_reprN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r)   r,   r-   r1   r   r   r   r   r      s   		r   N)Ú__doc__Zunittestr   Z
jsonschemar   r   r   Zjsonschema.validatorsr   r*   r	   ÚZeroDivisionErrorr   r   r   r   r   r   r   Ú<module>   s   