o
    i                     @   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 )zH
Tests for the parts of jsonschema related to the :kw:`format` keyword.
    )TestCase)FormatCheckerFormatErrorValidationError)Draft4ValidatorzBoom!zBang!c                 C   s   | dkrt t)Nbang)BANGBOOMthing r   W/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/jsonschema/tests/test_format.pyboom   s   r   c                   @   s\   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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   sp   t tj}| tjjd | t tdt W d    n1 s$w   Y  | 	tjt |tdfd d S Nr   r   )r   )
dictr   r   
addCleanuppopassertWarnsDeprecationWarning
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/   r0   r1   r	   r2   )r   r   	validatorr3   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_reprc                 C   sf   zddl m} W n
 ty   Y d S w t }| |dd | |dd | |dd d S )Nr   )is_duration   durationP4Ytest)jsonschema._formatrE   ImportErrorr   
assertTrueconformsr   )r   rE   r   r   r   r   test_duration_format[   s   z&TestFormatChecker.test_duration_formatc                 C   s@   t  }| |dd | |dd | |dd d S )NrF   uuidz$6e6659ec-4503-4428-9f03-2e2ea4d6c278rI   )r   rL   rM   r   r   r   r   r   test_uuid_formatf   s   
z"TestFormatChecker.test_uuid_formatN)__name__
__module____qualname__r   r   r$   r&   r4   r9   r;   rD   rN   rP   r   r   r   r   r      s    
	
r   N)__doc__unittestr   
jsonschemar   r   r   jsonschema.validatorsr   r6   r	   ZeroDivisionErrorr   r   r   r   r   r   r   <module>   s    