<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
B
    pSe                 @   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   M/opt/alt/python37/lib/python3.7/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 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   	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       z-TestFormatChecker.test_repr.<locals>.<lambda>Zbarc             S   s   dS )NTr   )r
   r   r   r   r/   T   r0   Zbazc             S   s   dS )NTr   )r
   r   r   r   r/   U   r0   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.   r2   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   