a
    �Ï?e2  ã                   @   sd   d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 e
dƒZedƒZdd	„ ZG d
d„ deƒZdS )zH
Tests for the parts of jsonschema related to the :kw:`format` keyword.
é    )ÚTestCase)ÚFormatCheckerÚValidationError)ÚFormatError)ÚDraft4ValidatorzBoom!zBang!c                 C   s   | dkrt ‚t‚d S )NÚbang)ÚBANGÚBOOM©Úthing© r   ú_/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-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   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   ƒ n1 s,0    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   sp   t tjƒ}|  tjjd¡ |  t¡� t d¡tƒ W d   ƒ n1 sH0    Y  |  	tjt |tdfd�¡ d S ©Nr   r   )r   )
Údictr   r   Z
addCleanupÚpopZassertWarnsÚDeprecationWarningZ
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 sJ0    Y  |  |j	j
t¡ |  |j	jt¡ |  ttƒ¡� |jddd� W d   ƒ n1 s¦0    Y  d S )Nr   ©Zraisesé   ©ÚinstanceÚformatr   )r   r!   Útyper	   r   r   r   ÚcheckÚassertIsÚ	exceptionÚcauseÚ	__cause__r   )r   r   Úcmr   r   r   Ú!test_it_catches_registered_errors0   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 sR0    Y  |  |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   sB   t ƒ }|  t¡� |jddd� W d   ƒ n1 s40    Y  d S )Nznot-an-ipv4Zipv4r%   )r   r   r   r)   r   r   r   r   Ú'test_format_checkers_come_with_defaultsI   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>T   ó    z-TestFormatChecker.test_repr.<locals>.<lambda>Úbarc                 S   s   dS r4   r   r
   r   r   r   r5   U   r6   Zbazc                 S   s   dS r4   r   r
   r   r   r   r5   V   r6   z.<FormatChecker checkers=['bar', 'baz', 'foo']>)r   r!   r   Úreprr   r   r   r   Ú	test_reprR   s    
þzTestFormatChecker.test_reprN)Ú__name__Ú
__module__Ú__qualname__r   r   r    r"   r/   r2   r3   r9   r   r   r   r   r      s   
	r   N)Ú__doc__Zunittestr   Z
jsonschemar   r   Zjsonschema.exceptionsr   Zjsonschema.validatorsr   r0   r	   ÚZeroDivisionErrorr   r   r   r   r   r   r   Ú<module>   s   